diff --git a/arch/arm/src/samdl/chip/saml_usart.h b/arch/arm/src/samdl/chip/saml_usart.h index 78609072a7..2d364f6e70 100644 --- a/arch/arm/src/samdl/chip/saml_usart.h +++ b/arch/arm/src/samdl/chip/saml_usart.h @@ -253,6 +253,8 @@ #define USART_SYNCBUSY_ENABLE (1 << 1) /* Bit 1: SERCOM enable synchronization busy */ #define USART_SYNCBUSY_CTRLB (1 << 2) /* Bit 2: CTRLB synchronization busy */ +#define USART_SYNCBUSY_ALL 0x00000007 + /* Data register */ #define USART_DATA_MASK (0x1ff) /* Bits 0-8: Data */ diff --git a/arch/arm/src/samdl/sam_lowputc.c b/arch/arm/src/samdl/sam_lowputc.c index bb120ae2e8..26eec9108f 100644 --- a/arch/arm/src/samdl/sam_lowputc.c +++ b/arch/arm/src/samdl/sam_lowputc.c @@ -80,6 +80,22 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: sam_wait_synchronization + * + * Description: + * Wait until the SERCOM USART reports that it is synchronized. + * + ****************************************************************************/ + +#ifdef SAMDL_HAVE_USART +static void +sam_wait_synchronization(const struct sam_usart_config_s * const config) +{ + while (usart_syncbusy(config)); +} +#endif + /**************************************************************************** * Name: sam_usart_configure * diff --git a/arch/arm/src/samdl/sam_usart.h b/arch/arm/src/samdl/sam_usart.h index a35923b7d3..528a15da8a 100644 --- a/arch/arm/src/samdl/sam_usart.h +++ b/arch/arm/src/samdl/sam_usart.h @@ -107,20 +107,21 @@ struct sam_usart_config_s * Name: sam_wait_synchronization * * Description: - * Wait until the SERCOM USART reports that it is synchronized. + * Return true is the SERCOM USART reports that it is synchronizing. This inline + * function hides register differences between the SAMD20 and SAML21. * ***********************************************************************************/ #ifdef SAMDL_HAVE_USART -static inline void -sam_wait_synchronization(const struct sam_usart_config_s * const config) +static inline bool usart_syncbusy(const struct sam_usart_config_s * const config) { #if defined(CONFIG_ARCH_FAMILY_SAMD20) - while ((getreg16(config->base + SAM_USART_STATUS_OFFSET) & USART_STATUS_SYNCBUSY) != 0); + return ((getreg16(config->base + SAM_USART_STATUS_OFFSET) & USART_STATUS_SYNCBUSY) != 0); #elif defined(CONFIG_ARCH_FAMILY_SAML21) -# warning Need SAML21 synchronization logic + return ((getreg16(config->base + SAM_USART_SYNCBUSY_OFFSET) & USART_SYNCBUSY_ALL) != 0); #else # error Unrecognized SAMD/L family + return false; #endif } #endif