usci_uart.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /**************************************************************************//**
  2. * @file usci_uart.h
  3. * @version V3.00
  4. * @brief M480 series USCI UART (UUART) driver header file
  5. *
  6. * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
  7. *****************************************************************************/
  8. #ifndef __USCI_UART_H__
  9. #define __USCI_UART_H__
  10. #ifdef __cplusplus
  11. extern "C"
  12. {
  13. #endif
  14. /** @addtogroup Standard_Driver Standard Driver
  15. @{
  16. */
  17. /** @addtogroup USCI_UART_Driver USCI_UART Driver
  18. @{
  19. */
  20. /** @addtogroup USCI_UART_EXPORTED_CONSTANTS USCI_UART Exported Constants
  21. @{
  22. */
  23. /*---------------------------------------------------------------------------------------------------------*/
  24. /* UUART_LINECTL constants definitions */
  25. /*---------------------------------------------------------------------------------------------------------*/
  26. #define UUART_WORD_LEN_6 (6ul << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 6 bits \hideinitializer */
  27. #define UUART_WORD_LEN_7 (7ul << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 7 bits \hideinitializer */
  28. #define UUART_WORD_LEN_8 (8ul << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 8 bits \hideinitializer */
  29. #define UUART_WORD_LEN_9 (9ul << UUART_LINECTL_DWIDTH_Pos) /*!< UUART_LINECTL setting to set UART word length to 9 bits \hideinitializer */
  30. /*---------------------------------------------------------------------------------------------------------*/
  31. /* UUART_PROTCTL constants definitions */
  32. /*---------------------------------------------------------------------------------------------------------*/
  33. #define UUART_PARITY_NONE (0x0ul << UUART_PROTCTL_PARITYEN_Pos) /*!< UUART_PROTCTL setting to set UART as no parity \hideinitializer */
  34. #define UUART_PARITY_ODD (0x1ul << UUART_PROTCTL_PARITYEN_Pos) /*!< UUART_PROTCTL setting to set UART as odd parity \hideinitializer */
  35. #define UUART_PARITY_EVEN (0x3ul << UUART_PROTCTL_PARITYEN_Pos) /*!< UUART_PROTCTL setting to set UART as even parity \hideinitializer */
  36. #define UUART_STOP_BIT_1 (0x0ul) /*!< UUART_PROTCTL setting for one stop bit \hideinitializer */
  37. #define UUART_STOP_BIT_2 (0x1ul) /*!< UUART_PROTCTL setting for two stop bit \hideinitializer */
  38. /*---------------------------------------------------------------------------------------------------------*/
  39. /* USCI UART interrupt mask definitions */
  40. /*---------------------------------------------------------------------------------------------------------*/
  41. #define UUART_ABR_INT_MASK (0x002ul) /*!< Auto-baud rate interrupt mask \hideinitializer */
  42. #define UUART_RLS_INT_MASK (0x004ul) /*!< Receive line status interrupt mask \hideinitializer */
  43. #define UUART_BUF_RXOV_INT_MASK (0x008ul) /*!< Buffer RX overrun interrupt mask \hideinitializer */
  44. #define UUART_TXST_INT_MASK (0x010ul) /*!< TX start interrupt mask \hideinitializer */
  45. #define UUART_TXEND_INT_MASK (0x020ul) /*!< Tx end interrupt mask \hideinitializer */
  46. #define UUART_RXST_INT_MASK (0x040ul) /*!< RX start interrupt mask \hideinitializer */
  47. #define UUART_RXEND_INT_MASK (0x080ul) /*!< RX end interrupt mask \hideinitializer */
  48. /*@}*/ /* end of group USCI_UART_EXPORTED_CONSTANTS */
  49. /** @addtogroup USCI_UART_EXPORTED_FUNCTIONS USCI_UART Exported Functions
  50. @{
  51. */
  52. /**
  53. * @brief Write USCI_UART data
  54. *
  55. * @param[in] uuart The pointer of the specified USCI_UART module
  56. * @param[in] u8Data Data byte to transmit.
  57. *
  58. * @return None
  59. *
  60. * @details This macro write Data to Tx data register.
  61. * \hideinitializer
  62. */
  63. #define UUART_WRITE(uuart, u8Data) ((uuart)->TXDAT = (u8Data))
  64. /**
  65. * @brief Read USCI_UART data
  66. *
  67. * @param[in] uuart The pointer of the specified USCI_UART module
  68. *
  69. * @return The oldest data byte in RX buffer.
  70. *
  71. * @details This macro read Rx data register.
  72. * \hideinitializer
  73. */
  74. #define UUART_READ(uuart) ((uuart)->RXDAT)
  75. /**
  76. * @brief Get Tx empty
  77. *
  78. * @param[in] uuart The pointer of the specified USCI_UART module
  79. *
  80. * @retval 0 Tx buffer is not empty
  81. * @retval >=1 Tx buffer is empty
  82. *
  83. * @details This macro get Transmitter buffer empty register value.
  84. * \hideinitializer
  85. */
  86. #define UUART_GET_TX_EMPTY(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_TXEMPTY_Msk)
  87. /**
  88. * @brief Get Rx empty
  89. *
  90. * @param[in] uuart The pointer of the specified USCI_UART module
  91. *
  92. * @retval 0 Rx buffer is not empty
  93. * @retval >=1 Rx buffer is empty
  94. *
  95. * @details This macro get Receiver buffer empty register value.
  96. * \hideinitializer
  97. */
  98. #define UUART_GET_RX_EMPTY(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_RXEMPTY_Msk)
  99. /**
  100. * @brief Check specified usci_uart port transmission is over.
  101. *
  102. * @param[in] uuart The pointer of the specified USCI_UART module
  103. *
  104. * @retval 0 Tx transmission is not over
  105. * @retval 1 Tx transmission is over
  106. *
  107. * @details This macro return Transmitter Empty Flag register bit value. \n
  108. * It indicates if specified usci_uart port transmission is over nor not.
  109. * \hideinitializer
  110. */
  111. #define UUART_IS_TX_EMPTY(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_TXEMPTY_Msk) >> UUART_BUFSTS_TXEMPTY_Pos)
  112. /**
  113. * @brief Check specified usci_uart port receiver is empty.
  114. *
  115. * @param[in] uuart The pointer of the specified USCI_UART module
  116. *
  117. * @retval 0 Rx receiver is not empty
  118. * @retval 1 Rx receiver is empty
  119. *
  120. * @details This macro return Receive Empty Flag register bit value. \n
  121. * It indicates if specified usci_uart port receiver is empty nor not.
  122. * \hideinitializer
  123. */
  124. #define UUART_IS_RX_EMPTY(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_RXEMPTY_Msk) >> UUART_BUFSTS_RXEMPTY_Pos)
  125. /**
  126. * @brief Wait specified usci_uart port transmission is over
  127. *
  128. * @param[in] uuart The pointer of the specified USCI_UART module
  129. *
  130. * @return None
  131. *
  132. * @details This macro wait specified usci_uart port transmission is over.
  133. * \hideinitializer
  134. */
  135. #define UUART_WAIT_TX_EMPTY(uuart) while(!((((uuart)->BUFSTS) & UUART_BUFSTS_TXEMPTY_Msk) >> UUART_BUFSTS_TXEMPTY_Pos))
  136. /**
  137. * @brief Check TX buffer is full or not
  138. *
  139. * @param[in] uuart The pointer of the specified USCI_UART module
  140. *
  141. * @retval 1 TX buffer is full
  142. * @retval 0 TX buffer is not full
  143. *
  144. * @details This macro check TX buffer is full or not.
  145. * \hideinitializer
  146. */
  147. #define UUART_IS_TX_FULL(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_TXFULL_Msk)>>UUART_BUFSTS_TXFULL_Pos)
  148. /**
  149. * @brief Check RX buffer is full or not
  150. *
  151. * @param[in] uuart The pointer of the specified USCI_UART module
  152. *
  153. * @retval 1 RX buffer is full
  154. * @retval 0 RX buffer is not full
  155. *
  156. * @details This macro check RX buffer is full or not.
  157. * \hideinitializer
  158. */
  159. #define UUART_IS_RX_FULL(uuart) (((uuart)->BUFSTS & UUART_BUFSTS_RXFULL_Msk)>>UUART_BUFSTS_RXFULL_Pos)
  160. /**
  161. * @brief Get Tx full register value
  162. *
  163. * @param[in] uuart The pointer of the specified USCI_UART module
  164. *
  165. * @retval 0 Tx buffer is not full.
  166. * @retval >=1 Tx buffer is full.
  167. *
  168. * @details This macro get Tx full register value.
  169. * \hideinitializer
  170. */
  171. #define UUART_GET_TX_FULL(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_TXFULL_Msk)
  172. /**
  173. * @brief Get Rx full register value
  174. *
  175. * @param[in] uuart The pointer of the specified USCI_UART module
  176. *
  177. * @retval 0 Rx buffer is not full.
  178. * @retval >=1 Rx buffer is full.
  179. *
  180. * @details This macro get Rx full register value.
  181. * \hideinitializer
  182. */
  183. #define UUART_GET_RX_FULL(uuart) ((uuart)->BUFSTS & UUART_BUFSTS_RXFULL_Msk)
  184. /**
  185. * @brief Enable specified USCI_UART protocol interrupt
  186. *
  187. * @param[in] uuart The pointer of the specified USCI_UART module
  188. * @param[in] u32IntSel Interrupt type select
  189. * - \ref UUART_PROTIEN_RLSIEN_Msk : Rx Line status interrupt
  190. * - \ref UUART_PROTIEN_ABRIEN_Msk : Auto-baud rate interrupt
  191. *
  192. * @return None
  193. *
  194. * @details This macro enable specified USCI_UART protocol interrupt.
  195. * \hideinitializer
  196. */
  197. #define UUART_ENABLE_PROT_INT(uuart, u32IntSel) ((uuart)->PROTIEN |= (u32IntSel))
  198. /**
  199. * @brief Disable specified USCI_UART protocol interrupt
  200. *
  201. * @param[in] uuart The pointer of the specified USCI_UART module
  202. * @param[in] u32IntSel Interrupt type select
  203. * - \ref UUART_PROTIEN_RLSIEN_Msk : Rx Line status interrupt
  204. * - \ref UUART_PROTIEN_ABRIEN_Msk : Auto-baud rate interrupt
  205. *
  206. * @return None
  207. *
  208. * @details This macro disable specified USCI_UART protocol interrupt.
  209. * \hideinitializer
  210. */
  211. #define UUART_DISABLE_PROT_INT(uuart, u32IntSel) ((uuart)->PROTIEN &= ~(u32IntSel))
  212. /**
  213. * @brief Enable specified USCI_UART buffer interrupt
  214. *
  215. * @param[in] uuart The pointer of the specified USCI_UART module
  216. * @param[in] u32IntSel Interrupt type select
  217. * - \ref UUART_BUFCTL_RXOVIEN_Msk : Receive buffer overrun error interrupt
  218. *
  219. * @return None
  220. *
  221. * @details This macro enable specified USCI_UART buffer interrupt.
  222. * \hideinitializer
  223. */
  224. #define UUART_ENABLE_BUF_INT(uuart, u32IntSel) ((uuart)->BUFCTL |= (u32IntSel))
  225. /**
  226. * @brief Disable specified USCI_UART buffer interrupt
  227. *
  228. * @param[in] uuart The pointer of the specified USCI_UART module
  229. * @param[in] u32IntSel Interrupt type select
  230. * - \ref UUART_BUFCTL_RXOVIEN_Msk : Receive buffer overrun error interrupt
  231. *
  232. * @return None
  233. *
  234. * @details This macro disable specified USCI_UART buffer interrupt.
  235. * \hideinitializer
  236. */
  237. #define UUART_DISABLE_BUF_INT(uuart, u32IntSel) ((uuart)->BUFCTL &= ~ (u32IntSel))
  238. /**
  239. * @brief Enable specified USCI_UART transfer interrupt
  240. *
  241. * @param[in] uuart The pointer of the specified USCI_UART module
  242. * @param[in] u32IntSel Interrupt type select
  243. * - \ref UUART_INTEN_RXENDIEN_Msk : Receive end interrupt
  244. * - \ref UUART_INTEN_RXSTIEN_Msk : Receive start interrupt
  245. * - \ref UUART_INTEN_TXENDIEN_Msk : Transmit end interrupt
  246. * - \ref UUART_INTEN_TXSTIEN_Msk : Transmit start interrupt
  247. *
  248. * @return None
  249. *
  250. * @details This macro enable specified USCI_UART transfer interrupt.
  251. * \hideinitializer
  252. */
  253. #define UUART_ENABLE_TRANS_INT(uuart, u32IntSel) ((uuart)->INTEN |= (u32IntSel))
  254. /**
  255. * @brief Disable specified USCI_UART transfer interrupt
  256. *
  257. * @param[in] uuart The pointer of the specified USCI_UART module
  258. * @param[in] u32IntSel Interrupt type select
  259. * - \ref UUART_INTEN_RXENDIEN_Msk : Receive end interrupt
  260. * - \ref UUART_INTEN_RXSTIEN_Msk : Receive start interrupt
  261. * - \ref UUART_INTEN_TXENDIEN_Msk : Transmit end interrupt
  262. * - \ref UUART_INTEN_TXSTIEN_Msk : Transmit start interrupt
  263. *
  264. * @return None
  265. *
  266. * @details This macro disable specified USCI_UART transfer interrupt.
  267. * \hideinitializer
  268. */
  269. #define UUART_DISABLE_TRANS_INT(uuart, u32IntSel) ((uuart)->INTEN &= ~(u32IntSel))
  270. /**
  271. * @brief Get protocol interrupt flag/status
  272. *
  273. * @param[in] uuart The pointer of the specified USCI_UART module
  274. *
  275. * @return The interrupt flag/status of protocol status register.
  276. *
  277. * @details This macro get protocol status register value.
  278. * \hideinitializer
  279. */
  280. #define UUART_GET_PROT_STATUS(uuart) ((uuart)->PROTSTS)
  281. /**
  282. * @brief Clear specified protocol interrupt flag
  283. *
  284. * @param[in] uuart The pointer of the specified USCI_UART module
  285. * @param[in] u32IntTypeFlag Interrupt Type Flag, should be
  286. * - \ref UUART_PROTSTS_ABERRSTS_Msk : Auto-baud Rate Error Interrupt Indicator
  287. * - \ref UUART_PROTSTS_ABRDETIF_Msk : Auto-baud Rate Detected Interrupt Flag
  288. * - \ref UUART_PROTSTS_BREAK_Msk : Break Flag
  289. * - \ref UUART_PROTSTS_FRMERR_Msk : Framing Error Flag
  290. * - \ref UUART_PROTSTS_PARITYERR_Msk : Parity Error Flag
  291. * - \ref UUART_PROTSTS_RXENDIF_Msk : Receive End Interrupt Flag
  292. * - \ref UUART_PROTSTS_RXSTIF_Msk : Receive Start Interrupt Flag
  293. * - \ref UUART_PROTSTS_TXENDIF_Msk : Transmit End Interrupt Flag
  294. * - \ref UUART_PROTSTS_TXSTIF_Msk : Transmit Start Interrupt Flag
  295. *
  296. * @return None
  297. *
  298. * @details This macro clear specified protocol interrupt flag.
  299. * \hideinitializer
  300. */
  301. #define UUART_CLR_PROT_INT_FLAG(uuart,u32IntTypeFlag) ((uuart)->PROTSTS = (u32IntTypeFlag))
  302. /**
  303. * @brief Get transmit/receive buffer interrupt flag/status
  304. *
  305. * @param[in] uuart The pointer of the specified USCI_UART module
  306. *
  307. * @return The interrupt flag/status of buffer status register.
  308. *
  309. * @details This macro get buffer status register value.
  310. * \hideinitializer
  311. */
  312. #define UUART_GET_BUF_STATUS(uuart) ((uuart)->BUFSTS)
  313. /**
  314. * @brief Clear specified buffer interrupt flag
  315. *
  316. * @param[in] uuart The pointer of the specified USCI_UART module
  317. * @param[in] u32IntTypeFlag Interrupt Type Flag, should be
  318. * - \ref UUART_BUFSTS_RXOVIF_Msk : Receive Buffer Over-run Error Interrupt Indicator
  319. *
  320. * @return None
  321. *
  322. * @details This macro clear specified buffer interrupt flag.
  323. * \hideinitializer
  324. */
  325. #define UUART_CLR_BUF_INT_FLAG(uuart,u32IntTypeFlag) ((uuart)->BUFSTS = (u32IntTypeFlag))
  326. /**
  327. * @brief Get wakeup flag
  328. *
  329. * @param[in] uuart The pointer of the specified USCI_UART module
  330. *
  331. * @retval 0 Chip did not wake up from power-down mode.
  332. * @retval 1 Chip waked up from power-down mode.
  333. *
  334. * @details This macro get wakeup flag.
  335. * \hideinitializer
  336. */
  337. #define UUART_GET_WAKEUP_FLAG(uuart) ((uuart)->WKSTS & UUART_WKSTS_WKF_Msk ? 1: 0 )
  338. /**
  339. * @brief Clear wakeup flag
  340. *
  341. * @param[in] uuart The pointer of the specified USCI_UART module
  342. *
  343. * @return None
  344. *
  345. * @details This macro clear wakeup flag.
  346. * \hideinitializer
  347. */
  348. #define UUART_CLR_WAKEUP_FLAG(uuart) ((uuart)->WKSTS = UUART_WKSTS_WKF_Msk)
  349. void UUART_ClearIntFlag(UUART_T* uuart, uint32_t u32Mask);
  350. uint32_t UUART_GetIntFlag(UUART_T* uuart, uint32_t u32Mask);
  351. void UUART_Close(UUART_T* uuart);
  352. void UUART_DisableInt(UUART_T* uuart, uint32_t u32Mask);
  353. void UUART_EnableInt(UUART_T* uuart, uint32_t u32Mask);
  354. uint32_t UUART_Open(UUART_T* uuart, uint32_t u32baudrate);
  355. uint32_t UUART_Read(UUART_T* uuart, uint8_t pu8RxBuf[], uint32_t u32ReadBytes);
  356. uint32_t UUART_SetLine_Config(UUART_T* uuart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
  357. uint32_t UUART_Write(UUART_T* uuart, uint8_t pu8TxBuf[], uint32_t u32WriteBytes);
  358. void UUART_EnableWakeup(UUART_T* uuart, uint32_t u32WakeupMode);
  359. void UUART_DisableWakeup(UUART_T* uuart);
  360. void UUART_EnableFlowCtrl(UUART_T* uuart);
  361. void UUART_DisableFlowCtrl(UUART_T* uuart);
  362. /*@}*/ /* end of group USCI_UART_EXPORTED_FUNCTIONS */
  363. /*@}*/ /* end of group USCI_UART_Driver */
  364. /*@}*/ /* end of group Standard_Driver */
  365. #ifdef __cplusplus
  366. }
  367. #endif
  368. #endif /* __USCI_UART_H__ */
  369. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/