MeterLogger
Data Structures | Macros | Enumerations | Functions
uart.h File Reference
#include "uart_register.h"
#include "eagle_soc.h"
#include "c_types.h"
Include dependency graph for uart.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RcvMsgBuff
 
struct  TrxMsgBuff
 
struct  UartDevice
 
struct  UartBuffer
 
struct  UartRxBuff
 

Macros

#define UART_TX_BUFFER_SIZE   256
 
#define UART_RX_BUFFER_SIZE   256
 
#define UART_BUFF_EN   0
 
#define UART_SELFTEST   0
 
#define UART_HW_RTS   0
 
#define UART_HW_CTS   0
 
#define UART_LINE_INV_MASK   (0x3f<<19)
 
#define UART0   0
 
#define UART1   1
 
#define UART_FIFO_LEN   128
 
#define UART_TX_EMPTY_THRESH_VAL   0x10
 

Enumerations

enum  UartBitsNum4Char { FIVE_BITS = 0x0, SIX_BITS = 0x1, SEVEN_BITS = 0x2, EIGHT_BITS = 0x3 }
 
enum  UartStopBitsNum { ONE_STOP_BIT = 0x1, ONE_HALF_STOP_BIT = 0x2, TWO_STOP_BIT = 0x3 }
 
enum  UartParityMode { NONE_BITS = 0x2, ODD_BITS = 1, EVEN_BITS = 0 }
 
enum  UartExistParity { STICK_PARITY_DIS = 0, STICK_PARITY_EN = 1 }
 
enum  UART_LineLevelInverse {
  UART_None_Inverse = 0x0, UART_Rxd_Inverse = UART_RXD_INV, UART_CTS_Inverse = UART_CTS_INV, UART_Txd_Inverse = UART_TXD_INV,
  UART_RTS_Inverse = UART_RTS_INV
}
 
enum  UartBautRate {
  BIT_RATE_300 = 300, BIT_RATE_600 = 600, BIT_RATE_1200 = 1200, BIT_RATE_2400 = 2400,
  BIT_RATE_4800 = 4800, BIT_RATE_9600 = 9600, BIT_RATE_19200 = 19200, BIT_RATE_38400 = 38400,
  BIT_RATE_57600 = 57600, BIT_RATE_74880 = 74880, BIT_RATE_115200 = 115200, BIT_RATE_230400 = 230400,
  BIT_RATE_460800 = 460800, BIT_RATE_921600 = 921600, BIT_RATE_1843200 = 1843200, BIT_RATE_3686400 = 3686400
}
 
enum  UartFlowCtrl { NONE_CTRL, HARDWARE_CTRL, XON_XOFF_CTRL }
 
enum  UART_HwFlowCtrl { USART_HardwareFlowControl_None = 0x0, USART_HardwareFlowControl_RTS = 0x1, USART_HardwareFlowControl_CTS = 0x2, USART_HardwareFlowControl_CTS_RTS = 0x3 }
 
enum  RcvMsgBuffState { EMPTY, UNDER_WRITE, WRITE_OVER }
 
enum  RcvMsgState {
  BAUD_RATE_DET, WAIT_SYNC_FRM, SRCH_MSG_HEAD, RCV_MSG_BODY,
  RCV_ESC_CHAR
}
 
enum  TCPState { RUN = 0, BLOCK = 1 }
 

Functions

void uart_init (UartBautRate uart0_br, UartBautRate uart1_br)
 
void uart0_sendStr (const char *str)
 
STATUS uart_tx_one_char (uint8 uart, uint8 TxChar)
 
STATUS uart_tx_one_char_no_wait (uint8 uart, uint8 TxChar)
 
void uart1_sendStr_no_wait (const char *str)
 
struct UartBufferUart_Buf_Init ()
 
void uart_rx_intr_enable (uint8 uart_no)
 
void uart_rx_intr_disable (uint8 uart_no)
 
void uart0_tx_buffer (uint8 *buf, uint16 len)
 
void ICACHE_FLASH_ATTR uart_set_word_length (uint8_t uart_no, UartBitsNum4Char len)
 
void ICACHE_FLASH_ATTR uart_set_stop_bits (uint8_t uart_no, UartStopBitsNum bit_num)
 
void ICACHE_FLASH_ATTR uart_set_line_inverse (uint8_t uart_no, UART_LineLevelInverse inverse_mask)
 
void ICACHE_FLASH_ATTR uart_set_parity (uint8_t uart_no, UartParityMode Parity_mode)
 
void ICACHE_FLASH_ATTR uart_set_baudrate (uint8_t uart_no, uint32_t baud_rate)
 

Macro Definition Documentation

◆ UART0

#define UART0   0

◆ UART1

#define UART1   1

