1
0

uart.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //###########################################################################
  2. //
  3. // FILE: uart.h
  4. //
  5. // TITLE: Stellaris style wrapper driver for C28x SCI peripheral.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. #ifndef __UART_H__
  43. #define __UART_H__
  44. //*****************************************************************************
  45. //
  46. // If building with a C++ compiler, make all of the definitions in this header
  47. // have a C binding.
  48. //
  49. //*****************************************************************************
  50. #ifdef __cplusplus
  51. extern "C"
  52. {
  53. #endif
  54. //*****************************************************************************
  55. //
  56. // Values that can be passed to UARTIntEnable, UARTIntDisable, and UARTIntClear
  57. // as the ui32IntFlags parameter, and returned from UARTIntStatus.
  58. //
  59. //*****************************************************************************
  60. #define UART_INT_RXERR 0x01
  61. #define UART_INT_RXRDY_BRKDT 0x02
  62. #define UART_INT_TXRDY 0x04
  63. #define UART_INT_TXFF 0x08
  64. #define UART_INT_RXFF 0x10
  65. //*****************************************************************************
  66. //
  67. // Values that can be passed to UARTConfigSetExpClk as the ui32Config parameter
  68. // and returned by UARTConfigGetExpClk in the pui32Config parameter.
  69. // Additionally, the UART_CONFIG_PAR_* subset can be passed to
  70. // UARTParityModeSet as the ui32Parity parameter, and are returned by
  71. // UARTParityModeGet.
  72. //
  73. //*****************************************************************************
  74. #define UART_CONFIG_WLEN_MASK 0x00000007 // Mask for extracting word length
  75. #define UART_CONFIG_WLEN_8 0x00000007 // 8 bit data
  76. #define UART_CONFIG_WLEN_7 0x00000006 // 7 bit data
  77. #define UART_CONFIG_WLEN_6 0x00000005 // 6 bit data
  78. #define UART_CONFIG_WLEN_5 0x00000004 // 5 bit data
  79. #define UART_CONFIG_STOP_MASK 0x00000080 // Mask for extracting stop bits
  80. #define UART_CONFIG_STOP_ONE 0x00000000 // One stop bit
  81. #define UART_CONFIG_STOP_TWO 0x00000080 // Two stop bits
  82. #define UART_CONFIG_PAR_MASK 0x00000060 // Parity Mask
  83. #define UART_CONFIG_PAR_NONE 0x00000000 // No parity
  84. #define UART_CONFIG_PAR_EVEN 0x00000060 // Even parity
  85. #define UART_CONFIG_PAR_ODD 0x00000020 // Odd parity
  86. #define UART_CONFIG_PAR_ONE 0x00000020 // Parity bit is one
  87. #define UART_CONFIG_PAR_ZERO 0x00000060 // Parity bit is zero
  88. //*****************************************************************************
  89. //
  90. // Values that can be passed to UARTFIFOLevelSet as the ui32TxLevel parameter and
  91. // returned by UARTFIFOLevelGet in the pui32TxLevel.
  92. //
  93. //*****************************************************************************
  94. #define UART_FIFO_TX1_8 0x00000001 // Transmit interrupt at 1/4 Full
  95. #define UART_FIFO_TX2_8 0x00000002 // Transmit interrupt at 1/2 Full
  96. #define UART_FIFO_TX4_8 0x00000003 // Transmit interrupt at 3/4 Full
  97. #define UART_FIFO_TX6_8 0x00000004 // Transmit interrupt Full
  98. //*****************************************************************************
  99. //
  100. // Values that can be passed to UARTFIFOLevelSet as the ui32RxLevel parameter and
  101. // returned by UARTFIFOLevelGet in the pui32RxLevel.
  102. //
  103. //*****************************************************************************
  104. #define UART_FIFO_RX1_8 0x00000001 // Receive interrupt at 1/4 Full
  105. #define UART_FIFO_RX2_8 0x00000002 // Receive interrupt at 1/2 Full
  106. #define UART_FIFO_RX4_8 0x00000003 // Receive interrupt at 3/4 Full
  107. #define UART_FIFO_RX6_8 0x00000004 // Receive interrupt at Full
  108. //*****************************************************************************
  109. //
  110. // Values that can be passed to UARTDMAEnable() and UARTDMADisable().
  111. //
  112. //*****************************************************************************
  113. #define UART_DMA_ERR_RXSTOP 0x00000004 // Stop DMA receive if UART error
  114. #define UART_DMA_TX 0x00000002 // Enable DMA for transmit
  115. #define UART_DMA_RX 0x00000001 // Enable DMA for receive
  116. //*****************************************************************************
  117. //
  118. // Values returned from UARTRxErrorGet().
  119. //
  120. //*****************************************************************************
  121. #define UART_RXERROR_OVERRUN 0x00000008
  122. #define UART_RXERROR_BREAK 0x00000020
  123. #define UART_RXERROR_PARITY 0x00000004
  124. #define UART_RXERROR_FRAMING 0x00000010
  125. //*****************************************************************************
  126. //
  127. // Values that can be passed to UARTHandshakeOutputsSet() or returned from
  128. // UARTHandshakeOutputGet().
  129. //
  130. //*****************************************************************************
  131. #define UART_OUTPUT_RTS 0x00000800
  132. #define UART_OUTPUT_DTR 0x00000400
  133. //*****************************************************************************
  134. //
  135. // Values that can be returned from UARTHandshakeInputsGet().
  136. //
  137. //*****************************************************************************
  138. #define UART_INPUT_RI 0x00000100
  139. #define UART_INPUT_DCD 0x00000004
  140. #define UART_INPUT_DSR 0x00000002
  141. #define UART_INPUT_CTS 0x00000001
  142. //*****************************************************************************
  143. //
  144. // Values that can be passed to UARTTxIntModeSet() or returned from
  145. // UARTTxIntModeGet().
  146. //
  147. //*****************************************************************************
  148. #define UART_TXINT_MODE_FIFO_M 0x0000001F
  149. #define UART_TXINT_MODE_EOT 0x00000000
  150. //*****************************************************************************
  151. //
  152. // API Function prototypes
  153. //
  154. //*****************************************************************************
  155. extern void UARTParityModeSet(uint32_t ui32Base, uint32_t ui32Parity);
  156. extern uint32_t UARTParityModeGet(uint32_t ui32Base);
  157. extern void UARTFIFOIntLevelSet(uint32_t ui32Base, uint32_t ui32TxLevel,
  158. uint32_t ui32RxLevel);
  159. extern void UARTFIFOIntLevelGet(uint32_t ui32Base, uint32_t *pui32TxLevel,
  160. uint32_t *pui32RxLevel);
  161. extern void UARTFIFOLevelGet(uint32_t ui32Base, uint32_t *pui32TxLevel,
  162. uint32_t *pui32RxLevel);
  163. extern void UARTConfigSetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  164. uint32_t ui32Baud, uint32_t ui32Config);
  165. extern void UARTConfigGetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk,
  166. uint32_t *pui32Baud, uint32_t *pui32Config);
  167. extern void UARTEnable(uint32_t ui32Base);
  168. extern void UARTDisable(uint32_t ui32Base);
  169. extern void UARTsetLoopBack(uint32_t ui32Base, bool enable);
  170. extern void UARTFIFOEnable(uint32_t ui32Base);
  171. extern void UARTFIFODisable(uint32_t ui32Base);
  172. extern bool UARTCharsAvail(uint32_t ui32Base);
  173. extern bool UARTSpaceAvail(uint32_t ui32Base);
  174. extern int32_t UARTCharGetNonBlocking(uint32_t ui32Base);
  175. extern int32_t UARTCharGet(uint32_t ui32Base);
  176. extern bool UARTCharPutNonBlocking(uint32_t ui32Base, unsigned char ucData);
  177. extern void UARTCharPut(uint32_t ui32Base, unsigned char ucData);
  178. extern bool UARTBusy(uint32_t ui32Base);
  179. extern void UARTRXIntRegister(uint32_t ui32Base, void(*pfnHandler)(void));
  180. extern void UARTTXIntRegister(uint32_t ui32Base, void(*pfnHandler)(void));
  181. extern void UARTRXIntUnregister(uint32_t ui32Base);
  182. extern void UARTTXIntUnregister(uint32_t ui32Base);
  183. extern void UARTIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
  184. extern void UARTIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
  185. extern uint32_t UARTIntStatus(uint32_t ui32Base, bool bMasked);
  186. extern void UARTIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
  187. extern uint32_t UARTRxErrorGet(uint32_t ui32Base);
  188. extern void UARTRxErrorClear(uint32_t ui32Base);
  189. extern void UARTTxIntModeSet(uint32_t ui32Base, uint32_t ui32Mode);
  190. extern uint32_t UARTTxIntModeGet(uint32_t ui32Base);
  191. //*****************************************************************************
  192. //
  193. // Mark the end of the C bindings section for C++ compilers.
  194. //
  195. //*****************************************************************************
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199. #endif // __UART_H__