MeterLogger
uart.h
Go to the documentation of this file.
1 /*
2  * File : uart.h
3  * Copyright (C) 2013 - 2016, Espressif Systems
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of version 3 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef UART_APP_H
18 #define UART_APP_H
19 
20 #include "uart_register.h"
21 #include "eagle_soc.h"
22 #include "c_types.h"
23 
24 #define UART_TX_BUFFER_SIZE 256 //Ring buffer length of tx buffer
25 #define UART_RX_BUFFER_SIZE 256 //Ring buffer length of rx buffer
26 
27 #define UART_BUFF_EN 0 //use uart buffer , FOR UART0
28 #define UART_SELFTEST 0 //set 1:enable the loop test demo for uart buffer, FOR UART0
29 
30 #define UART_HW_RTS 0 //set 1: enable uart hw flow control RTS, PIN MTDO, FOR UART0
31 #define UART_HW_CTS 0 //set1: enable uart hw flow contrl CTS , PIN MTCK, FOR UART0
32 
33 #define UART_LINE_INV_MASK (0x3f<<19)
34 
35 
36 
37 #define UART0 0
38 #define UART1 1
39 
40 
41 typedef enum {
42  FIVE_BITS = 0x0,
43  SIX_BITS = 0x1,
44  SEVEN_BITS = 0x2,
45  EIGHT_BITS = 0x3
47 
48 typedef enum {
49  ONE_STOP_BIT = 0x1,
53 
54 typedef enum {
55  NONE_BITS = 0x2,
56  ODD_BITS = 1,
59 
60 typedef enum {
64 
65 typedef enum {
72 
73 
74 typedef enum {
75  BIT_RATE_300 = 300,
76  BIT_RATE_600 = 600,
77  BIT_RATE_1200 = 1200,
78  BIT_RATE_2400 = 2400,
79  BIT_RATE_4800 = 4800,
80  BIT_RATE_9600 = 9600,
81  BIT_RATE_19200 = 19200,
82  BIT_RATE_38400 = 38400,
83  BIT_RATE_57600 = 57600,
84  BIT_RATE_74880 = 74880,
85  BIT_RATE_115200 = 115200,
86  BIT_RATE_230400 = 230400,
87  BIT_RATE_460800 = 460800,
88  BIT_RATE_921600 = 921600,
89  BIT_RATE_1843200 = 1843200,
90  BIT_RATE_3686400 = 3686400,
91 } UartBautRate;
92 
93 typedef enum {
97 } UartFlowCtrl;
98 
99 typedef enum {
105 
106 typedef enum {
111 
112 typedef struct {
117  uint8 TrigLvl; //JLU: may need to pad
119 } RcvMsgBuff;
120 
121 typedef struct {
124 } TrxMsgBuff;
125 
126 typedef enum {
132 } RcvMsgState;
133 
134 typedef struct {
144  int received;
145  int buff_uart_no; //indicate which uart use tx/rx buffer
146 } UartDevice;
147 
148 void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
149 void uart0_sendStr(const char *str);
150 
151 
152 ///////////////////////////////////////
153 #define UART_FIFO_LEN 128 //define the tx fifo length
154 #define UART_TX_EMPTY_THRESH_VAL 0x10
155 
156 
157  struct UartBuffer{
163  uint16 Space; //remanent space of the buffer
166 };
167 
168 struct UartRxBuff{
174  uint32 Space; //remanent space of the buffer
175 } ;
176 
177 typedef enum {
178  RUN = 0,
179  BLOCK = 1,
180 } TCPState;
181 
182 //void ICACHE_FLASH_ATTR uart_test_rx();
183 STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
185 void uart1_sendStr_no_wait(const char *str);
186 struct UartBuffer* Uart_Buf_Init();
187 
188 
189 void uart_rx_intr_enable(uint8 uart_no);
190 void uart_rx_intr_disable(uint8 uart_no);
191 void uart0_tx_buffer(uint8 *buf, uint16 len);
192 
193 void ICACHE_FLASH_ATTR uart_set_word_length(uint8_t uart_no, UartBitsNum4Char len);
194 void ICACHE_FLASH_ATTR uart_set_stop_bits(uint8_t uart_no, UartStopBitsNum bit_num);
195 void ICACHE_FLASH_ATTR uart_set_line_inverse(uint8_t uart_no, UART_LineLevelInverse inverse_mask);
196 void ICACHE_FLASH_ATTR uart_set_parity(uint8_t uart_no, UartParityMode Parity_mode);
197 void ICACHE_FLASH_ATTR uart_set_baudrate(uint8_t uart_no, uint32_t baud_rate);
198 
199 #endif
200 
UartFlowCtrl flow_ctrl
Definition: uart.h:140
uint8 * pOutPos
Definition: uart.h:161
UartExistParity
Definition: uart.h:60
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
Definition: uart.c:273
uint32 Space
Definition: uart.h:174
uint8 * pRcvMsgBuff
Definition: uart.h:114
RcvMsgBuffState
Definition: uart.h:106
RcvMsgBuffState BuffState
Definition: uart.h:118
Definition: uart.h:57
uint32 UartRxBuffSize
Definition: uart.h:169
Definition: uart.h:178
Definition: uart.h:94
void ICACHE_FLASH_ATTR uart_set_word_length(uint8_t uart_no, UartBitsNum4Char len)
Definition: uart.c:311
RcvMsgState rcv_state
Definition: uart.h:143
Definition: uart.h:55
struct UartBuffer * Uart_Buf_Init()
Definition: uart.h:179
RcvMsgState
Definition: uart.h:126
UartBautRate baut_rate
Definition: uart.h:135
unsigned short uint16
Definition: c_types.h:50
Definition: uart.h:43
#define ICACHE_FLASH_ATTR
Definition: c_types.h:99
STATUS RxBuffState
Definition: uart.h:173
uint8 * pUartBuff
Definition: uart.h:159
STATUS BuffState
Definition: uart.h:162
UartParityMode parity
Definition: uart.h:138
struct UartBuffer * nextBuff
Definition: uart.h:165
UART_HwFlowCtrl
Definition: uart.h:99
UartBitsNum4Char
Definition: uart.h:41
uint16 Space
Definition: uart.h:163
TrxMsgBuff trx_buff
Definition: uart.h:142
void ICACHE_FLASH_ATTR uart_set_stop_bits(uint8_t uart_no, UartStopBitsNum bit_num)
Definition: uart.c:316
#define UART_TXD_INV
UartParityMode
Definition: uart.h:54
#define UART_RXD_INV
Definition: uart.h:107
uint8 * pTrxBuff
Definition: uart.h:123
uint8 * pWritePos
Definition: uart.h:115
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
Definition: uart.c:104
Definition: uart.h:56
uint8 * pReadPos
Definition: uart.h:172
unsigned char uint8
Definition: c_types.h:45
uint8 TrigLvl
Definition: uart.h:117
Definition: uart.h:42
uint8 * pInPos
Definition: uart.h:160
#define UART_CTS_INV
STATUS
Definition: c_types.h:79
UartBitsNum4Char data_bits
Definition: uart.h:136
UartExistParity exist_parity
Definition: uart.h:137
void uart_rx_intr_enable(uint8 uart_no)
UART_LineLevelInverse
Definition: uart.h:65
uint8 * pUartRxBuff
Definition: uart.h:170
UartFlowCtrl
Definition: uart.h:93
unsigned int uint32
Definition: c_types.h:54
UartStopBitsNum
Definition: uart.h:48
uint8 TcpControl
Definition: uart.h:164
TCPState
Definition: uart.h:177
UartStopBitsNum stop_bits
Definition: uart.h:139
void ICACHE_FLASH_ATTR uart_set_baudrate(uint8_t uart_no, uint32_t baud_rate)
int received
Definition: uart.h:144
void uart0_sendStr(const char *str)
Definition: uart.c:181
int buff_uart_no
Definition: uart.h:145
RcvMsgBuff rcv_buff
Definition: uart.h:141
void uart_rx_intr_disable(uint8 uart_no)
uint8 * pReadPos
Definition: uart.h:116
void ICACHE_FLASH_ATTR uart_set_parity(uint8_t uart_no, UartParityMode Parity_mode)
Definition: uart.c:327
uint32 RcvBuffSize
Definition: uart.h:113
void uart0_tx_buffer(uint8 *buf, uint16 len)
Definition: uart.c:163
STATUS uart_tx_one_char_no_wait(uint8 uart, uint8 TxChar)
void uart1_sendStr_no_wait(const char *str)
UartBautRate
Definition: uart.h:74
void ICACHE_FLASH_ATTR uart_set_line_inverse(uint8_t uart_no, UART_LineLevelInverse inverse_mask)
Definition: uart.c:321
uint32 UartBuffSize
Definition: uart.h:158
uint32 TrxBuffSize
Definition: uart.h:122
#define UART_RTS_INV
Definition: uart_register.h:99
uint8 * pWritePos
Definition: uart.h:171