MeterLogger
Functions | Variables
uart.c File Reference
#include <esp8266.h>
#include "driver/uart.h"
#include "driver/uart_register.h"
#include "user_interface.h"
#include "kmp_request.h"
Include dependency graph for uart.c:

Go to the source code of this file.

Functions

LOCAL void uart0_rx_intr_handler (void *para)
 
LOCAL void ICACHE_FLASH_ATTR uart_config (uint8 uart_no)
 
STATUS uart_tx_one_char (uint8 uart, uint8 TxChar)
 
void ICACHE_FLASH_ATTR uart1_write_char (char c)
 
void ICACHE_FLASH_ATTR uart0_write_char (char c)
 
void ICACHE_FLASH_ATTR uart0_tx_buffer (uint8 *buf, uint16 len)
 
void ICACHE_FLASH_ATTR uart0_sendStr (const char *str)
 
void ICACHE_FLASH_ATTR uart_init (UartBautRate uart0_br, UartBautRate uart1_br)
 
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 uart_no, uint32_t baud_rate)
 

Variables

UartDevice UartDev
 

Function Documentation

◆ uart0_rx_intr_handler()

LOCAL void uart0_rx_intr_handler ( void *  para)

Definition at line 199 of file uart.c.

References en61107_fifo_put(), en61107_is_eod_char(), en61107_received_task_prio, ICACHE_FLASH_ATTR, kmp_fifo_put(), kmp_received_task_prio, READ_PERI_REG, system_os_post(), UART0, UART_FIFO, UART_FRM_ERR_INT_CLR, UART_FRM_ERR_INT_ST, UART_INT_CLR, UART_INT_ST, UART_RXFIFO_CNT, UART_RXFIFO_CNT_S, UART_RXFIFO_FULL_INT_CLR, UART_RXFIFO_FULL_INT_ST, UART_RXFIFO_TOUT_INT_CLR, UART_RXFIFO_TOUT_INT_ST, UART_STATUS, and WRITE_PERI_REG.

Referenced by uart_config().

200 {
201  /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents
202  * uart1 and uart0 respectively
203  */
204 // RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para;
205 
206  uint8 RcvChar;
207  uint8 uart_no = UART0;//UartDev.buff_uart_no;
208 
209 
211  //os_printf("FRM_ERR\r\n");
213  }
214 
216  //ETS_UART_INTR_DISABLE();/////////
218  //WRITE_PERI_REG(0X60000914, 0x73); //WTD
219  RcvChar = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
220 #ifdef EN61107
221  en61107_fifo_put(RcvChar);
222  if (en61107_is_eod_char(RcvChar)) { // if end of mc66 frame received
224  }
225 #elif defined IMPULSE
226  // nothing
227 #else
228  kmp_fifo_put(RcvChar);
229  if ((RcvChar == '\r') || (RcvChar == 0x06)) { // if end of kmp frame received or acknowledge
231  }
232 #endif
233  }
234  }
236  //ETS_UART_INTR_DISABLE();/////////
238  //WRITE_PERI_REG(0X60000914, 0x73); //WTD
239  RcvChar = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
240 #ifdef EN61107
241  en61107_fifo_put(RcvChar);
242  if (en61107_is_eod_char(RcvChar)) { // if end of mc66 frame received
244  }
245 #elif defined IMPULSE
246  // nothing
247 #else
248  kmp_fifo_put(RcvChar);
249  if ((RcvChar == '\r') || (RcvChar == 0x06)) { // if end of kmp frame received or acknowledge
251  }
252 #endif
253  }
254  }
255 
256  if (UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) {
258  }
259  else if (UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_TOUT_INT_ST)) {
261  }
262  //ETS_UART_INTR_ENABLE();
263 }
bool system_os_post(uint8 prio, os_signal_t sig, os_param_t par)
#define READ_PERI_REG(addr)
Definition: eagle_soc.h:68
#define UART_FIFO(i)
Definition: uart_register.h:28
#define UART_RXFIFO_CNT
Definition: uart_register.h:94
#define UART_RXFIFO_CNT_S
Definition: uart_register.h:95
#define UART_RXFIFO_FULL_INT_ST
Definition: uart_register.h:52
#define WRITE_PERI_REG(addr, val)
Definition: eagle_soc.h:69
#define UART_FRM_ERR_INT_CLR
Definition: uart_register.h:71
#define UART_RXFIFO_TOUT_INT_CLR
Definition: uart_register.h:66
#define UART_FRM_ERR_INT_ST
Definition: uart_register.h:49
#define UART_STATUS(i)
Definition: uart_register.h:85
unsigned char uint8
Definition: c_types.h:45
#define UART_RXFIFO_TOUT_INT_ST
Definition: uart_register.h:44
unsigned char en61107_fifo_put(unsigned char c)
#define UART_INT_ST(i)
Definition: uart_register.h:43
bool en61107_is_eod_char(uint8_t c)
#define UART0
Definition: uart.h:37
#define UART_RXFIFO_FULL_INT_CLR
Definition: uart_register.h:74
#define kmp_received_task_prio
Definition: kmp_request.h:3
unsigned char kmp_fifo_put(unsigned char c)
Definition: kmp_request.c:370
#define UART_INT_CLR(i)
Definition: uart_register.h:65
#define en61107_received_task_prio
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uart0_sendStr()

