nu_uart.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /**************************************************************************//**
  2. * @file nu_uart.h
  3. * @version V3.00
  4. * @brief M460 series UART driver header file
  5. *
  6. * @copyright SPDX-License-Identifier: Apache-2.0
  7. * @copyright Copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_UART_H__
  10. #define __NU_UART_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup UART_Driver UART Driver
  19. @{
  20. */
  21. /** @addtogroup UART_EXPORTED_CONSTANTS UART Exported Constants
  22. @{
  23. */
  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* UART FIFO size constants definitions */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. #define UART0_FIFO_SIZE 16ul /*!< UART0 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  28. #define UART1_FIFO_SIZE 16ul /*!< UART1 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  29. #define UART2_FIFO_SIZE 16ul /*!< UART2 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  30. #define UART3_FIFO_SIZE 16ul /*!< UART3 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  31. #define UART4_FIFO_SIZE 16ul /*!< UART4 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  32. #define UART5_FIFO_SIZE 16ul /*!< UART5 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  33. #define UART6_FIFO_SIZE 16ul /*!< UART6 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  34. #define UART7_FIFO_SIZE 16ul /*!< UART7 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  35. #define UART8_FIFO_SIZE 16ul /*!< UART8 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  36. #define UART9_FIFO_SIZE 16ul /*!< UART9 supports separated receive/transmit 16/16 bytes entry FIFO \hideinitializer */
  37. /*---------------------------------------------------------------------------------------------------------*/
  38. /* UART_FIFO constants definitions */
  39. /*---------------------------------------------------------------------------------------------------------*/
  40. #define UART_FIFO_RFITL_1BYTE (0x0ul << UART_FIFO_RFITL_Pos) /*!< UART_FIFO setting to set RX FIFO Trigger Level to 1 byte \hideinitializer */
  41. #define UART_FIFO_RFITL_4BYTES (0x1ul << UART_FIFO_RFITL_Pos) /*!< UART_FIFO setting to set RX FIFO Trigger Level to 4 bytes \hideinitializer */
  42. #define UART_FIFO_RFITL_8BYTES (0x2ul << UART_FIFO_RFITL_Pos) /*!< UART_FIFO setting to set RX FIFO Trigger Level to 8 bytes \hideinitializer */
  43. #define UART_FIFO_RFITL_14BYTES (0x3ul << UART_FIFO_RFITL_Pos) /*!< UART_FIFO setting to set RX FIFO Trigger Level to 14 bytes \hideinitializer */
  44. #define UART_FIFO_RTSTRGLV_1BYTE (0x0ul << UART_FIFO_RTSTRGLV_Pos) /*!< UART_FIFO setting to set RTS Trigger Level to 1 byte \hideinitializer */
  45. #define UART_FIFO_RTSTRGLV_4BYTES (0x1ul << UART_FIFO_RTSTRGLV_Pos) /*!< UART_FIFO setting to set RTS Trigger Level to 4 bytes \hideinitializer */
  46. #define UART_FIFO_RTSTRGLV_8BYTES (0x2ul << UART_FIFO_RTSTRGLV_Pos) /*!< UART_FIFO setting to set RTS Trigger Level to 8 bytes \hideinitializer */
  47. #define UART_FIFO_RTSTRGLV_14BYTES (0x3ul << UART_FIFO_RTSTRGLV_Pos) /*!< UART_FIFO setting to set RTS Trigger Level to 14 bytes \hideinitializer */
  48. /*---------------------------------------------------------------------------------------------------------*/
  49. /* UART_LINE constants definitions */
  50. /*---------------------------------------------------------------------------------------------------------*/
  51. #define UART_WORD_LEN_5 (0ul) /*!< UART_LINE setting to set UART word length to 5 bits \hideinitializer */
  52. #define UART_WORD_LEN_6 (1ul) /*!< UART_LINE setting to set UART word length to 6 bits \hideinitializer */
  53. #define UART_WORD_LEN_7 (2ul) /*!< UART_LINE setting to set UART word length to 7 bits \hideinitializer */
  54. #define UART_WORD_LEN_8 (3ul) /*!< UART_LINE setting to set UART word length to 8 bits \hideinitializer */
  55. #define UART_PARITY_NONE (0x0ul << UART_LINE_PBE_Pos) /*!< UART_LINE setting to set UART as no parity \hideinitializer */
  56. #define UART_PARITY_ODD (0x1ul << UART_LINE_PBE_Pos) /*!< UART_LINE setting to set UART as odd parity \hideinitializer */
  57. #define UART_PARITY_EVEN (0x3ul << UART_LINE_PBE_Pos) /*!< UART_LINE setting to set UART as even parity \hideinitializer */
  58. #define UART_PARITY_MARK (0x5ul << UART_LINE_PBE_Pos) /*!< UART_LINE setting to keep parity bit as '1' \hideinitializer */
  59. #define UART_PARITY_SPACE (0x7ul << UART_LINE_PBE_Pos) /*!< UART_LINE setting to keep parity bit as '0' \hideinitializer */
  60. #define UART_STOP_BIT_1 (0x0ul << UART_LINE_NSB_Pos) /*!< UART_LINE setting for one stop bit \hideinitializer */
  61. #define UART_STOP_BIT_1_5 (0x1ul << UART_LINE_NSB_Pos) /*!< UART_LINE setting for 1.5 stop bit when 5-bit word length \hideinitializer */
  62. #define UART_STOP_BIT_2 (0x1ul << UART_LINE_NSB_Pos) /*!< UART_LINE setting for two stop bit when 6, 7, 8-bit word length \hideinitializer */
  63. /*---------------------------------------------------------------------------------------------------------*/
  64. /* UART RTS ACTIVE LEVEL constants definitions */
  65. /*---------------------------------------------------------------------------------------------------------*/
  66. #define UART_RTS_IS_LOW_LEV_ACTIVE (0x1ul << UART_MODEM_RTSACTLV_Pos) /*!< Set RTS is Low Level Active \hideinitializer */
  67. #define UART_RTS_IS_HIGH_LEV_ACTIVE (0x0ul << UART_MODEM_RTSACTLV_Pos) /*!< Set RTS is High Level Active \hideinitializer */
  68. /*---------------------------------------------------------------------------------------------------------*/
  69. /* UART_IRDA constants definitions */
  70. /*---------------------------------------------------------------------------------------------------------*/
  71. #define UART_IRDA_TXEN (0x1ul << UART_IRDA_TXEN_Pos) /*!< Set IrDA function Tx mode \hideinitializer */
  72. #define UART_IRDA_RXEN (0x0ul << UART_IRDA_TXEN_Pos) /*!< Set IrDA function Rx mode \hideinitializer */
  73. /*---------------------------------------------------------------------------------------------------------*/
  74. /* UART_FUNCSEL constants definitions */
  75. /*---------------------------------------------------------------------------------------------------------*/
  76. #define UART_FUNCSEL_UART (0x0ul << UART_FUNCSEL_FUNCSEL_Pos) /*!< UART_FUNCSEL setting to set UART Function (Default) \hideinitializer */
  77. #define UART_FUNCSEL_LIN (0x1ul << UART_FUNCSEL_FUNCSEL_Pos) /*!< UART_FUNCSEL setting to set LIN Function \hideinitializer */
  78. #define UART_FUNCSEL_IrDA (0x2ul << UART_FUNCSEL_FUNCSEL_Pos) /*!< UART_FUNCSEL setting to set IrDA Function \hideinitializer */
  79. #define UART_FUNCSEL_RS485 (0x3ul << UART_FUNCSEL_FUNCSEL_Pos) /*!< UART_FUNCSEL setting to set RS485 Function \hideinitializer */
  80. #define UART_FUNCSEL_SINGLE_WIRE (0x4ul << UART_FUNCSEL_FUNCSEL_Pos) /*!< UART_FUNCSEL setting to set Single Wire Function */
  81. /*---------------------------------------------------------------------------------------------------------*/
  82. /* UART_LINCTL constants definitions */
  83. /*---------------------------------------------------------------------------------------------------------*/
  84. #define UART_LINCTL_BRKFL(x) (((x)-1) << UART_LINCTL_BRKFL_Pos) /*!< UART_LINCTL setting to set LIN Break Field Length, x = 10 ~ 15, default value is 12 \hideinitializer */
  85. #define UART_LINCTL_BSL(x) (((x)-1) << UART_LINCTL_BSL_Pos) /*!< UART_LINCTL setting to set LIN Break/Sync Delimiter Length, x = 1 ~ 4 \hideinitializer */
  86. #define UART_LINCTL_HSEL_BREAK (0x0UL << UART_LINCTL_HSEL_Pos) /*!< UART_LINCTL setting to set LIN Header Select to break field \hideinitializer */
  87. #define UART_LINCTL_HSEL_BREAK_SYNC (0x1UL << UART_LINCTL_HSEL_Pos) /*!< UART_LINCTL setting to set LIN Header Select to break field and sync field \hideinitializer */
  88. #define UART_LINCTL_HSEL_BREAK_SYNC_ID (0x2UL << UART_LINCTL_HSEL_Pos) /*!< UART_LINCTL setting to set LIN Header Select to break field, sync field and ID field \hideinitializer */
  89. #define UART_LINCTL_PID(x) ((x) << UART_LINCTL_PID_Pos) /*!< UART_LINCTL setting to set LIN PID value \hideinitializer */
  90. /*---------------------------------------------------------------------------------------------------------*/
  91. /* UART BAUDRATE MODE constants definitions */
  92. /*---------------------------------------------------------------------------------------------------------*/
  93. #define UART_BAUD_MODE0 (0ul) /*!< Set UART Baudrate Mode is Mode0 \hideinitializer */
  94. #define UART_BAUD_MODE2 (UART_BAUD_BAUDM1_Msk | UART_BAUD_BAUDM0_Msk) /*!< Set UART Baudrate Mode is Mode2 \hideinitializer */
  95. /*@}*/ /* end of group UART_EXPORTED_CONSTANTS */
  96. /** @addtogroup UART_EXPORTED_FUNCTIONS UART Exported Functions
  97. @{
  98. */
  99. /**
  100. * @brief Calculate UART baudrate mode0 divider
  101. *
  102. * @param[in] u32SrcFreq UART clock frequency
  103. * @param[in] u32BaudRate Baudrate of UART module
  104. *
  105. * @return UART baudrate mode0 divider
  106. *
  107. * @details This macro calculate UART baudrate mode0 divider.
  108. * \hideinitializer
  109. */
  110. #define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate) ((((u32SrcFreq) + ((u32BaudRate)*8ul)) / (u32BaudRate) >> 4ul)-2ul)
  111. /**
  112. * @brief Calculate UART baudrate mode2 divider
  113. *
  114. * @param[in] u32SrcFreq UART clock frequency
  115. * @param[in] u32BaudRate Baudrate of UART module
  116. *
  117. * @return UART baudrate mode2 divider
  118. *
  119. * @details This macro calculate UART baudrate mode2 divider.
  120. * \hideinitializer
  121. */
  122. #define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate) ((((u32SrcFreq) + ((u32BaudRate)/2ul)) / (u32BaudRate))-2ul)
  123. /**
  124. * @brief Write UART data
  125. *
  126. * @param[in] uart The pointer of the specified UART module
  127. * @param[in] u8Data Data byte to transmit.
  128. *
  129. * @return None
  130. *
  131. * @details This macro write Data to Tx data register.
  132. * \hideinitializer
  133. */
  134. #define UART_WRITE(uart, u8Data) ((uart)->DAT = (u8Data))
  135. /**
  136. * @brief Read UART data
  137. *
  138. * @param[in] uart The pointer of the specified UART module
  139. *
  140. * @return The oldest data byte in RX FIFO.
  141. *
  142. * @details This macro read Rx data register.
  143. * \hideinitializer
  144. */
  145. #define UART_READ(uart) ((uart)->DAT)
  146. /**
  147. * @brief Get Tx empty
  148. *
  149. * @param[in] uart The pointer of the specified UART module
  150. *
  151. * @retval 0 Tx FIFO is not empty
  152. * @retval >=1 Tx FIFO is empty
  153. *
  154. * @details This macro get Transmitter FIFO empty register value.
  155. * \hideinitializer
  156. */
  157. #define UART_GET_TX_EMPTY(uart) ((uart)->FIFOSTS & UART_FIFOSTS_TXEMPTY_Msk)
  158. /**
  159. * @brief Get Rx empty
  160. *
  161. * @param[in] uart The pointer of the specified UART module
  162. *
  163. * @retval 0 Rx FIFO is not empty
  164. * @retval >=1 Rx FIFO is empty
  165. *
  166. * @details This macro get Receiver FIFO empty register value.
  167. * \hideinitializer
  168. */
  169. #define UART_GET_RX_EMPTY(uart) ((uart)->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk)
  170. /**
  171. * @brief Check specified UART port transmission is over.
  172. *
  173. * @param[in] uart The pointer of the specified UART module
  174. *
  175. * @retval 0 Tx transmission is not over
  176. * @retval 1 Tx transmission is over
  177. *
  178. * @details This macro return Transmitter Empty Flag register bit value.
  179. * It indicates if specified UART port transmission is over nor not.
  180. * \hideinitializer
  181. */
  182. #define UART_IS_TX_EMPTY(uart) (((uart)->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos)
  183. /**
  184. * @brief Wait specified UART port transmission is over
  185. *
  186. * @param[in] uart The pointer of the specified UART module
  187. *
  188. * @return None
  189. *
  190. * @details This macro wait specified UART port transmission is over.
  191. * \hideinitializer
  192. */
  193. #define UART_WAIT_TX_EMPTY(uart) while(!((((uart)->FIFOSTS) & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos))
  194. /**
  195. * @brief Check RX is ready or not
  196. *
  197. * @param[in] uart The pointer of the specified UART module
  198. *
  199. * @retval 0 The number of bytes in the RX FIFO is less than the RFITL
  200. * @retval 1 The number of bytes in the RX FIFO equals or larger than RFITL
  201. *
  202. * @details This macro check receive data available interrupt flag is set or not.
  203. * \hideinitializer
  204. */
  205. #define UART_IS_RX_READY(uart) (((uart)->INTSTS & UART_INTSTS_RDAIF_Msk)>>UART_INTSTS_RDAIF_Pos)
  206. /**
  207. * @brief Check TX FIFO is full or not
  208. *
  209. * @param[in] uart The pointer of the specified UART module
  210. *
  211. * @retval 1 TX FIFO is full
  212. * @retval 0 TX FIFO is not full
  213. *
  214. * @details This macro check TX FIFO is full or not.
  215. * \hideinitializer
  216. */
  217. #define UART_IS_TX_FULL(uart) (((uart)->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)>>UART_FIFOSTS_TXFULL_Pos)
  218. /**
  219. * @brief Check RX FIFO is full or not
  220. *
  221. * @param[in] uart The pointer of the specified UART module
  222. *
  223. * @retval 1 RX FIFO is full
  224. * @retval 0 RX FIFO is not full
  225. *
  226. * @details This macro check RX FIFO is full or not.
  227. * \hideinitializer
  228. */
  229. #define UART_IS_RX_FULL(uart) (((uart)->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)>>UART_FIFOSTS_RXFULL_Pos)
  230. /**
  231. * @brief Get Tx full register value
  232. *
  233. * @param[in] uart The pointer of the specified UART module
  234. *
  235. * @retval 0 Tx FIFO is not full.
  236. * @retval >=1 Tx FIFO is full.
  237. *
  238. * @details This macro get Tx full register value.
  239. * \hideinitializer
  240. */
  241. #define UART_GET_TX_FULL(uart) ((uart)->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)
  242. /**
  243. * @brief Get Rx full register value
  244. *
  245. * @param[in] uart The pointer of the specified UART module
  246. *
  247. * @retval 0 Rx FIFO is not full.
  248. * @retval >=1 Rx FIFO is full.
  249. *
  250. * @details This macro get Rx full register value.
  251. * \hideinitializer
  252. */
  253. #define UART_GET_RX_FULL(uart) ((uart)->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)
  254. /**
  255. * @brief Rx Idle Status register value
  256. *
  257. * @param[in] uart The pointer of the specified UART module
  258. *
  259. * @retval 0 Rx is busy.
  260. * @retval 1 Rx is Idle(Default)
  261. *
  262. * @details This macro get Rx Idle Status register value.
  263. * \hideinitializer
  264. */
  265. #define UART_RX_IDLE(uart) (((uart)->FIFOSTS & UART_FIFOSTS_RXIDLE_Msk )>> UART_FIFOSTS_RXIDLE_Pos)
  266. /**
  267. * @brief Enable specified UART interrupt
  268. *
  269. * @param[in] uart The pointer of the specified UART module
  270. * @param[in] u32eIntSel Interrupt type select
  271. * - \ref UART_INTEN_TXENDIEN_Msk : Transmitter Empty Interrupt
  272. * - \ref UART_INTEN_ABRIEN_Msk : Single-wire Bit Error Detection Interrupt
  273. * - \ref UART_INTEN_SWBEIEN_Msk : Auto-baud Rate Interrupt
  274. * - \ref UART_INTEN_LINIEN_Msk : Lin Bus Interrupt
  275. * - \ref UART_INTEN_WKIEN_Msk : Wake-up Interrupt
  276. * - \ref UART_INTEN_BUFERRIEN_Msk : Buffer Error Interrupt
  277. * - \ref UART_INTEN_RXTOIEN_Msk : Rx Time-out Interrupt
  278. * - \ref UART_INTEN_MODEMIEN_Msk : MODEM Status Interrupt
  279. * - \ref UART_INTEN_RLSIEN_Msk : Receive Line Status Interrupt
  280. * - \ref UART_INTEN_THREIEN_Msk : Transmit Holding Register Empty Interrupt
  281. * - \ref UART_INTEN_RDAIEN_Msk : Receive Data Available Interrupt
  282. *
  283. * @return None
  284. *
  285. * @details This macro enable specified UART interrupt.
  286. * \hideinitializer
  287. */
  288. #define UART_ENABLE_INT(uart, u32eIntSel) ((uart)->INTEN |= (u32eIntSel))
  289. /**
  290. * @brief Disable specified UART interrupt
  291. *
  292. * @param[in] uart The pointer of the specified UART module
  293. * @param[in] u32eIntSel Interrupt type select
  294. * - \ref UART_INTEN_TXENDIEN_Msk : Transmitter Empty Interrupt
  295. * - \ref UART_INTEN_ABRIEN_Msk : Single-wire Bit Error Detection Interrupt
  296. * - \ref UART_INTEN_SWBEIEN_Msk : Auto-baud Rate Interrupt
  297. * - \ref UART_INTEN_LINIEN_Msk : Lin Bus Interrupt
  298. * - \ref UART_INTEN_WKIEN_Msk : Wake-up Interrupt
  299. * - \ref UART_INTEN_BUFERRIEN_Msk : Buffer Error Interrupt
  300. * - \ref UART_INTEN_RXTOIEN_Msk : Rx Time-out Interrupt
  301. * - \ref UART_INTEN_MODEMIEN_Msk : MODEM Status Interrupt
  302. * - \ref UART_INTEN_RLSIEN_Msk : Receive Line Status Interrupt
  303. * - \ref UART_INTEN_THREIEN_Msk : Transmit Holding Register Empty Interrupt
  304. * - \ref UART_INTEN_RDAIEN_Msk : Receive Data Available Interrupt
  305. *
  306. * @return None
  307. *
  308. * @details This macro disable specified UART interrupt.
  309. * \hideinitializer
  310. */
  311. #define UART_DISABLE_INT(uart, u32eIntSel) ((uart)->INTEN &= ~ (u32eIntSel))
  312. /**
  313. * @brief Get specified interrupt flag/status
  314. *
  315. * @param[in] uart The pointer of the specified UART module
  316. * @param[in] u32eIntTypeFlag Interrupt Type Flag, should be
  317. * - \ref UART_INTSTS_ABRINT_Msk : Auto-baud Rate Interrupt Indicator
  318. * - \ref UART_INTSTS_HWBUFEINT_Msk : PDMA Mode Buffer Error Interrupt Indicator
  319. * - \ref UART_INTSTS_HWTOINT_Msk : PDMA Mode Rx Time-out Interrupt Indicator
  320. * - \ref UART_INTSTS_HWMODINT_Msk : PDMA Mode MODEM Status Interrupt Indicator
  321. * - \ref UART_INTSTS_HWRLSINT_Msk : PDMA Mode Receive Line Status Interrupt Indicator
  322. * - \ref UART_INTSTS_TXENDINT_Msk : Transmitter Empty Interrupt Indicator
  323. * - \ref UART_INTSTS_SWBEINT_Msk : Single-wire Bit Error Detect Interrupt Indicator
  324. * - \ref UART_INTSTS_TXENDIF_Msk : Transmitter Empty Interrupt Flag
  325. * - \ref UART_INTSTS_HWBUFEIF_Msk : PDMA Mode Buffer Error Interrupt Flag
  326. * - \ref UART_INTSTS_HWTOIF_Msk : PDMA Mode Time-out Interrupt Flag
  327. * - \ref UART_INTSTS_HWMODIF_Msk : PDMA Mode MODEM Status Interrupt Flag
  328. * - \ref UART_INTSTS_HWRLSIF_Msk : PDMA Mode Receive Line Status Flag
  329. * - \ref UART_INTSTS_SWBEIF_Msk : Single-wire Bit Error Detect Interrupt Flag
  330. * - \ref UART_INTSTS_LININT_Msk : LIN Bus Interrupt Indicator
  331. * - \ref UART_INTSTS_WKINT_Msk : Wake-up Interrupt Indicator
  332. * - \ref UART_INTSTS_BUFERRINT_Msk : Buffer Error Interrupt Indicator
  333. * - \ref UART_INTSTS_RXTOINT_Msk : Rx Time-out Interrupt Indicator
  334. * - \ref UART_INTSTS_MODEMINT_Msk : Modem Status Interrupt Indicator
  335. * - \ref UART_INTSTS_RLSINT_Msk : Receive Line Status Interrupt Indicator
  336. * - \ref UART_INTSTS_THREINT_Msk : Transmit Holding Register Empty Interrupt Indicator
  337. * - \ref UART_INTSTS_RDAINT_Msk : Receive Data Available Interrupt Indicator
  338. * - \ref UART_INTSTS_LINIF_Msk : LIN Bus Interrupt Flag
  339. * - \ref UART_INTSTS_WKIF_Msk : Wake-up Interrupt Flag
  340. * - \ref UART_INTSTS_BUFERRIF_Msk : Buffer Error Interrupt Flag
  341. * - \ref UART_INTSTS_RXTOIF_Msk : Rx Time-out Interrupt Flag
  342. * - \ref UART_INTSTS_MODEMIF_Msk : MODEM Status Interrupt Flag
  343. * - \ref UART_INTSTS_RLSIF_Msk : Receive Line Status Interrupt Flag
  344. * - \ref UART_INTSTS_THREIF_Msk : Transmit Holding Register Empty Interrupt Flag
  345. * - \ref UART_INTSTS_RDAIF_Msk : Receive Data Available Interrupt Flag
  346. *
  347. * @retval 0 The specified interrupt is not happened.
  348. * 1 The specified interrupt is happened.
  349. *
  350. * @details This macro get specified interrupt flag or interrupt indicator status.
  351. * \hideinitializer
  352. */
  353. #define UART_GET_INT_FLAG(uart,u32eIntTypeFlag) (((uart)->INTSTS & (u32eIntTypeFlag))?1:0)
  354. /**
  355. * @brief Clear RS-485 Address Byte Detection Flag
  356. *
  357. * @param[in] uart The pointer of the specified UART module
  358. *
  359. * @return None
  360. *
  361. * @details This macro clear RS-485 address byte detection flag.
  362. * \hideinitializer
  363. */
  364. #define UART_RS485_CLEAR_ADDR_FLAG(uart) ((uart)->FIFOSTS = UART_FIFOSTS_ADDRDETF_Msk)
  365. /**
  366. * @brief Get RS-485 Address Byte Detection Flag
  367. *
  368. * @param[in] uart The pointer of the specified UART module
  369. *
  370. * @retval 0 Receiver detects a data that is not an address bit.
  371. * @retval 1 Receiver detects a data that is an address bit.
  372. *
  373. * @details This macro get RS-485 address byte detection flag.
  374. * \hideinitializer
  375. */
  376. #define UART_RS485_GET_ADDR_FLAG(uart) (((uart)->FIFOSTS & UART_FIFOSTS_ADDRDETF_Msk) >> UART_FIFOSTS_ADDRDETF_Pos)
  377. /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
  378. __STATIC_INLINE void UART_CLEAR_RTS(UART_T *uart);
  379. __STATIC_INLINE void UART_SET_RTS(UART_T *uart);
  380. /**
  381. * @brief Set RTS pin to low
  382. *
  383. * @param[in] uart The pointer of the specified UART module
  384. *
  385. * @return None
  386. *
  387. * @details This macro set RTS pin to low.
  388. * \hideinitializer
  389. */
  390. __STATIC_INLINE void UART_CLEAR_RTS(UART_T *uart)
  391. {
  392. uart->MODEM |= UART_MODEM_RTSACTLV_Msk;
  393. uart->MODEM &= ~UART_MODEM_RTS_Msk;
  394. }
  395. /**
  396. * @brief Set RTS pin to high
  397. *
  398. * @param[in] uart The pointer of the specified UART module
  399. *
  400. * @return None
  401. *
  402. * @details This macro set RTS pin to high.
  403. * \hideinitializer
  404. */
  405. __STATIC_INLINE void UART_SET_RTS(UART_T *uart)
  406. {
  407. uart->MODEM |= UART_MODEM_RTSACTLV_Msk | UART_MODEM_RTS_Msk;
  408. }
  409. /**
  410. * @brief Enable specified UART PDMA function
  411. *
  412. * @param[in] uart The pointer of the specified UART module
  413. * @param[in] u32FuncSel Combination of following functions
  414. * - \ref UART_INTEN_TXPDMAEN_Msk
  415. * - \ref UART_INTEN_RXPDMAEN_Msk
  416. *
  417. * @return None
  418. *
  419. * @details This macro enable specified UART PDMA function.
  420. * \hideinitializer
  421. */
  422. #define UART_PDMA_ENABLE(uart, u32FuncSel) ((uart)->INTEN |= (u32FuncSel))
  423. /**
  424. * @brief Disable specified UART PDMA function
  425. *
  426. * @param[in] uart The pointer of the specified UART module
  427. * @param[in] u32FuncSel Combination of following functions
  428. * - \ref UART_INTEN_TXPDMAEN_Msk
  429. * - \ref UART_INTEN_RXPDMAEN_Msk
  430. *
  431. * @return None
  432. *
  433. * @details This macro disable specified UART PDMA function.
  434. * \hideinitializer
  435. */
  436. #define UART_PDMA_DISABLE(uart, u32FuncSel) ((uart)->INTEN &= ~(u32FuncSel))
  437. void UART_ClearIntFlag(UART_T *uart, uint32_t u32InterruptFlag);
  438. void UART_Close(UART_T *uart);
  439. void UART_DisableFlowCtrl(UART_T *uart);
  440. void UART_DisableInt(UART_T *uart, uint32_t u32InterruptFlag);
  441. void UART_EnableFlowCtrl(UART_T *uart);
  442. void UART_EnableInt(UART_T *uart, uint32_t u32InterruptFlag);
  443. void UART_Open(UART_T *uart, uint32_t u32baudrate);
  444. uint32_t UART_Read(UART_T *uart, uint8_t pu8RxBuf[], uint32_t u32ReadBytes);
  445. void UART_SetLineConfig(UART_T *uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
  446. void UART_SetTimeoutCnt(UART_T *uart, uint32_t u32TOC);
  447. void UART_SelectIrDAMode(UART_T *uart, uint32_t u32Buadrate, uint32_t u32Direction);
  448. void UART_SelectRS485Mode(UART_T *uart, uint32_t u32Mode, uint32_t u32Addr);
  449. void UART_SelectLINMode(UART_T *uart, uint32_t u32Mode, uint32_t u32BreakLength);
  450. uint32_t UART_Write(UART_T *uart, uint8_t pu8TxBuf[], uint32_t u32WriteBytes);
  451. void UART_SelectSingleWireMode(UART_T *uart);
  452. /*@}*/ /* end of group UART_EXPORTED_FUNCTIONS */
  453. /*@}*/ /* end of group UART_Driver */
  454. /*@}*/ /* end of group Standard_Driver */
  455. #ifdef __cplusplus
  456. }
  457. #endif
  458. #endif /*__NU_UART_H__*/