uart_hw.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //Generated at 2012-07-03 18:44:06
  2. /*
  3. * Copyright (c) 2010 - 2011 Espressif System
  4. *
  5. */
  6. #ifndef UART_REGISTER_H_INCLUDED
  7. #define UART_REGISTER_H_INCLUDED
  8. #define REG_UART_BASE( i ) (0x60000000+(i)*0xf00)
  9. //version value:32'h062000
  10. #define UART_FIFO( i ) (REG_UART_BASE( i ) + 0x0)
  11. #define UART_RXFIFO_RD_BYTE 0x000000FF
  12. #define UART_RXFIFO_RD_BYTE_S 0
  13. #define UART_INT_RAW( i ) (REG_UART_BASE( i ) + 0x4)
  14. #define UART_RXFIFO_TOUT_INT_RAW (BIT(8))
  15. #define UART_BRK_DET_INT_RAW (BIT(7))
  16. #define UART_CTS_CHG_INT_RAW (BIT(6))
  17. #define UART_DSR_CHG_INT_RAW (BIT(5))
  18. #define UART_RXFIFO_OVF_INT_RAW (BIT(4))
  19. #define UART_FRM_ERR_INT_RAW (BIT(3))
  20. #define UART_PARITY_ERR_INT_RAW (BIT(2))
  21. #define UART_TXFIFO_EMPTY_INT_RAW (BIT(1))
  22. #define UART_RXFIFO_FULL_INT_RAW (BIT(0))
  23. #define UART_INT_ST( i ) (REG_UART_BASE( i ) + 0x8)
  24. #define UART_RXFIFO_TOUT_INT_ST (BIT(8))
  25. #define UART_BRK_DET_INT_ST (BIT(7))
  26. #define UART_CTS_CHG_INT_ST (BIT(6))
  27. #define UART_DSR_CHG_INT_ST (BIT(5))
  28. #define UART_RXFIFO_OVF_INT_ST (BIT(4))
  29. #define UART_FRM_ERR_INT_ST (BIT(3))
  30. #define UART_PARITY_ERR_INT_ST (BIT(2))
  31. #define UART_TXFIFO_EMPTY_INT_ST (BIT(1))
  32. #define UART_RXFIFO_FULL_INT_ST (BIT(0))
  33. #define UART_INT_ENA( i ) (REG_UART_BASE( i ) + 0xC)
  34. #define UART_RXFIFO_TOUT_INT_ENA (BIT(8))
  35. #define UART_BRK_DET_INT_ENA (BIT(7))
  36. #define UART_CTS_CHG_INT_ENA (BIT(6))
  37. #define UART_DSR_CHG_INT_ENA (BIT(5))
  38. #define UART_RXFIFO_OVF_INT_ENA (BIT(4))
  39. #define UART_FRM_ERR_INT_ENA (BIT(3))
  40. #define UART_PARITY_ERR_INT_ENA (BIT(2))
  41. #define UART_TXFIFO_EMPTY_INT_ENA (BIT(1))
  42. #define UART_RXFIFO_FULL_INT_ENA (BIT(0))
  43. #define UART_INT_CLR( i ) (REG_UART_BASE( i ) + 0x10)
  44. #define UART_RXFIFO_TOUT_INT_CLR (BIT(8))
  45. #define UART_BRK_DET_INT_CLR (BIT(7))
  46. #define UART_CTS_CHG_INT_CLR (BIT(6))
  47. #define UART_DSR_CHG_INT_CLR (BIT(5))
  48. #define UART_RXFIFO_OVF_INT_CLR (BIT(4))
  49. #define UART_FRM_ERR_INT_CLR (BIT(3))
  50. #define UART_PARITY_ERR_INT_CLR (BIT(2))
  51. #define UART_TXFIFO_EMPTY_INT_CLR (BIT(1))
  52. #define UART_RXFIFO_FULL_INT_CLR (BIT(0))
  53. #define UART_CLKDIV( i ) (REG_UART_BASE( i ) + 0x14)
  54. #define UART_CLKDIV_CNT 0x000FFFFF
  55. #define UART_CLKDIV_S 0
  56. #define UART_AUTOBAUD( i ) (REG_UART_BASE( i ) + 0x18)
  57. #define UART_GLITCH_FILT 0x000000FF
  58. #define UART_GLITCH_FILT_S 8
  59. #define UART_AUTOBAUD_EN (BIT(0))
  60. #define UART_STATUS( i ) (REG_UART_BASE( i ) + 0x1C)
  61. #define UART_TXD (BIT(31))
  62. #define UART_RTSN (BIT(30))
  63. #define UART_DTRN (BIT(29))
  64. #define UART_TXFIFO_CNT 0x000000FF
  65. #define UART_TXFIFO_CNT_S 16
  66. #define UART_RXD (BIT(15))
  67. #define UART_CTSN (BIT(14))
  68. #define UART_DSRN (BIT(13))
  69. #define UART_RXFIFO_CNT 0x000000FF
  70. #define UART_RXFIFO_CNT_S 0
  71. #define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
  72. #define UART_TXFIFO_RST (BIT(18))
  73. #define UART_RXFIFO_RST (BIT(17))
  74. #define UART_IRDA_EN (BIT(16))
  75. #define UART_TX_FLOW_EN (BIT(15))
  76. #define UART_LOOPBACK (BIT(14))
  77. #define UART_IRDA_RX_INV (BIT(13))
  78. #define UART_IRDA_TX_INV (BIT(12))
  79. #define UART_IRDA_WCTL (BIT(11))
  80. #define UART_IRDA_TX_EN (BIT(10))
  81. #define UART_IRDA_DPLX (BIT(9))
  82. #define UART_TXD_BRK (BIT(8))
  83. #define UART_SW_DTR (BIT(7))
  84. #define UART_SW_RTS (BIT(6))
  85. #define UART_STOP_BIT_NUM 0x00000003
  86. #define UART_STOP_BIT_NUM_S 4
  87. #define UART_BIT_NUM 0x00000003
  88. #define UART_BIT_NUM_S 2
  89. #define UART_PARITY_EN (BIT(1))
  90. #define UART_PARITY (BIT(0))
  91. #define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24)
  92. #define UART_RX_TOUT_EN (BIT(31))
  93. #define UART_RX_TOUT_THRHD 0x0000007F
  94. #define UART_RX_TOUT_THRHD_S 24
  95. #define UART_RX_FLOW_EN (BIT(23))
  96. #define UART_RX_FLOW_THRHD 0x0000007F
  97. #define UART_RX_FLOW_THRHD_S 16
  98. #define UART_TXFIFO_EMPTY_THRHD 0x0000007F
  99. #define UART_TXFIFO_EMPTY_THRHD_S 8
  100. #define UART_RXFIFO_FULL_THRHD 0x0000007F
  101. #define UART_RXFIFO_FULL_THRHD_S 0
  102. #define UART_LOWPULSE( i ) (REG_UART_BASE( i ) + 0x28)
  103. #define UART_LOWPULSE_MIN_CNT 0x000FFFFF
  104. #define UART_LOWPULSE_MIN_CNT_S 0
  105. #define UART_HIGHPULSE( i ) (REG_UART_BASE( i ) + 0x2C)
  106. #define UART_HIGHPULSE_MIN_CNT 0x000FFFFF
  107. #define UART_HIGHPULSE_MIN_CNT_S 0
  108. #define UART_PULSE_NUM( i ) (REG_UART_BASE( i ) + 0x30)
  109. #define UART_PULSE_NUM_CNT 0x0003FF
  110. #define UART_PULSE_NUM_CNT_S 0
  111. #define UART_DATE( i ) (REG_UART_BASE( i ) + 0x78)
  112. #define UART_ID( i ) (REG_UART_BASE( i ) + 0x7C)
  113. #define RX_BUFF_SIZE 256
  114. #define TX_BUFF_SIZE 100
  115. #define UART0 0
  116. #define UART1 1
  117. //calc bit 0..5 for UART_CONF0 register
  118. #define CALC_UARTMODE(data_bits,parity,stop_bits) \
  119. (((parity == NONE_BITS) ? 0x0 : (UART_PARITY_EN | (parity & UART_PARITY))) | \
  120. ((stop_bits & UART_STOP_BIT_NUM) << UART_STOP_BIT_NUM_S) | \
  121. ((data_bits & UART_BIT_NUM) << UART_BIT_NUM_S))
  122. typedef enum {
  123. FIVE_BITS = 0x0,
  124. SIX_BITS = 0x1,
  125. SEVEN_BITS = 0x2,
  126. EIGHT_BITS = 0x3
  127. } UartBitsNum4Char;
  128. typedef enum {
  129. ONE_STOP_BIT = 0,
  130. ONE_HALF_STOP_BIT = BIT2,
  131. TWO_STOP_BIT = BIT2
  132. } UartStopBitsNum;
  133. typedef enum {
  134. NONE_BITS = 0,
  135. ODD_BITS = 0,
  136. EVEN_BITS = BIT4
  137. } UartParityMode;
  138. typedef enum {
  139. STICK_PARITY_DIS = 0,
  140. STICK_PARITY_EN = BIT3 | BIT5
  141. } UartExistParity;
  142. typedef enum {
  143. BIT_RATE_300 = 300,
  144. BIT_RATE_600 = 600,
  145. BIT_RATE_1200 = 1200,
  146. BIT_RATE_2400 = 2400,
  147. BIT_RATE_4800 = 4800,
  148. BIT_RATE_9600 = 9600,
  149. BIT_RATE_19200 = 19200,
  150. BIT_RATE_38400 = 38400,
  151. BIT_RATE_57600 = 57600,
  152. BIT_RATE_74880 = 74880,
  153. BIT_RATE_115200 = 115200,
  154. BIT_RATE_230400 = 230400,
  155. BIT_RATE_460800 = 460800,
  156. BIT_RATE_921600 = 921600
  157. } UartBautRate;
  158. typedef enum {
  159. NONE_CTRL,
  160. HARDWARE_CTRL,
  161. XON_XOFF_CTRL
  162. } UartFlowCtrl;
  163. typedef enum {
  164. EMPTY,
  165. UNDER_WRITE,
  166. WRITE_OVER
  167. } RcvMsgBuffState;
  168. typedef struct {
  169. uint32 RcvBuffSize;
  170. uint8 *pRcvMsgBuff;
  171. uint8 *pWritePos;
  172. uint8 *pReadPos;
  173. uint8 TrigLvl; //JLU: may need to pad
  174. RcvMsgBuffState BuffState;
  175. } RcvMsgBuff;
  176. typedef struct {
  177. uint32 TrxBuffSize;
  178. uint8 *pTrxBuff;
  179. } TrxMsgBuff;
  180. typedef enum {
  181. BAUD_RATE_DET,
  182. WAIT_SYNC_FRM,
  183. SRCH_MSG_HEAD,
  184. RCV_MSG_BODY,
  185. RCV_ESC_CHAR,
  186. } RcvMsgState;
  187. typedef struct {
  188. UartBautRate baut_rate;
  189. UartBitsNum4Char data_bits;
  190. UartExistParity exist_parity;
  191. UartParityMode parity;
  192. UartStopBitsNum stop_bits;
  193. UartFlowCtrl flow_ctrl;
  194. RcvMsgBuff rcv_buff;
  195. TrxMsgBuff trx_buff;
  196. RcvMsgState rcv_state;
  197. int received;
  198. int buff_uart_no; //indicate which uart use tx/rx buffer
  199. } UartDevice;
  200. #endif // UART_REGISTER_H_INCLUDED