uart_ll.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2025 Gunar Schorcht
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
17 #ifndef DOXYGEN
18 
19 #include "esp8266/uart_struct.h"
20 #include "esp8266/uart_register.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define UART_SCLK_DEFAULT 1
27 
28 #define UART_LL_FIFO_DEF_LEN (128)
29 #define UART_LL_INTR_MASK ((uint32_t)~0)
30 
31 typedef uart_data_bits_t uart_word_length_t;
32 typedef unsigned int soc_module_clk_t;
33 
34 static inline void uart_ll_set_sclk(uart_dev_t *hw, soc_module_clk_t source)
35 {
36  /* dummy function for source code compatibility with ESP32 */
37  (void)hw;
38  (void)source;
39 }
40 
41 static inline void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud, uint32_t sclk_freq)
42 {
43  hw->clk_div.val = (sclk_freq / baud) & 0xFFFFF;
44 }
45 
46 static inline void uart_ll_set_stop_bits(uart_dev_t *hw, uart_stop_bits_t bits)
47 {
48  hw->conf0.stop_bit_num = bits;
49 }
50 
51 static inline void uart_ll_set_data_bit_num(uart_dev_t *hw, uart_word_length_t data_bit)
52 {
53  hw->conf0.bit_num = data_bit;
54 }
55 
56 static inline void uart_ll_set_parity(uart_dev_t *hw, uart_parity_t parity_mode)
57 {
58  hw->conf0.parity = (parity_mode & 0x1);
59  hw->conf0.parity_en = ((parity_mode >> 1) & 0x1);
60 }
61 
62 static inline uint32_t uart_ll_get_rxfifo_len(uart_dev_t *hw)
63 {
64  return hw->status.rxfifo_cnt;
65 }
66 
67 static inline uint32_t uart_ll_get_txfifo_len(uart_dev_t *hw)
68 {
69  return UART_LL_FIFO_DEF_LEN - hw->status.txfifo_cnt;
70 }
71 
72 static inline void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_t rd_len)
73 {
74  for (int i = 0; i < (int)rd_len; i++) {
75  buf[i] = hw->fifo.rw_byte;
76  }
77 }
78 
79 static inline void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len)
80 {
81  for (int i = 0; i < (int)wr_len; i++) {
82  hw->fifo.rw_byte = (int)buf[i];
83  }
84 }
85 
86 static inline void uart_ll_rxfifo_rst(uart_dev_t *hw)
87 {
88  hw->conf0.rxfifo_rst = 1;
89  hw->conf0.rxfifo_rst = 0;
90 }
91 
92 static inline void uart_ll_txfifo_rst(uart_dev_t *hw)
93 {
94  hw->conf0.rxfifo_rst = 1;
95  hw->conf0.rxfifo_rst = 0;
96 }
97 
98 static inline void uart_ll_set_rxfifo_full_thr(uart_dev_t *hw, uint16_t full_thrhd)
99 {
100  hw->conf1.rxfifo_full_thrhd = full_thrhd;
101 }
102 
103 static inline uint32_t uart_ll_get_intsts_mask(uart_dev_t *hw)
104 {
105  return hw->int_st.val;
106 }
107 
108 static inline void uart_ll_ena_intr_mask(uart_dev_t *hw, uint32_t mask)
109 {
110  hw->int_ena.val = hw->int_ena.val | mask;
111 }
112 
113 static inline void uart_ll_clr_intsts_mask(uart_dev_t *hw, uint32_t mask)
114 {
115  hw->int_clr.val = mask;
116 }
117 
118 static inline uint32_t uart_ll_get_intr_ena_status(uart_dev_t *hw)
119 {
120  return hw->int_ena.val;
121 }
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* DOXYGEN */
uart_parity_t
Definition of possible parity modes.
Definition: periph_cpu.h:501
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition: periph_cpu.h:533
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: periph_cpu.h:517