void ICACHE_FLASH_ATTR 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 ICACHE_FLASH_ATTR 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:

◆ uart0_write_char()

void ICACHE_FLASH_ATTR uart0_write_char ( char  c)

Definition at line 143 of file uart.c.

References ICACHE_FLASH_ATTR, UART0, and uart_tx_one_char().

Referenced by uart_init().

144 {
145  if (c == '\n')
146  {
147  uart_tx_one_char(UART0, '\r');
148  uart_tx_one_char(UART0, '\n');
149  }
150  else
151  {
153  }
154 }
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_write_char()

void ICACHE_FLASH_ATTR uart1_write_char ( char  c)

Definition at line 126 of file uart.c.

References ICACHE_FLASH_ATTR, UART1, and uart_tx_one_char().

127 {
128  if (c == '\n')
129  {
130  uart_tx_one_char(UART1, '\r');
131  uart_tx_one_char(UART1, '\n');
132  }
133  else if (c == '\r')
134  {
135  }
136  else
137  {
139  }
140 }
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar)
Definition: uart.c:104
#define UART1
Definition: uart.h:38
Here is the call graph for this function:

◆ uart_config()

LOCAL void ICACHE_FLASH_ATTR uart_config ( uint8  uart_no)

Definition at line 39 of file uart.c.

References UartDevice::baut_rate, CLEAR_PERI_REG_MASK, UartDevice::data_bits, ETS_UART_INTR_ATTACH, UartDevice::exist_parity, FUNC_U0RTS, FUNC_U0TXD, FUNC_U1TXD_BK, NONE_BITS, UartDevice::parity, PERIPHS_IO_MUX_GPIO2_U, PERIPHS_IO_MUX_MTDO_U, PERIPHS_IO_MUX_U0TXD_U, PIN_FUNC_SELECT, PIN_PULLUP_DIS, UartDevice::rcv_buff, SET_PERI_REG_MASK, STICK_PARITY_DIS, STICK_PARITY_EN, UartDevice::stop_bits, RcvMsgBuff::TrigLvl, UART0, uart0_rx_intr_handler(), UART1, UART_BIT_NUM, UART_BIT_NUM_S, UART_CLK_FREQ, UART_CONF0, UART_CONF1, UART_FRM_ERR_INT_ENA, UART_INT_CLR, UART_INT_ENA, UART_PARITY_EN_M, UART_PARITY_EN_S, UART_PARITY_M, UART_PARITY_S, UART_RX_FLOW_EN, UART_RX_FLOW_THRHD, UART_RX_FLOW_THRHD_S, UART_RX_TOUT_EN, UART_RX_TOUT_THRHD, UART_RX_TOUT_THRHD_S, UART_RXFIFO_FULL_INT_ENA, UART_RXFIFO_FULL_THRHD, UART_RXFIFO_FULL_THRHD_S, UART_RXFIFO_RST, UART_RXFIFO_TOUT_INT_ENA, UART_STOP_BIT_NUM, UART_STOP_BIT_NUM_S, UART_TXFIFO_RST, and WRITE_PERI_REG.

Referenced by uart_init().

