uart.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _UART_H_
  13. #define _UART_H_
  14. // Auto generated by dtools(see dtools.txt for its version).
  15. // Don't edit it manually!
  16. #define UART_RX_FIFO_SIZE (128)
  17. #define UART_TX_FIFO_SIZE (16)
  18. #define NB_RX_FIFO_BITS (7)
  19. #define NB_TX_FIFO_BITS (4)
  20. #define REG_UART1_BASE (0x51700000)
  21. #define REG_UART2_BASE (0x51400000)
  22. #define REG_UART3_BASE (0x51401000)
  23. #define REG_UART4_BASE (0x04400000)
  24. #define REG_UART5_BASE (0x04401000)
  25. #define REG_UART6_BASE (0x04402000)
  26. typedef volatile struct
  27. {
  28. uint32_t ctrl; // 0x00000000
  29. uint32_t status; // 0x00000004
  30. uint32_t rxtx_buffer; // 0x00000008
  31. uint32_t irq_mask; // 0x0000000c
  32. uint32_t irq_cause; // 0x00000010
  33. uint32_t triggers; // 0x00000014
  34. uint32_t cmd_set; // 0x00000018
  35. uint32_t cmd_clr; // 0x0000001c
  36. uint32_t auto_ratio; // 0x00000020
  37. uint32_t xon; // 0x00000024
  38. uint32_t xoff; // 0x00000028
  39. } HWP_UART_T;
  40. #define hwp_uart1 ((HWP_UART_T *)REG_ACCESS_ADDRESS(REG_UART1_BASE))
  41. #define hwp_uart2 ((HWP_UART_T *)REG_ACCESS_ADDRESS(REG_UART2_BASE))
  42. #define hwp_uart3 ((HWP_UART_T *)REG_ACCESS_ADDRESS(REG_UART3_BASE))
  43. #define hwp_uart4 ((HWP_UART_T *)REG_ACCESS_ADDRESS(REG_UART4_BASE))
  44. #define hwp_uart5 ((HWP_UART_T *)REG_ACCESS_ADDRESS(REG_UART5_BASE))
  45. #define hwp_uart6 ((HWP_UART_T *)REG_ACCESS_ADDRESS(REG_UART6_BASE))
  46. // ctrl
  47. typedef union {
  48. uint32_t v;
  49. struct
  50. {
  51. uint32_t enable : 1; // [0]
  52. uint32_t data_bits : 1; // [1]
  53. uint32_t tx_stop_bits : 1; // [2]
  54. uint32_t parity_enable : 1; // [3]
  55. uint32_t parity_select : 2; // [5:4]
  56. uint32_t soft_flow_ctrl_enable : 1; // [6]
  57. uint32_t __7_7 : 1; // [7]
  58. uint32_t auto_enable : 1; // [8]
  59. uint32_t __11_9 : 3; // [11:9]
  60. uint32_t data_bits_56 : 1; // [12]
  61. uint32_t __18_13 : 6; // [18:13]
  62. uint32_t divisor_mode : 2; // [20:19]
  63. uint32_t irda_enable : 1; // [21]
  64. uint32_t dma_mode : 1; // [22]
  65. uint32_t auto_flow_control : 1; // [23]
  66. uint32_t loop_back_mode : 1; // [24]
  67. uint32_t rx_lock_err : 1; // [25]
  68. uint32_t __27_26 : 2; // [27:26]
  69. uint32_t rx_break_length : 4; // [31:28]
  70. } b;
  71. } REG_UART_CTRL_T;
  72. // status
  73. typedef union {
  74. uint32_t v;
  75. struct
  76. {
  77. uint32_t rx_fifo_level : 8; // [7:0], read only
  78. uint32_t tx_fifo_space : 5; // [12:8], read only
  79. uint32_t at_match_flag : 1; // [13], read only
  80. uint32_t tx_active : 1; // [14], read only
  81. uint32_t rx_active : 1; // [15], read only
  82. uint32_t rx_overflow_err : 1; // [16], read only
  83. uint32_t tx_overflow_err : 1; // [17], read only
  84. uint32_t rx_parity_err : 1; // [18], read only
  85. uint32_t rx_framing_err : 1; // [19], read only
  86. uint32_t rx_break_int : 1; // [20], read only
  87. uint32_t character_miscompare : 1; // [21], read only
  88. uint32_t auto_baud_locked : 1; // [22], read only
  89. uint32_t __23_23 : 1; // [23]
  90. uint32_t dcts : 1; // [24], read only
  91. uint32_t cts : 1; // [25], read only
  92. uint32_t auto_ratio_flag : 1; // [26], read only
  93. uint32_t mask_tx_enable_flag : 1; // [27], read only
  94. uint32_t dtr : 1; // [28], read only
  95. uint32_t __30_29 : 2; // [30:29]
  96. uint32_t clk_enabled : 1; // [31], read only
  97. } b;
  98. } REG_UART_STATUS_T;
  99. // rxtx_buffer
  100. typedef union {
  101. uint32_t v;
  102. struct
  103. {
  104. uint32_t rxtx_data : 8; // [7:0]
  105. uint32_t __31_8 : 24; // [31:8]
  106. } b;
  107. } REG_UART_RXTX_BUFFER_T;
  108. // irq_mask
  109. typedef union {
  110. uint32_t v;
  111. struct
  112. {
  113. uint32_t tx_modem_status : 1; // [0]
  114. uint32_t rx_data_available : 1; // [1]
  115. uint32_t tx_data_needed : 1; // [2]
  116. uint32_t rx_timeout : 1; // [3]
  117. uint32_t rx_line_err : 1; // [4]
  118. uint32_t tx_dma_done : 1; // [5]
  119. uint32_t rx_dma_done : 1; // [6]
  120. uint32_t rx_dma_timeout : 1; // [7]
  121. uint32_t dtr_rise : 1; // [8]
  122. uint32_t dtr_fall : 1; // [9]
  123. uint32_t auto_fail : 1; // [10]
  124. uint32_t uart_dma_rx_adone : 1; // [11]
  125. uint32_t uart_dma_tx_adone : 1; // [12]
  126. uint32_t xoff_trig : 1; // [13]
  127. uint32_t xon_trig : 1; // [14]
  128. uint32_t start_det : 1; // [15]
  129. uint32_t __31_16 : 16; // [31:16]
  130. } b;
  131. } REG_UART_IRQ_MASK_T;
  132. // irq_cause
  133. typedef union {
  134. uint32_t v;
  135. struct
  136. {
  137. uint32_t tx_modem_status : 1; // [0], read only
  138. uint32_t rx_data_available : 1; // [1], read only
  139. uint32_t tx_data_needed : 1; // [2], read only
  140. uint32_t rx_timeout : 1; // [3], read only
  141. uint32_t rx_line_err : 1; // [4], read only
  142. uint32_t tx_dma_done : 1; // [5]
  143. uint32_t rx_dma_done : 1; // [6]
  144. uint32_t rx_dma_timeout : 1; // [7]
  145. uint32_t dtr_rise : 1; // [8]
  146. uint32_t dtr_fall : 1; // [9]
  147. uint32_t auto_fail : 1; // [10]
  148. uint32_t uart_dma_rx_adone : 1; // [11]
  149. uint32_t uart_dma_tx_adone : 1; // [12]
  150. uint32_t xoff_trig : 1; // [13]
  151. uint32_t xon_trig : 1; // [14]
  152. uint32_t start_det : 1; // [15]
  153. uint32_t tx_modem_status_u : 1; // [16], read only
  154. uint32_t rx_data_available_u : 1; // [17], read only
  155. uint32_t tx_data_needed_u : 1; // [18], read only
  156. uint32_t rx_timeout_u : 1; // [19], read only
  157. uint32_t rx_line_err_u : 1; // [20], read only
  158. uint32_t tx_dma_done_u : 1; // [21], read only
  159. uint32_t rx_dma_done_u : 1; // [22], read only
  160. uint32_t rx_dma_timeout_u : 1; // [23], read only
  161. uint32_t dtr_rise_u : 1; // [24], read only
  162. uint32_t dtr_fall_u : 1; // [25], read only
  163. uint32_t auto_fail_u : 1; // [26], read only
  164. uint32_t uart_dma_rx_adone_u : 1; // [27]
  165. uint32_t uart_dma_tx_adone_u : 1; // [28]
  166. uint32_t xoff_trig_u : 1; // [29]
  167. uint32_t xon_trig_u : 1; // [30]
  168. uint32_t start_det_u : 1; // [31]
  169. } b;
  170. } REG_UART_IRQ_CAUSE_T;
  171. // triggers
  172. typedef union {
  173. uint32_t v;
  174. struct
  175. {
  176. uint32_t rx_trigger : 7; // [6:0]
  177. uint32_t __7_7 : 1; // [7]
  178. uint32_t tx_trigger : 4; // [11:8]
  179. uint32_t __15_12 : 4; // [15:12]
  180. uint32_t afc_level : 7; // [22:16]
  181. uint32_t __31_23 : 9; // [31:23]
  182. } b;
  183. } REG_UART_TRIGGERS_T;
  184. // cmd_set
  185. typedef union {
  186. uint32_t v;
  187. struct
  188. {
  189. uint32_t ri : 1; // [0], write set
  190. uint32_t dcd : 1; // [1], write set
  191. uint32_t dsr : 1; // [2], write set
  192. uint32_t tx_break_control : 1; // [3], write set
  193. uint32_t tx_finish_n_wait : 1; // [4], write set
  194. uint32_t rts : 1; // [5], write set
  195. uint32_t rx_fifo_reset : 1; // [6], read only
  196. uint32_t tx_fifo_reset : 1; // [7], read only
  197. uint32_t __31_8 : 24; // [31:8]
  198. } b;
  199. } REG_UART_CMD_SET_T;
  200. // cmd_clr
  201. typedef union {
  202. uint32_t v;
  203. struct
  204. {
  205. uint32_t ri : 1; // [0], write clear
  206. uint32_t dcd : 1; // [1], write clear
  207. uint32_t dsr : 1; // [2], write clear
  208. uint32_t tx_break_control : 1; // [3], write clear
  209. uint32_t tx_finish_n_wait : 1; // [4], write clear
  210. uint32_t rts : 1; // [5], write clear
  211. uint32_t __31_6 : 26; // [31:6]
  212. } b;
  213. } REG_UART_CMD_CLR_T;
  214. // auto_ratio
  215. typedef union {
  216. uint32_t v;
  217. struct
  218. {
  219. uint32_t auto_ratio : 16; // [15:0], read only
  220. uint32_t __31_16 : 16; // [31:16]
  221. } b;
  222. } REG_UART_AUTO_RATIO_T;
  223. // xon
  224. typedef union {
  225. uint32_t v;
  226. struct
  227. {
  228. uint32_t xon : 8; // [7:0]
  229. uint32_t __31_8 : 24; // [31:8]
  230. } b;
  231. } REG_UART_XON_T;
  232. // xoff
  233. typedef union {
  234. uint32_t v;
  235. struct
  236. {
  237. uint32_t xoff : 8; // [7:0]
  238. uint32_t __31_8 : 24; // [31:8]
  239. } b;
  240. } REG_UART_XOFF_T;
  241. // ctrl
  242. #define UART_ENABLE_DISABLE (0 << 0)
  243. #define UART_ENABLE_ENABLE (1 << 0)
  244. #define UART_DATA_BITS (1 << 1)
  245. #define UART_TX_STOP_BITS_1_BIT (0 << 2)
  246. #define UART_TX_STOP_BITS_2_BITS (1 << 2)
  247. #define UART_PARITY_ENABLE_NO (0 << 3)
  248. #define UART_PARITY_ENABLE_YES (1 << 3)
  249. #define UART_PARITY_SELECT(n) (((n)&0x3) << 4)
  250. #define UART_PARITY_SELECT_ODD (0 << 4)
  251. #define UART_PARITY_SELECT_EVEN (1 << 4)
  252. #define UART_PARITY_SELECT_SPACE (2 << 4)
  253. #define UART_PARITY_SELECT_MARK (3 << 4)
  254. #define UART_SOFT_FLOW_CTRL_ENABLE (1 << 6)
  255. #define UART_AUTO_ENABLE (1 << 8)
  256. #define UART_DATA_BITS_56 (1 << 12)
  257. #define UART_DIVISOR_MODE(n) (((n)&0x3) << 19)
  258. #define UART_IRDA_ENABLE (1 << 21)
  259. #define UART_DMA_MODE_DISABLE (0 << 22)
  260. #define UART_DMA_MODE_ENABLE (1 << 22)
  261. #define UART_AUTO_FLOW_CONTROL_ENABLE (1 << 23)
  262. #define UART_AUTO_FLOW_CONTROL_DISABLE (0 << 23)
  263. #define UART_LOOP_BACK_MODE (1 << 24)
  264. #define UART_RX_LOCK_ERR (1 << 25)
  265. #define UART_RX_BREAK_LENGTH(n) (((n)&0xf) << 28)
  266. #define UART_ENABLE_V_DISABLE (0)
  267. #define UART_ENABLE_V_ENABLE (1)
  268. #define UART_TX_STOP_BITS_V_1_BIT (0)
  269. #define UART_TX_STOP_BITS_V_2_BITS (1)
  270. #define UART_PARITY_ENABLE_V_NO (0)
  271. #define UART_PARITY_ENABLE_V_YES (1)
  272. #define UART_PARITY_SELECT_V_ODD (0)
  273. #define UART_PARITY_SELECT_V_EVEN (1)
  274. #define UART_PARITY_SELECT_V_SPACE (2)
  275. #define UART_PARITY_SELECT_V_MARK (3)
  276. #define UART_DMA_MODE_V_DISABLE (0)
  277. #define UART_DMA_MODE_V_ENABLE (1)
  278. #define UART_AUTO_FLOW_CONTROL_V_ENABLE (1)
  279. #define UART_AUTO_FLOW_CONTROL_V_DISABLE (0)
  280. // status
  281. #define UART_RX_FIFO_LEVEL(n) (((n)&0xff) << 0)
  282. #define UART_TX_FIFO_SPACE(n) (((n)&0x1f) << 8)
  283. #define UART_AT_MATCH_FLAG (1 << 13)
  284. #define UART_TX_ACTIVE (1 << 14)
  285. #define UART_RX_ACTIVE (1 << 15)
  286. #define UART_RX_OVERFLOW_ERR (1 << 16)
  287. #define UART_TX_OVERFLOW_ERR (1 << 17)
  288. #define UART_RX_PARITY_ERR (1 << 18)
  289. #define UART_RX_FRAMING_ERR (1 << 19)
  290. #define UART_RX_BREAK_INT (1 << 20)
  291. #define UART_CHARACTER_MISCOMPARE (1 << 21)
  292. #define UART_AUTO_BAUD_LOCKED (1 << 22)
  293. #define UART_DCTS (1 << 24)
  294. #define UART_CTS (1 << 25)
  295. #define UART_AUTO_RATIO_FLAG (1 << 26)
  296. #define UART_MASK_TX_ENABLE_FLAG (1 << 27)
  297. #define UART_DTR (1 << 28)
  298. #define UART_CLK_ENABLED (1 << 31)
  299. // rxtx_buffer
  300. #define UART_RXTX_DATA(n) (((n)&0xff) << 0)
  301. // irq_mask
  302. #define UART_TX_MODEM_STATUS (1 << 0)
  303. #define UART_RX_DATA_AVAILABLE (1 << 1)
  304. #define UART_TX_DATA_NEEDED (1 << 2)
  305. #define UART_RX_TIMEOUT (1 << 3)
  306. #define UART_RX_LINE_ERR (1 << 4)
  307. #define UART_TX_DMA_DONE (1 << 5)
  308. #define UART_RX_DMA_DONE (1 << 6)
  309. #define UART_RX_DMA_TIMEOUT (1 << 7)
  310. #define UART_DTR_RISE (1 << 8)
  311. #define UART_DTR_FALL (1 << 9)
  312. #define UART_AUTO_FAIL (1 << 10)
  313. #define UART_UART_DMA_RX_ADONE (1 << 11)
  314. #define UART_UART_DMA_TX_ADONE (1 << 12)
  315. #define UART_XOFF_TRIG (1 << 13)
  316. #define UART_XON_TRIG (1 << 14)
  317. #define UART_START_DET (1 << 15)
  318. // irq_cause
  319. #define UART_TX_MODEM_STATUS (1 << 0)
  320. #define UART_RX_DATA_AVAILABLE (1 << 1)
  321. #define UART_TX_DATA_NEEDED (1 << 2)
  322. #define UART_RX_TIMEOUT (1 << 3)
  323. #define UART_RX_LINE_ERR (1 << 4)
  324. #define UART_TX_DMA_DONE (1 << 5)
  325. #define UART_RX_DMA_DONE (1 << 6)
  326. #define UART_RX_DMA_TIMEOUT (1 << 7)
  327. #define UART_DTR_RISE (1 << 8)
  328. #define UART_DTR_FALL (1 << 9)
  329. #define UART_AUTO_FAIL (1 << 10)
  330. #define UART_UART_DMA_RX_ADONE (1 << 11)
  331. #define UART_UART_DMA_TX_ADONE (1 << 12)
  332. #define UART_XOFF_TRIG (1 << 13)
  333. #define UART_XON_TRIG (1 << 14)
  334. #define UART_START_DET (1 << 15)
  335. #define UART_TX_MODEM_STATUS_U (1 << 16)
  336. #define UART_RX_DATA_AVAILABLE_U (1 << 17)
  337. #define UART_TX_DATA_NEEDED_U (1 << 18)
  338. #define UART_RX_TIMEOUT_U (1 << 19)
  339. #define UART_RX_LINE_ERR_U (1 << 20)
  340. #define UART_TX_DMA_DONE_U (1 << 21)
  341. #define UART_RX_DMA_DONE_U (1 << 22)
  342. #define UART_RX_DMA_TIMEOUT_U (1 << 23)
  343. #define UART_DTR_RISE_U (1 << 24)
  344. #define UART_DTR_FALL_U (1 << 25)
  345. #define UART_AUTO_FAIL_U (1 << 26)
  346. #define UART_UART_DMA_RX_ADONE_U (1 << 27)
  347. #define UART_UART_DMA_TX_ADONE_U (1 << 28)
  348. #define UART_XOFF_TRIG_U (1 << 29)
  349. #define UART_XON_TRIG_U (1 << 30)
  350. #define UART_START_DET_U (1 << 31)
  351. // triggers
  352. #define UART_RX_TRIGGER(n) (((n)&0x7f) << 0)
  353. #define UART_TX_TRIGGER(n) (((n)&0xf) << 8)
  354. #define UART_AFC_LEVEL(n) (((n)&0x7f) << 16)
  355. // cmd_set
  356. #define UART_RI (1 << 0)
  357. #define UART_DCD (1 << 1)
  358. #define UART_DSR (1 << 2)
  359. #define UART_TX_BREAK_CONTROL (1 << 3)
  360. #define UART_TX_FINISH_N_WAIT (1 << 4)
  361. #define UART_RTS (1 << 5)
  362. #define UART_RX_FIFO_RESET (1 << 6)
  363. #define UART_TX_FIFO_RESET (1 << 7)
  364. // cmd_clr
  365. #define UART_RI (1 << 0)
  366. #define UART_DCD (1 << 1)
  367. #define UART_DSR (1 << 2)
  368. #define UART_TX_BREAK_CONTROL (1 << 3)
  369. #define UART_TX_FINISH_N_WAIT (1 << 4)
  370. #define UART_RTS (1 << 5)
  371. // auto_ratio
  372. #define UART_AUTO_RATIO(n) (((n)&0xffff) << 0)
  373. // xon
  374. #define UART_XON(n) (((n)&0xff) << 0)
  375. // xoff
  376. #define UART_XOFF(n) (((n)&0xff) << 0)
  377. #endif // _UART_H_