diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-02-15 14:22:56 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-02-15 14:22:56 -0600 |
commit | e8b7ce0e4c2fa9d1c3ee452ec949433b4d51e334 (patch) | |
tree | 0685824fcc6ca9bbae8245cc0408c8be3dec334d /nuttx/arch/arm/src | |
parent | b1271722ab3bdd887c8a43b3d4fea7ded2e23828 (diff) | |
download | px4-nuttx-e8b7ce0e4c2fa9d1c3ee452ec949433b4d51e334.tar.gz px4-nuttx-e8b7ce0e4c2fa9d1c3ee452ec949433b4d51e334.tar.bz2 px4-nuttx-e8b7ce0e4c2fa9d1c3ee452ec949433b4d51e334.zip |
SAMD20: Beginning of SERCOM UART configuration logic
Diffstat (limited to 'nuttx/arch/arm/src')
-rw-r--r-- | nuttx/arch/arm/src/samd/Kconfig | 48 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/Make.defs | 4 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/chip/sam_usart.h | 4 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/sam_config.h | 206 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/sam_lowputc.c | 105 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/sam_lowputc.h | 11 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/sam_usart.c | 225 | ||||
-rw-r--r-- | nuttx/arch/arm/src/samd/sam_usart.h | 146 |
8 files changed, 616 insertions, 133 deletions
diff --git a/nuttx/arch/arm/src/samd/Kconfig b/nuttx/arch/arm/src/samd/Kconfig index 97a02a860..0b8ed7a5b 100644 --- a/nuttx/arch/arm/src/samd/Kconfig +++ b/nuttx/arch/arm/src/samd/Kconfig @@ -253,7 +253,7 @@ endmenu choice prompt "SERCOM0 mode" - default SAMD_SERCOM0_ISUART + default SAMD_SERCOM0_ISUSART depends on SAMD_SERCOM0 config SAMD_SERCOM0_ISI2C @@ -264,15 +264,15 @@ config SAMD_SERCOM0_ISSPI bool "SPI" select SPI -config SAMD_SERCOM0_ISUART -bool "UART" -select ARCH_HAVE_UART0 +config SAMD_SERCOM0_ISUSART +bool "USART" +select ARCH_HAVE_USART0 endchoice choice prompt "SERCOM1 mode" - default SAMD_SERCOM1_ISUART + default SAMD_SERCOM1_ISUSART depends on SAMD_SERCOM1 config SAMD_SERCOM1_ISI2C @@ -283,15 +283,15 @@ config SAMD_SERCOM1_ISSPI bool "SPI" select SPI -config SAMD_SERCOM1_ISUART -bool "UART" -select ARCH_HAVE_UART1 +config SAMD_SERCOM1_ISUSART +bool "USART" +select ARCH_HAVE_USART1 endchoice choice prompt "SERCOM2 mode" - default SAMD_SERCOM2_ISUART + default SAMD_SERCOM2_ISUSART depends on SAMD_SERCOM2 config SAMD_SERCOM2_ISI2C @@ -302,15 +302,15 @@ config SAMD_SERCOM2_ISSPI bool "SPI" select SPI -config SAMD_SERCOM2_ISUART -bool "UART" -select ARCH_HAVE_UART2 +config SAMD_SERCOM2_ISUSART +bool "USART" +select ARCH_HAVE_USART2 endchoice choice prompt "SERCOM3 mode" - default SAMD_SERCOM3_ISUART + default SAMD_SERCOM3_ISUSART depends on SAMD_SERCOM3 config SAMD_SERCOM3_ISI2C @@ -321,15 +321,15 @@ config SAMD_SERCOM3_ISSPI bool "SPI" select SPI -config SAMD_SERCOM3_ISUART -bool "UART" -select ARCH_HAVE_UART3 +config SAMD_SERCOM3_ISUSART +bool "USART" +select ARCH_HAVE_USART3 endchoice choice prompt "SERCOM4 mode" - default SAMD_SERCOM4_ISUART + default SAMD_SERCOM4_ISUSART depends on SAMD_SERCOM4 config SAMD_SERCOM4_ISI2C @@ -340,15 +340,15 @@ config SAMD_SERCOM4_ISSPI bool "SPI" select SPI -config SAMD_SERCOM4_ISUART -bool "UART" -select ARCH_HAVE_UART4 +config SAMD_SERCOM4_ISUSART +bool "USART" +select ARCH_HAVE_USART4 endchoice choice prompt "SERCOM5 mode" - default SAMD_SERCOM5_ISUART + default SAMD_SERCOM5_ISUSART depends on SAMD_SERCOM5 config SAMD_SERCOM5_ISI2C @@ -359,8 +359,8 @@ config SAMD_SERCOM5_ISSPI bool "SPI" select SPI -config SAMD_SERCOM5_ISUART -bool "UART" -select ARCH_HAVE_UART5 +config SAMD_SERCOM5_ISUSART +bool "USART" +select ARCH_HAVE_USART5 endchoice diff --git a/nuttx/arch/arm/src/samd/Make.defs b/nuttx/arch/arm/src/samd/Make.defs index baac8f4a2..029433fb7 100644 --- a/nuttx/arch/arm/src/samd/Make.defs +++ b/nuttx/arch/arm/src/samd/Make.defs @@ -68,8 +68,8 @@ CMN_CSRCS += up_dumpnvic.c endif CHIP_ASRCS = -CHIP_CSRCS = sam_clockconfig.c sam_idle.c sam_irq.c sam_port.c sam_start.c -CHIP_CSRCS += sam_timerisr.c +CHIP_CSRCS = sam_clockconfig.c sam_idle.c sam_irq.c sam_lowputc.c +CHIP_CSRCS += sam_port.c sam_start.c sam_timerisr.c sam_usart.c ifeq ($(CONFIG_NUTTX_KERNEL),y) CHIP_CSRCS += sam_userspace.c diff --git a/nuttx/arch/arm/src/samd/chip/sam_usart.h b/nuttx/arch/arm/src/samd/chip/sam_usart.h index 1bc316991..322d5bf37 100644 --- a/nuttx/arch/arm/src/samd/chip/sam_usart.h +++ b/nuttx/arch/arm/src/samd/chip/sam_usart.h @@ -153,8 +153,8 @@ # define USART_CTRLA_ASYNCH (0) # define USART_CTRLA_SYNCH USART_CTRLA_CMODE #define USART_CTRLA_CPOL (1 << 29) /* Bit 29: Clock polarity */ -# define USART_CTRLA_RISING (0) /* Rising XCK edge Falling XCK edge */ -# define USART_CTRLA_FALLING USART_CTRLA_CPOL /* Falling XCK edge Rising XCK edge */ +# define USART_CTRLA_CPOL_NORMAL (0) /* Rising XCK edge Falling XCK edge */ +# define USART_CTRLA_CPOL_INVERTED USART_CTRLA_CPOL /* Falling XCK edge Rising XCK edge */ #define USART_CTRLA_DORD (1 << 30) /* Bit 30: Data order */ # define USART_CTRLA_MSBFIRST (0) # define USART_CTRLA_LSBFIRST USART_CTRLA_DORD diff --git a/nuttx/arch/arm/src/samd/sam_config.h b/nuttx/arch/arm/src/samd/sam_config.h index cc126fa11..7d7e335c7 100644 --- a/nuttx/arch/arm/src/samd/sam_config.h +++ b/nuttx/arch/arm/src/samd/sam_config.h @@ -46,131 +46,137 @@ /************************************************************************************ * Pre-processor Definitions ************************************************************************************/ -/* How many SERCOM peripherals are configured as UART peripherals? */ - -#define SAMD_HAVE_UART0 1 -#define SAMD_HAVE_UART1 1 -#define SAMD_HAVE_UART2 1 -#define SAMD_HAVE_UART3 1 -#define SAMD_HAVE_UART4 1 -#define SAMD_HAVE_UART5 1 - -#if !defined(CONFIG_SAMD_SERCOM0) || !defined(CONFIG_SAMD_SERCOM0_ISUART) -# undef SAMD_HAVE_UART0 -# undef CONFIG_SAMD_SERCOM0_ISUART -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART0_FLOW_CONTROL -# undef CONFIG_UART0_IRDAMODE -# undef CONFIG_UART0_RS485MODE +/* How many SERCOM peripherals are configured as USART peripherals? */ + +#define SAMD_HAVE_USART0 1 +#define SAMD_HAVE_USART1 1 +#define SAMD_HAVE_USART2 1 +#define SAMD_HAVE_USART3 1 +#define SAMD_HAVE_USART4 1 +#define SAMD_HAVE_USART5 1 + +#if !defined(CONFIG_SAMD_SERCOM0) || !defined(CONFIG_SAMD_SERCOM0_ISUSART) || \ + !defined(CONFIG_USART0_ISUART) +# undef SAMD_HAVE_USART0 +# undef CONFIG_SAMD_SERCOM0_ISUSART +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART0_FLOW_CONTROL +# undef CONFIG_USART0_IRDAMODE +# undef CONFIG_USART0_RS485MODE #endif -#if !defined(CONFIG_SAMD_SERCOM1) || !defined(CONFIG_SAMD_SERCOM1_ISUART) -# undef SAMD_HAVE_UART1 -# undef CONFIG_SAMD_SERCOM1_ISUART -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART1_FLOW_CONTROL -# undef CONFIG_UART1_IRDAMODE -# undef CONFIG_UART1_RS485MODE +#if !defined(CONFIG_SAMD_SERCOM1) || !defined(CONFIG_SAMD_SERCOM1_ISUSART) || \ + !defined(CONFIG_USART1_ISUART) +# undef SAMD_HAVE_USART1 +# undef CONFIG_SAMD_SERCOM1_ISUSART +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART1_FLOW_CONTROL +# undef CONFIG_USART1_IRDAMODE +# undef CONFIG_USART1_RS485MODE #endif -#if !defined(CONFIG_SAMD_SERCOM2) || !defined(CONFIG_SAMD_SERCOM2_ISUART) -# undef SAMD_HAVE_UART2 -# undef CONFIG_SAMD_SERCOM2_ISUART -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART2_FLOW_CONTROL -# undef CONFIG_UART2_IRDAMODE -# undef CONFIG_UART2_RS485MODE +#if !defined(CONFIG_SAMD_SERCOM2) || !defined(CONFIG_SAMD_SERCOM2_ISUSART) || \ + !defined(CONFIG_USART2_ISUART) +# undef SAMD_HAVE_USART2 +# undef CONFIG_SAMD_SERCOM2_ISUSART +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART2_FLOW_CONTROL +# undef CONFIG_USART2_IRDAMODE +# undef CONFIG_USART2_RS485MODE #endif -#if !defined(CONFIG_SAMD_SERCOM3) || !defined(CONFIG_SAMD_SERCOM3_ISUART) -# undef SAMD_HAVE_UART3 -# undef CONFIG_SAMD_SERCOM3_ISUART -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART3_FLOW_CONTROL -# undef CONFIG_UART3_IRDAMODE -# undef CONFIG_UART3_RS485MODE +#if !defined(CONFIG_SAMD_SERCOM3) || !defined(CONFIG_SAMD_SERCOM3_ISUSART) || \ + !defined(CONFIG_USART3_ISUART) +# undef SAMD_HAVE_USART3 +# undef CONFIG_SAMD_SERCOM3_ISUSART +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART3_FLOW_CONTROL +# undef CONFIG_USART3_IRDAMODE +# undef CONFIG_USART3_RS485MODE #endif -#if !defined(CONFIG_SAMD_SERCOM4) || !defined(CONFIG_SAMD_SERCOM4_ISUART) -# undef SAMD_HAVE_UART4 -# undef CONFIG_SAMD_SERCOM4_ISUART -# undef CONFIG_UART4_SERIAL_CONSOLE -# undef CONFIG_UART4_FLOW_CONTROL -# undef CONFIG_UART4_IRDAMODE -# undef CONFIG_UART4_RS485MODE +#if !defined(CONFIG_SAMD_SERCOM4) || !defined(CONFIG_SAMD_SERCOM4_ISUSART) || \ + !defined(CONFIG_USART4_ISUART) +# undef SAMD_HAVE_USART4 +# undef CONFIG_SAMD_SERCOM4_ISUSART +# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_USART4_FLOW_CONTROL +# undef CONFIG_USART4_IRDAMODE +# undef CONFIG_USART4_RS485MODE #endif -#if !defined(CONFIG_SAMD_SERCOM5) || !defined(CONFIG_SAMD_SERCOM5_ISUART) -# undef SAMD_HAVE_UART5 -# undef CONFIG_SAMD_SERCOM5_ISUART -# undef CONFIG_UART5_SERIAL_CONSOLE -# undef CONFIG_UART5_FLOW_CONTROL -# undef CONFIG_UART5_IRDAMODE -# undef CONFIG_UART5_RS485MODE +#if !defined(CONFIG_SAMD_SERCOM5) || !defined(CONFIG_SAMD_SERCOM5_ISUSART) || \ + !defined(CONFIG_USART5_ISUART) +# undef SAMD_HAVE_USART5 +# undef CONFIG_SAMD_SERCOM5_ISUSART +# undef CONFIG_USART5_SERIAL_CONSOLE +# undef CONFIG_USART5_FLOW_CONTROL +# undef CONFIG_USART5_IRDAMODE +# undef CONFIG_USART5_RS485MODE #endif -/* Are any UARTs enabled? */ +/* Are any USARTs enabled? */ -#undef HAVE_UART -#if defined(SAMD_HAVE_UART0) || defined(SAMD_HAVE_UART1) || \ - defined(SAMD_HAVE_UART2) || defined(SAMD_HAVE_UART3) || \ - defined(SAMD_HAVE_UART4) || defined(SAMD_HAVE_UART5) -# define HAVE_UART 1 +#undef HAVE_USART +#if defined(SAMD_HAVE_USART0) || defined(SAMD_HAVE_USART1) || \ + defined(SAMD_HAVE_USART2) || defined(SAMD_HAVE_USART3) || \ + defined(SAMD_HAVE_USART4) || defined(SAMD_HAVE_USART5) +# define HAVE_USART 1 #endif /* Is there a serial console? There should be at most one defined. It could be on - * any UARTn, n=0,1,2 - OR - there might not be any serial console at all. + * any USARTn, n=0-5 - OR - there might not be any serial console at all. */ -#if defined(CONFIG_UART0_SERIAL_CONSOLE) -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART4_SERIAL_CONSOLE -# undef CONFIG_UART5_SERIAL_CONSOLE +#if defined(CONFIG_USART0_SERIAL_CONSOLE) +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_USART5_SERIAL_CONSOLE # define HAVE_SERIAL_CONSOLE 1 -#elif defined(CONFIG_UART1_SERIAL_CONSOLE) -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART4_SERIAL_CONSOLE -# undef CONFIG_UART5_SERIAL_CONSOLE +#elif defined(CONFIG_USART1_SERIAL_CONSOLE) +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_USART5_SERIAL_CONSOLE # define HAVE_SERIAL_CONSOLE 1 -#elif defined(CONFIG_UART2_SERIAL_CONSOLE) -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART4_SERIAL_CONSOLE -# undef CONFIG_UART5_SERIAL_CONSOLE +#elif defined(CONFIG_USART2_SERIAL_CONSOLE) +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_USART5_SERIAL_CONSOLE # define HAVE_SERIAL_CONSOLE 1 -#elif defined(CONFIG_UART3_SERIAL_CONSOLE) -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART4_SERIAL_CONSOLE -# undef CONFIG_UART5_SERIAL_CONSOLE +#elif defined(CONFIG_USART3_SERIAL_CONSOLE) +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_USART5_SERIAL_CONSOLE # define HAVE_SERIAL_CONSOLE 1 -#elif defined(CONFIG_UART4_SERIAL_CONSOLE) -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART5_SERIAL_CONSOLE +#elif defined(CONFIG_USART4_SERIAL_CONSOLE) +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART5_SERIAL_CONSOLE # define HAVE_SERIAL_CONSOLE 1 -#elif defined(CONFIG_UART5_SERIAL_CONSOLE) -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART4_SERIAL_CONSOLE +#elif defined(CONFIG_USART5_SERIAL_CONSOLE) +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART4_SERIAL_CONSOLE # define HAVE_SERIAL_CONSOLE 1 #else -# undef CONFIG_UART0_SERIAL_CONSOLE -# undef CONFIG_UART1_SERIAL_CONSOLE -# undef CONFIG_UART2_SERIAL_CONSOLE -# undef CONFIG_UART3_SERIAL_CONSOLE -# undef CONFIG_UART4_SERIAL_CONSOLE -# undef CONFIG_UART5_SERIAL_CONSOLE +# undef CONFIG_USART0_SERIAL_CONSOLE +# undef CONFIG_USART1_SERIAL_CONSOLE +# undef CONFIG_USART2_SERIAL_CONSOLE +# undef CONFIG_USART3_SERIAL_CONSOLE +# undef CONFIG_USART4_SERIAL_CONSOLE +# undef CONFIG_USART5_SERIAL_CONSOLE # undef HAVE_SERIAL_CONSOLE #endif diff --git a/nuttx/arch/arm/src/samd/sam_lowputc.c b/nuttx/arch/arm/src/samd/sam_lowputc.c new file mode 100644 index 000000000..58c043fc7 --- /dev/null +++ b/nuttx/arch/arm/src/samd/sam_lowputc.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * arch/arm/src/samd/sam_lowputc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <assert.h> + +#include "sam_config.h" +#include "sam_usart.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/************************************************************************************ + * Name: sam_lowsetup + * + * Description: + * Called at the very beginning of _start. Performs low level initialization. + * + ************************************************************************************/ + +void sam_lowsetup(void) +{ +#warning Missing logic +} + +/**************************************************************************** + * Name: sam_usartconfig + * + * Description: + * Set the configuration of a SERCOM for provided USART configuration. + * + *****************************************************************************/ + +#ifdef HAVE_USART +void sam_usartconfig(const struct sam_usart_config_s *config) +{ +#warning Missing logic +} +#endif + +/**************************************************************************** + * Name: sam_lowputc + * + * Description: + * Output one character to the USART using a simple polling method. + * + *****************************************************************************/ + +#ifdef HAVE_SERIAL_CONSOLE +void sam_lowputc(uint32_t ch) +{ +#warning Missing logic +} +#endif diff --git a/nuttx/arch/arm/src/samd/sam_lowputc.h b/nuttx/arch/arm/src/samd/sam_lowputc.h index 9d0429e96..af553fae5 100644 --- a/nuttx/arch/arm/src/samd/sam_lowputc.h +++ b/nuttx/arch/arm/src/samd/sam_lowputc.h @@ -81,22 +81,23 @@ extern "C" void sam_lowsetup(void); /**************************************************************************** - * Name: sam_setbaud + * Name: sam_usartconfig * * Description: - * Set the BAUD divisor for the selected UART. + * Set the configuration of a SERCOM for provided USART configuration. * *****************************************************************************/ -#ifdef HAVE_UART -void sam_setbaud(uintptr_t base, uint32_t baud); +#ifdef HAVE_USART +struct sam_usart_config_s; +void sam_usartconfig(const struct sam_usart_config_s *config); #endif /**************************************************************************** * Name: sam_lowputc * * Description: - * Output one character to the UART using a simple polling method. + * Output one character to the USART using a simple polling method. * *****************************************************************************/ diff --git a/nuttx/arch/arm/src/samd/sam_usart.c b/nuttx/arch/arm/src/samd/sam_usart.c new file mode 100644 index 000000000..2d3fe86b3 --- /dev/null +++ b/nuttx/arch/arm/src/samd/sam_usart.c @@ -0,0 +1,225 @@ +/**************************************************************************** + * arch/arm/src/samd/sam_usart.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <assert.h> + +#include "chip/sam_pinmap.h" +#include "chip/sam_usart.h" + +#include <arch/board/board.h> + +#include "sam_usart.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef SAMD_HAVE_USART0 +const struct sam_usart_config_s g_usart0config = +{ + .sercom = 0, + .parity = CONFIG_USART0_PARITY, + .bits = CONFIG_USART0_BITS, + .irq = SAM_IRQ_SERCOM0, + .stopbits2 = CONFIG_USART0_2STOP, + .baud = CONFIG_USART0_BAUD, + .pad0 = BOARD_SERCOM0_PINMAP_PAD0, + .pad1 = BOARD_SERCOM0_PINMAP_PAD1, + .pad2 = BOARD_SERCOM0_PINMAP_PAD2, + .pad3 = BOARD_SERCOM0_PINMAP_PAD3, + .muxconfig = BOARD_SERCOM0_MUXCONFIG, + .base = SAM_SERCOM0_BASE, +}; +#endif + +#ifdef SAMD_HAVE_USART1 +const struct sam_usart_config_s g_usart1config = +{ + .sercom = 1, + .parity = CONFIG_USART1_PARITY, + .bits = CONFIG_USART1_BITS, + .irq = SAM_IRQ_SERCOM1, + .stopbits2 = CONFIG_USART1_2STOP, + .baud = CONFIG_USART1_BAUD, + .pad0 = BOARD_SERCOM1_PINMAP_PAD0, + .pad1 = BOARD_SERCOM1_PINMAP_PAD1, + .pad2 = BOARD_SERCOM1_PINMAP_PAD2, + .pad3 = BOARD_SERCOM1_PINMAP_PAD3, + .muxconfig = BOARD_SERCOM1_MUXCONFIG, + .base = SAM_SERCOM1_BASE, +}; +#endif + +#ifdef SAMD_HAVE_USART2 +const struct sam_usart_config_s g_usart2config = +{ + .sercom = 2, + .parity = CONFIG_USART2_PARITY, + .bits = CONFIG_USART2_BITS, + .irq = SAM_IRQ_SERCOM2, + .stopbits2 = CONFIG_USART2_2STOP, + .baud = CONFIG_USART2_BAUD, + .pad0 = BOARD_SERCOM2_PINMAP_PAD0, + .pad1 = BOARD_SERCOM2_PINMAP_PAD1, + .pad2 = BOARD_SERCOM2_PINMAP_PAD2, + .pad3 = BOARD_SERCOM2_PINMAP_PAD3, + .muxconfig = BOARD_SERCOM2_MUXCONFIG, + .base = SAM_SERCOM2_BASE, +}; +#endif + +#ifdef SAMD_HAVE_USART3 +const struct sam_usart_config_s g_usart3config = +{ + .sercom = 3, + .parity = CONFIG_USART3_PARITY, + .bits = CONFIG_USART3_BITS, + .irq = SAM_IRQ_SERCOM3, + .stopbits2 = CONFIG_USART3_2STOP, + .baud = CONFIG_USART3_BAUD, + .pad0 = BOARD_SERCOM3_PINMAP_PAD0, + .pad1 = BOARD_SERCOM3_PINMAP_PAD1, + .pad2 = BOARD_SERCOM3_PINMAP_PAD2, + .pad3 = BOARD_SERCOM3_PINMAP_PAD3, + .muxconfig = BOARD_SERCOM3_MUXCONFIG, + .base = SAM_SERCOM3_BASE, +}; +#endif + +#ifdef SAMD_HAVE_USART4 +const struct sam_usart_config_s g_usart4config = +{ + .sercom = 4, + .parity = CONFIG_USART4_PARITY, + .bits = CONFIG_USART4_BITS, + .irq = SAM_IRQ_SERCOM4, + .stopbits2 = CONFIG_USART4_2STOP, + .baud = CONFIG_USART4_BAUD, + .pad0 = BOARD_SERCOM4_PINMAP_PAD0, + .pad1 = BOARD_SERCOM4_PINMAP_PAD1, + .pad2 = BOARD_SERCOM4_PINMAP_PAD2, + .pad3 = BOARD_SERCOM4_PINMAP_PAD3, + .muxconfig = BOARD_SERCOM4_MUXCONFIG, + .base = SAM_SERCOM4_BASE, +}; +#endif + +#ifdef SAMD_HAVE_USART5 +const struct sam_usart_config_s g_usart5config = +{ + .sercom = 5, + .parity = CONFIG_USART5_PARITY, + .bits = CONFIG_USART5_BITS, + .irq = SAM_IRQ_SERCOM5, + .stopbits2 = CONFIG_USART5_2STOP, + .baud = CONFIG_USART5_BAUD, + .pad0 = BOARD_SERCOM5_PINMAP_PAD0, + .pad1 = BOARD_SERCOM5_PINMAP_PAD1, + .pad2 = BOARD_SERCOM5_PINMAP_PAD2, + .pad3 = BOARD_SERCOM5_PINMAP_PAD3, + .muxconfig = BOARD_SERCOM5_MUXCONFIG, + .base = SAM_SERCOM5_BASE, +}; +#endif + +const struct sam_usart_config_s *g_usartconfig[SAMD_NSERCOM] = +{ +#if SAMD_NSERCOM > 5 +#ifdef SAMD_HAVE_USART5 + &g_usart5config, +#else + (const struct sam_usart_config_s *)0, +#endif +#endif + +#if SAMD_NSERCOM > 1 +#ifdef SAMD_HAVE_USART1 + &g_usart1config, +#else + (const struct sam_usart_config_s *)0, +#endif +#endif + +#if SAMD_NSERCOM > 2 +#ifdef SAMD_HAVE_USART2 + &g_usart2config, +#else + (const struct sam_usart_config_s *)0, +#endif +#endif + +#if SAMD_NSERCOM > 3 +#ifdef SAMD_HAVE_USART3 + &g_usart3config, +#else + (const struct sam_usart_config_s *)0, +#endif +#endif + +#if SAMD_NSERCOM > 4 +#ifdef SAMD_HAVE_USART4 + &g_usart4config, +#else + (const struct sam_usart_config_s *)0, +#endif +#endif + +#if SAMD_NSERCOM > 5 +#ifdef SAMD_HAVE_USART5 + &g_usart5config, +#else + (const struct sam_usart_config_s *)0, +#endif +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ diff --git a/nuttx/arch/arm/src/samd/sam_usart.h b/nuttx/arch/arm/src/samd/sam_usart.h new file mode 100644 index 000000000..a8585ae2d --- /dev/null +++ b/nuttx/arch/arm/src/samd/sam_usart.h @@ -0,0 +1,146 @@ +/************************************************************************************ + * arch/arm/src/samd/sam_usart.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_SAMD_SAM_USART_H +#define __ARCH_ARM_SRC_SAMD_SAM_USART_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> + +#include <arch/chip/chip.h> + +#include "sam_config.h" +#include "sam_port.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* Pick the console USART configuration */ + +#if defined(CONFIG_USART0_SERIAL_CONSOLE) +# define g_consoleconfig (&g_usart0config) +#elif defined(CONFIG_USART1_SERIAL_CONSOLE) +# define g_consoleconfig (&g_usart1config) +#elif defined(CONFIG_USART2_SERIAL_CONSOLE) +# define g_consoleconfig (&g_usart2config) +#elif defined(CONFIG_USART3_SERIAL_CONSOLE) +# define g_consoleconfig (&g_usart3config) +#elif defined(CONFIG_USART4_SERIAL_CONSOLE) +# define g_consoleconfig (&g_usart4config) +#elif defined(CONFIG_USART5_SERIAL_CONSOLE) +# define g_consoleconfig (&g_usart5config) +#else +# undef g_consoleconfig +#endif + +/************************************************************************************ + * Public Types + ************************************************************************************/ +/* This structure describes the static configuration of a USART */ + +struct sam_usart_config_s +{ + uint8_t sercom; /* Identifies the SERCOM peripheral */ + uint8_t parity; /* 0=none, 1=odd, 2=even */ + uint8_t bits; /* Number of bits (5-9) */ + uint8_t irq; /* SERCOM IRQ number */ + bool isconsole; /* True: The USART is the console device */ + bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */ + uint32_t baud; /* Configured baud */ + port_pinset_t pad0; /* Pin configuration for PAD0 */ + port_pinset_t pad1; /* Pin configuration for PAD1 */ + port_pinset_t pad2; /* Pin configuration for PAD2 */ + port_pinset_t pad3; /* Pin configuration for PAD3 */ + uint32_t muxconfig; /* Pad multiplexing configuration */ + uintptr_t base; /* SERCOM base address */ +}; + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#ifdef SAMD_HAVE_USART0 +EXTERN const struct sam_usart_config_s g_usart0config; +#endif + +#ifdef SAMD_HAVE_USART1 +EXTERN const struct sam_usart_config_s g_usart1config; +#endif + +#ifdef SAMD_HAVE_USART2 +EXTERN const struct sam_usart_config_s g_usart2config; +#endif + +#ifdef SAMD_HAVE_USART3 +EXTERN const struct sam_usart_config_s g_usart3config; +#endif + +#ifdef SAMD_HAVE_USART4 +EXTERN const struct sam_usart_config_s g_usart4config; +#endif + +#ifdef SAMD_HAVE_USART5 +EXTERN const struct sam_usart_config_s g_usart5config; +#endif + +EXTERN const struct sam_usart_config_s *g_usartconfig[SAMD_NSERCOM]; + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_SAMD_SAM_USART_H */ |