hal_uart.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**************************************************************************************************
  2. Filename: hal_uart.h
  3. Revised: $Date: 2009-03-09 05:27:36 -0700 (Mon, 09 Mar 2009) $
  4. Revision: $Revision: 19340 $
  5. Description: This file contains the interface to the UART Service.
  6. Copyright 2005-2009 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef HAL_UART_H
  34. #define HAL_UART_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /***************************************************************************************************
  40. * INCLUDES
  41. ***************************************************************************************************/
  42. #include "hal_board.h"
  43. /***************************************************************************************************
  44. * MACROS
  45. ***************************************************************************************************/
  46. /***************************************************************************************************
  47. * CONSTANTS
  48. ***************************************************************************************************/
  49. /* UART Ports */
  50. /*
  51. Serial Port Baudrate Settings
  52. Have to match with baudrate table
  53. Note that when using interrupt service based UART configuration (as opposed to DMA)
  54. higher baudrate such as 115200bps may have problem when radio is operational at the same time.
  55. */
  56. #define HAL_UART_BR_9600 0x00
  57. #define HAL_UART_BR_19200 0x01
  58. #define HAL_UART_BR_38400 0x02
  59. #define HAL_UART_BR_57600 0x03
  60. #define HAL_UART_BR_115200 0x04
  61. /* Frame Format constant */
  62. /* Stop Bits */
  63. #define HAL_UART_ONE_STOP_BIT 0x00
  64. #define HAL_UART_TWO_STOP_BITS 0x01
  65. /* Parity settings */
  66. #define HAL_UART_NO_PARITY 0x00
  67. #define HAL_UART_EVEN_PARITY 0x01
  68. #define HAL_UART_ODD_PARITY 0x02
  69. /* Character Size */
  70. #define HAL_UART_8_BITS_PER_CHAR 0x00
  71. #define HAL_UART_9_BITS_PER_CHAR 0x01
  72. /* Flow control */
  73. #define HAL_UART_FLOW_OFF 0x00
  74. #define HAL_UART_FLOW_ON 0x01
  75. /* Ports */
  76. #define HAL_UART_PORT_0 0x00
  77. #define HAL_UART_PORT_1 0x01
  78. #define HAL_UART_PORT_MAX 0x02
  79. /* UART Status */
  80. #define HAL_UART_SUCCESS 0x00
  81. #define HAL_UART_UNCONFIGURED 0x01
  82. #define HAL_UART_NOT_SUPPORTED 0x02
  83. #define HAL_UART_MEM_FAIL 0x03
  84. #define HAL_UART_BAUDRATE_ERROR 0x04
  85. /* UART Events */
  86. #define HAL_UART_RX_FULL 0x01
  87. #define HAL_UART_RX_ABOUT_FULL 0x02
  88. #define HAL_UART_RX_TIMEOUT 0x04
  89. #define HAL_UART_TX_FULL 0x08
  90. #define HAL_UART_TX_EMPTY 0x10
  91. /***************************************************************************************************
  92. * TYPEDEFS
  93. ***************************************************************************************************/
  94. typedef void (*halUARTCBack_t) (uint8 port, uint8 event);
  95. typedef struct
  96. {
  97. // The head or tail is updated by the Tx or Rx ISR respectively, when not polled.
  98. volatile uint16 bufferHead;
  99. volatile uint16 bufferTail;
  100. uint16 maxBufSize;
  101. uint8 *pBuffer;
  102. } halUARTBufControl_t;
  103. typedef struct
  104. {
  105. bool configured;
  106. uint8 baudRate;
  107. bool flowControl;
  108. uint16 flowControlThreshold;
  109. uint8 idleTimeout;
  110. halUARTBufControl_t rx;
  111. halUARTBufControl_t tx;
  112. bool intEnable;
  113. uint32 rxChRvdTime;
  114. halUARTCBack_t callBackFunc;
  115. }halUARTCfg_t;
  116. typedef union
  117. {
  118. bool paramCTS;
  119. bool paramRTS;
  120. bool paramDSR;
  121. bool paramDTR;
  122. bool paramCD;
  123. bool paramRI;
  124. uint16 baudRate;
  125. bool flowControl;
  126. bool flushControl;
  127. }halUARTIoctl_t;
  128. /***************************************************************************************************
  129. * GLOBAL VARIABLES
  130. ***************************************************************************************************/
  131. /***************************************************************************************************
  132. * FUNCTIONS - API
  133. ***************************************************************************************************/
  134. /*
  135. * Initialize UART at the startup
  136. */
  137. extern void HalUARTInit ( void );
  138. /*
  139. * Open a port based on the configuration
  140. */
  141. extern uint8 HalUARTOpen ( uint8 port, halUARTCfg_t *config );
  142. /*
  143. * Close a port
  144. */
  145. extern void HalUARTClose ( uint8 port );
  146. /*
  147. * Read a buffer from the UART
  148. */
  149. extern uint16 HalUARTRead ( uint8 port, uint8 *pBuffer, uint16 length );
  150. /*
  151. * Write a buff to the uart *
  152. */
  153. extern uint16 HalUARTWrite ( uint8 port, uint8 *pBuffer, uint16 length );
  154. /*
  155. * Write a buffer to the UART
  156. */
  157. extern uint8 HalUARTIoctl ( uint8 port, uint8 cmd, halUARTIoctl_t *pIoctl );
  158. /*
  159. * This to support polling
  160. */
  161. extern void HalUARTPoll( void );
  162. /*
  163. * Return the number of bytes in the Rx buffer
  164. */
  165. extern uint16 Hal_UART_RxBufLen ( uint8 port );
  166. /*
  167. * Return the number of bytes in the Tx buffer
  168. */
  169. extern uint16 Hal_UART_TxBufLen ( uint8 port );
  170. /*
  171. * This enable/disable flow control
  172. */
  173. extern void Hal_UART_FlowControlSet ( uint8 port, bool status );
  174. /*
  175. * Initialize hardware for UART
  176. */
  177. extern uint8 HalUART_HW_Init(uint8 port);
  178. /*
  179. * Abort UART when entering sleep mode
  180. */
  181. extern void HalUARTSuspend(void);
  182. /*
  183. * Resume UART after wakeup from sleep
  184. */
  185. extern void HalUARTResume(void);
  186. /***************************************************************************************************
  187. ***************************************************************************************************/
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif