22 #include "esp8266/uart_struct.h"
23 #include "esp8266/uart_register.h"
29 #define UART_SCLK_DEFAULT 1
31 #define UART_LL_FIFO_DEF_LEN (128)
32 #define UART_LL_INTR_MASK ((uint32_t)~0)
35 typedef unsigned int soc_module_clk_t;
37 static inline void uart_ll_set_sclk(uart_dev_t *hw, soc_module_clk_t source)
44 static inline void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq)
46 hw->clk_div.val = (sclk_freq / baud) & 0xFFFFF;
49 static inline void uart_ll_set_stop_bits(uart_dev_t *hw,
uart_stop_bits_t bits)
51 hw->conf0.stop_bit_num = bits;
54 static inline void uart_ll_set_data_bit_num(uart_dev_t *hw, uart_word_length_t data_bit)
56 hw->conf0.bit_num = data_bit;
59 static inline void uart_ll_set_parity(uart_dev_t *hw,
uart_parity_t parity_mode)
61 hw->conf0.parity = (parity_mode & 0x1);
62 hw->conf0.parity_en = ((parity_mode >> 1) & 0x1);
65 static inline uint32_t uart_ll_get_rxfifo_len(uart_dev_t *hw)
67 return hw->status.rxfifo_cnt;
70 static inline uint32_t uart_ll_get_txfifo_len(uart_dev_t *hw)
72 return UART_LL_FIFO_DEF_LEN - hw->status.txfifo_cnt;
75 static inline void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_t rd_len)
77 for (
int i = 0; i < (int)rd_len; i++) {
78 buf[i] = hw->fifo.rw_byte;
82 static inline void uart_ll_write_txfifo(uart_dev_t *hw,
const uint8_t *buf, uint32_t wr_len)
84 for (
int i = 0; i < (int)wr_len; i++) {
85 hw->fifo.rw_byte = (int)buf[i];
89 static inline void uart_ll_rxfifo_rst(uart_dev_t *hw)
91 hw->conf0.rxfifo_rst = 1;
92 hw->conf0.rxfifo_rst = 0;
95 static inline void uart_ll_txfifo_rst(uart_dev_t *hw)
97 hw->conf0.rxfifo_rst = 1;
98 hw->conf0.rxfifo_rst = 0;
101 static inline void uart_ll_set_rxfifo_full_thr(uart_dev_t *hw, uint16_t full_thrhd)
103 hw->conf1.rxfifo_full_thrhd = full_thrhd;
106 static inline uint32_t uart_ll_get_intsts_mask(uart_dev_t *hw)
108 return hw->int_st.val;
111 static inline void uart_ll_ena_intr_mask(uart_dev_t *hw, uint32_t mask)
113 hw->int_ena.val = hw->int_ena.val | mask;
116 static inline void uart_ll_clr_intsts_mask(uart_dev_t *hw, uint32_t mask)
118 hw->int_clr.val = mask;
121 static inline uint32_t uart_ll_get_intr_ena_status(uart_dev_t *hw)
123 return hw->int_ena.val;
uart_parity_t
Definition of possible parity modes.
uart_stop_bits_t
Definition of possible stop bits lengths.
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.