M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
uart.h
Go to the documentation of this file.
1/**************************************************************************/
8#ifndef __UART_H__
9#define __UART_H__
10
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17
30/*---------------------------------------------------------------------------------------------------------*/
31/* UART FIFO size constants definitions */
32/*---------------------------------------------------------------------------------------------------------*/
33
34#define UART0_FIFO_SIZE 16
35#define UART1_FIFO_SIZE 16
36#define UART2_FIFO_SIZE 16
37#define UART3_FIFO_SIZE 16
39/*---------------------------------------------------------------------------------------------------------*/
40/* UART_FIFO constants definitions */
41/*---------------------------------------------------------------------------------------------------------*/
42
43#define UART_FIFO_RFITL_1BYTE (0x0 << UART_FIFO_RFITL_Pos)
44#define UART_FIFO_RFITL_4BYTES (0x1 << UART_FIFO_RFITL_Pos)
45#define UART_FIFO_RFITL_8BYTES (0x2 << UART_FIFO_RFITL_Pos)
46#define UART_FIFO_RFITL_14BYTES (0x3 << UART_FIFO_RFITL_Pos)
48#define UART_FIFO_RTSTRGLV_1BYTE (0x0 << UART_FIFO_RTSTRGLV_Pos)
49#define UART_FIFO_RTSTRGLV_4BYTES (0x1 << UART_FIFO_RTSTRGLV_Pos)
50#define UART_FIFO_RTSTRGLV_8BYTES (0x2 << UART_FIFO_RTSTRGLV_Pos)
51#define UART_FIFO_RTSTRGLV_14BYTES (0x3 << UART_FIFO_RTSTRGLV_Pos)
53/*---------------------------------------------------------------------------------------------------------*/
54/* UART_LINE constants definitions */
55/*---------------------------------------------------------------------------------------------------------*/
56#define UART_WORD_LEN_5 (0)
57#define UART_WORD_LEN_6 (1)
58#define UART_WORD_LEN_7 (2)
59#define UART_WORD_LEN_8 (3)
61#define UART_PARITY_NONE (0x0 << UART_LINE_PBE_Pos)
62#define UART_PARITY_ODD (0x1 << UART_LINE_PBE_Pos)
63#define UART_PARITY_EVEN (0x3 << UART_LINE_PBE_Pos)
64#define UART_PARITY_MARK (0x5 << UART_LINE_PBE_Pos)
65#define UART_PARITY_SPACE (0x7 << UART_LINE_PBE_Pos)
67#define UART_STOP_BIT_1 (0x0 << UART_LINE_NSB_Pos)
68#define UART_STOP_BIT_1_5 (0x1 << UART_LINE_NSB_Pos)
69#define UART_STOP_BIT_2 (0x1 << UART_LINE_NSB_Pos)
72/*---------------------------------------------------------------------------------------------------------*/
73/* UART RTS ACTIVE LEVEL constants definitions */
74/*---------------------------------------------------------------------------------------------------------*/
75#define UART_RTS_IS_LOW_LEV_ACTIVE (0x1 << UART_MODEM_RTSACTLV_Pos)
76#define UART_RTS_IS_HIGH_LEV_ACTIVE (0x0 << UART_MODEM_RTSACTLV_Pos)
79/*---------------------------------------------------------------------------------------------------------*/
80/* UART_IRDA constants definitions */
81/*---------------------------------------------------------------------------------------------------------*/
82#define UART_IRDA_TXEN (0x1 << UART_IRDA_TXEN_Pos)
83#define UART_IRDA_RXEN (0x0 << UART_IRDA_TXEN_Pos)
86/*---------------------------------------------------------------------------------------------------------*/
87/* UART_FUNCSEL constants definitions */
88/*---------------------------------------------------------------------------------------------------------*/
89#define UART_FUNCSEL_UART (0x0 << UART_FUNCSEL_FUNCSEL_Pos)
90#define UART_FUNCSEL_IrDA (0x2 << UART_FUNCSEL_FUNCSEL_Pos)
91#define UART_FUNCSEL_RS485 (0x3 << UART_FUNCSEL_FUNCSEL_Pos)
94/*---------------------------------------------------------------------------------------------------------*/
95/* UART BAUDRATE MODE constants definitions */
96/*---------------------------------------------------------------------------------------------------------*/
97#define UART_BAUD_MODE0 (0)
98#define UART_BAUD_MODE2 (UART_BAUD_BAUDM1_Msk | UART_BAUD_BAUDM0_Msk) /* end of group UART_EXPORTED_CONSTANTS */
102
103
119#define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate) ((((u32SrcFreq) + ((u32BaudRate)*8)) / (u32BaudRate) >> 4)-2)
120
121
132#define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate) ((((u32SrcFreq) + ((u32BaudRate)/2)) / (u32BaudRate))-2)
133
134
145#define UART_WRITE(uart, u8Data) ((uart)->DAT = (u8Data))
146
147
157#define UART_READ(uart) ((uart)->DAT)
158
159
170#define UART_GET_TX_EMPTY(uart) ((uart)->FIFOSTS & UART_FIFOSTS_TXEMPTY_Msk)
171
172
183#define UART_GET_RX_EMPTY(uart) ((uart)->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk)
184
185
197#define UART_IS_TX_EMPTY(uart) (((uart)->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos)
198
199
209#define UART_WAIT_TX_EMPTY(uart) while(!((((uart)->FIFOSTS) & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos))
210
211
222#define UART_IS_RX_READY(uart) (((uart)->INTSTS & UART_INTSTS_RDAIF_Msk)>>UART_INTSTS_RDAIF_Pos)
223
224
235#define UART_IS_TX_FULL(uart) (((uart)->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)>>UART_FIFOSTS_TXFULL_Pos)
236
237
248#define UART_IS_RX_FULL(uart) (((uart)->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)>>UART_FIFOSTS_RXFULL_Pos)
249
250
261#define UART_GET_TX_FULL(uart) ((uart)->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)
262
263
274#define UART_GET_RX_FULL(uart) ((uart)->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)
275
276
296#define UART_ENABLE_INT(uart, u32eIntSel) ((uart)->INTEN |= (u32eIntSel))
297
298
318#define UART_DISABLE_INT(uart, u32eIntSel) ((uart)->INTEN &= ~ (u32eIntSel))
319
320
352#define UART_GET_INT_FLAG(uart,u32eIntTypeFlag) (((uart)->INTSTS & (u32eIntTypeFlag))?1:0)
353
354
364__STATIC_INLINE void UART_CLEAR_RTS(UART_T* uart)
365{
367 uart->MODEM &= ~UART_MODEM_RTS_Msk;
368}
369
370
380__STATIC_INLINE void UART_SET_RTS(UART_T* uart)
381{
383}
384
385
395#define UART_RS485_CLEAR_ADDR_FLAG(uart) ((uart)->FIFOSTS = UART_FIFOSTS_ADDRDETF_Msk)
396
397
408#define UART_RS485_GET_ADDR_FLAG(uart) (((uart)->FIFOSTS & UART_FIFOSTS_ADDRDETF_Msk) >> UART_FIFOSTS_ADDRDETF_Pos)
409
410
411void UART_ClearIntFlag(UART_T* uart, uint32_t u32InterruptFlag);
412void UART_Close(UART_T* uart);
413void UART_DisableFlowCtrl(UART_T* uart);
414void UART_DisableInt(UART_T* uart, uint32_t u32InterruptFlag);
415void UART_EnableFlowCtrl(UART_T* uart);
416void UART_EnableInt(UART_T* uart, uint32_t u32InterruptFlag);
417void UART_Open(UART_T* uart, uint32_t u32baudrate);
418uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
419void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
420void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
421void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
422void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
423uint32_t UART_Write(UART_T* uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes);
424
425
426
427 /* end of group UART_EXPORTED_FUNCTIONS */
429 /* end of group UART_Driver */
431 /* end of group Standard_Driver */
433
434#ifdef __cplusplus
435}
436#endif
437
438#endif //__UART_H__
439
#define UART_MODEM_RTS_Msk
Definition: M471M_R1_S.h:11987
#define UART_MODEM_RTSACTLV_Msk
Definition: M471M_R1_S.h:11990
__IO uint32_t MODEM
Definition: M471M_R1_S.h:11887
void UART_SelectRS485Mode(UART_T *uart, uint32_t u32Mode, uint32_t u32Addr)
Select and configure RS485 function.
Definition: uart.c:402
void UART_EnableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to enable UART specified interrupt and enable NVIC UART IRQ.
Definition: uart.c:164
__STATIC_INLINE void UART_CLEAR_RTS(UART_T *uart)
Set RTS pin to low.
Definition: uart.h:364
__STATIC_INLINE void UART_SET_RTS(UART_T *uart)
Set RTS pin to high.
Definition: uart.h:380
void UART_SetTimeoutCnt(UART_T *uart, uint32_t u32TOC)
Set Rx timeout count.
Definition: uart.c:322
void UART_Close(UART_T *uart)
Disable UART interrupt.
Definition: uart.c:78
void UART_ClearIntFlag(UART_T *uart, uint32_t u32InterruptFlag)
Clear UART specified interrupt flag.
Definition: uart.c:40
void UART_DisableFlowCtrl(UART_T *uart)
Disable UART auto flow control function.
Definition: uart.c:93
void UART_EnableFlowCtrl(UART_T *uart)
Enable UART auto flow control function.
Definition: uart.c:133
uint32_t UART_Write(UART_T *uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
Write UART data.
Definition: uart.c:426
void UART_SetLine_Config(UART_T *uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits)
Set UART line configuration.
Definition: uart.c:280
void UART_DisableInt(UART_T *uart, uint32_t u32InterruptFlag)
Disable UART specified interrupt.
Definition: uart.c:117
void UART_SelectIrDAMode(UART_T *uart, uint32_t u32Buadrate, uint32_t u32Direction)
Select and configure IrDA function.
Definition: uart.c:345
uint32_t UART_Read(UART_T *uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes)
Read UART data.
Definition: uart.c:232
void UART_Open(UART_T *uart, uint32_t u32baudrate)
Open and set UART function.
Definition: uart.c:183