EFR32 Mighty Gecko 1 Software Documentation
efr32mg1-doc-5.1.2
|
Low Energy Universal Asynchronous Receiver/Transmitter (LEUART) Peripheral API.
This module contains functions to control the LEUART peripheral of Silicon Labs 32-bit MCUs and SoCs. The LEUART provides full UART communication using a low frequency 32.768 kHz clock, and has special features for communication without CPU intervention.
Data Structures | |
struct | LEUART_Init_TypeDef |
Macros | |
#define | LEUART_INIT_DEFAULT |
Enumerations | |
enum | LEUART_Databits_TypeDef { leuartDatabits8 = LEUART_CTRL_DATABITS_EIGHT, leuartDatabits9 = LEUART_CTRL_DATABITS_NINE } |
enum | LEUART_Enable_TypeDef { leuartDisable = 0x0, leuartEnableRx = LEUART_CMD_RXEN, leuartEnableTx = LEUART_CMD_TXEN, leuartEnable = (LEUART_CMD_RXEN | LEUART_CMD_TXEN) } |
enum | LEUART_Parity_TypeDef { leuartNoParity = LEUART_CTRL_PARITY_NONE, leuartEvenParity = LEUART_CTRL_PARITY_EVEN, leuartOddParity = LEUART_CTRL_PARITY_ODD } |
enum | LEUART_Stopbits_TypeDef { leuartStopbits1 = LEUART_CTRL_STOPBITS_ONE, leuartStopbits2 = LEUART_CTRL_STOPBITS_TWO } |
Functions | |
uint32_t | LEUART_BaudrateCalc (uint32_t refFreq, uint32_t clkdiv) |
Calculate baudrate for LEUART given reference frequency and clock division. More... | |
uint32_t | LEUART_BaudrateGet (LEUART_TypeDef *leuart) |
Get current baudrate for LEUART. More... | |
void | LEUART_BaudrateSet (LEUART_TypeDef *leuart, uint32_t refFreq, uint32_t baudrate) |
Configure baudrate (or as close as possible to specified baudrate). More... | |
void | LEUART_Enable (LEUART_TypeDef *leuart, LEUART_Enable_TypeDef enable) |
Enable/disable LEUART receiver and/or transmitter. More... | |
void | LEUART_FreezeEnable (LEUART_TypeDef *leuart, bool enable) |
LEUART register synchronization freeze control. More... | |
void | LEUART_Init (LEUART_TypeDef *leuart, LEUART_Init_TypeDef const *init) |
Init LEUART. More... | |
__STATIC_INLINE void | LEUART_IntClear (LEUART_TypeDef *leuart, uint32_t flags) |
Clear one or more pending LEUART interrupts. More... | |
__STATIC_INLINE void | LEUART_IntDisable (LEUART_TypeDef *leuart, uint32_t flags) |
Disable one or more LEUART interrupts. More... | |
__STATIC_INLINE void | LEUART_IntEnable (LEUART_TypeDef *leuart, uint32_t flags) |
Enable one or more LEUART interrupts. More... | |
__STATIC_INLINE uint32_t | LEUART_IntGet (LEUART_TypeDef *leuart) |
Get pending LEUART interrupt flags. More... | |
__STATIC_INLINE uint32_t | LEUART_IntGetEnabled (LEUART_TypeDef *leuart) |
Get enabled and pending LEUART interrupt flags. Useful for handling more interrupt sources in the same interrupt handler. More... | |
__STATIC_INLINE void | LEUART_IntSet (LEUART_TypeDef *leuart, uint32_t flags) |
Set one or more pending LEUART interrupts from SW. More... | |
void | LEUART_Reset (LEUART_TypeDef *leuart) |
Reset LEUART to same state as after a HW reset. More... | |
uint8_t | LEUART_Rx (LEUART_TypeDef *leuart) |
Receive one 8 bit frame, (or part of 9 bit frame). More... | |
__STATIC_INLINE uint8_t | LEUART_RxDataGet (LEUART_TypeDef *leuart) |
Receive one 8 bit frame, (or part of a 9 bit frame). More... | |
__STATIC_INLINE uint16_t | LEUART_RxDataXGet (LEUART_TypeDef *leuart) |
Receive one 8-9 bit frame, with extended information. More... | |
void | LEUART_RxDmaInEM2Enable (LEUART_TypeDef *leuart, bool enable) |
Enables handling of LEUART RX by DMA in EM2. More... | |
uint16_t | LEUART_RxExt (LEUART_TypeDef *leuart) |
Receive one 8-9 bit frame, with extended information. More... | |
__STATIC_INLINE uint32_t | LEUART_StatusGet (LEUART_TypeDef *leuart) |
Get LEUART STATUS register. More... | |
void | LEUART_Tx (LEUART_TypeDef *leuart, uint8_t data) |
Transmit one frame. More... | |
void | LEUART_TxDmaInEM2Enable (LEUART_TypeDef *leuart, bool enable) |
Enables handling of LEUART TX by DMA in EM2. More... | |
void | LEUART_TxExt (LEUART_TypeDef *leuart, uint16_t data) |
Transmit one 8-9 bit frame with extended control. More... | |
#define LEUART_INIT_DEFAULT |
Default config for LEUART init structure.
Definition at line 132 of file em_leuart.h.
Referenced by BSP_BccInit(), RETARGET_SerialInit(), and UARTDRV_InitLeuart().
Databit selection.
Enumerator | |
---|---|
leuartDatabits8 |
8 databits. |
leuartDatabits9 |
9 databits. |
Definition at line 61 of file em_leuart.h.
Enable selection.
Definition at line 69 of file em_leuart.h.
Parity selection.
Enumerator | |
---|---|
leuartNoParity |
No parity. |
leuartEvenParity |
Even parity. |
leuartOddParity |
Odd parity. |
Definition at line 86 of file em_leuart.h.
Stopbits selection.
Enumerator | |
---|---|
leuartStopbits1 |
1 stopbits. |
leuartStopbits2 |
2 stopbits. |
Definition at line 95 of file em_leuart.h.
uint32_t LEUART_BaudrateCalc | ( | uint32_t | refFreq, |
uint32_t | clkdiv | ||
) |
Calculate baudrate for LEUART given reference frequency and clock division.
This function returns the baudrate that a LEUART module will use if configured with the given frequency and clock divisor. Notice that this function will not use actual HW configuration. It can be used to determinate if a given configuration is sufficiently accurate for the application.
[in] | refFreq | LEUART peripheral frequency used. |
[in] | clkdiv | Clock division factor to be used. |
Definition at line 134 of file em_leuart.c.
References _LEUART_CLKDIV_MASK.
Referenced by LEUART_BaudrateGet().
uint32_t LEUART_BaudrateGet | ( | LEUART_TypeDef * | leuart | ) |
Get current baudrate for LEUART.
This function returns the actual baudrate (not considering oscillator inaccuracies) used by a LEUART peripheral.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 212 of file em_leuart.c.
References LEUART_TypeDef::CLKDIV, CMU_ClockFreqGet(), cmuClock_LEUART0, LEUART0, and LEUART_BaudrateCalc().
void LEUART_BaudrateSet | ( | LEUART_TypeDef * | leuart, |
uint32_t | refFreq, | ||
uint32_t | baudrate | ||
) |
Configure baudrate (or as close as possible to specified baudrate).
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | refFreq | LEUART reference clock frequency in Hz that will be used. If set to 0, the currently configured reference clock is assumed. |
[in] | baudrate | Baudrate to try to achieve for LEUART. |
Definition at line 260 of file em_leuart.c.
References _LEUART_CLKDIV_MASK, LEUART_TypeDef::CLKDIV, CMU_ClockFreqGet(), cmuClock_LEUART0, LEUART0, and LEUART_SYNCBUSY_CLKDIV.
Referenced by LEUART_Init().
void LEUART_Enable | ( | LEUART_TypeDef * | leuart, |
LEUART_Enable_TypeDef | enable | ||
) |
Enable/disable LEUART receiver and/or transmitter.
Notice that this function does not do any configuration. Enabling should normally be done after initialization is done (if not enabled as part of init).
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | enable | Select status for receiver/transmitter. |
Definition at line 357 of file em_leuart.c.
References _LEUART_CMD_RXEN_MASK, _LEUART_CMD_TXEN_MASK, LEUART_TypeDef::CMD, and LEUART_SYNCBUSY_CMD.
Referenced by RETARGET_SerialInit(), and UARTDRV_InitLeuart().
void LEUART_FreezeEnable | ( | LEUART_TypeDef * | leuart, |
bool | enable | ||
) |
LEUART register synchronization freeze control.
Some LEUART registers require synchronization into the low frequency (LF) domain. The freeze feature allows for several such registers to be modified before passing them to the LF domain simultaneously (which takes place when the freeze mode is disabled).
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | enable |
|
Definition at line 405 of file em_leuart.c.
References LEUART_TypeDef::FREEZE, LEUART_FREEZE_REGFREEZE, and LEUART_TypeDef::SYNCBUSY.
Referenced by LEUART_Init(), and LEUART_Reset().
void LEUART_Init | ( | LEUART_TypeDef * | leuart, |
LEUART_Init_TypeDef const * | init | ||
) |
Init LEUART.
This function will configure basic settings in order to operate in normal asynchronous mode. Consider using LEUART_Reset() prior to this function if state of configuration is not known, since only configuration settings specified by init
are set.
Special control setup not covered by this function may be done either before or after using this function (but normally before enabling) by direct modification of the CTRL register.
Notice that pins used by the LEUART module must be properly configured by the user explicitly, in order for the LEUART to work as intended. (When configuring pins, one should remember to consider the sequence of configuration, in order to avoid unintended pulses/glitches on output pins.)
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | init | Pointer to initialization structure used to configure basic async setup. |
Definition at line 461 of file em_leuart.c.
References _LEUART_CTRL_PARITY_MASK, _LEUART_CTRL_STOPBITS_MASK, LEUART_Init_TypeDef::baudrate, LEUART_TypeDef::CMD, LEUART_TypeDef::CTRL, LEUART_Init_TypeDef::databits, LEUART_Init_TypeDef::enable, LEUART_BaudrateSet(), LEUART_CMD_RXDIS, LEUART_CMD_TXDIS, LEUART_FreezeEnable(), LEUART_SYNCBUSY_CMD, LEUART_Init_TypeDef::parity, LEUART_Init_TypeDef::refFreq, and LEUART_Init_TypeDef::stopbits.
Referenced by BSP_BccInit(), RETARGET_SerialInit(), and UARTDRV_InitLeuart().
__STATIC_INLINE void LEUART_IntClear | ( | LEUART_TypeDef * | leuart, |
uint32_t | flags | ||
) |
Clear one or more pending LEUART interrupts.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | flags | Pending LEUART interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for the LEUART module (LEUART_IF_nnn). |
Definition at line 169 of file em_leuart.h.
References LEUART_TypeDef::IFC.
Referenced by RETARGET_SerialInit(), and UARTDRV_InitLeuart().
__STATIC_INLINE void LEUART_IntDisable | ( | LEUART_TypeDef * | leuart, |
uint32_t | flags | ||
) |
Disable one or more LEUART interrupts.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | flags | LEUART interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for the LEUART module (LEUART_IF_nnn). |
Definition at line 186 of file em_leuart.h.
References LEUART_TypeDef::IEN.
__STATIC_INLINE void LEUART_IntEnable | ( | LEUART_TypeDef * | leuart, |
uint32_t | flags | ||
) |
Enable one or more LEUART interrupts.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | flags | LEUART interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for the LEUART module (LEUART_IF_nnn). |
Definition at line 208 of file em_leuart.h.
References LEUART_TypeDef::IEN.
Referenced by RETARGET_SerialInit().
__STATIC_INLINE uint32_t LEUART_IntGet | ( | LEUART_TypeDef * | leuart | ) |
Get pending LEUART interrupt flags.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 228 of file em_leuart.h.
References LEUART_TypeDef::IF.
__STATIC_INLINE uint32_t LEUART_IntGetEnabled | ( | LEUART_TypeDef * | leuart | ) |
Get enabled and pending LEUART interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 253 of file em_leuart.h.
References LEUART_TypeDef::IEN, and LEUART_TypeDef::IF.
__STATIC_INLINE void LEUART_IntSet | ( | LEUART_TypeDef * | leuart, |
uint32_t | flags | ||
) |
Set one or more pending LEUART interrupts from SW.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | flags | LEUART interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for the LEUART module (LEUART_IF_nnn). |
Definition at line 277 of file em_leuart.h.
References LEUART_TypeDef::IFS.
void LEUART_Reset | ( | LEUART_TypeDef * | leuart | ) |
Reset LEUART to same state as after a HW reset.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 500 of file em_leuart.c.
References _LEUART_CLKDIV_RESETVALUE, _LEUART_CTRL_RESETVALUE, _LEUART_IEN_RESETVALUE, _LEUART_IFC_MASK, _LEUART_PULSECTRL_RESETVALUE, _LEUART_ROUTELOC0_RESETVALUE, _LEUART_ROUTEPEN_RESETVALUE, _LEUART_SIGFRAME_RESETVALUE, _LEUART_STARTFRAME_RESETVALUE, LEUART_TypeDef::CLKDIV, LEUART_TypeDef::CMD, LEUART_TypeDef::CTRL, LEUART_TypeDef::IEN, LEUART_TypeDef::IFC, LEUART_CMD_CLEARRX, LEUART_CMD_CLEARTX, LEUART_CMD_RXBLOCKDIS, LEUART_CMD_RXDIS, LEUART_CMD_TXDIS, LEUART_FreezeEnable(), LEUART_TypeDef::PULSECTRL, LEUART_TypeDef::ROUTELOC0, LEUART_TypeDef::ROUTEPEN, LEUART_TypeDef::SIGFRAME, and LEUART_TypeDef::STARTFRAME.
Referenced by BSP_BccDeInit(), and UARTDRV_DeInit().
uint8_t LEUART_Rx | ( | LEUART_TypeDef * | leuart | ) |
Receive one 8 bit frame, (or part of 9 bit frame).
This function is normally used to receive one frame when operating with frame length 8 bits. Please refer to LEUART_RxExt() for reception of 9 bit frames.
Notice that possible parity/stop bits are not considered part of specified frame bit length.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 551 of file em_leuart.c.
References LEUART_STATUS_RXDATAV, LEUART_TypeDef::RXDATA, and LEUART_TypeDef::STATUS.
__STATIC_INLINE uint8_t LEUART_RxDataGet | ( | LEUART_TypeDef * | leuart | ) |
Receive one 8 bit frame, (or part of a 9 bit frame).
This function is used to quickly receive one 8 bit frame by reading the RXDATA register directly, without checking the STATUS register for the RXDATAV flag. This can be useful from the RXDATAV interrupt handler, i.e. waiting is superfluous, in order to quickly read the received data. Please refer to LEUART_RxDataXGet() for reception of 9 bit frames.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 334 of file em_leuart.h.
References LEUART_TypeDef::RXDATA.
__STATIC_INLINE uint16_t LEUART_RxDataXGet | ( | LEUART_TypeDef * | leuart | ) |
Receive one 8-9 bit frame, with extended information.
This function is used to quickly receive one 8-9 bit frame with extended information by reading the RXDATAX register directly, without checking the STATUS register for the RXDATAV flag. This can be useful from the RXDATAV interrupt handler, i.e. waiting is superfluous, in order to quickly read the received data.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 368 of file em_leuart.h.
References LEUART_TypeDef::RXDATAX.
void LEUART_RxDmaInEM2Enable | ( | LEUART_TypeDef * | leuart, |
bool | enable | ||
) |
Enables handling of LEUART RX by DMA in EM2.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | enable | true - enables functionality false - disables functionality |
Definition at line 692 of file em_leuart.c.
References LEUART_TypeDef::CTRL, LEUART_CTRL_RXDMAWU, and LEUART_SYNCBUSY_CTRL.
uint16_t LEUART_RxExt | ( | LEUART_TypeDef * | leuart | ) |
Receive one 8-9 bit frame, with extended information.
This function is normally used to receive one frame and additional RX status information is required.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 577 of file em_leuart.c.
References LEUART_STATUS_RXDATAV, LEUART_TypeDef::RXDATAX, and LEUART_TypeDef::STATUS.
__STATIC_INLINE uint32_t LEUART_StatusGet | ( | LEUART_TypeDef * | leuart | ) |
Get LEUART STATUS register.
[in] | leuart | Pointer to LEUART peripheral register block. |
Definition at line 294 of file em_leuart.h.
References LEUART_TypeDef::STATUS.
void LEUART_Tx | ( | LEUART_TypeDef * | leuart, |
uint8_t | data | ||
) |
Transmit one frame.
Depending on frame length configuration, 8 (least significant) bits from data
are transmitted. If frame length is 9, 8 bits are transmitted from data
and one bit as specified by CTRL register, BIT8DV field. Please refer to LEUART_TxExt() for transmitting 9 bit frame with full control of all 9 bits.
Notice that possible parity/stop bits in asynchronous mode are not considered part of specified frame bit length.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | data | Data to transmit. See details above for further info. |
Definition at line 609 of file em_leuart.c.
References LEUART_STATUS_TXBL, LEUART_SYNCBUSY_TXDATA, LEUART_TypeDef::STATUS, and LEUART_TypeDef::TXDATA.
Referenced by UARTDRV_ForceTransmit().
void LEUART_TxDmaInEM2Enable | ( | LEUART_TypeDef * | leuart, |
bool | enable | ||
) |
Enables handling of LEUART TX by DMA in EM2.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | enable | true - enables functionality false - disables functionality |
Definition at line 665 of file em_leuart.c.
References LEUART_TypeDef::CTRL, LEUART_CTRL_TXDMAWU, and LEUART_SYNCBUSY_CTRL.
void LEUART_TxExt | ( | LEUART_TypeDef * | leuart, |
uint16_t | data | ||
) |
Transmit one 8-9 bit frame with extended control.
Notice that possible parity/stop bits in asynchronous mode are not considered part of specified frame bit length.
[in] | leuart | Pointer to LEUART peripheral register block. |
[in] | data | Data to transmit with extended control. Least significant bits contains frame bits, and additional control bits are available as documented in the reference manual (set to 0 if not used). |
Definition at line 641 of file em_leuart.c.
References LEUART_STATUS_TXBL, LEUART_SYNCBUSY_TXDATAX, LEUART_TypeDef::STATUS, and LEUART_TypeDef::TXDATAX.