uart.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /******************************************************************************
  2. * Filename: uart.h
  3. * Revised: $Date: 2013-04-16 12:01:40 +0200 (Tue, 16 Apr 2013) $
  4. * Revision: $Revision: 9777 $
  5. *
  6. * Description: Defines and Macros for the UART.
  7. *
  8. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
  9. *
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. *
  22. * Neither the name of Texas Instruments Incorporated nor the names of
  23. * its contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************/
  39. #ifndef __UART_H__
  40. #define __UART_H__
  41. //*****************************************************************************
  42. //
  43. // If building with a C++ compiler, make all of the definitions in this header
  44. // have a C binding.
  45. //
  46. //*****************************************************************************
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif
  51. #include "hw_types.h"
  52. //*****************************************************************************
  53. //
  54. // Values that can be passed to UARTIntEnable, UARTIntDisable, and UARTIntClear
  55. // as the ui32IntFlags parameter, and returned from UARTIntStatus.
  56. //
  57. //*****************************************************************************
  58. #define UART_INT_9BIT 0x1000 // 9-bit address match interrupt
  59. #define UART_INT_OE 0x400 // Overrun Error Interrupt Mask
  60. #define UART_INT_BE 0x200 // Break Error Interrupt Mask
  61. #define UART_INT_PE 0x100 // Parity Error Interrupt Mask
  62. #define UART_INT_FE 0x080 // Framing Error Interrupt Mask
  63. #define UART_INT_RT 0x040 // Receive Timeout Interrupt Mask
  64. #define UART_INT_TX 0x020 // Transmit Interrupt Mask
  65. #define UART_INT_RX 0x010 // Receive Interrupt Mask
  66. #define UART_INT_CTS 0x002 // CTS Modem Interrupt Mask (only
  67. // UART1)
  68. //*****************************************************************************
  69. //
  70. // Values that can be passed to UARTConfigSetExpClk as the ui32Config parameter
  71. // and returned by UARTConfigGetExpClk in the pui32Config parameter.
  72. // Additionally, the UART_CONFIG_PAR_* subset can be passed to
  73. // UARTParityModeSet as the ui32Parity parameter, and are returned by
  74. // UARTParityModeGet.
  75. //
  76. //*****************************************************************************
  77. #define UART_CONFIG_WLEN_MASK 0x00000060 // Mask for extracting word length
  78. #define UART_CONFIG_WLEN_8 0x00000060 // 8 bit data
  79. #define UART_CONFIG_WLEN_7 0x00000040 // 7 bit data
  80. #define UART_CONFIG_WLEN_6 0x00000020 // 6 bit data
  81. #define UART_CONFIG_WLEN_5 0x00000000 // 5 bit data
  82. #define UART_CONFIG_STOP_MASK 0x00000008 // Mask for extracting stop bits
  83. #define UART_CONFIG_STOP_ONE 0x00000000 // One stop bit
  84. #define UART_CONFIG_STOP_TWO 0x00000008 // Two stop bits
  85. #define UART_CONFIG_PAR_MASK 0x00000086 // Mask for extracting parity
  86. #define UART_CONFIG_PAR_NONE 0x00000000 // No parity
  87. #define UART_CONFIG_PAR_EVEN 0x00000006 // Even parity
  88. #define UART_CONFIG_PAR_ODD 0x00000002 // Odd parity
  89. #define UART_CONFIG_PAR_ONE 0x00000082 // Parity bit is one
  90. #define UART_CONFIG_PAR_ZERO 0x00000086 // Parity bit is zero
  91. //*****************************************************************************
  92. //
  93. // Values that can be passed to UARTFIFOLevelSet as the ui32TxLevel parameter and
  94. // returned by UARTFIFOLevelGet in the pui32TxLevel.
  95. //
  96. //*****************************************************************************
  97. #define UART_FIFO_TX1_8 0x00000000 // Transmit interrupt at 1/8 Full
  98. #define UART_FIFO_TX2_8 0x00000001 // Transmit interrupt at 1/4 Full
  99. #define UART_FIFO_TX4_8 0x00000002 // Transmit interrupt at 1/2 Full
  100. #define UART_FIFO_TX6_8 0x00000003 // Transmit interrupt at 3/4 Full
  101. #define UART_FIFO_TX7_8 0x00000004 // Transmit interrupt at 7/8 Full
  102. //*****************************************************************************
  103. //
  104. // Values that can be passed to UARTFIFOLevelSet as the ui32RxLevel parameter and
  105. // returned by UARTFIFOLevelGet in the pui32RxLevel.
  106. //
  107. //*****************************************************************************
  108. #define UART_FIFO_RX1_8 0x00000000 // Receive interrupt at 1/8 Full
  109. #define UART_FIFO_RX2_8 0x00000008 // Receive interrupt at 1/4 Full
  110. #define UART_FIFO_RX4_8 0x00000010 // Receive interrupt at 1/2 Full
  111. #define UART_FIFO_RX6_8 0x00000018 // Receive interrupt at 3/4 Full
  112. #define UART_FIFO_RX7_8 0x00000020 // Receive interrupt at 7/8 Full
  113. //*****************************************************************************
  114. //
  115. // Values that can be passed to UARTDMAEnable() and UARTDMADisable().
  116. //
  117. //*****************************************************************************
  118. #define UART_DMA_ERR_RXSTOP 0x00000004 // Stop DMA receive if UART error
  119. #define UART_DMA_TX 0x00000002 // Enable DMA for transmit
  120. #define UART_DMA_RX 0x00000001 // Enable DMA for receive
  121. //*****************************************************************************
  122. //
  123. // Values returned from UARTRxErrorGet().
  124. //
  125. //*****************************************************************************
  126. #define UART_RXERROR_OVERRUN 0x00000008
  127. #define UART_RXERROR_BREAK 0x00000004
  128. #define UART_RXERROR_PARITY 0x00000002
  129. #define UART_RXERROR_FRAMING 0x00000001
  130. //*****************************************************************************
  131. //
  132. // Values that can be passed to UARTTxIntModeSet() or returned from
  133. // UARTTxIntModeGet().
  134. //
  135. //*****************************************************************************
  136. #define UART_TXINT_MODE_FIFO 0x00000000
  137. #define UART_TXINT_MODE_EOT 0x00000010
  138. //*****************************************************************************
  139. //
  140. // Values that can be passed to UARTClockSourceSet() or returned from
  141. // UARTClockSourceGet().
  142. //
  143. //*****************************************************************************
  144. #define UART_CLOCK_SYSTEM 0x00000000
  145. #define UART_CLOCK_PIOSC 0x00000001
  146. //*****************************************************************************
  147. //
  148. // API Function prototypes
  149. //
  150. //*****************************************************************************
  151. extern void UARTParityModeSet(uint32_t ui32Base, uint32_t ui32Parity);
  152. extern uint32_t UARTParityModeGet(uint32_t ui32Base);
  153. extern void UARTFIFOLevelSet(uint32_t ui32Base, uint32_t ui32TxLevel,
  154. uint32_t ui32RxLevel);
  155. extern void UARTFIFOLevelGet(uint32_t ui32Base, uint32_t *pui32TxLevel,
  156. uint32_t *pui32RxLevel);
  157. extern void UARTConfigSetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  158. uint32_t ui32Baud, uint32_t ui32Config);
  159. extern void UARTConfigGetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  160. uint32_t *pui32Baud,
  161. uint32_t *pui32Config);
  162. extern void UARTEnable(uint32_t ui32Base);
  163. extern void UARTDisable(uint32_t ui32Base);
  164. extern void UARTFIFOEnable(uint32_t ui32Base);
  165. extern void UARTFIFODisable(uint32_t ui32Base);
  166. extern void UARTEnableSIR(uint32_t ui32Base, bool bLowPower);
  167. extern void UARTDisableSIR(uint32_t ui32Base);
  168. extern bool UARTCharsAvail(uint32_t ui32Base);
  169. extern bool UARTSpaceAvail(uint32_t ui32Base);
  170. extern int32_t UARTCharGetNonBlocking(uint32_t ui32Base);
  171. extern int32_t UARTCharGet(uint32_t ui32Base);
  172. extern bool UARTCharPutNonBlocking(uint32_t ui32Base,
  173. uint8_t ui8Data);
  174. extern void UARTCharPut(uint32_t ui32Base, uint8_t ui8Data);
  175. extern void UARTBreakCtl(uint32_t ui32Base, bool bBreakState);
  176. extern bool UARTBusy(uint32_t ui32Base);
  177. extern void UARTIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
  178. extern void UARTIntUnregister(uint32_t ui32Base);
  179. extern void UARTIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
  180. extern void UARTIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
  181. extern uint32_t UARTIntStatus(uint32_t ui32Base, bool bMasked);
  182. extern void UARTIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
  183. extern void UARTDMAEnable(uint32_t ui32Base, uint32_t ui32DMAFlags);
  184. extern void UARTDMADisable(uint32_t ui32Base, uint32_t ui32DMAFlags);
  185. extern uint32_t UARTRxErrorGet(uint32_t ui32Base);
  186. extern void UARTRxErrorClear(uint32_t ui32Base);
  187. extern void UARTTxIntModeSet(uint32_t ui32Base, uint32_t ui32Mode);
  188. extern uint32_t UARTTxIntModeGet(uint32_t ui32Base);
  189. extern void UARTClockSourceSet(uint32_t ui32Base, uint32_t ui32Source);
  190. extern uint32_t UARTClockSourceGet(uint32_t ui32Base);
  191. extern void UART9BitEnable(uint32_t ui32Base);
  192. extern void UART9BitDisable(uint32_t ui32Base);
  193. extern void UART9BitAddrSet(uint32_t ui32Base, uint8_t ui8Addr,
  194. uint8_t ui8Mask);
  195. extern void UART9BitAddrSend(uint32_t ui32Base, uint8_t ui8Addr);
  196. //*****************************************************************************
  197. //
  198. // Mark the end of the C bindings section for C++ compilers.
  199. //
  200. //*****************************************************************************
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif // __UART_H__