| MINI58_BSP V3.01.003 The Board Support Package for Mini58 Series MCU

uart.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __UART_H__
13#define __UART_H__
14
15#ifdef __cplusplus
16 extern "C"
17{
18#endif
19
20
33/*---------------------------------------------------------------------------------------------------------*/
34/* UART_FIFO constants definitions */
35/*---------------------------------------------------------------------------------------------------------*/
36
37#define UART_FIFO_RFITL_1BYTE (0x0 << UART_FIFO_RFITL_Pos)
38#define UART_FIFO_RFITL_4BYTES (0x1 << UART_FIFO_RFITL_Pos)
39#define UART_FIFO_RFITL_8BYTES (0x2 << UART_FIFO_RFITL_Pos)
40#define UART_FIFO_RFITL_14BYTES (0x3 << UART_FIFO_RFITL_Pos)
42#define UART_FIFO_RTSTRGLV_1BYTE (0x0 << UART_FIFO_RTSTRGLV_Pos)
43#define UART_FIFO_RTSTRGLV_4BYTES (0x1 << UART_FIFO_RTSTRGLV_Pos)
44#define UART_FIFO_RTSTRGLV_8BYTES (0x2 << UART_FIFO_RTSTRGLV_Pos)
45#define UART_FIFO_RTSTRGLV_14BYTES (0x3 << UART_FIFO_RTSTRGLV_Pos)
47/*---------------------------------------------------------------------------------------------------------*/
48/* UART_LINE constants definitions */
49/*---------------------------------------------------------------------------------------------------------*/
50#define UART_WORD_LEN_5 (0)
51#define UART_WORD_LEN_6 (1)
52#define UART_WORD_LEN_7 (2)
53#define UART_WORD_LEN_8 (3)
55#define UART_PARITY_NONE (0x0 << UART_LINE_PBE_Pos)
56#define UART_PARITY_ODD (0x1 << UART_LINE_PBE_Pos)
57#define UART_PARITY_EVEN (0x3 << UART_LINE_PBE_Pos)
58#define UART_PARITY_MARK (0x5 << UART_LINE_PBE_Pos)
59#define UART_PARITY_SPACE (0x7 << UART_LINE_PBE_Pos)
61#define UART_STOP_BIT_1 (0x0 << UART_LINE_NSB_Pos)
62#define UART_STOP_BIT_1_5 (0x1 << UART_LINE_NSB_Pos)
63#define UART_STOP_BIT_2 (0x1 << UART_LINE_NSB_Pos)
66/*---------------------------------------------------------------------------------------------------------*/
67/* UART RTS LEVEL TRIGGER constants definitions */
68/*---------------------------------------------------------------------------------------------------------*/
69#define UART_RTS_IS_HIGH_LEV_TRG (0x1 << UART_MODEM_RTSACTLV_Pos)
70#define UART_RTS_IS_LOW_LEV_TRG (0x0 << UART_MODEM_RTSACTLV_Pos)
72/*---------------------------------------------------------------------------------------------------------*/
73/* UA_FUNC_SEL constants definitions */
74/*---------------------------------------------------------------------------------------------------------*/
75#define UART_FUNC_SEL_UART (0x0 << UART_FUNSEL_FUN_SEL_Pos)
76#define UART_FUNC_SEL_IrDA (0x2 << UART_FUNSEL_FUN_SEL_Pos)
77#define UART_FUNC_SEL_RS485 (0x3 << UART_FUNSEL_FUN_SEL_Pos) /* end of group Mini58_UART_EXPORTED_CONSTANTS */
81
82
95#define UART_BAUD_MODE0 (0)
96
105#define UART_BAUD_MODE2 (UART_BAUD_BAUDM1_Msk | UART_BAUD_BAUDM0_Msk)
106
107
117#define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate*8)) / u32BaudRate >> 4)-2)
118
127#define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate/2)) / u32BaudRate)-2)
128
129
138#define UART_WRITE(uart, u8Data) (uart->DAT = (u8Data))
139
147#define UART_READ(uart) (uart->DAT)
148
149
157#define UART_GET_TX_EMPTY(uart) (uart->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk)
158
159
167#define UART_GET_RX_EMPTY(uart) (uart->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk)
168
176#define UART_IS_TX_EMPTY(uart) ((uart->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos)
177
178
186#define UART_WAIT_TX_EMPTY(uart) while(!(((uart->FIFOSTS) & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos))
187
197#define UART_IS_RX_READY(uart) ((uart->INTSTS & UART_INTSTS_RDAIF_Msk)>>UART_INTSTS_RDAIF_Pos)
198
199
209#define UART_IS_TX_FULL(uart) ((uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)>>UART_FIFOSTS_TXFULL_Pos)
210
221#define UART_IS_RX_FULL(uart) ((uart->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)>>UART_FIFOSTS_RXFULL_Pos)
222
223
231#define UART_GET_TX_FULL(uart) (uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)
232
233
241#define UART_GET_RX_FULL(uart) (uart->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)
242
243
260#define UART_ENABLE_INT(uart, u32eIntSel) (uart->INTEN |= (u32eIntSel))
261
262
278#define UART_DISABLE_INT(uart, u32eIntSel) (uart->INTEN &= ~ (u32eIntSel))
279
280
304#define UART_GET_INT_FLAG(uart,u32eIntTypeFlag) ((uart->INTSTS & (u32eIntTypeFlag))?1:0)
305
306
313__INLINE void UART_CLEAR_RTS(UART_T* uart)
314{
315 uart->MODEM |= UART_MODEM_RTSACTLV_Msk;
316 uart->MODEM &= ~UART_MODEM_RTS_Msk;
317}
318
325__INLINE void UART_SET_RTS(UART_T* uart)
326{
327 uart->MODEM |= UART_MODEM_RTSACTLV_Msk | UART_MODEM_RTS_Msk;
328}
329
336#define UART_RS485_CLEAR_ADDR_FLAG(uart) (uart->FIFOSTS |= UART_FIFOSTS_ADDRDETF_Msk)
337
338
345#define UART_RS485_GET_ADDR_FLAG(uart) ((uart->FIFOSTS & UART_FIFOSTS_ADDRDETF_Msk) >> UART_FIFOSTS_ADDRDETF_Pos)
346
347
348 void UART_ClearIntFlag(UART_T* uart, uint32_t u32InterruptFlag);
349 void UART_Close(UART_T* uart );
350 void UART_DisableFlowCtrl(UART_T* uart );
351 void UART_DisableInt(UART_T* uart, uint32_t u32InterruptFlag );
352 void UART_EnableFlowCtrl(UART_T* uart );
353 void UART_EnableInt(UART_T* uart, uint32_t u32InterruptFlag );
354 void UART_Open(UART_T* uart, uint32_t u32baudrate);
355uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
356 void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
357 void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
358 void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
359 void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
360uint32_t UART_Write(UART_T* uart,uint8_t *pu8TxBuf, uint32_t u32WriteBytes);
361
362 /* end of group Mini58_UART_EXPORTED_FUNCTIONS */
364 /* end of group Mini58_UART_Driver */
366 /* end of group Mini58_Device_Driver */
368
369#ifdef __cplusplus
370}
371#endif
372
373#endif //__UART_H__
374
375/*** (C) COPYRIGHT 2022 Nuvoton Technology Corp. ***/
UART_MODEM_RTS_Msk
#define UART_MODEM_RTS_Msk
Definition: Mini58Series.h:11232
UART_MODEM_RTSACTLV_Msk
#define UART_MODEM_RTSACTLV_Msk
Definition: Mini58Series.h:11235
UART_SelectRS485Mode
void UART_SelectRS485Mode(UART_T *uart, uint32_t u32Mode, uint32_t u32Addr)
The function is used to set RS485 relative setting.
Definition: uart.c:326
UART_EnableInt
void UART_EnableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to enable UART specified interrupt and disable NVIC UART IRQ.
Definition: uart.c:141
UART_SetTimeoutCnt
void UART_SetTimeoutCnt(UART_T *uart, uint32_t u32TOC)
This function use to set Rx timeout count.
Definition: uart.c:274
UART_Close
void UART_Close(UART_T *uart)
The function is used to disable UART.
Definition: uart.c:67
UART_ClearIntFlag
void UART_ClearIntFlag(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to clear UART specified interrupt flag.
Definition: uart.c:37
UART_DisableFlowCtrl
void UART_DisableFlowCtrl(UART_T *uart)
The function is used to disable UART auto flow control.
Definition: uart.c:80
UART_EnableFlowCtrl
void UART_EnableFlowCtrl(UART_T *uart)
The function is used to Enable UART auto flow control.
Definition: uart.c:116
UART_Write
uint32_t UART_Write(UART_T *uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
The function is to write data into TX buffer to transmit data by UART.
Definition: uart.c:343
UART_SetLine_Config
void UART_SetLine_Config(UART_T *uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits)
This function use to config UART line setting.
Definition: uart.c:233
UART_DisableInt
void UART_DisableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to disable UART specified interrupt and disable NVIC UART IRQ.
Definition: uart.c:102
UART_SET_RTS
__INLINE void UART_SET_RTS(UART_T *uart)
Set RTS pin is high.
Definition: uart.h:325
UART_SelectIrDAMode
void UART_SelectIrDAMode(UART_T *uart, uint32_t u32Buadrate, uint32_t u32Direction)
The function is used to configure IrDA relative settings. It consists of TX or RX mode and baudrate.
Definition: uart.c:290
UART_Read
uint32_t UART_Read(UART_T *uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes)
The function is used to read Rx data from RX FIFO and the data will be stored in pu8RxBuf.
Definition: uart.c:199
UART_Open
void UART_Open(UART_T *uart, uint32_t u32baudrate)
This function use to enable UART function and set baud-rate.
Definition: uart.c:155
UART_CLEAR_RTS
__INLINE void UART_CLEAR_RTS(UART_T *uart)
Set RTS pin is low.
Definition: uart.h:313
UART_T::MODEM
__IO uint32_t MODEM
Definition: Mini58Series.h:10863
UART_T
Definition: Mini58Series.h:10702