1 /******************************************************************************
\r
4 * @brief M2351 series USCI UART (UUART) driver header file
\r
7 * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
\r
8 *****************************************************************************/
\r
9 #ifndef __USCI_UART_H__
\r
10 #define __USCI_UART_H__
\r
19 /** @addtogroup Standard_Driver Standard Driver
\r
23 /** @addtogroup USCI_UART_Driver USCI_UART Driver
\r
27 /** @addtogroup USCI_UART_EXPORTED_CONSTANTS USCI_UART Exported Constants
\r
31 /*---------------------------------------------------------------------------------------------------------*/
\r
32 /* UUART_LINECTL constants definitions */
\r
33 /*---------------------------------------------------------------------------------------------------------*/
\r
34 #define UUART_WORD_LEN_6 (6UL << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 6 bits */
\r
35 #define UUART_WORD_LEN_7 (7UL << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 7 bits */
\r
36 #define UUART_WORD_LEN_8 (8UL << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 8 bits */
\r
37 #define UUART_WORD_LEN_9 (9UL << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 9 bits */
\r
39 /*---------------------------------------------------------------------------------------------------------*/
\r
40 /* UUART_PROTCTL constants definitions */
\r
41 /*---------------------------------------------------------------------------------------------------------*/
\r
42 #define UUART_PARITY_NONE (0x0UL << UUART_PROTCTL_PARITYEN_Pos) /*!< UUART_PROTCTL setting to set UART as no parity */
\r
43 #define UUART_PARITY_ODD (0x1UL << UUART_PROTCTL_PARITYEN_Pos) /*!< UUART_PROTCTL setting to set UART as odd parity */
\r
44 #define UUART_PARITY_EVEN (0x3UL << UUART_PROTCTL_PARITYEN_Pos) /*!< UUART_PROTCTL setting to set UART as even parity */
\r
46 #define UUART_STOP_BIT_1 (0x0UL) /*!< UUART_PROTCTL setting for one stop bit */
\r
47 #define UUART_STOP_BIT_2 (0x1UL) /*!< UUART_PROTCTL setting for two stop bit */
\r
49 /*---------------------------------------------------------------------------------------------------------*/
\r
50 /* USCI UART interrupt mask definitions */
\r
51 /*---------------------------------------------------------------------------------------------------------*/
\r
52 #define UUART_ABR_INT_MASK (0x002UL) /*!< Auto-baud rate interrupt mask */
\r
53 #define UUART_RLS_INT_MASK (0x004UL) /*!< Receive line status interrupt mask */
\r
54 #define UUART_BUF_RXOV_INT_MASK (0x008UL) /*!< Buffer RX overrun interrupt mask */
\r
55 #define UUART_TXST_INT_MASK (0x010UL) /*!< TX start interrupt mask */
\r
56 #define UUART_TXEND_INT_MASK (0x020UL) /*!< Tx end interrupt mask */
\r
57 #define UUART_RXST_INT_MASK (0x040UL) /*!< RX start interrupt mask */
\r
58 #define UUART_RXEND_INT_MASK (0x080UL) /*!< RX end interrupt mask */
\r
61 /*@}*/ /* end of group USCI_UART_EXPORTED_CONSTANTS */
\r
64 /** @addtogroup USCI_UART_EXPORTED_FUNCTIONS USCI_UART Exported Functions
\r
70 * @brief Write USCI_UART data
\r
72 * @param[in] uuart The pointer of the specified USCI_UART module
\r
73 * @param[in] u8Data Data byte to transmit.
\r
77 * @details This macro write Data to Tx data register.
\r
79 #define UUART_WRITE(uuart, u8Data) ((uuart)->TXDAT = (u8Data))
\r
83 * @brief Read USCI_UART data
\r
85 * @param[in] uuart The pointer of the specified USCI_UART module
\r
87 * @return The oldest data byte in RX buffer.
\r
89 * @details This macro read Rx data register.
\r
91 #define UUART_READ(uuart) ((uuart)->RXDAT)
\r
95 * @brief Get Tx empty
\r
97 * @param[in] uuart The pointer of the specified USCI_UART module
\r
99 * @retval 0 Tx buffer is not empty
\r
100 * @retval >=1 Tx buffer is empty
\r
102 * @details This macro get Transmitter buffer empty register value.
\r
104 #define UUART_GET_TX_EMPTY(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_TXEMPTY_Msk)
\r
108 * @brief Get Rx empty
\r
110 * @param[in] uuart The pointer of the specified USCI_UART module
\r
112 * @retval 0 Rx buffer is not empty
\r
113 * @retval >=1 Rx buffer is empty
\r
115 * @details This macro get Receiver buffer empty register value.
\r
117 #define UUART_GET_RX_EMPTY(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_RXEMPTY_Msk)
\r
121 * @brief Check specified usci_uart port transmission is over.
\r
123 * @param[in] uuart The pointer of the specified USCI_UART module
\r
125 * @retval 0 Tx transmission is not over
\r
126 * @retval 1 Tx transmission is over
\r
128 * @details This macro return Transmitter Empty Flag register bit value. \n
\r
129 * It indicates if specified usci_uart port transmission is over nor not.
\r
131 #define UUART_IS_TX_EMPTY(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_TXEMPTY_Msk) >> UUART_BUFSTS_TXEMPTY_Pos)
\r
135 * @brief Check specified usci_uart port receiver is empty.
\r
137 * @param[in] uuart The pointer of the specified USCI_UART module
\r
139 * @retval 0 Rx receiver is not empty
\r
140 * @retval 1 Rx receiver is empty
\r
142 * @details This macro return Receive Empty Flag register bit value. \n
\r
143 * It indicates if specified usci_uart port receiver is empty nor not.
\r
145 #define UUART_IS_RX_EMPTY(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_RXEMPTY_Msk) >> UUART_BUFSTS_RXEMPTY_Pos)
\r
149 * @brief Wait specified usci_uart port transmission is over
\r
151 * @param[in] uuart The pointer of the specified USCI_UART module
\r
155 * @details This macro wait specified usci_uart port transmission is over.
\r
157 #define UUART_WAIT_TX_EMPTY(uuart) while(!((((uuart)->BUFSTS) & UUART_BUFSTS_TXEMPTY_Msk) >> UUART_BUFSTS_TXEMPTY_Pos))
\r
161 * @brief Check TX buffer is full or not
\r
163 * @param[in] uuart The pointer of the specified USCI_UART module
\r
165 * @retval 1 TX buffer is full
\r
166 * @retval 0 TX buffer is not full
\r
168 * @details This macro check TX buffer is full or not.
\r
170 #define UUART_IS_TX_FULL(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_TXFULL_Msk)>>UUART_BUFSTS_TXFULL_Pos)
\r
174 * @brief Check RX buffer is full or not
\r
176 * @param[in] uuart The pointer of the specified USCI_UART module
\r
178 * @retval 1 RX buffer is full
\r
179 * @retval 0 RX buffer is not full
\r
181 * @details This macro check RX buffer is full or not.
\r
183 #define UUART_IS_RX_FULL(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_RXFULL_Msk)>>UUART_BUFSTS_RXFULL_Pos)
\r
187 * @brief Get Tx full register value
\r
189 * @param[in] uuart The pointer of the specified USCI_UART module
\r
191 * @retval 0 Tx buffer is not full.
\r
192 * @retval >=1 Tx buffer is full.
\r
194 * @details This macro get Tx full register value.
\r
196 #define UUART_GET_TX_FULL(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_TXFULL_Msk)
\r
200 * @brief Get Rx full register value
\r
202 * @param[in] uuart The pointer of the specified USCI_UART module
\r
204 * @retval 0 Rx buffer is not full.
\r
205 * @retval >=1 Rx buffer is full.
\r
207 * @details This macro get Rx full register value.
\r
209 #define UUART_GET_RX_FULL(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_RXFULL_Msk)
\r
213 * @brief Enable specified USCI_UART protocol interrupt
\r
215 * @param[in] uuart The pointer of the specified USCI_UART module
\r
216 * @param[in] u32IntSel Interrupt type select
\r
217 * - \ref UUART_PROTIEN_RLSIEN_Msk : Rx Line status interrupt
\r
218 * - \ref UUART_PROTIEN_ABRIEN_Msk : Auto-baud rate interrupt
\r
222 * @details This macro enable specified USCI_UART protocol interrupt.
\r
224 #define UUART_ENABLE_PROT_INT(uuart, u32IntSel) ((uuart)->PROTIEN |= (u32IntSel))
\r
228 * @brief Disable specified USCI_UART protocol interrupt
\r
230 * @param[in] uuart The pointer of the specified USCI_UART module
\r
231 * @param[in] u32IntSel Interrupt type select
\r
232 * - \ref UUART_PROTIEN_RLSIEN_Msk : Rx Line status interrupt
\r
233 * - \ref UUART_PROTIEN_ABRIEN_Msk : Auto-baud rate interrupt
\r
237 * @details This macro disable specified USCI_UART protocol interrupt.
\r
239 #define UUART_DISABLE_PROT_INT(uuart, u32IntSel) ((uuart)->PROTIEN &= ~(u32IntSel))
\r
243 * @brief Enable specified USCI_UART buffer interrupt
\r
245 * @param[in] uuart The pointer of the specified USCI_UART module
\r
246 * @param[in] u32IntSel Interrupt type select
\r
247 * - \ref UUART_BUFCTL_RXOVIEN_Msk : Receive buffer overrun error interrupt
\r
251 * @details This macro enable specified USCI_UART buffer interrupt.
\r
253 #define UUART_ENABLE_BUF_INT(uuart, u32IntSel) ((uuart)->BUFCTL |= (u32IntSel))
\r
257 * @brief Disable specified USCI_UART buffer interrupt
\r
259 * @param[in] uuart The pointer of the specified USCI_UART module
\r
260 * @param[in] u32IntSel Interrupt type select
\r
261 * - \ref UUART_BUFCTL_RXOVIEN_Msk : Receive buffer overrun error interrupt
\r
265 * @details This macro disable specified USCI_UART buffer interrupt.
\r
267 #define UUART_DISABLE_BUF_INT(uuart, u32IntSel) ((uuart)->BUFCTL &= ~ (u32IntSel))
\r
271 * @brief Enable specified USCI_UART transfer interrupt
\r
273 * @param[in] uuart The pointer of the specified USCI_UART module
\r
274 * @param[in] u32IntSel Interrupt type select
\r
275 * - \ref UUART_INTEN_RXENDIEN_Msk : Receive end interrupt
\r
276 * - \ref UUART_INTEN_RXSTIEN_Msk : Receive start interrupt
\r
277 * - \ref UUART_INTEN_TXENDIEN_Msk : Transmit end interrupt
\r
278 * - \ref UUART_INTEN_TXSTIEN_Msk : Transmit start interrupt
\r
282 * @details This macro enable specified USCI_UART transfer interrupt.
\r
284 #define UUART_ENABLE_TRANS_INT(uuart, u32IntSel) ((uuart)->INTEN |= (u32IntSel))
\r
288 * @brief Disable specified USCI_UART transfer interrupt
\r
290 * @param[in] uuart The pointer of the specified USCI_UART module
\r
291 * @param[in] u32IntSel Interrupt type select
\r
292 * - \ref UUART_INTEN_RXENDIEN_Msk : Receive end interrupt
\r
293 * - \ref UUART_INTEN_RXSTIEN_Msk : Receive start interrupt
\r
294 * - \ref UUART_INTEN_TXENDIEN_Msk : Transmit end interrupt
\r
295 * - \ref UUART_INTEN_TXSTIEN_Msk : Transmit start interrupt
\r
299 * @details This macro disable specified USCI_UART transfer interrupt.
\r
301 #define UUART_DISABLE_TRANS_INT(uuart, u32IntSel) ((uuart)->INTEN &= ~(u32IntSel))
\r
305 * @brief Get protocol interrupt flag/status
\r
307 * @param[in] uuart The pointer of the specified USCI_UART module
\r
309 * @return The interrupt flag/status of protocol status register.
\r
311 * @details This macro get protocol status register value.
\r
313 #define UUART_GET_PROT_STATUS(uuart) ((uuart)->PROTSTS)
\r
317 * @brief Clear specified protocol interrupt flag
\r
319 * @param[in] uuart The pointer of the specified USCI_UART module
\r
320 * @param[in] u32IntTypeFlag Interrupt Type Flag, should be
\r
321 * - \ref UUART_PROTSTS_ABERRSTS_Msk : Auto-baud Rate Error Interrupt Indicator
\r
322 * - \ref UUART_PROTSTS_ABRDETIF_Msk : Auto-baud Rate Detected Interrupt Flag
\r
323 * - \ref UUART_PROTSTS_BREAK_Msk : Break Flag
\r
324 * - \ref UUART_PROTSTS_FRMERR_Msk : Framing Error Flag
\r
325 * - \ref UUART_PROTSTS_PARITYERR_Msk : Parity Error Flag
\r
326 * - \ref UUART_PROTSTS_RXENDIF_Msk : Receive End Interrupt Flag
\r
327 * - \ref UUART_PROTSTS_RXSTIF_Msk : Receive Start Interrupt Flag
\r
328 * - \ref UUART_PROTSTS_TXENDIF_Msk : Transmit End Interrupt Flag
\r
329 * - \ref UUART_PROTSTS_TXSTIF_Msk : Transmit Start Interrupt Flag
\r
333 * @details This macro clear specified protocol interrupt flag.
\r
335 #define UUART_CLR_PROT_INT_FLAG(uuart,u32IntTypeFlag) ((uuart)->PROTSTS = (u32IntTypeFlag))
\r
339 * @brief Get transmit/receive buffer interrupt flag/status
\r
341 * @param[in] uuart The pointer of the specified USCI_UART module
\r
343 * @return The interrupt flag/status of buffer status register.
\r
345 * @details This macro get buffer status register value.
\r
347 #define UUART_GET_BUF_STATUS(uuart) ((uuart)->BUFSTS)
\r
351 * @brief Clear specified buffer interrupt flag
\r
353 * @param[in] uuart The pointer of the specified USCI_UART module
\r
354 * @param[in] u32IntTypeFlag Interrupt Type Flag, should be
\r
355 * - \ref UUART_BUFSTS_RXOVIF_Msk : Receive Buffer Over-run Error Interrupt Indicator
\r
359 * @details This macro clear specified buffer interrupt flag.
\r
361 #define UUART_CLR_BUF_INT_FLAG(uuart,u32IntTypeFlag) ((uuart)->BUFSTS = (u32IntTypeFlag))
\r
365 * @brief Get wakeup flag
\r
367 * @param[in] uuart The pointer of the specified USCI_UART module
\r
369 * @retval 0 Chip did not wake up from power-down mode.
\r
370 * @retval 1 Chip waked up from power-down mode.
\r
372 * @details This macro get wakeup flag.
\r
374 #define UUART_GET_WAKEUP_FLAG(uuart) ((uuart)->WKSTS & UUART_WKSTS_WKF_Msk ? 1: 0 )
\r
378 * @brief Clear wakeup flag
\r
380 * @param[in] uuart The pointer of the specified USCI_UART module
\r
384 * @details This macro clear wakeup flag.
\r
386 #define UUART_CLR_WAKEUP_FLAG(uuart) ((uuart)->WKSTS = UUART_WKSTS_WKF_Msk)
\r
389 void UUART_ClearIntFlag(UUART_T* uuart, uint32_t u32Mask);
\r
390 uint32_t UUART_GetIntFlag(UUART_T* uuart, uint32_t u32Mask);
\r
391 void UUART_Close(UUART_T* uuart);
\r
392 void UUART_DisableInt(UUART_T* uuart, uint32_t u32Mask);
\r
393 void UUART_EnableInt(UUART_T* uuart, uint32_t u32Mask);
\r
394 uint32_t UUART_Open(UUART_T* uuart, uint32_t u32baudrate);
\r
395 uint32_t UUART_Read(UUART_T* uuart, uint8_t pu8RxBuf[], uint32_t u32ReadBytes);
\r
396 uint32_t UUART_SetLine_Config(UUART_T* uuart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
\r
397 uint32_t UUART_Write(UUART_T* uuart, uint8_t pu8TxBuf[], uint32_t u32WriteBytes);
\r
398 void UUART_EnableWakeup(UUART_T* uuart, uint32_t u32WakeupMode);
\r
399 void UUART_DisableWakeup(UUART_T* uuart);
\r
400 void UUART_EnableFlowCtrl(UUART_T* uuart);
\r
401 void UUART_DisableFlowCtrl(UUART_T* uuart);
\r
404 /*@}*/ /* end of group USCI_UART_EXPORTED_FUNCTIONS */
\r
406 /*@}*/ /* end of group USCI_UART_Driver */
\r
408 /*@}*/ /* end of group Standard_Driver */
\r
414 #endif /* __USCI_UART_H__ */
\r
416 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
\r