LEUART
[EM_Library]

Low Energy Universal Asynchronous Receiver/Transmitter (LEUART) Peripheral API. More...

Collaboration diagram for LEUART:

Data Structures

struct  LEUART_Init_TypeDef

Defines

#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.
uint32_t LEUART_BaudrateGet (LEUART_TypeDef *leuart)
 Get current baudrate for LEUART.
void LEUART_BaudrateSet (LEUART_TypeDef *leuart, uint32_t refFreq, uint32_t baudrate)
 Configure baudrate (or as close as possible to specified baudrate).
void LEUART_Enable (LEUART_TypeDef *leuart, LEUART_Enable_TypeDef enable)
 Enable/disable LEUART receiver and/or transmitter.
void LEUART_FreezeEnable (LEUART_TypeDef *leuart, bool enable)
 LEUART register synchronization freeze control.
void LEUART_Init (LEUART_TypeDef *leuart, LEUART_Init_TypeDef const *init)
 Init LEUART.
void LEUART_TxDmaInEM2Enable (LEUART_TypeDef *leuart, bool enable)
 Enables handling of LEUART TX by DMA in EM2.
void LEUART_RxDmaInEM2Enable (LEUART_TypeDef *leuart, bool enable)
 Enables handling of LEUART RX by DMA in EM2.
__STATIC_INLINE void LEUART_IntClear (LEUART_TypeDef *leuart, uint32_t flags)
 Clear one or more pending LEUART interrupts.
__STATIC_INLINE void LEUART_IntDisable (LEUART_TypeDef *leuart, uint32_t flags)
 Disable one or more LEUART interrupts.
__STATIC_INLINE void LEUART_IntEnable (LEUART_TypeDef *leuart, uint32_t flags)
 Enable one or more LEUART interrupts.
__STATIC_INLINE uint32_t LEUART_IntGet (LEUART_TypeDef *leuart)
 Get pending LEUART interrupt flags.
__STATIC_INLINE void LEUART_IntSet (LEUART_TypeDef *leuart, uint32_t flags)
 Set one or more pending LEUART interrupts from SW.
void LEUART_Reset (LEUART_TypeDef *leuart)
 Reset LEUART to same state as after a HW reset.
uint8_t LEUART_Rx (LEUART_TypeDef *leuart)
 Receive one 8 bit frame, (or part of 9 bit frame).
uint16_t LEUART_RxExt (LEUART_TypeDef *leuart)
 Receive one 8-9 bit frame, with extended information.
void LEUART_Tx (LEUART_TypeDef *leuart, uint8_t data)
 Transmit one frame.
void LEUART_TxExt (LEUART_TypeDef *leuart, uint16_t data)
 Transmit one 8-9 bit frame with extended control.

Detailed Description

Low Energy Universal Asynchronous Receiver/Transmitter (LEUART) Peripheral API.


Define Documentation

#define LEUART_INIT_DEFAULT
Value:
{ leuartEnable,      /* Enable RX/TX when init completed. */                                \
    0,                 /* Use current configured reference clock for configuring baudrate. */ \
    9600,              /* 9600 bits/s. */                                                     \
    leuartDatabits8,   /* 8 databits. */                                                      \
    leuartNoParity,    /* No parity. */                                                       \
    leuartStopbits1    /* 1 stopbit. */                                                       \
  }

Default config for LEUART init structure.

Definition at line 133 of file em_leuart.h.


Enumeration Type Documentation

Databit selection.

Enumerator:
leuartDatabits8 

8 databits.

leuartDatabits9 

9 databits.

Definition at line 62 of file em_leuart.h.

Enable selection.

Enumerator:
leuartDisable 

Disable both receiver and transmitter.

leuartEnableRx 

Enable receiver only, transmitter disabled.

leuartEnableTx 

Enable transmitter only, receiver disabled.

leuartEnable 

Enable both receiver and transmitter.

Definition at line 70 of file em_leuart.h.

Parity selection.

Enumerator:
leuartNoParity 

No parity.

leuartEvenParity 

Even parity.

leuartOddParity 

Odd parity.

Definition at line 87 of file em_leuart.h.

Stopbits selection.

Enumerator:
leuartStopbits1 

1 stopbits.

leuartStopbits2 

2 stopbits.

Definition at line 96 of file em_leuart.h.


Function Documentation

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.

Parameters:
[in] refFreq LEUART peripheral frequency used.
[in] clkdiv Clock division factor to be used.
Returns:
Baudrate with given settings.

Definition at line 130 of file em_leuart.c.

Referenced by LEUART_BaudrateGet().

Here is the caller graph for this function:

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.

Parameters:
[in] leuart Pointer to LEUART peripheral register block.
Returns:
Current baudrate.

Definition at line 209 of file em_leuart.c.

References CMU_ClockFreqGet(), cmuClock_LEUART0, cmuClock_LEUART1, and LEUART_BaudrateCalc().