40 {
41  if (uart_no == UART1)
42  {
44  }
45  else
46  {
47  /* rcv_buff size if 0x100 */
52  }
53 
54  uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));
55 
57  WRITE_PERI_REG(UART_CONF0(uart_no),
62 
63  //clear rx and tx fifo,not ready
66 
67  //set rx fifo trigger
68 // WRITE_PERI_REG(UART_CONF1(uart_no),
69 // ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
70 // ((96 & UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S) |
71 // UART_RX_FLOW_EN);
72  if (uart_no == UART0)
73  {
74  //set rx fifo trigger
75  WRITE_PERI_REG(UART_CONF1(uart_no),
83  }
84  else
85  {
86  WRITE_PERI_REG(UART_CONF1(uart_no),
87  ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));
88  }
89 
90  //clear all interrupt
91  WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
92  //enable rx_interrupt
94 }
#define PIN_FUNC_SELECT(PIN_NAME, FUNC)
Definition: eagle_soc.h:270
#define UART_RXFIFO_RST
#define UART_RX_FLOW_THRHD
#define FUNC_U0RTS
Definition: eagle_soc.h:227
#define UART_CONF0(i)
Definition: uart_register.h:97
#define UART_RX_TOUT_EN
LOCAL void uart0_rx_intr_handler(void *para)
Definition: uart.c:199
#define UART_RX_TOUT_THRHD
#define UART_STOP_BIT_NUM_S
Definition: uart.h:55
UartBautRate baut_rate
Definition: uart.h:135
#define PERIPHS_IO_MUX_GPIO2_U
Definition: eagle_soc.h:258
#define UART_RXFIFO_FULL_THRHD_S
UartParityMode parity
Definition: uart.h:138
#define UART_CLK_FREQ
Definition: eagle_soc.h:78
#define WRITE_PERI_REG(addr, val)
Definition: eagle_soc.h:69
#define UART_CONF1(i)
#define UART_FRM_ERR_INT_ENA
Definition: uart_register.h:60
#define CLEAR_PERI_REG_MASK(reg, mask)
Definition: eagle_soc.h:70
#define FUNC_U1TXD_BK
Definition: eagle_soc.h:260
#define UART_RXFIFO_TOUT_INT_ENA
Definition: uart_register.h:55
#define UART1
Definition: uart.h:38
#define UART_RXFIFO_FULL_THRHD
#define UART_BIT_NUM_S
#define FUNC_U0TXD
Definition: eagle_soc.h:231
uint8 TrigLvl
Definition: uart.h:117
#define UART_RX_FLOW_THRHD_S
#define UART_TXFIFO_RST
#define UART_PARITY_S
#define UART_STOP_BIT_NUM
#define UART_PARITY_EN_S
UartBitsNum4Char data_bits
Definition: uart.h:136
UartExistParity exist_parity
Definition: uart.h:137
#define PERIPHS_IO_MUX_MTDO_U
Definition: eagle_soc.h:225
#define UART_RXFIFO_FULL_INT_ENA
Definition: uart_register.h:63
#define ETS_UART_INTR_ATTACH(func, arg)
Definition: ets_sys.h:81
UartStopBitsNum stop_bits
Definition: uart.h:139
#define UART0
Definition: uart.h:37
#define UART_RX_FLOW_EN
UartDevice UartDev
#define UART_PARITY_M
RcvMsgBuff rcv_buff
Definition: uart.h:141
#define SET_PERI_REG_MASK(reg, mask)
Definition: eagle_soc.h:71
#define UART_RX_TOUT_THRHD_S
#define PERIPHS_IO_MUX_U0TXD_U
Definition: eagle_soc.h:230
#define UART_PARITY_EN_M
#define UART_BIT_NUM
#define UART_INT_ENA(i)
Definition: uart_register.h:54
#define PIN_PULLUP_DIS(PIN_NAME)
Definition: eagle_soc.h:267
#define UART_INT_CLR(i)
Definition: uart_register.h:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uart_init()

void ICACHE_FLASH_ATTR 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_set_baudrate()

void ICACHE_FLASH_ATTR uart_set_baudrate ( uint8  uart_no,
uint32_t  baud_rate 
)

Definition at line 337 of file uart.c.

References UART_CLK_FREQ.

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().

337  {
338  uart_div_modify(uart_no, UART_CLK_FREQ / baud_rate);
339 }
#define UART_CLK_FREQ
Definition: eagle_soc.h:78
Here is the caller graph for this function:

◆ 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:

Variable Documentation

◆ UartDev

UartDevice UartDev