EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
em_leuart.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef EM_LEUART_H
35 #define EM_LEUART_H
36 
37 #include "em_device.h"
38 #if defined(LEUART_COUNT) && (LEUART_COUNT > 0)
39 
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
56 /*******************************************************************************
57  ******************************** ENUMS ************************************
58  ******************************************************************************/
59 
61 typedef enum
62 {
66 
67 
69 typedef enum
70 {
73 
76 
79 
83 
84 
86 typedef enum
87 {
92 
93 
95 typedef enum
96 {
100 
101 
102 /*******************************************************************************
103  ******************************* STRUCTS ***********************************
104  ******************************************************************************/
105 
107 typedef struct
108 {
111 
116  uint32_t refFreq;
117 
119  uint32_t baudrate;
120 
123 
126 
130 
132 #define LEUART_INIT_DEFAULT \
133 { \
134  leuartEnable, /* Enable RX/TX when init completed. */ \
135  0, /* Use current configured reference clock for configuring baudrate. */ \
136  9600, /* 9600 bits/s. */ \
137  leuartDatabits8, /* 8 databits. */ \
138  leuartNoParity, /* No parity. */ \
139  leuartStopbits1 /* 1 stopbit. */ \
140 }
141 
142 
143 /*******************************************************************************
144  ***************************** PROTOTYPES **********************************
145  ******************************************************************************/
146 
147 uint32_t LEUART_BaudrateCalc(uint32_t refFreq, uint32_t clkdiv);
148 uint32_t LEUART_BaudrateGet(LEUART_TypeDef *leuart);
150  uint32_t refFreq,
151  uint32_t baudrate);
153 void LEUART_FreezeEnable(LEUART_TypeDef *leuart, bool enable);
154 void LEUART_Init(LEUART_TypeDef *leuart, LEUART_Init_TypeDef const *init);
155 void LEUART_TxDmaInEM2Enable(LEUART_TypeDef *leuart, bool enable);
156 void LEUART_RxDmaInEM2Enable(LEUART_TypeDef *leuart, bool enable);
157 
158 /***************************************************************************/
169 __STATIC_INLINE void LEUART_IntClear(LEUART_TypeDef *leuart, uint32_t flags)
170 {
171  leuart->IFC = flags;
172 }
173 
174 
175 /***************************************************************************/
186 __STATIC_INLINE void LEUART_IntDisable(LEUART_TypeDef *leuart, uint32_t flags)
187 {
188  leuart->IEN &= ~flags;
189 }
190 
191 
192 /***************************************************************************/
208 __STATIC_INLINE void LEUART_IntEnable(LEUART_TypeDef *leuart, uint32_t flags)
209 {
210  leuart->IEN |= flags;
211 }
212 
213 
214 /***************************************************************************/
228 __STATIC_INLINE uint32_t LEUART_IntGet(LEUART_TypeDef *leuart)
229 {
230  return leuart->IF;
231 }
232 
233 
234 /***************************************************************************/
253 __STATIC_INLINE uint32_t LEUART_IntGetEnabled(LEUART_TypeDef *leuart)
254 {
255  uint32_t tmp;
256 
257  /* Store LEUARTx->IEN in temporary variable in order to define explicit order
258  * of volatile accesses. */
259  tmp = leuart->IEN;
260 
261  /* Bitwise AND of pending and enabled interrupts */
262  return leuart->IF & tmp;
263 }
264 
265 
266 /***************************************************************************/
277 __STATIC_INLINE void LEUART_IntSet(LEUART_TypeDef *leuart, uint32_t flags)
278 {
279  leuart->IFS = flags;
280 }
281 
282 
283 /***************************************************************************/
294 __STATIC_INLINE uint32_t LEUART_StatusGet(LEUART_TypeDef *leuart)
295 {
296  return leuart->STATUS;
297 }
298 
299 void LEUART_Reset(LEUART_TypeDef *leuart);
300 uint8_t LEUART_Rx(LEUART_TypeDef *leuart);
301 uint16_t LEUART_RxExt(LEUART_TypeDef *leuart);
302 void LEUART_Tx(LEUART_TypeDef *leuart, uint8_t data);
303 void LEUART_TxExt(LEUART_TypeDef *leuart, uint16_t data);
304 
305 
306 /***************************************************************************/
334 __STATIC_INLINE uint8_t LEUART_RxDataGet(LEUART_TypeDef *leuart)
335 {
336  return (uint8_t)leuart->RXDATA;
337 }
338 
339 
340 /***************************************************************************/
368 __STATIC_INLINE uint16_t LEUART_RxDataXGet(LEUART_TypeDef *leuart)
369 {
370  return (uint16_t)leuart->RXDATAX;
371 }
372 
373 
377 #ifdef __cplusplus
378 }
379 #endif
380 
381 #endif /* defined(LEUART_COUNT) && (LEUART_COUNT > 0) */
382 #endif /* EM_LEUART_H */
void LEUART_Tx(LEUART_TypeDef *leuart, uint8_t data)
Transmit one frame.
Definition: em_leuart.c:609
LEUART_Parity_TypeDef
Definition: em_leuart.h:86
LEUART_Stopbits_TypeDef stopbits
Definition: em_leuart.h:128
#define LEUART_CMD_RXEN
__STATIC_INLINE uint8_t LEUART_RxDataGet(LEUART_TypeDef *leuart)
Receive one 8 bit frame, (or part of a 9 bit frame).
Definition: em_leuart.h:334
__IOM uint32_t IFS
Definition: efm32g_leuart.h:55
#define LEUART_CTRL_DATABITS_EIGHT
Definition: efm32g_leuart.h:87
__STATIC_INLINE uint16_t LEUART_RxDataXGet(LEUART_TypeDef *leuart)
Receive one 8-9 bit frame, with extended information.
Definition: em_leuart.h:368
#define LEUART_CTRL_PARITY_NONE
Definition: efm32g_leuart.h:96
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__IOM uint32_t IEN
Definition: efm32g_leuart.h:57
__STATIC_INLINE void LEUART_IntDisable(LEUART_TypeDef *leuart, uint32_t flags)
Disable one or more LEUART interrupts.
Definition: em_leuart.h:186
#define LEUART_CMD_TXEN
__STATIC_INLINE void LEUART_IntClear(LEUART_TypeDef *leuart, uint32_t flags)
Clear one or more pending LEUART interrupts.
Definition: em_leuart.h:169
void LEUART_Init(LEUART_TypeDef *leuart, LEUART_Init_TypeDef const *init)
Init LEUART.
Definition: em_leuart.c:461
__STATIC_INLINE uint32_t LEUART_IntGetEnabled(LEUART_TypeDef *leuart)
Get enabled and pending LEUART interrupt flags. Useful for handling more interrupt sources in the sam...
Definition: em_leuart.h:253
void LEUART_TxExt(LEUART_TypeDef *leuart, uint16_t data)
Transmit one 8-9 bit frame with extended control.
Definition: em_leuart.c:641
__STATIC_INLINE void LEUART_IntEnable(LEUART_TypeDef *leuart, uint32_t flags)
Enable one or more LEUART interrupts.
Definition: em_leuart.h:208
__STATIC_INLINE uint32_t LEUART_StatusGet(LEUART_TypeDef *leuart)
Get LEUART STATUS register.
Definition: em_leuart.h:294
LEUART_Databits_TypeDef
Definition: em_leuart.h:61
__STATIC_INLINE uint32_t LEUART_IntGet(LEUART_TypeDef *leuart)
Get pending LEUART interrupt flags.
Definition: em_leuart.h:228
void LEUART_BaudrateSet(LEUART_TypeDef *leuart, uint32_t refFreq, uint32_t baudrate)
Configure baudrate (or as close as possible to specified baudrate).
Definition: em_leuart.c:260
#define LEUART_CTRL_PARITY_EVEN
Definition: efm32g_leuart.h:97
uint32_t LEUART_BaudrateGet(LEUART_TypeDef *leuart)
Get current baudrate for LEUART.
Definition: em_leuart.c:212
LEUART_Parity_TypeDef parity
Definition: em_leuart.h:125
__IM uint32_t RXDATAX
Definition: efm32g_leuart.h:49
void LEUART_Enable(LEUART_TypeDef *leuart, LEUART_Enable_TypeDef enable)
Enable/disable LEUART receiver and/or transmitter.
Definition: em_leuart.c:357
__IM uint32_t RXDATA
Definition: efm32g_leuart.h:50
#define LEUART_CTRL_STOPBITS_TWO
#define LEUART_CTRL_DATABITS_NINE
Definition: efm32g_leuart.h:88
LEUART_Stopbits_TypeDef
Definition: em_leuart.h:95
void LEUART_Reset(LEUART_TypeDef *leuart)
Reset LEUART to same state as after a HW reset.
Definition: em_leuart.c:500
__IM uint32_t IF
Definition: efm32g_leuart.h:54
__IM uint32_t STATUS
Definition: efm32g_leuart.h:45
void LEUART_RxDmaInEM2Enable(LEUART_TypeDef *leuart, bool enable)
Enables handling of LEUART RX by DMA in EM2.
Definition: em_leuart.c:692
uint16_t LEUART_RxExt(LEUART_TypeDef *leuart)
Receive one 8-9 bit frame, with extended information.
Definition: em_leuart.c:577
__STATIC_INLINE void LEUART_IntSet(LEUART_TypeDef *leuart, uint32_t flags)
Set one or more pending LEUART interrupts from SW.
Definition: em_leuart.h:277
uint32_t LEUART_BaudrateCalc(uint32_t refFreq, uint32_t clkdiv)
Calculate baudrate for LEUART given reference frequency and clock division.
Definition: em_leuart.c:134
uint8_t LEUART_Rx(LEUART_TypeDef *leuart)
Receive one 8 bit frame, (or part of 9 bit frame).
Definition: em_leuart.c:551
void LEUART_TxDmaInEM2Enable(LEUART_TypeDef *leuart, bool enable)
Enables handling of LEUART TX by DMA in EM2.
Definition: em_leuart.c:665
#define LEUART_CTRL_STOPBITS_ONE
__IOM uint32_t IFC
Definition: efm32g_leuart.h:56
#define LEUART_CTRL_PARITY_ODD
Definition: efm32g_leuart.h:98
void LEUART_FreezeEnable(LEUART_TypeDef *leuart, bool enable)
LEUART register synchronization freeze control.
Definition: em_leuart.c:405
LEUART_Enable_TypeDef
Definition: em_leuart.h:69
LEUART_Databits_TypeDef databits
Definition: em_leuart.h:122
LEUART_Enable_TypeDef enable
Definition: em_leuart.h:110