lpc17xx_usart.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. #ifndef _LPC17XX_USART_H_
  2. #define _LPC17XX_USART_H_
  3. /*
  4. * Copyright (C) 2012 by Ole Reinhardt <ole.reinhardt@embedded-it.de>
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. /*
  37. * \verbatim
  38. * $Id: $
  39. * \endverbatim
  40. */
  41. /*----------------------------------------------------------------------------*
  42. General defines
  43. *----------------------------------------------------------------------------*/
  44. /* Accepted Error baud rate value (in percent unit) */
  45. #define UART_ACCEPTED_BAUDRATE_ERROR 3
  46. /*----------------------------------------------------------------------------*
  47. Receive and transmit register masks
  48. *----------------------------------------------------------------------------*/
  49. /* UART Received Buffer mask bit (8 bits) */
  50. #define UART_RBR_MASK 0xFF
  51. /* UART Transmit Holding mask bit (8 bits) */
  52. #define UART_THR_MASK 0xFF
  53. /*----------------------------------------------------------------------------*
  54. Devisior latch defines
  55. *----------------------------------------------------------------------------*/
  56. /* Macro for loading least significant halfs of divisors into LSB register */
  57. #define UART_LOAD_DLL(div) ((div) & 0xFF)
  58. /* Divisor latch LSB bit mask */
  59. #define UART_DLL_MASKBIT 0xFF
  60. /* Divisor latch MSB bit mask */
  61. #define UART_DLM_MASKBIT 0xFF
  62. /* Macro for loading most significant halfs of divisors */
  63. #define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF)
  64. /*----------------------------------------------------------------------------*
  65. Interrupt defines
  66. *----------------------------------------------------------------------------*/
  67. /* RBR Interrupt enable */
  68. #define UART_IER_RBRINT_EN_POS 0
  69. #define UART_IER_RBRINT_EN 0x00000001
  70. /* THR Interrupt enable */
  71. #define UART_IER_THREINT_EN_POS 1
  72. #define UART_IER_THREINT_EN 0x00000002
  73. /* RX line status interrupt enable */
  74. #define UART_IER_RLSINT_EN_POS 2
  75. #define UART_IER_RLSINT_EN 0x00000004
  76. /* Modem status interrupt enable */
  77. #define UART1_IER_MSINT_EN_POS 3
  78. #define UART1_IER_MSINT_EN 0x00000008
  79. /* CTS1 signal transition interrupt enable */
  80. #define UART1_IER_CTSINT_EN_POS 7
  81. #define UART1_IER_CTSINT_EN 0x00000080
  82. /* Enables the end of auto-baud interrupt */
  83. #define UART_IER_ABEOINT_EN_POS 8
  84. #define UART_IER_ABEOINT_EN 0x00000100
  85. /* Enables the auto-baud time-out interrupt */
  86. #define UART_IER_ABTOINT_EN_POS 9
  87. #define UART_IER_ABTOINT_EN 0x00000200
  88. /* UART interrupt enable register bit mask */
  89. #define UART_IER_BITMASK 0x00000307
  90. /* UART1 interrupt enable register bit mask */
  91. #define UART1_IER_BITMASK 0x0000038F
  92. /*----------------------------------------------------------------------------*
  93. UART interrupt identification register defines
  94. *----------------------------------------------------------------------------*/
  95. /* Interrupt Status - Active low */
  96. #define UART_IIR_INTSTAT_PEND 0x00000001
  97. /* Interrupt identification: Receive line status*/
  98. #define UART_IIR_INTID_RLS 0x00000006
  99. /* Interrupt identification: Receive data available*/
  100. #define UART_IIR_INTID_RDA 0x00000004
  101. /* Interrupt identification: Character time-out indicator*/
  102. #define UART_IIR_INTID_CTI 0x0000000C
  103. /* Interrupt identification: THRE interrupt*/
  104. #define UART_IIR_INTID_THRE 0x00000002
  105. /* Interrupt identification: Modem interrupt*/
  106. #define UART1_IIR_INTID_MODEM 0x00000000
  107. /* Interrupt identification: Interrupt ID mask */
  108. #define UART_IIR_INTID_MASK 0x0000000E
  109. /* These bits are equivalent to UnFCR[0] */
  110. #define UART_IIR_FIFO_EN 0x000000C0
  111. /* End of auto-baud interrupt */
  112. #define UART_IIR_ABEO_INT 0x00000100
  113. /* Auto-baud time-out interrupt */
  114. #define UART_IIR_ABTO_INT 0x00000200
  115. /* UART interrupt identification register bit mask */
  116. #define UART_IIR_BITMASK 0x000003CF
  117. /*----------------------------------------------------------------------------*
  118. UART FIFO control register defines
  119. *----------------------------------------------------------------------------*/
  120. /* UART FIFO enable */
  121. #define UART_FCR_FIFO_EN 0x00000001
  122. /* UART FIFO RX reset */
  123. #define UART_FCR_RX_RS 0x00000002
  124. /* UART FIFO TX reset */
  125. #define UART_FCR_TX_RS 0x00000004
  126. /* UART DMA mode selection */
  127. #define UART_FCR_DMAMODE_SEL 0x00000008
  128. /* UART FIFO trigger level 0: 1 character */
  129. #define UART_FCR_TRG_LEV0 0x00000000
  130. /* UART FIFO trigger level 1: 4 character */
  131. #define UART_FCR_TRG_LEV1 0x00000040
  132. /* UART FIFO trigger level 2: 8 character */
  133. #define UART_FCR_TRG_LEV2 0x00000080
  134. /* UART FIFO trigger level 3: 14 character */
  135. #define UART_FCR_TRG_LEV3 0x000000C0
  136. /* UART FIFO control bit mask */
  137. #define UART_FCR_BITMASK 0x000000CF
  138. #define UART_TX_FIFO_SIZE 16
  139. /*----------------------------------------------------------------------------*
  140. UART line control register defines
  141. *----------------------------------------------------------------------------*/
  142. #define UART_LCR_WLEN_POS 0
  143. /* UART 5 bit data mode */
  144. #define UART_LCR_WLEN5 0x00000000
  145. /* UART 6 bit data mode */
  146. #define UART_LCR_WLEN6 0x00000001
  147. /* UART 7 bit data mode */
  148. #define UART_LCR_WLEN7 0x00000002
  149. /* UART 8 bit data mode */
  150. #define UART_LCR_WLEN8 0x00000003
  151. /* UART WLEN Bitmask */
  152. #define UART_LCR_WLEN_BITMASK 0x00000003
  153. /* UART 1.5 ot 2 Stop Bits Select */
  154. #define UART_LCR_STOPBIT_SEL_POS 2
  155. #define UART_LCR_STOPBIT_SEL 0x00000004
  156. /* UART Parity Enable */
  157. #define UART_LCR_PARITY_EN_POS 3
  158. #define UART_LCR_PARITY_EN 0x00000008
  159. #define UART_LCR_PARITY_POS 4
  160. /* UART Odd Parity Select */
  161. #define UART_LCR_PARITY_ODD 0x00000000
  162. /* UART Even Parity Select */
  163. #define UART_LCR_PARITY_EVEN 0x00000010
  164. /* UART force 1 stick parity */
  165. #define UART_LCR_PARITY_F_1 0x00000020
  166. /* UART force 0 stick parity */
  167. #define UART_LCR_PARITY_F_0 0x00000030
  168. /* UART Parity Bitmask */
  169. #define UART_LCR_PARITY_BITMASK 0x00000038
  170. /* UART Transmission Break enable */
  171. #define UART_LCR_BREAK_EN_POS 6
  172. #define UART_LCR_BREAK_EN 0x00000040
  173. /* UART Divisor Latches Access bit enable */
  174. #define UART_LCR_DLAB_EN_POS 7
  175. #define UART_LCR_DLAB_EN 0x00000080
  176. /* UART line control bit mask */
  177. #define UART_LCR_BITMASK 0x000000FF
  178. /*----------------------------------------------------------------------------*
  179. UART1 modem control register defines
  180. *----------------------------------------------------------------------------*/
  181. /* Source for modem output pin DTR */
  182. #define UART1_MCR_DTR_CTRL 0x00000001
  183. /* Source for modem output pin RTS */
  184. #define UART1_MCR_RTS_CTRL 0x00000002
  185. /* Loop back mode select */
  186. #define UART1_MCR_LOOPB_EN 0x00000010
  187. /* Enable Auto RTS flow-control */
  188. #define UART1_MCR_AUTO_RTS_EN 0x00000040
  189. /* Enable Auto CTS flow-control */
  190. #define UART1_MCR_AUTO_CTS_EN 0x00000080
  191. /* UART1 bit mask value */
  192. #define UART1_MCR_BITMASK 0x000000D3
  193. /*----------------------------------------------------------------------------*
  194. UART line status register defines
  195. *----------------------------------------------------------------------------*/
  196. /* Line status register: Receive data ready*/
  197. #define UART_LSR_RDR 0x00000001
  198. /* Line status register: Overrun error*/
  199. #define UART_LSR_OE 0x00000002
  200. /* Line status register: Parity error*/
  201. #define UART_LSR_PE 0x00000004
  202. /* Line status register: Framing error*/
  203. #define UART_LSR_FE 0x00000008
  204. /* Line status register: Break interrupt*/
  205. #define UART_LSR_BI 0x00000010
  206. /* Line status register: Transmit holding register empty*/
  207. #define UART_LSR_THRE 0x00000020
  208. /* Line status register: Transmitter empty*/
  209. #define UART_LSR_TEMT 0x00000040
  210. /* Error in RX FIFO*/
  211. #define UART_LSR_RXFE 0x00000080
  212. /* UART Line status bit mask */
  213. #define UART_LSR_BITMASK 0x000000FF
  214. /*----------------------------------------------------------------------------*
  215. UART Modem (UART1 only) status register defines
  216. *----------------------------------------------------------------------------*/
  217. /* Set upon state change of input CTS */
  218. #define UART1_MSR_DELTA_CTS 0x00000001
  219. /* Set upon state change of input DSR */
  220. #define UART1_MSR_DELTA_DSR 0x00000002
  221. /* Set upon low to high transition of input RI */
  222. #define UART1_MSR_LO2HI_RI 0x00000004
  223. /* Set upon state change of input DCD */
  224. #define UART1_MSR_DELTA_DCD 0x00000008
  225. /* Clear To Send State */
  226. #define UART1_MSR_CTS 0x00000010
  227. /* Data Set Ready State */
  228. #define UART1_MSR_DSR 0x00000020
  229. /* Ring Indicator State */
  230. #define UART1_MSR_RI 0x00000040
  231. /* Data Carrier Detect State */
  232. #define UART1_MSR_DCD 0x00000080
  233. /* MSR register bit-mask value */
  234. #define UART1_MSR_BITMASK 0x000000FF
  235. /*----------------------------------------------------------------------------*
  236. UART Scratch Pad Register defines
  237. *----------------------------------------------------------------------------*/
  238. /* UART Scratch Pad bit mask */
  239. #define UART_SCR_BIMASK 0x000000FF
  240. /*----------------------------------------------------------------------------*
  241. UART Auto baudrate control register defines
  242. *----------------------------------------------------------------------------*/
  243. /* UART Auto-baud start */
  244. #define UART_ACR_START 0x00000001
  245. /* UART Auto baudrate Mode 1 */
  246. #define UART_ACR_MODE 0x00000002
  247. /* UART Auto baudrate restart */
  248. #define UART_ACR_AUTO_RESTART 0x00000004
  249. /* UART End of auto-baud interrupt clear */
  250. #define UART_ACR_ABEOINT_CLR 0x00000100
  251. /* UART Auto-baud time-out interrupt clear */
  252. #define UART_ACR_ABTOINT_CLR 0x00000200
  253. /* UART Auto Baudrate register bit mask */
  254. #define UART_ACR_BITMASK 0x00000307
  255. /*----------------------------------------------------------------------------*
  256. UART IrDA control register defines
  257. *----------------------------------------------------------------------------*/
  258. /* IrDA mode enable */
  259. #define UART_ICR_IRDAEN 0x00000001
  260. /* IrDA serial input inverted */
  261. #define UART_ICR_IRDAINV 0x00000002
  262. /* IrDA fixed pulse width mode */
  263. #define UART_ICR_FIXPULSE_EN 0x00000004
  264. /* PulseDiv - Configures the pulse when FixPulseEn = 1 */
  265. #define UART_ICR_PULSEDIV(n) ((uint32_t)(((n) & 0x07) <<3))
  266. /* UART IRDA bit mask */
  267. #define UART_ICR_BITMASK 0x0000003F
  268. /*----------------------------------------------------------------------------*
  269. UART Fractional divider register defines
  270. *----------------------------------------------------------------------------*/
  271. /* Baud-rate generation pre-scaler divisor */
  272. #define UART_FDR_DIVADDVAL(n) ((uint32_t)((n) & 0x0F))
  273. /* Baud-rate pre-scaler multiplier value */
  274. #define UART_FDR_MULVAL(n) ((uint32_t)(((n) << 4) & 0xF0))
  275. /* UART Fractional Divider register bit mask */
  276. #define UART_FDR_BITMASK 0x000000FF
  277. /*----------------------------------------------------------------------------*
  278. UART Tx Enable register defines
  279. *----------------------------------------------------------------------------*/
  280. /* Transmit enable bit */
  281. #define UART_TER_TXEN_POS 7
  282. #define UART_TER_TXEN 0x00000080
  283. /* UART Transmit Enable Register bit mask */
  284. #define UART_TER_BITMASK 0x00000080
  285. /*----------------------------------------------------------------------------*
  286. UART1 RS485 Control register defines
  287. *----------------------------------------------------------------------------*/
  288. /* RS-485/EIA-485 Normal Multi-drop Mode (NMM) is disabled */
  289. #define UART1_RS485CTRL_NMM_EN 0x00000001
  290. /* The receiver is disabled */
  291. #define UART1_RS485CTRL_RX_DIS 0x00000002
  292. /* Auto Address Detect (AAD) is enabled */
  293. #define UART1_RS485CTRL_AADEN 0x00000004
  294. /* If direction control is enabled (bit DCTRL = 1), pin DTR is used for direction control */
  295. #define UART1_RS485CTRL_SEL_DTR 0x00000008
  296. /* Enable Auto Direction Control */
  297. #define UART1_RS485CTRL_DCTRL_EN 0x00000010
  298. /* This bit reverses the polarity of the direction control signal on the RTS (or DTR) pin.
  299. The direction control pin will be driven to logic "1" when the transmitter has data to be sent */
  300. #define UART1_RS485CTRL_OINV_1 0x00000020
  301. /* RS485 control bit-mask value */
  302. #define UART1_RS485CTRL_BITMASK 0x0000003F
  303. /*----------------------------------------------------------------------------*
  304. UART1 RS-485 Address Match register defines
  305. *----------------------------------------------------------------------------*/
  306. /* Address match register bitmask */
  307. #define UART1_RS485ADRMATCH_BITMASK 0x000000FF
  308. /*----------------------------------------------------------------------------*
  309. UART1 RS-485 Delay value register defines
  310. *----------------------------------------------------------------------------*/
  311. /* RS-485 Delay value register bitmask */
  312. #define UART1_RS485DLY_BITMASK 0x000000FF
  313. /*----------------------------------------------------------------------------*
  314. UART FIFO Level register defines
  315. *----------------------------------------------------------------------------*/
  316. /* Reflects the current level of the UART receiver FIFO */
  317. #define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t)((n) & 0x0F))
  318. /* Reflects the current level of the UART transmitter FIFO */
  319. #define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t)(((n) >> 8) & 0x0F))
  320. /* UART FIFO Level Register bit mask */
  321. #define UART_FIFOLVL_BITMASK 0x00000F0F
  322. #endif /* _LPC17XX_USART_H_ */