ESP8266 Centre + NB
include/driver/uart.h
浏览该文件的文档.
1 /*
2  * ESPRESSIF MIT License
3  *
4  * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef UART_APP_H
26 #define UART_APP_H
27 
28 #include "uart_register.h"
29 #include "eagle_soc.h"
30 #include "c_types.h"
31 
32 #define UART_TX_BUFFER_SIZE 256 //Ring buffer length of tx buffer
33 #define UART_RX_BUFFER_SIZE 256 //Ring buffer length of rx buffer
34 
35 #define UART_BUFF_EN 1 //use uart buffer , FOR UART0
36 #define UART_SELFTEST 1 //set 1:enable the loop test demo for uart buffer, FOR UART0
37 
38 #define UART_HW_RTS 0 //set 1: enable uart hw flow control RTS, PIN MTDO, FOR UART0
39 #define UART_HW_CTS 0 //set1: enable uart hw flow contrl CTS , PIN MTCK, FOR UART0
40 
41 
42 
43 
44 #define UART0 0
45 #define UART1 1
46 
47 
48 typedef enum {
49  FIVE_BITS = 0x0,
50  SIX_BITS = 0x1,
51  SEVEN_BITS = 0x2,
52  EIGHT_BITS = 0x3
54 
55 typedef enum {
56  ONE_STOP_BIT = 0x1,
60 
61 typedef enum {
62  NONE_BITS = 0x2,
63  ODD_BITS = 1,
66 
67 typedef enum {
71 
72 typedef enum {
79 
80 
81 typedef enum {
82  BIT_RATE_300 = 300,
83  BIT_RATE_600 = 600,
84  BIT_RATE_1200 = 1200,
85  BIT_RATE_2400 = 2400,
86  BIT_RATE_4800 = 4800,
87  BIT_RATE_9600 = 9600,
88  BIT_RATE_19200 = 19200,
89  BIT_RATE_38400 = 38400,
90  BIT_RATE_57600 = 57600,
91  BIT_RATE_74880 = 74880,
92  BIT_RATE_115200 = 115200,
93  BIT_RATE_230400 = 230400,
94  BIT_RATE_460800 = 460800,
95  BIT_RATE_921600 = 921600,
96  BIT_RATE_1843200 = 1843200,
97  BIT_RATE_3686400 = 3686400,
98 } UartBautRate;
99 
100 typedef enum {
104 } UartFlowCtrl;
105 
106 typedef enum {
112 
113 typedef enum {
118 
119 typedef struct {
120  uint32 RcvBuffSize;
121  uint8 *pRcvMsgBuff;
122  uint8 *pWritePos;
123  uint8 *pReadPos;
124  uint8 TrigLvl; //JLU: may need to pad
126 } RcvMsgBuff;
127 
128 typedef struct {
129  uint32 TrxBuffSize;
130  uint8 *pTrxBuff;
131 } TrxMsgBuff;
132 
133 typedef enum {
139 } RcvMsgState;
140 
141 typedef struct {
142  UartBautRate baut_rate;
143  UartBitsNum4Char data_bits;
144  UartExistParity exist_parity;
145  UartParityMode parity;
146  UartStopBitsNum stop_bits;
147  UartFlowCtrl flow_ctrl;
148  RcvMsgBuff rcv_buff;
149  TrxMsgBuff trx_buff;
150  RcvMsgState rcv_state;
151  int received;
152  int buff_uart_no; //indicate which uart use tx/rx buffer
153 } UartDevice;
154 
155 void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
156 void uart0_sendStr(const char *str);
157 
158 
160 #define UART_FIFO_LEN 128 //define the tx fifo length
161 #define UART_TX_EMPTY_THRESH_VAL 0x10
162 
163 
164  struct UartBuffer{
166  uint8 *pUartBuff;
167  uint8 *pInPos;
168  uint8 *pOutPos;
170  uint16 Space; //remanent space of the buffer
172  struct UartBuffer * nextBuff;
173 };
174 
175 struct UartRxBuff{
178  uint8 *pWritePos;
179  uint8 *pReadPos;
181  uint32 Space; //remanent space of the buffer
182 } ;
183 
184 typedef enum {
185  RUN = 0,
186  BLOCK = 1,
187 } TCPState;
188 
189 //void ICACHE_FLASH_ATTR uart_test_rx();
190 STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
192 void uart1_sendStr_no_wait(const char *str);
193 struct UartBuffer* Uart_Buf_Init();
194 
195 
196 #if UART_BUFF_EN
197 LOCAL void Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len);
198 void uart_buf_free(struct UartBuffer* pBuff);
199 void tx_buff_enq(char* pdata, uint16 data_len );
200 LOCAL void tx_fifo_insert(struct UartBuffer* pTxBuff, uint8 data_len, uint8 uart_no);
201 void tx_start_uart_buffer(uint8 uart_no);
202 uint16 rx_buff_deq(char* pdata, uint16 data_len );
203 void Uart_rx_buff_enq();
204 #endif
205 void uart_rx_intr_enable(uint8 uart_no);
206 void uart_rx_intr_disable(uint8 uart_no);
207 void uart0_tx_buffer(uint8 *buf, uint16 len);
208 
209 //==============================================
210 #define FUNC_UART0_CTS 4
211 #define FUNC_U0CTS 4
212 #define FUNC_U1TXD_BK 2
213 #define UART_LINE_INV_MASK (0x3f<<19)
214 void UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len);
215 void UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num);
216 void UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask);
217 void UART_SetParity(uint8 uart_no, UartParityMode Parity_mode);
218 void UART_SetBaudrate(uint8 uart_no,uint32 baud_rate);
219 void UART_SetFlowCtrl(uint8 uart_no,UART_HwFlowCtrl flow_ctrl,uint8 rx_thresh);
220 void UART_WaitTxFifoEmpty(uint8 uart_no , uint32 time_out_us); //do not use if tx flow control enabled
221 void UART_ResetFifo(uint8 uart_no);
222 void UART_ClearIntrStatus(uint8 uart_no,uint32 clr_mask);
223 void UART_SetIntrEna(uint8 uart_no,uint32 ena_mask);
224 void UART_SetPrintPort(uint8 uart_no);
225 bool UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us);
226 //==============================================
227 
228 #endif
229 
UartExistParity
Definition: include/driver/uart.h:67
Definition: include/driver/uart.h:137
void uart0_sendStr(const char *str)
Definition: uart.c:231
UartBautRate
Definition: include/driver/uart.h:81
Definition: driver/uart.h:152
Definition: include/driver/uart.h:138
UART_HwFlowCtrl
Definition: include/driver/uart.h:106
UartBitsNum4Char
Definition: driver/uart.h:59
uint8 * pInPos
Definition: driver/uart.h:178
uint32 Space
Definition: driver/uart.h:192
Definition: include/driver/uart.h:49
Definition: include/driver/uart.h:109
void Uart_rx_buff_enq()
UART_HwFlowCtrl
Definition: driver/uart.h:117
uint32 UartRxBuffSize
Definition: driver/uart.h:187
Definition: include/driver/uart.h:103
TCPState
Definition: include/driver/uart.h:184
RcvMsgBuffState
Definition: driver/uart.h:124
Definition: include/driver/uart.h:92
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
Definition: uart.c:353
void uart0_tx_buffer(uint8 *buf, uint16 len)
Definition: uart.c:197
struct UartBuffer * nextBuff
Definition: driver/uart.h:183
UART_LineLevelInverse
Definition: driver/uart.h:83
void uart_buf_free(struct UartBuffer *pBuff)
Definition: driver/uart.h:186
void tx_start_uart_buffer(uint8 uart_no)
Definition: include/driver/uart.h:95
UartStopBitsNum
Definition: driver/uart.h:66
uint8 * pWritePos
Definition: driver/uart.h:189
#define UART_RXD_INV
Definition: driver/uart_register.h:106
UART_LineLevelInverse
Definition: include/driver/uart.h:72
UartFlowCtrl
Definition: driver/uart.h:111
Definition: include/driver/uart.h:185
void uart1_sendStr_no_wait(const char *str)
Definition: uart.c:427
Definition: include/driver/uart.h:52
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
Definition: uart.c:128
void UART_WaitTxFifoEmpty(uint8 uart_no, uint32 time_out_us)
Definition: uart.c:735
void UART_SetBaudrate(uint8 uart_no, uint32 baud_rate)
Definition: uart.c:711
Definition: include/driver/uart.h:84
Definition: driver/uart.h:175
Definition: include/driver/uart.h:83
unsigned short uint16
Definition: c_types.h:48
void UART_SetPrintPort(uint8 uart_no)
Definition: uart.c:795
void UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num)
Definition: uart.c:688
Definition: include/driver/uart.h:56
void uart_rx_intr_disable(uint8 uart_no)
Definition: uart.c:649
Definition: include/driver/uart.h:136
STATUS RxBuffState
Definition: driver/uart.h:191
Definition: driver/uart.h:130
Definition: include/driver/uart.h:76
Definition: include/driver/uart.h:74
STATUS BuffState
Definition: driver/uart.h:180
Definition: include/driver/uart.h:73
Definition: include/driver/uart.h:186
Definition: include/driver/uart.h:135
RcvMsgState
Definition: include/driver/uart.h:133
Definition: include/driver/uart.h:77
Definition: include/driver/uart.h:107
uint16 Space
Definition: driver/uart.h:181
Definition: driver/uart.h:139
void UART_SetFlowCtrl(uint8 uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh)
Definition: uart.c:717
Definition: include/driver/uart.h:97
LOCAL void tx_fifo_insert(struct UartBuffer *pTxBuff, uint8 data_len, uint8 uart_no)
void UART_SetParity(uint8 uart_no, UartParityMode Parity_mode)
Definition: uart.c:701
uint8 * pOutPos
Definition: driver/uart.h:179
uint8 * pUartRxBuff
Definition: driver/uart.h:188
Definition: include/driver/uart.h:89
Definition: include/driver/uart.h:82
Definition: include/driver/uart.h:91
Definition: include/driver/uart.h:86
Definition: include/driver/uart.h:134
void UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len)
Definition: uart.c:682
Definition: include/driver/uart.h:94
Definition: include/driver/uart.h:101
Definition: include/driver/uart.h:88
Definition: include/driver/uart.h:68
unsigned char uint8
Definition: c_types.h:43
#define UART_CTS_INV
Definition: driver/uart_register.h:105
UartExistParity
Definition: driver/uart.h:78
uint8 * pReadPos
Definition: driver/uart.h:190
UartBautRate
Definition: driver/uart.h:92
UartBitsNum4Char
Definition: include/driver/uart.h:48
Definition: include/driver/uart.h:64
uint8 * pUartBuff
Definition: driver/uart.h:177
STATUS
Definition: c_types.h:77
Definition: include/driver/uart.h:115
struct UartBuffer * Uart_Buf_Init()
UartStopBitsNum
Definition: include/driver/uart.h:55
bool UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us)
Definition: uart.c:750
Definition: include/driver/uart.h:110
STATUS uart_tx_one_char_no_wait(uint8 uart, uint8 TxChar)
Definition: uart.c:402
void UART_ResetFifo(uint8 uart_no)
Definition: uart.c:775
unsigned int uint32
Definition: c_types.h:52
LOCAL void Uart_Buf_Cpy(struct UartBuffer *pCur, char *pdata, uint16 data_len)
uint8 TcpControl
Definition: driver/uart.h:182
void UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask)
Definition: uart.c:694
Definition: include/driver/uart.h:93
Definition: include/driver/uart.h:102
RcvMsgBuffState
Definition: include/driver/uart.h:113
Definition: include/driver/uart.h:116
Definition: include/driver/uart.h:62
Definition: include/driver/uart.h:108
uint16 rx_buff_deq(char *pdata, uint16 data_len)
Definition: include/driver/uart.h:63
Definition: include/driver/uart.h:75
UartFlowCtrl
Definition: include/driver/uart.h:100
void UART_ClearIntrStatus(uint8 uart_no, uint32 clr_mask)
Definition: uart.c:782
Definition: include/driver/uart.h:50
RcvMsgState
Definition: driver/uart.h:144
Definition: include/driver/uart.h:69
Definition: include/driver/uart.h:85
#define UART_TXD_INV
Definition: driver/uart_register.h:103
#define LOCAL
Definition: c_types.h:70
Definition: include/driver/uart.h:90
Definition: include/driver/uart.h:96
Definition: include/driver/uart.h:58
void UART_SetIntrEna(uint8 uart_no, uint32 ena_mask)
Definition: uart.c:788
uint32 UartBuffSize
Definition: driver/uart.h:176
Definition: include/driver/uart.h:114
Definition: include/driver/uart.h:87
UartParityMode
Definition: include/driver/uart.h:61
Definition: include/driver/uart.h:51
Definition: include/driver/uart.h:57
void tx_buff_enq(char *pdata, uint16 data_len)
UartParityMode
Definition: driver/uart.h:72
void uart_rx_intr_enable(uint8 uart_no)
Definition: uart.c:658
#define UART_RTS_INV
Definition: driver/uart_register.h:102