Fix SYNCBUSY wait for the SAML21

This commit is contained in:
Gregory Nutt 2015-05-20 11:49:24 -06:00
parent 5ef695f3b7
commit ea1adddbcd
3 changed files with 24 additions and 5 deletions

View File

@ -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 */

View File

@ -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
*

View File

@ -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