My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /**********************************************************************
  2. * $Id$ lpc17xx_uart.h 2010-06-18
  3. *//**
  4. * @file lpc17xx_uart.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for UART firmware library on LPC17xx
  7. * @version 3.0
  8. * @date 18. June. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup UART UART (Universal Asynchronous Receiver/Transmitter)
  34. * @ingroup LPC1700CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC17XX_UART_H
  38. #define __LPC17XX_UART_H
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC17xx.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Macros -------------------------------------------------------------- */
  47. /** @defgroup UART_Public_Macros UART Public Macros
  48. * @{
  49. */
  50. /** UART time-out definitions in case of using Read() and Write function
  51. * with Blocking Flag mode
  52. */
  53. #define UART_BLOCKING_TIMEOUT (0xFFFFFFFFUL)
  54. /**
  55. * @}
  56. */
  57. /* Private Macros ------------------------------------------------------------- */
  58. /** @defgroup UART_Private_Macros UART Private Macros
  59. * @{
  60. */
  61. /* Accepted Error baud rate value (in percent unit) */
  62. #define UART_ACCEPTED_BAUDRATE_ERROR (3) /*!< Acceptable UART baudrate error */
  63. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  64. /*********************************************************************//**
  65. * Macro defines for Macro defines for UARTn Receiver Buffer Register
  66. **********************************************************************/
  67. #define UART_RBR_MASKBIT ((uint8_t)0xFF) /*!< UART Received Buffer mask bit (8 bits) */
  68. /*********************************************************************//**
  69. * Macro defines for Macro defines for UARTn Transmit Holding Register
  70. **********************************************************************/
  71. #define UART_THR_MASKBIT ((uint8_t)0xFF) /*!< UART Transmit Holding mask bit (8 bits) */
  72. /*********************************************************************//**
  73. * Macro defines for Macro defines for UARTn Divisor Latch LSB register
  74. **********************************************************************/
  75. #define UART_LOAD_DLL(div) ((div) & 0xFF) /**< Macro for loading least significant halfs of divisors */
  76. #define UART_DLL_MASKBIT ((uint8_t)0xFF) /*!< Divisor latch LSB bit mask */
  77. /*********************************************************************//**
  78. * Macro defines for Macro defines for UARTn Divisor Latch MSB register
  79. **********************************************************************/
  80. #define UART_DLM_MASKBIT ((uint8_t)0xFF) /*!< Divisor latch MSB bit mask */
  81. #define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF) /**< Macro for loading most significant halfs of divisors */
  82. /*********************************************************************//**
  83. * Macro defines for Macro defines for UART interrupt enable register
  84. **********************************************************************/
  85. #define UART_IER_RBRINT_EN ((uint32_t)(1<<0)) /*!< RBR Interrupt enable*/
  86. #define UART_IER_THREINT_EN ((uint32_t)(1<<1)) /*!< THR Interrupt enable*/
  87. #define UART_IER_RLSINT_EN ((uint32_t)(1<<2)) /*!< RX line status interrupt enable*/
  88. #define UART1_IER_MSINT_EN ((uint32_t)(1<<3)) /*!< Modem status interrupt enable */
  89. #define UART1_IER_CTSINT_EN ((uint32_t)(1<<7)) /*!< CTS1 signal transition interrupt enable */
  90. #define UART_IER_ABEOINT_EN ((uint32_t)(1<<8)) /*!< Enables the end of auto-baud interrupt */
  91. #define UART_IER_ABTOINT_EN ((uint32_t)(1<<9)) /*!< Enables the auto-baud time-out interrupt */
  92. #define UART_IER_BITMASK ((uint32_t)(0x307)) /*!< UART interrupt enable register bit mask */
  93. #define UART1_IER_BITMASK ((uint32_t)(0x38F)) /*!< UART1 interrupt enable register bit mask */
  94. /*********************************************************************//**
  95. * Macro defines for Macro defines for UART interrupt identification register
  96. **********************************************************************/
  97. #define UART_IIR_INTSTAT_PEND ((uint32_t)(1<<0)) /*!<Interrupt Status - Active low */
  98. #define UART_IIR_INTID_RLS ((uint32_t)(3<<1)) /*!<Interrupt identification: Receive line status*/
  99. #define UART_IIR_INTID_RDA ((uint32_t)(2<<1)) /*!<Interrupt identification: Receive data available*/
  100. #define UART_IIR_INTID_CTI ((uint32_t)(6<<1)) /*!<Interrupt identification: Character time-out indicator*/
  101. #define UART_IIR_INTID_THRE ((uint32_t)(1<<1)) /*!<Interrupt identification: THRE interrupt*/
  102. #define UART1_IIR_INTID_MODEM ((uint32_t)(0<<1)) /*!<Interrupt identification: Modem interrupt*/
  103. #define UART_IIR_INTID_MASK ((uint32_t)(7<<1)) /*!<Interrupt identification: Interrupt ID mask */
  104. #define UART_IIR_FIFO_EN ((uint32_t)(3<<6)) /*!<These bits are equivalent to UnFCR[0] */
  105. #define UART_IIR_ABEO_INT ((uint32_t)(1<<8)) /*!< End of auto-baud interrupt */
  106. #define UART_IIR_ABTO_INT ((uint32_t)(1<<9)) /*!< Auto-baud time-out interrupt */
  107. #define UART_IIR_BITMASK ((uint32_t)(0x3CF)) /*!< UART interrupt identification register bit mask */
  108. /*********************************************************************//**
  109. * Macro defines for Macro defines for UART FIFO control register
  110. **********************************************************************/
  111. #define UART_FCR_FIFO_EN ((uint8_t)(1<<0)) /*!< UART FIFO enable */
  112. #define UART_FCR_RX_RS ((uint8_t)(1<<1)) /*!< UART FIFO RX reset */
  113. #define UART_FCR_TX_RS ((uint8_t)(1<<2)) /*!< UART FIFO TX reset */
  114. #define UART_FCR_DMAMODE_SEL ((uint8_t)(1<<3)) /*!< UART DMA mode selection */
  115. #define UART_FCR_TRG_LEV0 ((uint8_t)(0)) /*!< UART FIFO trigger level 0: 1 character */
  116. #define UART_FCR_TRG_LEV1 ((uint8_t)(1<<6)) /*!< UART FIFO trigger level 1: 4 character */
  117. #define UART_FCR_TRG_LEV2 ((uint8_t)(2<<6)) /*!< UART FIFO trigger level 2: 8 character */
  118. #define UART_FCR_TRG_LEV3 ((uint8_t)(3<<6)) /*!< UART FIFO trigger level 3: 14 character */
  119. #define UART_FCR_BITMASK ((uint8_t)(0xCF)) /*!< UART FIFO control bit mask */
  120. #define UART_TX_FIFO_SIZE (16)
  121. /*********************************************************************//**
  122. * Macro defines for Macro defines for UART line control register
  123. **********************************************************************/
  124. #define UART_LCR_WLEN5 ((uint8_t)(0)) /*!< UART 5 bit data mode */
  125. #define UART_LCR_WLEN6 ((uint8_t)(1<<0)) /*!< UART 6 bit data mode */
  126. #define UART_LCR_WLEN7 ((uint8_t)(2<<0)) /*!< UART 7 bit data mode */
  127. #define UART_LCR_WLEN8 ((uint8_t)(3<<0)) /*!< UART 8 bit data mode */
  128. #define UART_LCR_STOPBIT_SEL ((uint8_t)(1<<2)) /*!< UART Two Stop Bits Select */
  129. #define UART_LCR_PARITY_EN ((uint8_t)(1<<3)) /*!< UART Parity Enable */
  130. #define UART_LCR_PARITY_ODD ((uint8_t)(0)) /*!< UART Odd Parity Select */
  131. #define UART_LCR_PARITY_EVEN ((uint8_t)(1<<4)) /*!< UART Even Parity Select */
  132. #define UART_LCR_PARITY_F_1 ((uint8_t)(2<<4)) /*!< UART force 1 stick parity */
  133. #define UART_LCR_PARITY_F_0 ((uint8_t)(3<<4)) /*!< UART force 0 stick parity */
  134. #define UART_LCR_BREAK_EN ((uint8_t)(1<<6)) /*!< UART Transmission Break enable */
  135. #define UART_LCR_DLAB_EN ((uint8_t)(1<<7)) /*!< UART Divisor Latches Access bit enable */
  136. #define UART_LCR_BITMASK ((uint8_t)(0xFF)) /*!< UART line control bit mask */
  137. /*********************************************************************//**
  138. * Macro defines for Macro defines for UART1 Modem Control Register
  139. **********************************************************************/
  140. #define UART1_MCR_DTR_CTRL ((uint8_t)(1<<0)) /*!< Source for modem output pin DTR */
  141. #define UART1_MCR_RTS_CTRL ((uint8_t)(1<<1)) /*!< Source for modem output pin RTS */
  142. #define UART1_MCR_LOOPB_EN ((uint8_t)(1<<4)) /*!< Loop back mode select */
  143. #define UART1_MCR_AUTO_RTS_EN ((uint8_t)(1<<6)) /*!< Enable Auto RTS flow-control */
  144. #define UART1_MCR_AUTO_CTS_EN ((uint8_t)(1<<7)) /*!< Enable Auto CTS flow-control */
  145. #define UART1_MCR_BITMASK ((uint8_t)(0x0F3)) /*!< UART1 bit mask value */
  146. /*********************************************************************//**
  147. * Macro defines for Macro defines for UART line status register
  148. **********************************************************************/
  149. #define UART_LSR_RDR ((uint8_t)(1<<0)) /*!<Line status register: Receive data ready*/
  150. #define UART_LSR_OE ((uint8_t)(1<<1)) /*!<Line status register: Overrun error*/
  151. #define UART_LSR_PE ((uint8_t)(1<<2)) /*!<Line status register: Parity error*/
  152. #define UART_LSR_FE ((uint8_t)(1<<3)) /*!<Line status register: Framing error*/
  153. #define UART_LSR_BI ((uint8_t)(1<<4)) /*!<Line status register: Break interrupt*/
  154. #define UART_LSR_THRE ((uint8_t)(1<<5)) /*!<Line status register: Transmit holding register empty*/
  155. #define UART_LSR_TEMT ((uint8_t)(1<<6)) /*!<Line status register: Transmitter empty*/
  156. #define UART_LSR_RXFE ((uint8_t)(1<<7)) /*!<Error in RX FIFO*/
  157. #define UART_LSR_BITMASK ((uint8_t)(0xFF)) /*!<UART Line status bit mask */
  158. /*********************************************************************//**
  159. * Macro defines for Macro defines for UART Modem (UART1 only) status register
  160. **********************************************************************/
  161. #define UART1_MSR_DELTA_CTS ((uint8_t)(1<<0)) /*!< Set upon state change of input CTS */
  162. #define UART1_MSR_DELTA_DSR ((uint8_t)(1<<1)) /*!< Set upon state change of input DSR */
  163. #define UART1_MSR_LO2HI_RI ((uint8_t)(1<<2)) /*!< Set upon low to high transition of input RI */
  164. #define UART1_MSR_DELTA_DCD ((uint8_t)(1<<3)) /*!< Set upon state change of input DCD */
  165. #define UART1_MSR_CTS ((uint8_t)(1<<4)) /*!< Clear To Send State */
  166. #define UART1_MSR_DSR ((uint8_t)(1<<5)) /*!< Data Set Ready State */
  167. #define UART1_MSR_RI ((uint8_t)(1<<6)) /*!< Ring Indicator State */
  168. #define UART1_MSR_DCD ((uint8_t)(1<<7)) /*!< Data Carrier Detect State */
  169. #define UART1_MSR_BITMASK ((uint8_t)(0xFF)) /*!< MSR register bit-mask value */
  170. /*********************************************************************//**
  171. * Macro defines for Macro defines for UART Scratch Pad Register
  172. **********************************************************************/
  173. #define UART_SCR_BIMASK ((uint8_t)(0xFF)) /*!< UART Scratch Pad bit mask */
  174. /*********************************************************************//**
  175. * Macro defines for Macro defines for UART Auto baudrate control register
  176. **********************************************************************/
  177. #define UART_ACR_START ((uint32_t)(1<<0)) /**< UART Auto-baud start */
  178. #define UART_ACR_MODE ((uint32_t)(1<<1)) /**< UART Auto baudrate Mode 1 */
  179. #define UART_ACR_AUTO_RESTART ((uint32_t)(1<<2)) /**< UART Auto baudrate restart */
  180. #define UART_ACR_ABEOINT_CLR ((uint32_t)(1<<8)) /**< UART End of auto-baud interrupt clear */
  181. #define UART_ACR_ABTOINT_CLR ((uint32_t)(1<<9)) /**< UART Auto-baud time-out interrupt clear */
  182. #define UART_ACR_BITMASK ((uint32_t)(0x307)) /**< UART Auto Baudrate register bit mask */
  183. /*********************************************************************//**
  184. * Macro defines for Macro defines for UART IrDA control register
  185. **********************************************************************/
  186. #define UART_ICR_IRDAEN ((uint32_t)(1<<0)) /**< IrDA mode enable */
  187. #define UART_ICR_IRDAINV ((uint32_t)(1<<1)) /**< IrDA serial input inverted */
  188. #define UART_ICR_FIXPULSE_EN ((uint32_t)(1<<2)) /**< IrDA fixed pulse width mode */
  189. #define UART_ICR_PULSEDIV(n) ((uint32_t)((n&0x07)<<3)) /**< PulseDiv - Configures the pulse when FixPulseEn = 1 */
  190. #define UART_ICR_BITMASK ((uint32_t)(0x3F)) /*!< UART IRDA bit mask */
  191. /*********************************************************************//**
  192. * Macro defines for Macro defines for UART Fractional divider register
  193. **********************************************************************/
  194. #define UART_FDR_DIVADDVAL(n) ((uint32_t)(n&0x0F)) /**< Baud-rate generation pre-scaler divisor */
  195. #define UART_FDR_MULVAL(n) ((uint32_t)((n<<4)&0xF0)) /**< Baud-rate pre-scaler multiplier value */
  196. #define UART_FDR_BITMASK ((uint32_t)(0xFF)) /**< UART Fractional Divider register bit mask */
  197. /*********************************************************************//**
  198. * Macro defines for Macro defines for UART Tx Enable register
  199. **********************************************************************/
  200. #define UART_TER_TXEN ((uint8_t)(1<<7)) /*!< Transmit enable bit */
  201. #define UART_TER_BITMASK ((uint8_t)(0x80)) /**< UART Transmit Enable Register bit mask */
  202. /*********************************************************************//**
  203. * Macro defines for Macro defines for UART1 RS485 Control register
  204. **********************************************************************/
  205. #define UART1_RS485CTRL_NMM_EN ((uint32_t)(1<<0)) /*!< RS-485/EIA-485 Normal Multi-drop Mode (NMM)
  206. is disabled */
  207. #define UART1_RS485CTRL_RX_DIS ((uint32_t)(1<<1)) /*!< The receiver is disabled */
  208. #define UART1_RS485CTRL_AADEN ((uint32_t)(1<<2)) /*!< Auto Address Detect (AAD) is enabled */
  209. #define UART1_RS485CTRL_SEL_DTR ((uint32_t)(1<<3)) /*!< If direction control is enabled
  210. (bit DCTRL = 1), pin DTR is used for direction control */
  211. #define UART1_RS485CTRL_DCTRL_EN ((uint32_t)(1<<4)) /*!< Enable Auto Direction Control */
  212. #define UART1_RS485CTRL_OINV_1 ((uint32_t)(1<<5)) /*!< This bit reverses the polarity of the direction
  213. control signal on the RTS (or DTR) pin. The direction control pin
  214. will be driven to logic "1" when the transmitter has data to be sent */
  215. #define UART1_RS485CTRL_BITMASK ((uint32_t)(0x3F)) /**< RS485 control bit-mask value */
  216. /*********************************************************************//**
  217. * Macro defines for Macro defines for UART1 RS-485 Address Match register
  218. **********************************************************************/
  219. #define UART1_RS485ADRMATCH_BITMASK ((uint8_t)(0xFF)) /**< Bit mask value */
  220. /*********************************************************************//**
  221. * Macro defines for Macro defines for UART1 RS-485 Delay value register
  222. **********************************************************************/
  223. /* Macro defines for UART1 RS-485 Delay value register */
  224. #define UART1_RS485DLY_BITMASK ((uint8_t)(0xFF)) /** Bit mask value */
  225. /*********************************************************************//**
  226. * Macro defines for Macro defines for UART FIFO Level register
  227. **********************************************************************/
  228. #define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t)(n&0x0F)) /**< Reflects the current level of the UART receiver FIFO */
  229. #define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t)((n>>8)&0x0F)) /**< Reflects the current level of the UART transmitter FIFO */
  230. #define UART_FIFOLVL_BITMASK ((uint32_t)(0x0F0F)) /**< UART FIFO Level Register bit mask */
  231. /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
  232. /** Macro to check the input UART_DATABIT parameters */
  233. #define PARAM_UART_DATABIT(databit) ((databit==UART_DATABIT_5) || (databit==UART_DATABIT_6)\
  234. || (databit==UART_DATABIT_7) || (databit==UART_DATABIT_8))
  235. /** Macro to check the input UART_STOPBIT parameters */
  236. #define PARAM_UART_STOPBIT(stopbit) ((stopbit==UART_STOPBIT_1) || (stopbit==UART_STOPBIT_2))
  237. /** Macro to check the input UART_PARITY parameters */
  238. #define PARAM_UART_PARITY(parity) ((parity==UART_PARITY_NONE) || (parity==UART_PARITY_ODD) \
  239. || (parity==UART_PARITY_EVEN) || (parity==UART_PARITY_SP_1) \
  240. || (parity==UART_PARITY_SP_0))
  241. /** Macro to check the input UART_FIFO parameters */
  242. #define PARAM_UART_FIFO_LEVEL(fifo) ((fifo==UART_FIFO_TRGLEV0) \
  243. || (fifo==UART_FIFO_TRGLEV1) || (fifo==UART_FIFO_TRGLEV2) \
  244. || (fifo==UART_FIFO_TRGLEV3))
  245. /** Macro to check the input UART_INTCFG parameters */
  246. #define PARAM_UART_INTCFG(IntCfg) ((IntCfg==UART_INTCFG_RBR) || (IntCfg==UART_INTCFG_THRE) \
  247. || (IntCfg==UART_INTCFG_RLS) || (IntCfg==UART_INTCFG_ABEO) \
  248. || (IntCfg==UART_INTCFG_ABTO))
  249. /** Macro to check the input UART1_INTCFG parameters - expansion input parameter for UART1 */
  250. #define PARAM_UART1_INTCFG(IntCfg) ((IntCfg==UART1_INTCFG_MS) || (IntCfg==UART1_INTCFG_CTS))
  251. /** Macro to check the input UART_AUTOBAUD_MODE parameters */
  252. #define PARAM_UART_AUTOBAUD_MODE(ABmode) ((ABmode==UART_AUTOBAUD_MODE0) || (ABmode==UART_AUTOBAUD_MODE1))
  253. /** Macro to check the input UART_AUTOBAUD_INTSTAT parameters */
  254. #define PARAM_UART_AUTOBAUD_INTSTAT(ABIntStat) ((ABIntStat==UART_AUTOBAUD_INTSTAT_ABEO) || \
  255. (ABIntStat==UART_AUTOBAUD_INTSTAT_ABTO))
  256. /** Macro to check the input UART_IrDA_PULSEDIV parameters */
  257. #define PARAM_UART_IrDA_PULSEDIV(PulseDiv) ((PulseDiv==UART_IrDA_PULSEDIV2) || (PulseDiv==UART_IrDA_PULSEDIV4) \
  258. || (PulseDiv==UART_IrDA_PULSEDIV8) || (PulseDiv==UART_IrDA_PULSEDIV16) \
  259. || (PulseDiv==UART_IrDA_PULSEDIV32) || (PulseDiv==UART_IrDA_PULSEDIV64) \
  260. || (PulseDiv==UART_IrDA_PULSEDIV128) || (PulseDiv==UART_IrDA_PULSEDIV256))
  261. /* Macro to check the input UART1_SignalState parameters */
  262. #define PARAM_UART1_SIGNALSTATE(x) ((x==INACTIVE) || (x==ACTIVE))
  263. /** Macro to check the input PARAM_UART1_MODEM_PIN parameters */
  264. #define PARAM_UART1_MODEM_PIN(x) ((x==UART1_MODEM_PIN_DTR) || (x==UART1_MODEM_PIN_RTS))
  265. /** Macro to check the input PARAM_UART1_MODEM_MODE parameters */
  266. #define PARAM_UART1_MODEM_MODE(x) ((x==UART1_MODEM_MODE_LOOPBACK) || (x==UART1_MODEM_MODE_AUTO_RTS) \
  267. || (x==UART1_MODEM_MODE_AUTO_CTS))
  268. /** Macro to check the direction control pin type */
  269. #define PARAM_UART_RS485_DIRCTRL_PIN(x) ((x==UART1_RS485_DIRCTRL_RTS) || (x==UART1_RS485_DIRCTRL_DTR))
  270. /* Macro to determine if it is valid UART port number */
  271. #define PARAM_UARTx(x) ((((uint32_t *)x)==((uint32_t *)LPC_UART0)) \
  272. || (((uint32_t *)x)==((uint32_t *)LPC_UART1)) \
  273. || (((uint32_t *)x)==((uint32_t *)LPC_UART2)) \
  274. || (((uint32_t *)x)==((uint32_t *)LPC_UART3)))
  275. #define PARAM_UART_IrDA(x) (((uint32_t *)x)==((uint32_t *)LPC_UART3))
  276. #define PARAM_UART1_MODEM(x) (((uint32_t *)x)==((uint32_t *)LPC_UART1))
  277. /** Macro to check the input value for UART1_RS485_CFG_MATCHADDRVALUE parameter */
  278. #define PARAM_UART1_RS485_CFG_MATCHADDRVALUE(x) ((x<0xFF))
  279. /** Macro to check the input value for UART1_RS485_CFG_DELAYVALUE parameter */
  280. #define PARAM_UART1_RS485_CFG_DELAYVALUE(x) ((x<0xFF))
  281. /**
  282. * @}
  283. */
  284. /* Public Types --------------------------------------------------------------- */
  285. /** @defgroup UART_Public_Types UART Public Types
  286. * @{
  287. */
  288. /**
  289. * @brief UART Databit type definitions
  290. */
  291. typedef enum {
  292. UART_DATABIT_5 = 0, /*!< UART 5 bit data mode */
  293. UART_DATABIT_6, /*!< UART 6 bit data mode */
  294. UART_DATABIT_7, /*!< UART 7 bit data mode */
  295. UART_DATABIT_8 /*!< UART 8 bit data mode */
  296. } UART_DATABIT_Type;
  297. /**
  298. * @brief UART Stop bit type definitions
  299. */
  300. typedef enum {
  301. UART_STOPBIT_1 = (0), /*!< UART 1 Stop Bits Select */
  302. UART_STOPBIT_2 /*!< UART Two Stop Bits Select */
  303. } UART_STOPBIT_Type;
  304. /**
  305. * @brief UART Parity type definitions
  306. */
  307. typedef enum {
  308. UART_PARITY_NONE = 0, /*!< No parity */
  309. UART_PARITY_ODD, /*!< Odd parity */
  310. UART_PARITY_EVEN, /*!< Even parity */
  311. UART_PARITY_SP_1, /*!< Forced "1" stick parity */
  312. UART_PARITY_SP_0 /*!< Forced "0" stick parity */
  313. } UART_PARITY_Type;
  314. /**
  315. * @brief FIFO Level type definitions
  316. */
  317. typedef enum {
  318. UART_FIFO_TRGLEV0 = 0, /*!< UART FIFO trigger level 0: 1 character */
  319. UART_FIFO_TRGLEV1, /*!< UART FIFO trigger level 1: 4 character */
  320. UART_FIFO_TRGLEV2, /*!< UART FIFO trigger level 2: 8 character */
  321. UART_FIFO_TRGLEV3 /*!< UART FIFO trigger level 3: 14 character */
  322. } UART_FITO_LEVEL_Type;
  323. /********************************************************************//**
  324. * @brief UART Interrupt Type definitions
  325. **********************************************************************/
  326. typedef enum {
  327. UART_INTCFG_RBR = 0, /*!< RBR Interrupt enable*/
  328. UART_INTCFG_THRE, /*!< THR Interrupt enable*/
  329. UART_INTCFG_RLS, /*!< RX line status interrupt enable*/
  330. UART1_INTCFG_MS, /*!< Modem status interrupt enable (UART1 only) */
  331. UART1_INTCFG_CTS, /*!< CTS1 signal transition interrupt enable (UART1 only) */
  332. UART_INTCFG_ABEO, /*!< Enables the end of auto-baud interrupt */
  333. UART_INTCFG_ABTO /*!< Enables the auto-baud time-out interrupt */
  334. } UART_INT_Type;
  335. /**
  336. * @brief UART Line Status Type definition
  337. */
  338. typedef enum {
  339. UART_LINESTAT_RDR = UART_LSR_RDR, /*!<Line status register: Receive data ready*/
  340. UART_LINESTAT_OE = UART_LSR_OE, /*!<Line status register: Overrun error*/
  341. UART_LINESTAT_PE = UART_LSR_PE, /*!<Line status register: Parity error*/
  342. UART_LINESTAT_FE = UART_LSR_FE, /*!<Line status register: Framing error*/
  343. UART_LINESTAT_BI = UART_LSR_BI, /*!<Line status register: Break interrupt*/
  344. UART_LINESTAT_THRE = UART_LSR_THRE, /*!<Line status register: Transmit holding register empty*/
  345. UART_LINESTAT_TEMT = UART_LSR_TEMT, /*!<Line status register: Transmitter empty*/
  346. UART_LINESTAT_RXFE = UART_LSR_RXFE /*!<Error in RX FIFO*/
  347. } UART_LS_Type;
  348. /**
  349. * @brief UART Auto-baudrate mode type definition
  350. */
  351. typedef enum {
  352. UART_AUTOBAUD_MODE0 = 0, /**< UART Auto baudrate Mode 0 */
  353. UART_AUTOBAUD_MODE1 /**< UART Auto baudrate Mode 1 */
  354. } UART_AB_MODE_Type;
  355. /**
  356. * @brief Auto Baudrate mode configuration type definition
  357. */
  358. typedef struct {
  359. UART_AB_MODE_Type ABMode; /**< Autobaudrate mode */
  360. FunctionalState AutoRestart; /**< Auto Restart state */
  361. } UART_AB_CFG_Type;
  362. /**
  363. * @brief UART End of Auto-baudrate type definition
  364. */
  365. typedef enum {
  366. UART_AUTOBAUD_INTSTAT_ABEO = UART_IIR_ABEO_INT, /**< UART End of auto-baud interrupt */
  367. UART_AUTOBAUD_INTSTAT_ABTO = UART_IIR_ABTO_INT /**< UART Auto-baud time-out interrupt */
  368. }UART_ABEO_Type;
  369. /**
  370. * UART IrDA Control type Definition
  371. */
  372. typedef enum {
  373. UART_IrDA_PULSEDIV2 = 0, /**< Pulse width = 2 * Tpclk
  374. - Configures the pulse when FixPulseEn = 1 */
  375. UART_IrDA_PULSEDIV4, /**< Pulse width = 4 * Tpclk
  376. - Configures the pulse when FixPulseEn = 1 */
  377. UART_IrDA_PULSEDIV8, /**< Pulse width = 8 * Tpclk
  378. - Configures the pulse when FixPulseEn = 1 */
  379. UART_IrDA_PULSEDIV16, /**< Pulse width = 16 * Tpclk
  380. - Configures the pulse when FixPulseEn = 1 */
  381. UART_IrDA_PULSEDIV32, /**< Pulse width = 32 * Tpclk
  382. - Configures the pulse when FixPulseEn = 1 */
  383. UART_IrDA_PULSEDIV64, /**< Pulse width = 64 * Tpclk
  384. - Configures the pulse when FixPulseEn = 1 */
  385. UART_IrDA_PULSEDIV128, /**< Pulse width = 128 * Tpclk
  386. - Configures the pulse when FixPulseEn = 1 */
  387. UART_IrDA_PULSEDIV256 /**< Pulse width = 256 * Tpclk
  388. - Configures the pulse when FixPulseEn = 1 */
  389. } UART_IrDA_PULSE_Type;
  390. /********************************************************************//**
  391. * @brief UART1 Full modem - Signal states definition
  392. **********************************************************************/
  393. typedef enum {
  394. INACTIVE = 0, /* In-active state */
  395. ACTIVE = !INACTIVE /* Active state */
  396. }UART1_SignalState;
  397. /**
  398. * @brief UART modem status type definition
  399. */
  400. typedef enum {
  401. UART1_MODEM_STAT_DELTA_CTS = UART1_MSR_DELTA_CTS, /*!< Set upon state change of input CTS */
  402. UART1_MODEM_STAT_DELTA_DSR = UART1_MSR_DELTA_DSR, /*!< Set upon state change of input DSR */
  403. UART1_MODEM_STAT_LO2HI_RI = UART1_MSR_LO2HI_RI, /*!< Set upon low to high transition of input RI */
  404. UART1_MODEM_STAT_DELTA_DCD = UART1_MSR_DELTA_DCD, /*!< Set upon state change of input DCD */
  405. UART1_MODEM_STAT_CTS = UART1_MSR_CTS, /*!< Clear To Send State */
  406. UART1_MODEM_STAT_DSR = UART1_MSR_DSR, /*!< Data Set Ready State */
  407. UART1_MODEM_STAT_RI = UART1_MSR_RI, /*!< Ring Indicator State */
  408. UART1_MODEM_STAT_DCD = UART1_MSR_DCD /*!< Data Carrier Detect State */
  409. } UART_MODEM_STAT_type;
  410. /**
  411. * @brief Modem output pin type definition
  412. */
  413. typedef enum {
  414. UART1_MODEM_PIN_DTR = 0, /*!< Source for modem output pin DTR */
  415. UART1_MODEM_PIN_RTS /*!< Source for modem output pin RTS */
  416. } UART_MODEM_PIN_Type;
  417. /**
  418. * @brief UART Modem mode type definition
  419. */
  420. typedef enum {
  421. UART1_MODEM_MODE_LOOPBACK = 0, /*!< Loop back mode select */
  422. UART1_MODEM_MODE_AUTO_RTS, /*!< Enable Auto RTS flow-control */
  423. UART1_MODEM_MODE_AUTO_CTS /*!< Enable Auto CTS flow-control */
  424. } UART_MODEM_MODE_Type;
  425. /**
  426. * @brief UART Direction Control Pin type definition
  427. */
  428. typedef enum {
  429. UART1_RS485_DIRCTRL_RTS = 0, /**< Pin RTS is used for direction control */
  430. UART1_RS485_DIRCTRL_DTR /**< Pin DTR is used for direction control */
  431. } UART_RS485_DIRCTRL_PIN_Type;
  432. /********************************************************************//**
  433. * @brief UART Configuration Structure definition
  434. **********************************************************************/
  435. typedef struct {
  436. uint32_t Baud_rate; /**< UART baud rate */
  437. UART_PARITY_Type Parity; /**< Parity selection, should be:
  438. - UART_PARITY_NONE: No parity
  439. - UART_PARITY_ODD: Odd parity
  440. - UART_PARITY_EVEN: Even parity
  441. - UART_PARITY_SP_1: Forced "1" stick parity
  442. - UART_PARITY_SP_0: Forced "0" stick parity
  443. */
  444. UART_DATABIT_Type Databits; /**< Number of data bits, should be:
  445. - UART_DATABIT_5: UART 5 bit data mode
  446. - UART_DATABIT_6: UART 6 bit data mode
  447. - UART_DATABIT_7: UART 7 bit data mode
  448. - UART_DATABIT_8: UART 8 bit data mode
  449. */
  450. UART_STOPBIT_Type Stopbits; /**< Number of stop bits, should be:
  451. - UART_STOPBIT_1: UART 1 Stop Bits Select
  452. - UART_STOPBIT_2: UART 2 Stop Bits Select
  453. */
  454. } UART_CFG_Type;
  455. /********************************************************************//**
  456. * @brief UART FIFO Configuration Structure definition
  457. **********************************************************************/
  458. typedef struct {
  459. FunctionalState FIFO_ResetRxBuf; /**< Reset Rx FIFO command state , should be:
  460. - ENABLE: Reset Rx FIFO in UART
  461. - DISABLE: Do not reset Rx FIFO in UART
  462. */
  463. FunctionalState FIFO_ResetTxBuf; /**< Reset Tx FIFO command state , should be:
  464. - ENABLE: Reset Tx FIFO in UART
  465. - DISABLE: Do not reset Tx FIFO in UART
  466. */
  467. FunctionalState FIFO_DMAMode; /**< DMA mode, should be:
  468. - ENABLE: Enable DMA mode in UART
  469. - DISABLE: Disable DMA mode in UART
  470. */
  471. UART_FITO_LEVEL_Type FIFO_Level; /**< Rx FIFO trigger level, should be:
  472. - UART_FIFO_TRGLEV0: UART FIFO trigger level 0: 1 character
  473. - UART_FIFO_TRGLEV1: UART FIFO trigger level 1: 4 character
  474. - UART_FIFO_TRGLEV2: UART FIFO trigger level 2: 8 character
  475. - UART_FIFO_TRGLEV3: UART FIFO trigger level 3: 14 character
  476. */
  477. } UART_FIFO_CFG_Type;
  478. /********************************************************************//**
  479. * @brief UART1 Full modem - RS485 Control configuration type
  480. **********************************************************************/
  481. typedef struct {
  482. FunctionalState NormalMultiDropMode_State; /*!< Normal MultiDrop mode State:
  483. - ENABLE: Enable this function.
  484. - DISABLE: Disable this function. */
  485. FunctionalState Rx_State; /*!< Receiver State:
  486. - ENABLE: Enable Receiver.
  487. - DISABLE: Disable Receiver. */
  488. FunctionalState AutoAddrDetect_State; /*!< Auto Address Detect mode state:
  489. - ENABLE: ENABLE this function.
  490. - DISABLE: Disable this function. */
  491. FunctionalState AutoDirCtrl_State; /*!< Auto Direction Control State:
  492. - ENABLE: Enable this function.
  493. - DISABLE: Disable this function. */
  494. UART_RS485_DIRCTRL_PIN_Type DirCtrlPin; /*!< If direction control is enabled, state:
  495. - UART1_RS485_DIRCTRL_RTS:
  496. pin RTS is used for direction control.
  497. - UART1_RS485_DIRCTRL_DTR:
  498. pin DTR is used for direction control. */
  499. SetState DirCtrlPol_Level; /*!< Polarity of the direction control signal on
  500. the RTS (or DTR) pin:
  501. - RESET: The direction control pin will be driven
  502. to logic "0" when the transmitter has data to be sent.
  503. - SET: The direction control pin will be driven
  504. to logic "1" when the transmitter has data to be sent. */
  505. uint8_t MatchAddrValue; /*!< address match value for RS-485/EIA-485 mode, 8-bit long */
  506. uint8_t DelayValue; /*!< delay time is in periods of the baud clock, 8-bit long */
  507. } UART1_RS485_CTRLCFG_Type;
  508. /**
  509. * @}
  510. */
  511. /* Public Functions ----------------------------------------------------------- */
  512. /** @defgroup UART_Public_Functions UART Public Functions
  513. * @{
  514. */
  515. /* UART Init/DeInit functions --------------------------------------------------*/
  516. void UART_Init(LPC_UART_TypeDef *UARTx, UART_CFG_Type *UART_ConfigStruct);
  517. void UART_DeInit(LPC_UART_TypeDef* UARTx);
  518. void UART_ConfigStructInit(UART_CFG_Type *UART_InitStruct);
  519. /* UART Send/Receive functions -------------------------------------------------*/
  520. void UART_SendByte(LPC_UART_TypeDef* UARTx, uint8_t Data);
  521. uint8_t UART_ReceiveByte(LPC_UART_TypeDef* UARTx);
  522. uint32_t UART_Send(LPC_UART_TypeDef *UARTx, uint8_t *txbuf,
  523. uint32_t buflen, TRANSFER_BLOCK_Type flag);
  524. uint32_t UART_Receive(LPC_UART_TypeDef *UARTx, uint8_t *rxbuf, \
  525. uint32_t buflen, TRANSFER_BLOCK_Type flag);
  526. /* UART FIFO functions ----------------------------------------------------------*/
  527. void UART_FIFOConfig(LPC_UART_TypeDef *UARTx, UART_FIFO_CFG_Type *FIFOCfg);
  528. void UART_FIFOConfigStructInit(UART_FIFO_CFG_Type *UART_FIFOInitStruct);
  529. /* UART get information functions -----------------------------------------------*/
  530. uint32_t UART_GetIntId(LPC_UART_TypeDef* UARTx);
  531. uint8_t UART_GetLineStatus(LPC_UART_TypeDef* UARTx);
  532. /* UART operate functions -------------------------------------------------------*/
  533. void UART_IntConfig(LPC_UART_TypeDef *UARTx, UART_INT_Type UARTIntCfg, \
  534. FunctionalState NewState);
  535. void UART_TxCmd(LPC_UART_TypeDef *UARTx, FunctionalState NewState);
  536. FlagStatus UART_CheckBusy(LPC_UART_TypeDef *UARTx);
  537. void UART_ForceBreak(LPC_UART_TypeDef* UARTx);
  538. /* UART Auto-baud functions -----------------------------------------------------*/
  539. void UART_ABClearIntPending(LPC_UART_TypeDef *UARTx, UART_ABEO_Type ABIntType);
  540. void UART_ABCmd(LPC_UART_TypeDef *UARTx, UART_AB_CFG_Type *ABConfigStruct, \
  541. FunctionalState NewState);
  542. /* UART1 FullModem functions ----------------------------------------------------*/
  543. void UART_FullModemForcePinState(LPC_UART1_TypeDef *UARTx, UART_MODEM_PIN_Type Pin, \
  544. UART1_SignalState NewState);
  545. void UART_FullModemConfigMode(LPC_UART1_TypeDef *UARTx, UART_MODEM_MODE_Type Mode, \
  546. FunctionalState NewState);
  547. uint8_t UART_FullModemGetStatus(LPC_UART1_TypeDef *UARTx);
  548. /* UART RS485 functions ----------------------------------------------------------*/
  549. void UART_RS485Config(LPC_UART1_TypeDef *UARTx, \
  550. UART1_RS485_CTRLCFG_Type *RS485ConfigStruct);
  551. void UART_RS485ReceiverCmd(LPC_UART1_TypeDef *UARTx, FunctionalState NewState);
  552. void UART_RS485SendSlvAddr(LPC_UART1_TypeDef *UARTx, uint8_t SlvAddr);
  553. uint32_t UART_RS485SendData(LPC_UART1_TypeDef *UARTx, uint8_t *pData, uint32_t size);
  554. /* UART IrDA functions-------------------------------------------------------------*/
  555. void UART_IrDAInvtInputCmd(LPC_UART_TypeDef* UARTx, FunctionalState NewState);
  556. void UART_IrDACmd(LPC_UART_TypeDef* UARTx, FunctionalState NewState);
  557. void UART_IrDAPulseDivConfig(LPC_UART_TypeDef *UARTx, UART_IrDA_PULSE_Type PulseDiv);
  558. /**
  559. * @}
  560. */
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564. #endif /* __LPC17XX_UART_H */
  565. /**
  566. * @}
  567. */
  568. /* --------------------------------- End Of File ------------------------------ */