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