diff --git a/arch/arm/src/samd2l2/sam_lowputc.c b/arch/arm/src/samd2l2/sam_lowputc.c index bfd0dcc10a..67d70b370c 100644 --- a/arch/arm/src/samd2l2/sam_lowputc.c +++ b/arch/arm/src/samd2l2/sam_lowputc.c @@ -90,7 +90,7 @@ #ifdef SAMD2L2_HAVE_USART static void -sam_wait_synchronization(const struct sam_usart_config_s * const config) +sam_wait_synchronization(const struct sam_usart_config_s *const config) { while (usart_syncbusy(config)); } @@ -106,7 +106,7 @@ sam_wait_synchronization(const struct sam_usart_config_s * const config) #ifdef SAMD2L2_HAVE_USART static inline int -sam_usart_configure(const struct sam_usart_config_s * const config) +sam_usart_configure(const struct sam_usart_config_s *const config) { uint32_t ctrla; uint32_t ctrlb; @@ -257,7 +257,7 @@ sam_usart_configure(const struct sam_usart_config_s * const config) #ifdef SAMD2L2_HAVE_USART static inline void -sam_pad_configure(const struct sam_usart_config_s * const config) +sam_pad_configure(const struct sam_usart_config_s *const config) { /* Configure SERCOM pads */ @@ -294,7 +294,7 @@ sam_pad_configure(const struct sam_usart_config_s * const config) ****************************************************************************/ #ifdef SAMD2L2_HAVE_USART -int sam_usart_internal(const struct sam_usart_config_s * const config) +int sam_usart_internal(const struct sam_usart_config_s *const config) { #ifdef CONFIG_ARCH_FAMILY_SAML21 int channel; @@ -339,34 +339,6 @@ int sam_usart_internal(const struct sam_usart_config_s * const config) } #endif -/**************************************************************************** - * Name: sam_usart_enable - * - * Description: - * Enable the SERCOM USART (without enabling interrupts). - * - ****************************************************************************/ - -#ifdef SAMD2L2_HAVE_USART -static inline void -sam_usart_enable(const struct sam_usart_config_s * const config) -{ - uintptr_t regaddr; - uint32_t regval; - - /* Wait until synchronization is complete */ - - sam_wait_synchronization(config); - - /* Enable USART module */ - - regaddr = config->base + SAM_USART_CTRLA_OFFSET; - regval = getreg32(regaddr); - regval |= USART_CTRLA_ENABLE; - putreg32(regval, regaddr); -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -401,7 +373,7 @@ void sam_lowsetup(void) ****************************************************************************/ #ifdef SAMD2L2_HAVE_USART -int sam_usart_initialize(const struct sam_usart_config_s * const config) +int sam_usart_initialize(const struct sam_usart_config_s *const config) { irqstate_t flags; int ret; @@ -431,7 +403,7 @@ int sam_usart_initialize(const struct sam_usart_config_s * const config) ****************************************************************************/ #ifdef SAMD2L2_HAVE_USART -void sam_usart_reset(const struct sam_usart_config_s * const config) +void sam_usart_reset(const struct sam_usart_config_s *const config) { uintptr_t regaddr = config->base + SAM_USART_CTRLA_OFFSET; uint32_t regval; @@ -451,6 +423,33 @@ void sam_usart_reset(const struct sam_usart_config_s * const config) } #endif +/**************************************************************************** + * Name: sam_usart_enable + * + * Description: + * Enable the SERCOM USART (without enabling interrupts). + * + ****************************************************************************/ + +#ifdef SAMD2L2_HAVE_USART +void sam_usart_enable(const struct sam_usart_config_s *const config) +{ + uintptr_t regaddr; + uint32_t regval; + + /* Wait until synchronization is complete */ + + sam_wait_synchronization(config); + + /* Enable USART module */ + + regaddr = config->base + SAM_USART_CTRLA_OFFSET; + regval = getreg32(regaddr); + regval |= USART_CTRLA_ENABLE; + putreg32(regval, regaddr); +} +#endif + /**************************************************************************** * Name: sam_lowputc * diff --git a/arch/arm/src/samd2l2/sam_lowputc.h b/arch/arm/src/samd2l2/sam_lowputc.h index c51f895bf6..b84fcf3e57 100644 --- a/arch/arm/src/samd2l2/sam_lowputc.h +++ b/arch/arm/src/samd2l2/sam_lowputc.h @@ -93,7 +93,7 @@ void sam_lowsetup(void); #ifdef SAMD2L2_HAVE_USART struct sam_usart_config_s; -int sam_usart_initialize(const struct sam_usart_config_s * const config); +int sam_usart_initialize(const struct sam_usart_config_s *const config); #endif /**************************************************************************** @@ -107,7 +107,20 @@ int sam_usart_initialize(const struct sam_usart_config_s * const config); #ifdef SAMD2L2_HAVE_USART struct sam_usart_config_s; -void sam_usart_reset(const struct sam_usart_config_s * const config); +void sam_usart_reset(const struct sam_usart_config_s *const config); +#endif + +/**************************************************************************** + * Name: sam_usart_enable + * + * Description: + * Enable the SERCOM USART (without enabling interrupts). + * + ****************************************************************************/ + +#ifdef SAMD2L2_HAVE_USART +struct sam_usart_config_s; +void sam_usart_enable(const struct sam_usart_config_s *const config); #endif /**************************************************************************** diff --git a/arch/arm/src/samd2l2/sam_serial.c b/arch/arm/src/samd2l2/sam_serial.c index 70ee942dba..6ad9b3d31b 100644 --- a/arch/arm/src/samd2l2/sam_serial.c +++ b/arch/arm/src/samd2l2/sam_serial.c @@ -666,6 +666,10 @@ static int sam_setup(struct uart_dev_s *dev) if (!dev->isconsole) { ret = sam_usart_initialize(priv->config); + if (ret >= 0) + { + sam_usart_enable(priv->config); + } } #endif diff --git a/include/nuttx/symtab.h b/include/nuttx/symtab.h index b2cea91348..34e015a80d 100644 --- a/include/nuttx/symtab.h +++ b/include/nuttx/symtab.h @@ -137,6 +137,19 @@ FAR const struct symtab_s * symtab_findbyvalue(FAR const struct symtab_s *symtab, FAR void *value, int nsyms); +/**************************************************************************** + * Name: symtab_sortbyname + * + * Description: + * Sort the symbol table by name. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void symtab_sortbyname(FAR struct symtab_s *symtab, int nsyms); + #undef EXTERN #if defined(__cplusplus) } diff --git a/libs/libc/symtab/Make.defs b/libs/libc/symtab/Make.defs index 5a7ddab07f..74daa2c73c 100644 --- a/libs/libc/symtab/Make.defs +++ b/libs/libc/symtab/Make.defs @@ -36,7 +36,7 @@ # Symbol table source files CSRCS += symtab_findbyname.c symtab_findbyvalue.c -CSRCS += symtab_findorderedbyname.c +CSRCS += symtab_findorderedbyname.c symtab_sortbyname.c # Add the symtab directory to the build diff --git a/libs/libc/symtab/symtab_sortbyname.c b/libs/libc/symtab/symtab_sortbyname.c new file mode 100644 index 0000000000..383fb61b1d --- /dev/null +++ b/libs/libc/symtab/symtab_sortbyname.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * libs/libc/symtab/symtab_sortbyname.c + * + * Copyright (C) 2019 Pinecone Inc. All rights reserved. + * Author: Xiang Xiao + * + * 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 + +#include +#include +#include + +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int symtab_comparename(FAR const void *arg1, FAR const void *arg2) +{ + FAR const struct symtab_s *symtab1 = arg1; + FAR const struct symtab_s *symtab2 = arg2; + + return strcmp(symtab1->sym_name, symtab2->sym_name); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: symtab_sortbyname + * + * Description: + * Sort the symbol table by name. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void symtab_sortbyname(FAR struct symtab_s *symtab, int nsyms) +{ + DEBUGASSERT(symtab != NULL && nsyms != 0); + qsort(symtab, nsyms, sizeof(symtab[0]), symtab_comparename); +}