uart.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //*****************************************************************************
  2. //
  3. // uart.h - Defines and Macros for the UART.
  4. //
  5. // Copyright (c) 2005-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  25. //
  26. //*****************************************************************************
  27. #ifndef __UART_H__
  28. #define __UART_H__
  29. //*****************************************************************************
  30. //
  31. // If building with a C++ compiler, make all of the definitions in this header
  32. // have a C binding.
  33. //
  34. //*****************************************************************************
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. //*****************************************************************************
  40. //
  41. // Values that can be passed to UARTIntEnable, UARTIntDisable, and UARTIntClear
  42. // as the ulIntFlags parameter, and returned from UARTIntStatus.
  43. //
  44. //*****************************************************************************
  45. #define UART_INT_OE 0x400 // Overrun Error Interrupt Mask
  46. #define UART_INT_BE 0x200 // Break Error Interrupt Mask
  47. #define UART_INT_PE 0x100 // Parity Error Interrupt Mask
  48. #define UART_INT_FE 0x080 // Framing Error Interrupt Mask
  49. #define UART_INT_RT 0x040 // Receive Timeout Interrupt Mask
  50. #define UART_INT_TX 0x020 // Transmit Interrupt Mask
  51. #define UART_INT_RX 0x010 // Receive Interrupt Mask
  52. #define UART_INT_DSR 0x008 // DSR Modem Interrupt Mask
  53. #define UART_INT_DCD 0x004 // DCD Modem Interrupt Mask
  54. #define UART_INT_CTS 0x002 // CTS Modem Interrupt Mask
  55. #define UART_INT_RI 0x001 // RI Modem Interrupt Mask
  56. //*****************************************************************************
  57. //
  58. // Values that can be passed to UARTConfigSetExpClk as the ulConfig parameter
  59. // and returned by UARTConfigGetExpClk in the pulConfig parameter.
  60. // Additionally, the UART_CONFIG_PAR_* subset can be passed to
  61. // UARTParityModeSet as the ulParity parameter, and are returned by
  62. // UARTParityModeGet.
  63. //
  64. //*****************************************************************************
  65. #define UART_CONFIG_WLEN_MASK 0x00000060 // Mask for extracting word length
  66. #define UART_CONFIG_WLEN_8 0x00000060 // 8 bit data
  67. #define UART_CONFIG_WLEN_7 0x00000040 // 7 bit data
  68. #define UART_CONFIG_WLEN_6 0x00000020 // 6 bit data
  69. #define UART_CONFIG_WLEN_5 0x00000000 // 5 bit data
  70. #define UART_CONFIG_STOP_MASK 0x00000008 // Mask for extracting stop bits
  71. #define UART_CONFIG_STOP_ONE 0x00000000 // One stop bit
  72. #define UART_CONFIG_STOP_TWO 0x00000008 // Two stop bits
  73. #define UART_CONFIG_PAR_MASK 0x00000086 // Mask for extracting parity
  74. #define UART_CONFIG_PAR_NONE 0x00000000 // No parity
  75. #define UART_CONFIG_PAR_EVEN 0x00000006 // Even parity
  76. #define UART_CONFIG_PAR_ODD 0x00000002 // Odd parity
  77. #define UART_CONFIG_PAR_ONE 0x00000082 // Parity bit is one
  78. #define UART_CONFIG_PAR_ZERO 0x00000086 // Parity bit is zero
  79. //*****************************************************************************
  80. //
  81. // Values that can be passed to UARTFIFOLevelSet as the ulTxLevel parameter and
  82. // returned by UARTFIFOLevelGet in the pulTxLevel.
  83. //
  84. //*****************************************************************************
  85. #define UART_FIFO_TX1_8 0x00000000 // Transmit interrupt at 1/8 Full
  86. #define UART_FIFO_TX2_8 0x00000001 // Transmit interrupt at 1/4 Full
  87. #define UART_FIFO_TX4_8 0x00000002 // Transmit interrupt at 1/2 Full
  88. #define UART_FIFO_TX6_8 0x00000003 // Transmit interrupt at 3/4 Full
  89. #define UART_FIFO_TX7_8 0x00000004 // Transmit interrupt at 7/8 Full
  90. //*****************************************************************************
  91. //
  92. // Values that can be passed to UARTFIFOLevelSet as the ulRxLevel parameter and
  93. // returned by UARTFIFOLevelGet in the pulRxLevel.
  94. //
  95. //*****************************************************************************
  96. #define UART_FIFO_RX1_8 0x00000000 // Receive interrupt at 1/8 Full
  97. #define UART_FIFO_RX2_8 0x00000008 // Receive interrupt at 1/4 Full
  98. #define UART_FIFO_RX4_8 0x00000010 // Receive interrupt at 1/2 Full
  99. #define UART_FIFO_RX6_8 0x00000018 // Receive interrupt at 3/4 Full
  100. #define UART_FIFO_RX7_8 0x00000020 // Receive interrupt at 7/8 Full
  101. //*****************************************************************************
  102. //
  103. // Values that can be passed to UARTDMAEnable() and UARTDMADisable().
  104. //
  105. //*****************************************************************************
  106. #define UART_DMA_ERR_RXSTOP 0x00000004 // Stop DMA receive if UART error
  107. #define UART_DMA_TX 0x00000002 // Enable DMA for transmit
  108. #define UART_DMA_RX 0x00000001 // Enable DMA for receive
  109. //*****************************************************************************
  110. //
  111. // Values returned from UARTRxErrorGet().
  112. //
  113. //*****************************************************************************
  114. #define UART_RXERROR_OVERRUN 0x00000008
  115. #define UART_RXERROR_BREAK 0x00000004
  116. #define UART_RXERROR_PARITY 0x00000002
  117. #define UART_RXERROR_FRAMING 0x00000001
  118. //*****************************************************************************
  119. //
  120. // Values that can be passed to UARTHandshakeOutputsSet() or returned from
  121. // UARTHandshakeOutputGet().
  122. //
  123. //*****************************************************************************
  124. #define UART_OUTPUT_RTS 0x00000800
  125. #define UART_OUTPUT_DTR 0x00000400
  126. //*****************************************************************************
  127. //
  128. // Values that can be returned from UARTHandshakeInputsGet().
  129. //
  130. //*****************************************************************************
  131. #define UART_INPUT_RI 0x00000100
  132. #define UART_INPUT_DCD 0x00000004
  133. #define UART_INPUT_DSR 0x00000002
  134. #define UART_INPUT_CTS 0x00000001
  135. //*****************************************************************************
  136. //
  137. // Values that can be passed to UARTFlowControl() or returned from
  138. // UARTFlowControlGet().
  139. //
  140. //*****************************************************************************
  141. #define UART_FLOWCONTROL_TX 0x00008000
  142. #define UART_FLOWCONTROL_RX 0x00004000
  143. #define UART_FLOWCONTROL_NONE 0x00000000
  144. //*****************************************************************************
  145. //
  146. // Values that can be passed to UARTTxIntModeSet() or returned from
  147. // UARTTxIntModeGet().
  148. //
  149. //*****************************************************************************
  150. #define UART_TXINT_MODE_FIFO 0x00000000
  151. #define UART_TXINT_MODE_EOT 0x00000010
  152. //*****************************************************************************
  153. //
  154. // API Function prototypes
  155. //
  156. //*****************************************************************************
  157. extern void UARTParityModeSet(unsigned long ulBase, unsigned long ulParity);
  158. extern unsigned long UARTParityModeGet(unsigned long ulBase);
  159. extern void UARTFIFOLevelSet(unsigned long ulBase, unsigned long ulTxLevel,
  160. unsigned long ulRxLevel);
  161. extern void UARTFIFOLevelGet(unsigned long ulBase, unsigned long *pulTxLevel,
  162. unsigned long *pulRxLevel);
  163. extern void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
  164. unsigned long ulBaud, unsigned long ulConfig);
  165. extern void UARTConfigGetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
  166. unsigned long *pulBaud,
  167. unsigned long *pulConfig);
  168. extern void UARTEnable(unsigned long ulBase);
  169. extern void UARTDisable(unsigned long ulBase);
  170. extern void UARTFIFOEnable(unsigned long ulBase);
  171. extern void UARTFIFODisable(unsigned long ulBase);
  172. extern void UARTEnableSIR(unsigned long ulBase, tBoolean bLowPower);
  173. extern void UARTDisableSIR(unsigned long ulBase);
  174. extern tBoolean UARTCharsAvail(unsigned long ulBase);
  175. extern tBoolean UARTSpaceAvail(unsigned long ulBase);
  176. extern long UARTCharGetNonBlocking(unsigned long ulBase);
  177. extern long UARTCharGet(unsigned long ulBase);
  178. extern tBoolean UARTCharPutNonBlocking(unsigned long ulBase,
  179. unsigned char ucData);
  180. extern void UARTCharPut(unsigned long ulBase, unsigned char ucData);
  181. extern void UARTBreakCtl(unsigned long ulBase, tBoolean bBreakState);
  182. extern tBoolean UARTBusy(unsigned long ulBase);
  183. extern void UARTIntRegister(unsigned long ulBase, void(*pfnHandler)(void));
  184. extern void UARTIntUnregister(unsigned long ulBase);
  185. extern void UARTIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
  186. extern void UARTIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
  187. extern unsigned long UARTIntStatus(unsigned long ulBase, tBoolean bMasked);
  188. extern void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags);
  189. extern void UARTDMAEnable(unsigned long ulBase, unsigned long ulDMAFlags);
  190. extern void UARTDMADisable(unsigned long ulBase, unsigned long ulDMAFlags);
  191. extern unsigned long UARTRxErrorGet(unsigned long ulBase);
  192. extern void UARTRxErrorClear(unsigned long ulBase);
  193. extern void UARTSmartCardEnable(unsigned long ulBase);
  194. extern void UARTSmartCardDisable(unsigned long ulBase);
  195. extern void UARTModemControlSet(unsigned long ulBase,
  196. unsigned long ulControl);
  197. extern void UARTModemControlClear(unsigned long ulBase,
  198. unsigned long ulControl);
  199. extern unsigned long UARTModemControlGet(unsigned long ulBase);
  200. extern unsigned long UARTModemStatusGet(unsigned long ulBase);
  201. extern void UARTFlowControlSet(unsigned long ulBase, unsigned long ulMode);
  202. extern unsigned long UARTFlowControlGet(unsigned long ulBase);
  203. extern void UARTTxIntModeSet(unsigned long ulBase, unsigned long ulMode);
  204. extern unsigned long UARTTxIntModeGet(unsigned long ulBase);
  205. //*****************************************************************************
  206. //
  207. // Several UART APIs have been renamed, with the original function name being
  208. // deprecated. These defines provide backward compatibility.
  209. //
  210. //*****************************************************************************
  211. #ifndef DEPRECATED
  212. #include "driverlib/sysctl.h"
  213. #define UARTConfigSet(a, b, c) \
  214. UARTConfigSetExpClk(a, SysCtlClockGet(), b, c)
  215. #define UARTConfigGet(a, b, c) \
  216. UARTConfigGetExpClk(a, SysCtlClockGet(), b, c)
  217. #define UARTCharNonBlockingGet(a) \
  218. UARTCharGetNonBlocking(a)
  219. #define UARTCharNonBlockingPut(a, b) \
  220. UARTCharPutNonBlocking(a, b)
  221. #endif
  222. //*****************************************************************************
  223. //
  224. // Mark the end of the C bindings section for C++ compilers.
  225. //
  226. //*****************************************************************************
  227. #ifdef __cplusplus
  228. }
  229. #endif
  230. #endif // __UART_H__