nu_uart.h 24 KB

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