Definition at line 38 of file uart.h.

Referenced by uart1_write_char(), uart_config(), and uart_init().

◆ UART_BUFF_EN

#define UART_BUFF_EN   0

Definition at line 27 of file uart.h.

◆ UART_FIFO_LEN

#define UART_FIFO_LEN   128

Definition at line 153 of file uart.h.

◆ UART_HW_CTS

#define UART_HW_CTS   0

Definition at line 31 of file uart.h.

◆ UART_HW_RTS

#define UART_HW_RTS   0

Definition at line 30 of file uart.h.

◆ UART_LINE_INV_MASK

#define UART_LINE_INV_MASK   (0x3f<<19)

Definition at line 33 of file uart.h.

Referenced by uart_set_line_inverse().

◆ UART_RX_BUFFER_SIZE

#define UART_RX_BUFFER_SIZE   256

Definition at line 25 of file uart.h.

◆ UART_SELFTEST

#define UART_SELFTEST   0

Definition at line 28 of file uart.h.

◆ UART_TX_BUFFER_SIZE

#define UART_TX_BUFFER_SIZE   256

Definition at line 24 of file uart.h.

◆ UART_TX_EMPTY_THRESH_VAL

#define UART_TX_EMPTY_THRESH_VAL   0x10

Definition at line 154 of file uart.h.

Enumeration Type Documentation

◆ RcvMsgBuffState

Enumerator
EMPTY 
UNDER_WRITE 
WRITE_OVER 

Definition at line 106 of file uart.h.

