ESP8266 Centre + NB
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 
33 
34 #define ESP_DEBUG_ON 1
35 #define ESP_DEBUG(fmt, ...) \
36  do \
37  { \
38  if (ESP_DEBUG_ON) \
39  os_printf("<<-ESP-DEBUG->> File: %20s" \
40  " | FUNC: %25s" \
41  " | LINE:[%5d] > " fmt "\n", \
42  __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
43  } while (0)
44 
46 
47 #define UART_TX_BUFFER_SIZE 256 //Ring buffer length of tx buffer
48 #define UART_RX_BUFFER_SIZE 256 //Ring buffer length of rx buffer
49 
50 #define UART_BUFF_EN 1 //use uart buffer , FOR UART0
51 #define UART_SELFTEST 1 //set 1:enable the loop test demo for uart buffer, FOR UART0
52 
53 #define UART_HW_RTS 0 //set 1: enable uart hw flow control RTS, PIN MTDO, FOR UART0
54 #define UART_HW_CTS 0 //set1: enable uart hw flow contrl CTS , PIN MTCK, FOR UART0
55 
56 #define UART0 0
57 #define UART1 1
58 
59 typedef enum {
60  FIVE_BITS = 0x0,
61  SIX_BITS = 0x1,
62  SEVEN_BITS = 0x2,
63  EIGHT_BITS = 0x3
65 
66 typedef enum {
67  ONE_STOP_BIT = 0x1,
71 
72 typedef enum {
73  NONE_BITS = 0x2,
74  ODD_BITS = 1,
77 
78 typedef enum {
82 
83 typedef enum {
90 
91 
92 typedef enum {
93  BIT_RATE_300 = 300,
94  BIT_RATE_600 = 600,
95  BIT_RATE_1200 = 1200,
96  BIT_RATE_2400 = 2400,
97  BIT_RATE_4800 = 4800,
98  BIT_RATE_9600 = 9600,
99  BIT_RATE_19200 = 19200,
100  BIT_RATE_38400 = 38400,
101  BIT_RATE_57600 = 57600,
102  BIT_RATE_74880 = 74880,
103  BIT_RATE_115200 = 115200,
104  BIT_RATE_230400 = 230400,
105  BIT_RATE_460800 = 460800,
106  BIT_RATE_921600 = 921600,
107  BIT_RATE_1843200 = 1843200,
108  BIT_RATE_3686400 = 3686400,
109 } UartBautRate;
110 
111 typedef enum {
115 } UartFlowCtrl;
116 
117 typedef enum {
123 
124 typedef enum {
129 
130 typedef struct {
135  uint8 TrigLvl; //JLU: may need to pad
137 } RcvMsgBuff;
138 
139 typedef struct {
142 } TrxMsgBuff;
143 
144 typedef enum {
150 } RcvMsgState;
151 
152 typedef struct {
162  int received;
163  int buff_uart_no; //indicate which uart use tx/rx buffer
164 } UartDevice;
165 
166 void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
167 void uart0_sendStr(const char *str);
168 
169 
171 #define UART_FIFO_LEN 128 //define the tx fifo length
172 #define UART_TX_EMPTY_THRESH_VAL 0x10
173 
174 
175  struct UartBuffer{
181  uint16 Space; //remanent space of the buffer
184 };
185 
186 struct UartRxBuff{
192  uint32 Space; //remanent space of the buffer
193 } ;
194 
195 typedef enum {
196  RUN = 0,
197  BLOCK = 1,
198 } TCPState;
199 
200 //void ICACHE_FLASH_ATTR uart_test_rx();
201 STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
203 void uart1_sendStr_no_wait(const char *str);
204 struct UartBuffer* Uart_Buf_Init();
205 
206 
207 #if UART_BUFF_EN
208 LOCAL void Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len);
209 void uart_buf_free(struct UartBuffer* pBuff);
210 void tx_buff_enq(char* pdata, uint16 data_len );
211 LOCAL void tx_fifo_insert(struct UartBuffer* pTxBuff, uint8 data_len, uint8 uart_no);
212 void tx_start_uart_buffer(uint8 uart_no);
213 uint16 rx_buff_deq(char* pdata, uint16 data_len );
214 void Uart_rx_buff_enq();
215 #endif
216 void uart_rx_intr_enable(uint8 uart_no);
217 void uart_rx_intr_disable(uint8 uart_no);
218 void uart0_tx_buffer(uint8 *buf, uint16 len);
219 void uart1_tx_buffer(uint8 *buf, uint16 len);
220 
221 //==============================================
222 #define FUNC_UART0_CTS 4
223 #define FUNC_U0CTS 4
224 #define FUNC_U1TXD_BK 2
225 #define UART_LINE_INV_MASK (0x3f<<19)
226 void UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len);
227 void UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num);
228 void UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask);
229 void UART_SetParity(uint8 uart_no, UartParityMode Parity_mode);
230 void UART_SetBaudrate(uint8 uart_no,uint32 baud_rate);
231 void UART_SetFlowCtrl(uint8 uart_no,UART_HwFlowCtrl flow_ctrl,uint8 rx_thresh);
232 void UART_WaitTxFifoEmpty(uint8 uart_no , uint32 time_out_us); //do not use if tx flow control enabled
233 void UART_ResetFifo(uint8 uart_no);
234 void UART_ClearIntrStatus(uint8 uart_no,uint32 clr_mask);
235 void UART_SetIntrEna(uint8 uart_no,uint32 ena_mask);
236 void UART_SetPrintPort(uint8 uart_no);
237 bool UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us);
238 //==============================================
239 
240 #endif
241 
UartFlowCtrl flow_ctrl
Definition: driver/uart.h:158
Definition: driver/uart.h:152
UartBitsNum4Char
Definition: driver/uart.h:59
uint8 * pInPos
Definition: driver/uart.h:178
uint32 Space
Definition: driver/uart.h:192
void uart0_sendStr(const char *str)
Definition: uart.c:231
RcvMsgBuffState BuffState
Definition: driver/uart.h:136
Definition: driver/uart.h:104
Definition: driver/uart.h:125
UART_HwFlowCtrl
Definition: driver/uart.h:117
uint32 UartRxBuffSize
Definition: driver/uart.h:187
RcvMsgBuffState
Definition: driver/uart.h:124
Definition: driver/uart.h:88
Definition: driver/uart.h:67
struct UartBuffer * nextBuff
Definition: driver/uart.h:183
UART_LineLevelInverse
Definition: driver/uart.h:83
Definition: driver/uart.h:87
void UART_SetPrintPort(uint8 uart_no)
Definition: uart.c:795
void UART_SetParity(uint8 uart_no, UartParityMode Parity_mode)
Definition: uart.c:701
Definition: driver/uart.h:186
UartStopBitsNum
Definition: driver/uart.h:66
uint8 * pWritePos
Definition: driver/uart.h:189
RcvMsgState rcv_state
Definition: driver/uart.h:161
Definition: driver/uart.h:149
#define UART_RXD_INV
Definition: driver/uart_register.h:106
UartFlowCtrl
Definition: driver/uart.h:111
LOCAL void tx_fifo_insert(struct UartBuffer *pTxBuff, uint8 data_len, uint8 uart_no)
Definition: driver/uart.h:75
Definition: driver/uart.h:103
void UART_SetFlowCtrl(uint8 uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh)
Definition: uart.c:717
Definition: driver/uart.h:196
Definition: driver/uart.h:147
void UART_SetIntrEna(uint8 uart_no, uint32 ena_mask)
Definition: uart.c:788
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
Definition: uart.c:128
Definition: driver/uart.h:127
void uart1_tx_buffer(uint8 *buf, uint16 len)
Definition: uart.c:214
UartBautRate baut_rate
Definition: driver/uart.h:153
Definition: driver/uart.h:175
Definition: driver/uart.h:63
unsigned short uint16
Definition: c_types.h:48
void UART_ClearIntrStatus(uint8 uart_no, uint32 clr_mask)
Definition: uart.c:782
void UART_SetBaudrate(uint8 uart_no, uint32 baud_rate)
Definition: uart.c:711
void Uart_rx_buff_enq()
void tx_buff_enq(char *pdata, uint16 data_len)
Definition: driver/uart.h:99
STATUS RxBuffState
Definition: driver/uart.h:191
Definition: driver/uart.h:130
Definition: driver/uart.h:79
Definition: driver/uart.h:69
void UART_WaitTxFifoEmpty(uint8 uart_no, uint32 time_out_us)
Definition: uart.c:735
void UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len)
Definition: uart.c:682
STATUS BuffState
Definition: driver/uart.h:180
Definition: driver/uart.h:118
UartParityMode parity
Definition: driver/uart.h:156
Definition: driver/uart.h:146
void UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num)
Definition: uart.c:688
Definition: driver/uart.h:93
uint16 Space
Definition: driver/uart.h:181
Definition: driver/uart.h:139
TrxMsgBuff trx_buff
Definition: driver/uart.h:160
Definition: driver/uart.h:197
Definition: driver/uart.h:62
void UART_ResetFifo(uint8 uart_no)
Definition: uart.c:775
void uart_rx_intr_enable(uint8 uart_no)
Definition: uart.c:658
uint8 * pOutPos
Definition: driver/uart.h:179
uint8 * pUartRxBuff
Definition: driver/uart.h:188
Definition: driver/uart.h:98
void uart_buf_free(struct UartBuffer *pBuff)
uint8 * pTrxBuff
Definition: driver/uart.h:141
Definition: driver/uart.h:96
void UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask)
Definition: uart.c:694
Definition: driver/uart.h:101
LOCAL void Uart_Buf_Cpy(struct UartBuffer *pCur, char *pdata, uint16 data_len)
void tx_start_uart_buffer(uint8 uart_no)
TCPState
Definition: driver/uart.h:195
Definition: driver/uart.h:73
Definition: driver/uart.h:113
STATUS uart_tx_one_char_no_wait(uint8 uart, uint8 TxChar)
Definition: uart.c:402
unsigned char uint8
Definition: c_types.h:43
struct UartBuffer * Uart_Buf_Init()
#define UART_CTS_INV
Definition: driver/uart_register.h:105
UartExistParity
Definition: driver/uart.h:78
uint8 TrigLvl
Definition: driver/uart.h:135
uint8 * pReadPos
Definition: driver/uart.h:190
UartBautRate
Definition: driver/uart.h:92
Definition: driver/uart.h:145
Definition: driver/uart.h:126
uint8 * pUartBuff
Definition: driver/uart.h:177
STATUS
Definition: c_types.h:77
UartBitsNum4Char data_bits
Definition: driver/uart.h:154
Definition: driver/uart.h:114
Definition: driver/uart.h:105
UartExistParity exist_parity
Definition: driver/uart.h:155
Definition: driver/uart.h:112
Definition: driver/uart.h:84
Definition: driver/uart.h:61
void uart_rx_intr_disable(uint8 uart_no)
Definition: uart.c:649
Definition: driver/uart.h:85
unsigned int uint32
Definition: c_types.h:52
Definition: driver/uart.h:106
bool UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us)
Definition: uart.c:750
Definition: driver/uart.h:102
Definition: driver/uart.h:74
uint8 TcpControl
Definition: driver/uart.h:182
Definition: driver/uart.h:60
UartStopBitsNum stop_bits
Definition: driver/uart.h:157
Definition: driver/uart.h:108
Definition: driver/uart.h:100
Definition: driver/uart.h:107
int received
Definition: driver/uart.h:162
uint8 * pRcvMsgBuff
Definition: driver/uart.h:132
void uart0_tx_buffer(uint8 *buf, uint16 len)
Definition: uart.c:197
Definition: driver/uart.h:95
Definition: driver/uart.h:68
int buff_uart_no
Definition: driver/uart.h:163
RcvMsgBuff rcv_buff
Definition: driver/uart.h:159
Definition: driver/uart.h:120
Definition: driver/uart.h:97
Definition: driver/uart.h:86
RcvMsgState
Definition: driver/uart.h:144
uint32 RcvBuffSize
Definition: driver/uart.h:131
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
Definition: uart.c:353
void uart1_sendStr_no_wait(const char *str)
Definition: uart.c:427
uint16 rx_buff_deq(char *pdata, uint16 data_len)
#define UART_TXD_INV
Definition: driver/uart_register.h:103
#define LOCAL
Definition: c_types.h:70
uint8 * pReadPos
Definition: driver/uart.h:134
Definition: driver/uart.h:148
Definition: driver/uart.h:121
uint8 * pWritePos
Definition: driver/uart.h:133
uint32 UartBuffSize
Definition: driver/uart.h:176
Definition: driver/uart.h:119
Definition: driver/uart.h:94
UartParityMode
Definition: driver/uart.h:72
Definition: driver/uart.h:80
uint32 TrxBuffSize
Definition: driver/uart.h:140
#define UART_RTS_INV
Definition: driver/uart_register.h:102