| NUC472_NUC442_BSP V3.04.000 The Board Support Package for NUC472/NUC442

uart.h
Go to the documentation of this file.
1/**************************************************************************/
14#ifndef __UART_H__
15#define __UART_H__
16
17#ifdef __cplusplus
18extern "C"
19{
20#endif
21
22
35/*---------------------------------------------------------------------------------------------------------*/
36/* UART_FCR constants definitions */
37/*---------------------------------------------------------------------------------------------------------*/
38
39#define UART_FIFO_RFITL_1BYTE (0x0 << UART_FIFO_RFITL_Pos)
40#define UART_FIFO_RFITL_4BYTES (0x1 << UART_FIFO_RFITL_Pos)
41#define UART_FIFO_RFITL_8BYTES (0x2 << UART_FIFO_RFITL_Pos)
42#define UART_FIFO_RFITL_14BYTES (0x3 << UART_FIFO_RFITL_Pos)
44#define UART_FIFO_RTSTRGLV_1BYTE (0x0 << UART_FIFO_RTSTRGLV_Pos)
45#define UART_FIFO_RTSTRGLV_4BYTES (0x1 << UART_FIFO_RTSTRGLV_Pos)
46#define UART_FIFO_RTSTRGLV_8BYTES (0x2 << UART_FIFO_RTSTRGLV_Pos)
47#define UART_FIFO_RTSTRGLV_14BYTES (0x3 << UART_FIFO_RTSTRGLV_Pos)
49/*---------------------------------------------------------------------------------------------------------*/
50/* UART_LCR constants definitions */
51/*---------------------------------------------------------------------------------------------------------*/
52#define UART_WORD_LEN_5 (0)
53#define UART_WORD_LEN_6 (1)
54#define UART_WORD_LEN_7 (2)
55#define UART_WORD_LEN_8 (3)
57#define UART_PARITY_NONE (0x0 << UART_LINE_PBE_Pos)
58#define UART_PARITY_ODD (0x1 << UART_LINE_PBE_Pos)
59#define UART_PARITY_EVEN (0x3 << UART_LINE_PBE_Pos)
60#define UART_PARITY_MARK (0x5 << UART_LINE_PBE_Pos)
61#define UART_PARITY_SPACE (0x7 << UART_LINE_PBE_Pos)
63#define UART_STOP_BIT_1 (0x0 << UART_LINE_NSB_Pos)
64#define UART_STOP_BIT_1_5 (0x1 << UART_LINE_NSB_Pos)
65#define UART_STOP_BIT_2 (0x1 << UART_LINE_NSB_Pos)
68/*---------------------------------------------------------------------------------------------------------*/
69/* UART RTS LEVEL TRIGGER constants definitions */
70/*---------------------------------------------------------------------------------------------------------*/
71#define UART_RTS_IS_HIGH_LEV_TRG (0x1 << UART_MODEM_RTSACTLV_Pos)
72#define UART_RTS_IS_LOW_LEV_TRG (0x0 << UART_MODEM_RTSACTLV_Pos)
74/*---------------------------------------------------------------------------------------------------------*/
75/* UART CTS LEVEL TRIGGER constants definitions */
76/*---------------------------------------------------------------------------------------------------------*/
77#define UART_CTS_IS_HIGH_LEV_TRG (0x1 << UART_MODEMSTS_CTSACTLV_Pos)
78#define UART_CTS_IS_LOW_LEV_TRG (0x0 << UART_MODEMSTS_CTSACTLV_Pos)
80/*---------------------------------------------------------------------------------------------------------*/
81/* UART_FUNC_SEL constants definitions */
82/*---------------------------------------------------------------------------------------------------------*/
83#define UART_FUNCSEL_UART (0x0 << UART_FUNCSEL_FUNCSEL_Pos)
84#define UART_FUNCSEL_LIN (0x1 << UART_FUNCSEL_FUNCSEL_Pos)
85#define UART_FUNCSEL_IrDA (0x2 << UART_FUNCSEL_FUNCSEL_Pos)
86#define UART_FUNCSEL_RS485 (0x3 << UART_FUNCSEL_FUNCSEL_Pos)
88/*---------------------------------------------------------------------------------------------------------*/
89/* UART_LINCTL constants definitions */
90/*---------------------------------------------------------------------------------------------------------*/
91#define UART_LINCTL_BRKFL(x) (((x)-1) << UART_LINCTL_BRKFL_Pos)
92#define UART_LINCTL_BSL(x) (((x)-1) << UART_LINCTL_BSL_Pos)
93#define UART_LINCTL_HSEL_BREAK (0x0UL << UART_LINCTL_HSEL_Pos)
94#define UART_LINCTL_HSEL_BREAK_SYNC (0x1UL << UART_LINCTL_HSEL_Pos)
95#define UART_LINCTL_HSEL_BREAK_SYNC_ID (0x2UL << UART_LINCTL_HSEL_Pos)
96#define UART_LINCTL_PID(x) ((x) << UART_LINCTL_PID_Pos)
98/*---------------------------------------------------------------------------------------------------------*/
99/* UART BAUDRATE MODE constants definitions */
100/*---------------------------------------------------------------------------------------------------------*/
101#define UART_BAUD_MODE0 (0)
102#define UART_BAUD_MODE2 (UART_BAUD_BAUDM1_Msk | UART_BAUD_BAUDM0_Msk) /* end of group NUC472_442_UART_EXPORTED_CONSTANTS */
107
108
124#define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate*8)) / u32BaudRate >> 4)-2)
125
135#define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate/2)) / u32BaudRate)-2)
136
137
147#define UART_WRITE(uart, u8Data) (uart->DAT = (u8Data))
148
157#define UART_READ(uart) (uart->DAT)
158
159
168#define UART_GET_TX_EMPTY(uart) (uart->FIFOSTS & UART_FIFOSTS_TXEMPTY_Msk)
169
170
179#define UART_GET_RX_EMPTY(uart) (uart->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk)
180
189#define UART_IS_TX_EMPTY(uart) ((uart->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos)
190
191
200#define UART_WAIT_TX_EMPTY(uart) while(!(((uart->FIFOSTS) & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos))
201
212#define UART_IS_RX_READY(uart) ((uart->INTSTS & UART_INTSTS_RDAIF_Msk)>>UART_INTSTS_RDAIF_Pos)
213
214
225#define UART_IS_TX_FULL(uart) ((uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)>>UART_FIFOSTS_TXFULL_Pos)
226
238#define UART_IS_RX_FULL(uart) ((uart->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)>>UART_FIFOSTS_RXFULL_Pos)
239
240
249#define UART_GET_TX_FULL(uart) (uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)
250
251
260#define UART_GET_RX_FULL(uart) (uart->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)
261
262
280#define UART_ENABLE_INT(uart, u32eIntSel) (uart->INTEN |= (u32eIntSel))
281
282
299#define UART_DISABLE_INT(uart, u32eIntSel) (uart->INTEN &= ~ (u32eIntSel))
300
301
335#define UART_GET_INT_FLAG(uart,u32eIntTypeFlag) ((uart->INTSTS & (u32eIntTypeFlag))?1:0)
336
337
344__STATIC_INLINE void UART_CLEAR_RTS(UART_T* uart)
345{
346 uart->MODEM |= UART_MODEM_RTSACTLV_Msk;
347 uart->MODEM &= UART_MODEM_RTS_Msk;
348}
349
356__STATIC_INLINE void UART_SET_RTS(UART_T* uart)
357{
358 uart->MODEM |= UART_MODEM_RTSACTLV_Msk | UART_MODEM_RTS_Msk;
359}
360
368#define UART_RS485_CLEAR_ADDR_FLAG(uart) (uart->FIFOSTS |= UART_FIFOSTS_ADDRDETF_Msk)
369
370
378#define UART_RS485_GET_ADDR_FLAG(uart) ((uart->FIFOSTS & UART_FIFOSTS_ADDRDETF_Msk) >> UART_FIFOSTS_ADDRDETF_Pos)
379
380
381void UART_ClearIntFlag(UART_T* uart, uint32_t u32InterruptFlag);
382void UART_Close(UART_T* uart );
383void UART_DisableFlowCtrl(UART_T* uart );
384void UART_DisableInt(UART_T* uart, uint32_t u32InterruptFlag );
385void UART_EnableFlowCtrl(UART_T* uart );
386void UART_EnableInt(UART_T* uart, uint32_t u32InterruptFlag );
387void UART_Open(UART_T* uart, uint32_t u32baudrate);
388uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
389void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
390void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
391void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
392void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
393uint32_t UART_Write(UART_T* uart,uint8_t *pu8TxBuf, uint32_t u32WriteBytes);
394
395 /* end of group NUC472_442_UART_EXPORTED_FUNCTIONS */
397 /* end of group NUC472_442_UART_Driver */
399 /* end of group NUC472_442_Device_Driver */
401
402#ifdef __cplusplus
403}
404#endif
405
406#endif //__UART_H__
407
408/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
409
410
411
412
UART_MODEM_RTS_Msk
#define UART_MODEM_RTS_Msk
Definition: NUC472_442.h:25884
UART_MODEM_RTSACTLV_Msk
#define UART_MODEM_RTSACTLV_Msk
Definition: NUC472_442.h:25887
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:310
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:146
UART_CLEAR_RTS
__STATIC_INLINE void UART_CLEAR_RTS(UART_T *uart)
Set RTS pin is low.
Definition: uart.h:344
UART_SET_RTS
__STATIC_INLINE void UART_SET_RTS(UART_T *uart)
Set RTS pin is high.
Definition: uart.h:356
UART_SetTimeoutCnt
void UART_SetTimeoutCnt(UART_T *uart, uint32_t u32TOC)
This function use to set Rx timeout count.
Definition: uart.c:264
UART_Close
void UART_Close(UART_T *uart)
The function is used to disable UART.
Definition: uart.c:72
UART_ClearIntFlag
void UART_ClearIntFlag(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to clear UART specified interrupt flag.
Definition: uart.c:43
UART_DisableFlowCtrl
void UART_DisableFlowCtrl(UART_T *uart)
The function is used to disable UART auto flow control.
Definition: uart.c:85
UART_EnableFlowCtrl
void UART_EnableFlowCtrl(UART_T *uart)
The function is used to Enable UART auto flow control.
Definition: uart.c:121
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:329
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:229
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:107
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:280
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:160
UART_T::MODEM
__IO uint32_t MODEM
Definition: NUC472_442.h:25344
UART_T
Definition: NUC472_442.h:25170