106  {
107  EMPTY,
108  UNDER_WRITE,
109  WRITE_OVER
RcvMsgBuffState
Definition: uart.h:106
Definition: uart.h:107

◆ RcvMsgState

Enumerator
BAUD_RATE_DET 
WAIT_SYNC_FRM 
SRCH_MSG_HEAD 
RCV_MSG_BODY 
RCV_ESC_CHAR 

Definition at line 126 of file uart.h.

126  {
130  RCV_MSG_BODY,
131  RCV_ESC_CHAR,
132 } RcvMsgState;
RcvMsgState
Definition: uart.h:126

◆ TCPState

enum TCPState
Enumerator
RUN 
BLOCK 

Definition at line 177 of file uart.h.

177  {
178  RUN = 0,
179  BLOCK = 1,
180 } TCPState;
Definition: uart.h:178
Definition: uart.h:179
TCPState
Definition: uart.h:177

◆ UART_HwFlowCtrl

Enumerator
USART_HardwareFlowControl_None 
USART_HardwareFlowControl_RTS 
USART_HardwareFlowControl_CTS 
USART_HardwareFlowControl_CTS_RTS 

Definition at line 99 of file uart.h.

◆ UART_LineLevelInverse

Enumerator
UART_None_Inverse 
UART_Rxd_Inverse 
UART_CTS_Inverse 
UART_Txd_Inverse 
UART_RTS_Inverse 

Definition at line 65 of file uart.h.

65  {
66  UART_None_Inverse = 0x0,
#define UART_TXD_INV
#define UART_RXD_INV
#define UART_CTS_INV
UART_LineLevelInverse
Definition: uart.h:65
#define UART_RTS_INV
Definition: uart_register.h:99

◆ UartBautRate

Enumerator
BIT_RATE_300 
BIT_RATE_600 
BIT_RATE_1200 
BIT_RATE_2400 
BIT_RATE_4800 
BIT_RATE_9600 
BIT_RATE_19200 
BIT_RATE_38400 
BIT_RATE_57600 
BIT_RATE_74880 
BIT_RATE_115200 
BIT_RATE_230400 
BIT_RATE_460800 
BIT_RATE_921600 
BIT_RATE_1843200 
BIT_RATE_3686400 

Definition at line 74 of file uart.h.

74  {
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;
UartBautRate
Definition: uart.h:74

◆ UartBitsNum4Char

Enumerator
FIVE_BITS 
SIX_BITS 
SEVEN_BITS 
EIGHT_BITS 

Definition at line 41 of file uart.h.

41  {
42  FIVE_BITS = 0x0,
43  SIX_BITS = 0x1,
44  SEVEN_BITS = 0x2,
45  EIGHT_BITS = 0x3
Definition: uart.h:43
UartBitsNum4Char
Definition: uart.h:41
Definition: uart.h:42

◆ UartExistParity

Enumerator
STICK_PARITY_DIS 
STICK_PARITY_EN 

Definition at line 60 of file uart.h.

60  {
61  STICK_PARITY_DIS = 0,
62  STICK_PARITY_EN = 1
UartExistParity
Definition: uart.h:60

◆ UartFlowCtrl

Enumerator
NONE_CTRL 
HARDWARE_CTRL 
XON_XOFF_CTRL 

Definition at line 93 of file uart.h.

93  {
94  NONE_CTRL,
97 } UartFlowCtrl;
Definition: uart.h:94
UartFlowCtrl
Definition: uart.h:93

◆ UartParityMode

Enumerator
NONE_BITS 
ODD_BITS 
EVEN_BITS 

Definition at line 54 of file uart.h.

54  {
55  NONE_BITS = 0x2,
56  ODD_BITS = 1,
57  EVEN_BITS = 0
Definition: uart.h:57
Definition: uart.h:55
UartParityMode
Definition: uart.h:54
Definition: uart.h:56

◆ UartStopBitsNum

Enumerator
ONE_STOP_BIT 
ONE_HALF_STOP_BIT 
TWO_STOP_BIT 

Definition at line 48 of file uart.h.

48  {
49  ONE_STOP_BIT = 0x1,
50  ONE_HALF_STOP_BIT = 0x2,
51  TWO_STOP_BIT = 0x3
UartStopBitsNum
Definition: uart.h:48

Function Documentation

◆ uart0_sendStr()

void uart0_sendStr ( const char *  str)

Definition at line 181 of file uart.c.

References LOCAL, UART0, and uart_tx_one_char().

182 {
183  while(*str)
184  {
185  uart_tx_one_char(UART0, *str++);
186  }
187 }
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
Definition: uart.c:104
#define UART0
Definition: uart.h:37
Here is the call graph for this function:

◆ uart0_tx_buffer()

void uart0_tx_buffer ( uint8 buf,
uint16  len 
)

Definition at line 163 of file uart.c.

References ICACHE_FLASH_ATTR, UART0, and uart_tx_one_char().

Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), en61107_uart_send_standard_data_2(), kmp_get_register_timer_func(), and kmp_get_serial_timer_func().

164 {
165  uint16 i;
166 
167  for (i = 0; i < len; i++)
168  {
169  uart_tx_one_char(UART0, buf[i]);
170  }
171 }
unsigned short uint16
Definition: c_types.h:50
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
Definition: uart.c:104
#define UART0
Definition: uart.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uart1_sendStr_no_wait()

void uart1_sendStr_no_wait ( const char *  str)

◆ Uart_Buf_Init()

struct UartBuffer* Uart_Buf_Init ( )

◆ uart_init()

void uart_init ( UartBautRate  uart0_br,
UartBautRate  uart1_br 
)

Definition at line 273 of file uart.c.

References UartDevice::baut_rate, UartDevice::data_bits, EIGHT_BITS, ETS_UART_INTR_ENABLE, EVEN_BITS, UartDevice::exist_parity, ICACHE_FLASH_ATTR, NONE_BITS, os_install_putc1, UartDevice::parity, SEVEN_BITS, STICK_PARITY_DIS, STICK_PARITY_EN, UartDevice::stop_bits, TWO_STOP_BIT, UART0, uart0_write_char(), UART1, and uart_config().

274 {
275  // rom use 74880 baut_rate, here reinitialize
276 #ifndef EN61107
277  UartDev.baut_rate = uart0_br;
282 #else
283  UartDev.baut_rate = uart0_br;
288 #endif
290 #ifndef EN61107
291  UartDev.baut_rate = uart1_br;
296 #else
297  UartDev.baut_rate = uart1_br;
302 #endif
305 
306  // install uart1 putc callback
308 }
Definition: uart.h:57
Definition: uart.h:55
#define ETS_UART_INTR_ENABLE()
Definition: ets_sys.h:93
void ICACHE_FLASH_ATTR uart0_write_char(char c)
Definition: uart.c:143
UartBautRate baut_rate
Definition: uart.h:135
UartParityMode parity
Definition: uart.h:138
#define UART1
Definition: uart.h:38
#define os_install_putc1
Definition: osapi.h:33
LOCAL void ICACHE_FLASH_ATTR uart_config(uint8 uart_no)
Definition: uart.c:39
UartBitsNum4Char data_bits
Definition: uart.h:136
UartExistParity exist_parity
Definition: uart.h:137
UartStopBitsNum stop_bits
Definition: uart.h:139
#define UART0
Definition: uart.h:37
UartDevice UartDev
Here is the call graph for this function:

◆ uart_rx_intr_disable()

void uart_rx_intr_disable ( uint8  uart_no)

◆ uart_rx_intr_enable()

void uart_rx_intr_enable ( uint8  uart_no)

◆ uart_set_baudrate()

void ICACHE_FLASH_ATTR uart_set_baudrate ( uint8_t  uart_no,
uint32_t  baud_rate 
)

◆ uart_set_line_inverse()

void ICACHE_FLASH_ATTR uart_set_line_inverse ( uint8_t  uart_no,
UART_LineLevelInverse  inverse_mask 
)

Definition at line 321 of file uart.c.

References CLEAR_PERI_REG_MASK, ICACHE_FLASH_ATTR, SET_PERI_REG_MASK, UART_CONF0, and UART_LINE_INV_MASK.

321  {
323  SET_PERI_REG_MASK(UART_CONF0(uart_no), inverse_mask);
324 }
#define UART_CONF0(i)
Definition: uart_register.h:97
#define CLEAR_PERI_REG_MASK(reg, mask)
Definition: eagle_soc.h:70
#define SET_PERI_REG_MASK(reg, mask)
Definition: eagle_soc.h:71
#define UART_LINE_INV_MASK
Definition: uart.h:33

◆ uart_set_parity()

void ICACHE_FLASH_ATTR uart_set_parity ( uint8_t  uart_no,
UartParityMode  Parity_mode 
)

Definition at line 327 of file uart.c.

References CLEAR_PERI_REG_MASK, ICACHE_FLASH_ATTR, NONE_BITS, SET_PERI_REG_MASK, UART_CONF0, UART_PARITY, and UART_PARITY_EN.

Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().

327  {
329  if (Parity_mode == NONE_BITS) {
330  }
331  else {
332  SET_PERI_REG_MASK(UART_CONF0(uart_no), Parity_mode| UART_PARITY_EN);
333  }
334 }
#define UART_CONF0(i)
Definition: uart_register.h:97
Definition: uart.h:55
#define UART_PARITY_EN
#define CLEAR_PERI_REG_MASK(reg, mask)
Definition: eagle_soc.h:70
#define SET_PERI_REG_MASK(reg, mask)
Definition: eagle_soc.h:71
#define UART_PARITY
Here is the caller graph for this function:

◆ uart_set_stop_bits()

void ICACHE_FLASH_ATTR uart_set_stop_bits ( uint8_t  uart_no,
UartStopBitsNum  bit_num 
)

Definition at line 316 of file uart.c.

References ICACHE_FLASH_ATTR, SET_PERI_REG_BITS, UART_CONF0, UART_STOP_BIT_NUM, and UART_STOP_BIT_NUM_S.

Referenced by en61107_delayed_uart_change_setting_timer_func(), en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().

316  {
318 }
#define UART_CONF0(i)
Definition: uart_register.h:97
#define UART_STOP_BIT_NUM_S
#define UART_STOP_BIT_NUM
#define SET_PERI_REG_BITS(reg, bit_map, value, shift)
Definition: eagle_soc.h:73
Here is the caller graph for this function:

◆ uart_set_word_length()

void ICACHE_FLASH_ATTR uart_set_word_length ( uint8_t  uart_no,
UartBitsNum4Char  len 
)

Definition at line 311 of file uart.c.

References ICACHE_FLASH_ATTR, SET_PERI_REG_BITS, UART_BIT_NUM, UART_BIT_NUM_S, and UART_CONF0.

Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().

311  {
313 }
#define UART_CONF0(i)
Definition: uart_register.h:97
#define UART_BIT_NUM_S
#define UART_BIT_NUM
#define SET_PERI_REG_BITS(reg, bit_map, value, shift)
Definition: eagle_soc.h:73
Here is the caller graph for this function:

◆ uart_tx_one_char()

STATUS uart_tx_one_char ( uint8  uart,
uint8  TxChar 
)

Definition at line 104 of file uart.c.

References ICACHE_FLASH_ATTR, OK, READ_PERI_REG, UART_FIFO, UART_STATUS, UART_TXFIFO_CNT, UART_TXFIFO_CNT_S, and WRITE_PERI_REG.

Referenced by uart0_sendStr(), uart0_tx_buffer(), uart0_write_char(), and uart1_write_char().

105 {
106  while (true)
107  {
109  if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) {
110  break;
111  }
112  }
113 
114  WRITE_PERI_REG(UART_FIFO(uart) , TxChar);
115  return OK;
116 }
#define UART_TXFIFO_CNT_S
Definition: uart_register.h:90
#define UART_TXFIFO_CNT
Definition: uart_register.h:89
#define READ_PERI_REG(addr)
Definition: eagle_soc.h:68
#define UART_FIFO(i)
Definition: uart_register.h:28
#define WRITE_PERI_REG(addr, val)
Definition: eagle_soc.h:69
#define UART_STATUS(i)
Definition: uart_register.h:85
Definition: c_types.h:80
unsigned int uint32
Definition: c_types.h:54
Here is the caller graph for this function:

◆ uart_tx_one_char_no_wait()

STATUS uart_tx_one_char_no_wait ( uint8  uart,
uint8  TxChar 
)