Here is the call graph for this function:

void LEUART_BaudrateSet ( LEUART_TypeDef *  leuart,
uint32_t  refFreq,
uint32_t  baudrate 
)

Configure baudrate (or as close as possible to specified baudrate).

Note:
The setting of a baudrate requires synchronization into the low frequency domain. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed.
Parameters:
[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 257 of file em_leuart.c.

References CMU_ClockFreqGet(), cmuClock_LEUART0, and cmuClock_LEUART1.

Referenced by LEUART_Init().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Note:
Enabling/disabling requires synchronization into the low frequency domain. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
[in] enable Select status for receiver/transmitter.

Definition at line 354 of file em_leuart.c.

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).

Note:
When enabling freeze mode, this function will wait for all current ongoing LEUART synchronization to LF domain to complete (Normally synchronization will not be in progress.) However for this reason, when using freeze mode, modifications of registers requiring LF synchronization should be done within one freeze enable/disable block to avoid unecessary stalling.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
[in] enable 
  • true - enable freeze, modified registers are not propagated to the LF domain
  • false - disables freeze, modified registers are propagated to LF domain

Definition at line 402 of file em_leuart.c.

Referenced by LEUART_Init(), and LEUART_Reset().

Here is the caller graph for this function:

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.)

Note:
Initializing requires synchronization into the low frequency domain. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
[in] init Pointer to initialization structure used to configure basic async setup.

Definition at line 458 of file em_leuart.c.

References LEUART_Init_TypeDef::baudrate, LEUART_Init_TypeDef::databits, LEUART_Init_TypeDef::enable, LEUART_BaudrateSet(), LEUART_FreezeEnable(), LEUART_Init_TypeDef::parity, LEUART_Init_TypeDef::refFreq, and LEUART_Init_TypeDef::stopbits.

Here is the call graph for this function:

__STATIC_INLINE void LEUART_IntClear ( LEUART_TypeDef *  leuart,
uint32_t  flags 
)

Clear one or more pending LEUART interrupts.

Parameters:
[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.

__STATIC_INLINE void LEUART_IntDisable ( LEUART_TypeDef *  leuart,
uint32_t  flags 
)

Disable one or more LEUART interrupts.

Parameters:
[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.

__STATIC_INLINE void LEUART_IntEnable ( LEUART_TypeDef *  leuart,
uint32_t  flags 
)

Enable one or more LEUART interrupts.

Note:
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. Consider using LEUART_IntClear() prior to enabling if such a pending interrupt should be ignored.
Parameters:
[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.

__STATIC_INLINE uint32_t LEUART_IntGet ( LEUART_TypeDef *  leuart  ) 

Get pending LEUART interrupt flags.

Note:
The event bits are not cleared by the use of this function.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
Returns:
LEUART interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for the LEUART module (LEUART_IF_nnn).

Definition at line 228 of file em_leuart.h.

__STATIC_INLINE void LEUART_IntSet ( LEUART_TypeDef *  leuart,
uint32_t  flags 
)

Set one or more pending LEUART interrupts from SW.

Parameters:
[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 245 of file em_leuart.h.

void LEUART_Reset ( LEUART_TypeDef *  leuart  ) 

Reset LEUART to same state as after a HW reset.

Parameters:
[in] leuart Pointer to LEUART peripheral register block.

Definition at line 497 of file em_leuart.c.

References LEUART_FreezeEnable().

Here is the call graph for this function:

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.

Note:
This function will stall if buffer is empty, until data is received.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
Returns:
Data received.

Definition at line 543 of file em_leuart.c.

void LEUART_RxDmaInEM2Enable ( LEUART_TypeDef *  leuart,
bool  enable 
)

Enables handling of LEUART RX by DMA in EM2.

Parameters:
[in] leuart Pointer to LEUART peripheral register block.
[in] enable true - enables functionality false - disables functionality

Definition at line 684 of file em_leuart.c.

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.

Note:
This function will stall if buffer is empty, until data is received.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
Returns:
Data received.

Definition at line 569 of file em_leuart.c.

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.

Note:
This function will stall if buffer is full, until buffer becomes available.
Parameters:
[in] leuart Pointer to LEUART peripheral register block.
[in] data Data to transmit. See details above for further info.

Definition at line 601 of file em_leuart.c.

void LEUART_TxDmaInEM2Enable ( LEUART_TypeDef *  leuart,
bool  enable 
)

Enables handling of LEUART TX by DMA in EM2.

Parameters:
[in] leuart Pointer to LEUART peripheral register block.
[in] enable true - enables functionality false - disables functionality

Definition at line 657 of file em_leuart.c.

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.

Note:
This function will stall if buffer is full, until buffer becomes available.
Parameters:
[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 EFM32 reference manual (set to 0 if not used).

Definition at line 633 of file em_leuart.c.