ESP8266_RTOS_SDK v1.4.0

- Main Page
- Modules
- Data Structures
- Files

- File List

uart.h
1 /*
2 * ESPRSSIF MIT License
3 *
4 * Copyright (c) 2015 <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_H__
26 #define __UART_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #define ETS_UART_INTR_ENABLE() _xt_isr_unmask(1 << ETS_UART_INUM)
33 #define ETS_UART_INTR_DISABLE() _xt_isr_mask(1 << ETS_UART_INUM)
34 #define UART_INTR_MASK 0x1ff
35 #define UART_LINE_INV_MASK (0x3f<<19)
36
37 typedef enum {
38 UART_WordLength_5b = 0x0,
39 UART_WordLength_6b = 0x1,
40 UART_WordLength_7b = 0x2,
41 UART_WordLength_8b = 0x3
42 } UART_WordLength;
43
44 typedef enum {
45 USART_StopBits_1 = 0x1,
46 USART_StopBits_1_5 = 0x2,
47 USART_StopBits_2 = 0x3,
48 } UART_StopBits;
49
50 typedef enum {
51 UART0 = 0x0,
52 UART1 = 0x1,
53 } UART_Port;
54
55 typedef enum {
56 USART_Parity_None = 0x2,
57 USART_Parity_Even = 0x0,
58 USART_Parity_Odd = 0x1
59 } UART_ParityMode;
60
61 typedef enum {
62 PARITY_DIS = 0x0,
63 PARITY_EN = 0x2
64 } UartExistParity;
65
66 typedef enum {
67 BIT_RATE_300 = 300,
68 BIT_RATE_600 = 600,
69 BIT_RATE_1200 = 1200,
70 BIT_RATE_2400 = 2400,
71 BIT_RATE_4800 = 4800,
72 BIT_RATE_9600 = 9600,
73 BIT_RATE_19200 = 19200,
74 BIT_RATE_38400 = 38400,
75 BIT_RATE_57600 = 57600,
76 BIT_RATE_74880 = 74880,
77 BIT_RATE_115200 = 115200,
78 BIT_RATE_230400 = 230400,
79 BIT_RATE_460800 = 460800,
80 BIT_RATE_921600 = 921600,
81 BIT_RATE_1843200 = 1843200,
82 BIT_RATE_3686400 = 3686400,
83 } UART_BautRate; //you can add any rate you need in this range
84
85 typedef enum {
86 USART_HardwareFlowControl_None = 0x0,
87 USART_HardwareFlowControl_RTS = 0x1,
88 USART_HardwareFlowControl_CTS = 0x2,
89 USART_HardwareFlowControl_CTS_RTS = 0x3
90 } UART_HwFlowCtrl;
91
92 typedef enum {
93 UART_None_Inverse = 0x0,
94 UART_Rxd_Inverse = UART_RXD_INV,
95 UART_CTS_Inverse = UART_CTS_INV,
96 UART_Txd_Inverse = UART_TXD_INV,
97 UART_RTS_Inverse = UART_RTS_INV,
98 } UART_LineLevelInverse;
99
100 typedef struct {
101 UART_BautRate baud_rate;
102 UART_WordLength data_bits;
103 UART_ParityMode parity; // chip size in byte
104 UART_StopBits stop_bits;
105 UART_HwFlowCtrl flow_ctrl;
106 uint8 UART_RxFlowThresh ;
107 uint32 UART_InverseMask;
108 } UART_ConfigTypeDef;
109
110 typedef struct {
111 uint32 UART_IntrEnMask;
112 uint8 UART_RX_TimeOutIntrThresh;
113 uint8 UART_TX_FifoEmptyIntrThresh;
114 uint8 UART_RX_FifoFullIntrThresh;
115 } UART_IntrConfTypeDef;
116
117 //=======================================
118
142 void UART_WaitTxFifoEmpty(UART_Port uart_no); //do not use if tx flow control enabled
143
151 void UART_ResetFifo(UART_Port uart_no);
152
161 void UART_ClearIntrStatus(UART_Port uart_no, uint32 clr_mask);
162
171 void UART_SetIntrEna(UART_Port uart_no, uint32 ena_mask);
172
181 void UART_intr_handler_register(void *fn, void *arg);
182
190 void UART_SetPrintPort(UART_Port uart_no);
191
200 void UART_ParamConfig(UART_Port uart_no, UART_ConfigTypeDef *pUARTConfig);
201
210 void UART_IntrConfig(UART_Port uart_no, UART_IntrConfTypeDef *pUARTIntrConf);
211
220 void UART_SetWordLength(UART_Port uart_no, UART_WordLength len);
221
230 void UART_SetStopBits(UART_Port uart_no, UART_StopBits bit_num);
231
240 void UART_SetParity(UART_Port uart_no, UART_ParityMode Parity_mode) ;
241
250 void UART_SetBaudrate(UART_Port uart_no, uint32 baud_rate);
251
261 void UART_SetFlowCtrl(UART_Port uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh);
262
271 void UART_SetLineInverse(UART_Port uart_no, UART_LineLevelInverse inverse_mask) ;
272
280 void uart_init_new(void);
281
290 #ifdef __cplusplus
291 }
292 #endif
293
294 #endif
UART_ParamConfig
void UART_ParamConfig(UART_Port uart_no, UART_ConfigTypeDef *pUARTConfig)
Config Common parameters of serial ports.
UART_SetFlowCtrl
void UART_SetFlowCtrl(UART_Port uart_no, UART_HwFlowCtrl flow_ctrl, uint8 rx_thresh)
Configure Hardware flow control.
UART_SetBaudrate
void UART_SetBaudrate(UART_Port uart_no, uint32 baud_rate)
Configure the Baud rate.
uart_init_new
void uart_init_new(void)
An example illustrates how to configure the serial port.
UART_SetIntrEna
void UART_SetIntrEna(UART_Port uart_no, uint32 ena_mask)
Enable uart interrupts .
UART_ConfigTypeDef
Definition: uart.h:100
UART_IntrConfig
void UART_IntrConfig(UART_Port uart_no, UART_IntrConfTypeDef *pUARTIntrConf)
Config types of uarts.
UART_IntrConfTypeDef
Definition: uart.h:110
UART_SetParity
void UART_SetParity(UART_Port uart_no, UART_ParityMode Parity_mode)
Configure whether to open the parity.
UART_ClearIntrStatus
void UART_ClearIntrStatus(UART_Port uart_no, uint32 clr_mask)
Clear uart interrupt flags.
UART_SetLineInverse
void UART_SetLineInverse(UART_Port uart_no, UART_LineLevelInverse inverse_mask)
Configure trigging signal of uarts.
UART_SetWordLength
void UART_SetWordLength(UART_Port uart_no, UART_WordLength len)
Config the length of the uart communication data bits.
UART_intr_handler_register
void UART_intr_handler_register(void *fn, void *arg)
Register an application-specific interrupt handler for Uarts interrupts.
UART_WaitTxFifoEmpty
void UART_WaitTxFifoEmpty(UART_Port uart_no)
Wait uart tx fifo empty, do not use it if tx flow control enabled.
UART_SetStopBits
void UART_SetStopBits(UART_Port uart_no, UART_StopBits bit_num)
Config the length of the uart communication stop bits.
UART_SetPrintPort
void UART_SetPrintPort(UART_Port uart_no)
Config from which serial output printf function.
UART_ResetFifo
void UART_ResetFifo(UART_Port uart_no)
Clear uart tx fifo and rx fifo.