35 #if defined(USART_COUNT) && (USART_COUNT > 0)
59 #if (USART_COUNT == 1) && defined(USART0)
60 #define USART_REF_VALID(ref) ((ref) == USART0)
62 #elif (USART_COUNT == 1) && defined(USART1)
63 #define USART_REF_VALID(ref) ((ref) == USART1)
65 #elif (USART_COUNT == 2) && defined(USART2)
66 #define USART_REF_VALID(ref) (((ref) == USART1) || ((ref) == USART2))
68 #elif (USART_COUNT == 2)
69 #define USART_REF_VALID(ref) (((ref) == USART0) || ((ref) == USART1))
71 #elif (USART_COUNT == 3)
72 #define USART_REF_VALID(ref) (((ref) == USART0) || ((ref) == USART1) || \
74 #elif (USART_COUNT == 4)
75 #define USART_REF_VALID(ref) (((ref) == USART0) || ((ref) == USART1) || \
76 ((ref) == USART2) || ((ref) == USART3))
77 #elif (USART_COUNT == 5)
78 #define USART_REF_VALID(ref) (((ref) == USART0) || ((ref) == USART1) || \
79 ((ref) == USART2) || ((ref) == USART3) || \
81 #elif (USART_COUNT == 6)
82 #define USART_REF_VALID(ref) (((ref) == USART0) || ((ref) == USART1) || \
83 ((ref) == USART2) || ((ref) == USART3) || \
84 ((ref) == USART4) || ((ref) == USART5))
86 #error "Undefined number of USARTs."
89 #if defined(USARTRF_COUNT) && (USARTRF_COUNT > 0)
90 #if (USARTRF_COUNT == 1) && defined(USARTRF0)
91 #define USARTRF_REF_VALID(ref) ((ref) == USARTRF0)
92 #elif (USARTRF_COUNT == 1) && defined(USARTRF1)
93 #define USARTRF_REF_VALID(ref) ((ref) == USARTRF1)
95 #define USARTRF_REF_VALID(ref) (0)
98 #define USARTRF_REF_VALID(ref) (0)
101 #if defined(_EZR32_HAPPY_FAMILY)
102 #define USART_IRDA_VALID(ref) ((ref) == USART0)
103 #elif defined(_EFM32_HAPPY_FAMILY)
104 #define USART_IRDA_VALID(ref) (((ref) == USART0) || ((ref) == USART1))
105 #elif defined(USART0)
106 #define USART_IRDA_VALID(ref) ((ref) == USART0)
107 #elif (USART_COUNT == 1) && defined(USART1)
108 #define USART_IRDA_VALID(ref) ((ref) == USART1)
110 #define USART_IRDA_VALID(ref) (0)
113 #if defined(_SILICON_LABS_32B_SERIES_1)
114 #define USART_I2S_VALID(ref) ((ref) == USART1)
115 #elif defined(_SILICON_LABS_32B_SERIES_0)
116 #if defined(_EZR32_HAPPY_FAMILY)
117 #define USART_I2S_VALID(ref) ((ref) == USART0)
118 #elif defined(_EFM32_HAPPY_FAMILY)
119 #define USART_I2S_VALID(ref) (((ref) == USART0) || ((ref) == USART1))
120 #elif defined(_EFM32_TINY_FAMILY) || defined(_EFM32_ZERO_FAMILY)
121 #define USART_I2S_VALID(ref) ((ref) == USART1)
122 #elif defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
123 #define USART_I2S_VALID(ref) (((ref) == USART1) || ((ref) == USART2))
127 #if (UART_COUNT == 1)
128 #define UART_REF_VALID(ref) ((ref) == UART0)
129 #elif (UART_COUNT == 2)
130 #define UART_REF_VALID(ref) (((ref) == UART0) || ((ref) == UART1))
132 #define UART_REF_VALID(ref) (0)
173 EFM_ASSERT(baudrate);
213 EFM_ASSERT(baudrate <= (refFreq / 16));
218 EFM_ASSERT(baudrate <= (refFreq / 8));
223 EFM_ASSERT(baudrate <= (refFreq / 6));
228 EFM_ASSERT(baudrate <= (refFreq / 4));
243 #if defined(_USART_CLKDIV_DIV_MASK) && (_USART_CLKDIV_DIV_MASK >= 0x7FFFF8UL)
244 clkdiv = 32 * refFreq + (oversample * baudrate) / 2;
245 clkdiv /= (oversample * baudrate);
249 clkdiv = 4 * refFreq + (oversample * baudrate) / 2;
250 clkdiv /= (oversample * baudrate);
396 divisor = oversample * (256 + clkdiv);
398 quotient = refFreq / divisor;
399 remainder = refFreq % divisor;
404 br = (uint32_t)(factor * quotient);
411 br += (uint32_t)((factor * remainder) / divisor);
485 EFM_ASSERT(baudrate);
499 clkdiv = (refFreq - 1) / (2 * baudrate);
500 clkdiv = clkdiv << 8;
532 EFM_ASSERT( USART_REF_VALID(usart)
533 || USARTRF_REF_VALID(usart)
534 || UART_REF_VALID(usart) );
537 tmp = ~((uint32_t) (enable));
539 usart->
CMD = tmp << 1;
542 usart->
CMD = (uint32_t) (enable);
572 EFM_ASSERT( USART_REF_VALID(usart)
573 || USARTRF_REF_VALID(usart)
574 || UART_REF_VALID(usart) );
579 #if defined(USART_INPUT_RXPRS) && defined(USART_CTRL_MVDIS)
601 #if defined(_USART_TIMING_CSHOLD_MASK)
602 usart->TIMING = ((init->autoCsHold << _USART_TIMING_CSHOLD_SHIFT)
603 & _USART_TIMING_CSHOLD_MASK)
604 | ((init->autoCsSetup << _USART_TIMING_CSSETUP_SHIFT)
605 & _USART_TIMING_CSSETUP_MASK);
606 if (init->autoCsEnable)
643 EFM_ASSERT( USART_REF_VALID(usart) || USARTRF_REF_VALID(usart) );
653 #if defined(_USART_CTRL_AUTOTX_MASK)
657 #if defined(_USART_INPUT_RXPRS_MASK)
679 #if defined(_USART_TIMING_CSHOLD_MASK)
680 usart->TIMING = ((init->autoCsHold << _USART_TIMING_CSHOLD_SHIFT)
681 & _USART_TIMING_CSHOLD_MASK)
682 | ((init->autoCsSetup << _USART_TIMING_CSSETUP_SHIFT)
683 & _USART_TIMING_CSSETUP_MASK);
684 if (init->autoCsEnable)
723 EFM_ASSERT(USART_IRDA_VALID(usart));
747 #if defined(_USART_I2SCTRL_MASK)
782 EFM_ASSERT(USART_I2S_VALID(usart));
823 #if defined(USART_TRIGCTRL_AUTOTXTEN)
828 #if defined(USART_TRIGCTRL_AUTOTXTEN)
859 EFM_ASSERT( USART_REF_VALID(usart)
860 || USARTRF_REF_VALID(usart)
861 || UART_REF_VALID(usart) );
873 #if defined(_USART_ROUTEPEN_MASK) || defined(_UART_ROUTEPEN_MASK)
874 usart->ROUTEPEN = _USART_ROUTEPEN_RESETVALUE;
875 usart->ROUTELOC0 = _USART_ROUTELOC0_RESETVALUE;
876 usart->ROUTELOC1 = _USART_ROUTELOC1_RESETVALUE;
881 if (USART_IRDA_VALID(usart))
886 #if defined(_USART_INPUT_RESETVALUE)
890 #if defined(_USART_I2SCTRL_RESETVALUE)
891 if (USART_I2S_VALID(usart))
928 return (uint8_t)usart->
RXDATA;
1027 return (uint16_t)usart->
RXDATAX;
1054 usart->
TXDATA = (uint32_t)data;
1057 return (uint8_t)usart->
RXDATA;
1089 usart->
TXDATA = (uint32_t)data;
1189 usart->
TXDATAX = (uint32_t)data;
Clock management unit (CMU) API.
USART_Stopbits_TypeDef stopbits
USART_I2sJustify_TypeDef justify
#define USART_STATUS_TXBL
void USART_Tx(USART_TypeDef *usart, uint8_t data)
Transmit one 4-9 bit frame.
#define _USART_CLKDIV_DIV_MASK
#define USART_I2SCTRL_DELAY
Emlib peripheral API "assert" implementation.
#define _USART_CLKDIV_RESETVALUE
USART_PrsTriggerCh_TypeDef prsTriggerChannel
#define _USART_INPUT_RESETVALUE
#define USART_CTRL_AUTOCS
void USART_InitSync(USART_TypeDef *usart, const USART_InitSync_TypeDef *init)
Init USART for synchronous mode.
#define _USART_CTRL_OVS_MASK
USART_OVS_TypeDef oversampling
#define USART_TRIGCTRL_AUTOTXTEN
#define _USART_CMD_RXEN_MASK
RAM and peripheral bit-field set and clear API.
#define USART_FRAME_STOPBITS_DEFAULT
void USART_BaudrateSyncSet(USART_TypeDef *usart, uint32_t refFreq, uint32_t baudrate)
Configure USART operating in synchronous mode to use a given baudrate (or as close as possible to spe...
#define _USART_TRIGCTRL_AUTOTXTEN_MASK
USART_Databits_TypeDef databits
uint8_t USART_Rx(USART_TypeDef *usart)
Receive one 4-8 bit frame, (or part of 10-16 bit frame).
USART_InitAsync_TypeDef async
void USART_TxDoubleExt(USART_TypeDef *usart, uint32_t data)
Transmit two 4-9 bit frames, or one 10-16 bit frame with extended control.
USART_InitSync_TypeDef sync
uint32_t USART_RxDoubleExt(USART_TypeDef *usart)
Receive two 4-9 bit frames, or one 10-16 bit frame with extended information.
uint32_t USART_BaudrateCalc(uint32_t refFreq, uint32_t clkdiv, bool syncmode, USART_OVS_TypeDef ovs)
Calculate baudrate for USART/UART given reference frequency, clock division and oversampling rate (if...
USART_PrsRxCh_TypeDef prsRxCh
#define USART_CMD_RXBLOCKDIS
USART_IrDAPw_Typedef irPw
USART_Parity_TypeDef parity
#define _USART_TRIGCTRL_TSEL_MASK
Universal synchronous/asynchronous receiver/transmitter (USART/UART) peripheral API.
#define USART_TRIGCTRL_TXTEN
#define USART_CMD_TXTRIDIS
USART_Enable_TypeDef enable
#define USART_I2SCTRL_DMASPLIT
#define USART_CMD_MASTERDIS
#define _USART_IRCTRL_RESETVALUE
#define _USART_ROUTE_RESETVALUE
#define USART_TRIGCTRL_RXTEN
USART_I2sFormat_TypeDef format
#define USART_I2SCTRL_MONO
#define _USART_TRIGCTRL_TXTEN_MASK
#define _USART_FRAME_RESETVALUE
#define USART_STATUS_RXDATAV
#define USART_STATUS_RXFULL
#define _USART_I2SCTRL_RESETVALUE
#define USART_FRAME_PARITY_DEFAULT
#define _USART_CMD_TXEN_MASK
uint16_t USART_RxExt(USART_TypeDef *usart)
Receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended information.
#define USART_CMD_CLEARRX
#define USART_IRCTRL_IREN
#define USART_CTRL_AUTOTX
USART_IrDAPrsSel_Typedef irPrsSel
#define USART_CMD_MASTEREN
#define USART_CMD_CLEARTX
USART_ClockMode_TypeDef clockMode
void USARTn_InitIrDA(USART_TypeDef *usart, const USART_InitIrDA_TypeDef *init)
Init USART for asynchronous IrDA mode.
#define _USART_TRIGCTRL_RESETVALUE
#define _USART_CTRL_RESETVALUE
USART_Enable_TypeDef enable
void USART_TxExt(USART_TypeDef *usart, uint16_t data)
Transmit one 4-9 bit frame with extended control.
USART_Databits_TypeDef databits
void USART_Reset(USART_TypeDef *usart)
Reset USART/UART to same state as after a HW reset.
uint8_t USART_SpiTransfer(USART_TypeDef *usart, uint8_t data)
Perform one 8 bit frame SPI transfer.
#define _USART_IRCTRL_IRPRSEN_SHIFT
__STATIC_INLINE void BUS_RegMaskedWrite(volatile uint32_t *addr, uint32_t mask, uint32_t val)
Perform peripheral register masked clear and value write.
void USART_InitI2s(USART_TypeDef *usart, USART_InitI2s_TypeDef *init)
Init USART for I2S mode.
#define _USART_IEN_RESETVALUE
#define _USART_TRIGCTRL_RXTEN_MASK
void USART_Enable(USART_TypeDef *usart, USART_Enable_TypeDef enable)
Enable/disable USART/UART receiver and/or transmitter.
void USART_InitPrsTrigger(USART_TypeDef *usart, const USART_PrsTriggerInit_TypeDef *init)
Initialize automatic transmissions using PRS channel as trigger.
void USART_InitAsync(USART_TypeDef *usart, const USART_InitAsync_TypeDef *init)
Init USART/UART for normal asynchronous mode.
uint16_t USART_RxDouble(USART_TypeDef *usart)
Receive two 4-8 bit frames, or one 10-16 bit frame.
uint32_t USART_BaudrateGet(USART_TypeDef *usart)
Get current baudrate for USART/UART.
uint32_t CMU_ClockFreqGet(CMU_Clock_TypeDef clock)
Get clock frequency for a clock point.
void USART_TxDouble(USART_TypeDef *usart, uint16_t data)
Transmit two 4-9 bit frames, or one 10-16 bit frame.
USART_PrsRxCh_TypeDef prsRxCh
#define USART_INPUT_RXPRS
#define _USART_IRCTRL_IRFILT_SHIFT
void USART_BaudrateAsyncSet(USART_TypeDef *usart, uint32_t refFreq, uint32_t baudrate, USART_OVS_TypeDef ovs)
Configure USART/UART operating in asynchronous mode to use a given baudrate (or as close as possible ...