|
libxr
1.0
Want to be the best embedded framework
|
ESP32 UART backend with FIFO and optional GDMA fast paths. More...
#include <esp_uart.hpp>
Public Member Functions | |
| ESP32UART (uart_port_t uart_num, int tx_pin, int rx_pin, int rts_pin=PIN_NO_CHANGE, int cts_pin=PIN_NO_CHANGE, size_t rx_buffer_size=1024, size_t tx_buffer_size=512, uint32_t tx_queue_size=5, UART::Configuration config={115200, UART::Parity::NO_PARITY, 8, 1}, bool enable_dma=true) | |
| Create and initialize one ESP32 UART instance. | |
| ErrorCode | SetConfig (UART::Configuration config) override |
| Apply a new UART framing and baud configuration. | |
| ErrorCode | SetLoopback (bool enable) |
| Toggle UART peripheral internal loopback mode. | |
Public Member Functions inherited from LibXR::UART | |
| template<typename ReadPortType = ReadPort, typename WritePortType = WritePort> | |
| UART (ReadPortType *read_port, WritePortType *write_port) | |
| UART 构造函数 / UART constructor. | |
| template<typename OperationType , typename = std::enable_if_t<std::is_base_of_v< WriteOperation, std::decay_t<OperationType>>>> | |
| ErrorCode | Write (ConstRawData data, OperationType &&op, bool in_isr=false) |
| template<typename OperationType , typename = std::enable_if_t<std::is_base_of_v< ReadOperation, std::decay_t<OperationType>>>> | |
| ErrorCode | Read (RawData data, OperationType &&op, bool in_isr=false) |
Static Public Member Functions | |
| static ErrorCode | WriteFun (WritePort &port, bool in_isr) |
Queue-driven TX entry used by WritePort. | |
| static ErrorCode | ReadFun (ReadPort &port, bool in_isr) |
Queue-driven RX entry used by ReadPort. | |
Static Public Attributes | |
| static constexpr int | PIN_NO_CHANGE = -1 |
| Sentinel for an unmapped GPIO. | |
Private Member Functions | |
| ErrorCode | InitUartHardware () |
| Initialize UART hardware and base HAL state. | |
| ErrorCode | ConfigurePins () |
| Configure the selected GPIO pins. | |
| ErrorCode | InstallUartIsr () |
| Install the UART interrupt handler. | |
| void | ConfigureRxInterruptPath () |
| Program RX interrupt thresholds and masks. | |
| ErrorCode | TryStartTx (bool in_isr) |
| Try to start queued transmit work. | |
| bool | LoadActiveTxFromQueue (bool in_isr) |
| Load one active TX request from the queue. | |
| bool | LoadPendingTxFromQueue (bool in_isr) |
| Preload one pending TX request for DMA mode. | |
| bool | PromotePendingTxToActive () |
| Promote one preloaded DMA pending request into the active slot. | |
| bool | StartPendingTxIfIdle (bool in_isr) |
| Start the current pending DMA request when TX is fully idle. | |
| bool | DequeueTxToBuffer (uint8_t *buffer, size_t &size, WriteInfoBlock &info, bool in_isr) |
| Dequeue one TX payload into the selected buffer. | |
| bool | StartActiveTransfer (bool in_isr) |
| Start the active request on the selected TX backend. | |
| bool | StartAndReportActive (bool in_isr) |
| Start the active request and report queue completion ownership. | |
| void | ClearActiveTx () |
| Clear active TX state. | |
| void | ClearPendingTx () |
| Clear pending TX state. | |
| void | FillTxFifo (bool in_isr) |
| Drain active TX bytes into the UART FIFO backend. | |
| void | PushRxBytes (const uint8_t *data, size_t size, bool in_isr) |
| Push RX bytes into the software queue. | |
| void | DrainRxFifo (bool in_isr) |
| Drain pending bytes from the hardware RX FIFO. | |
| void | HandleRxInterrupt (uint32_t uart_intr_status) |
| Handle RX-side UART interrupt reasons. | |
| void | HandleTxInterrupt (uint32_t uart_intr_status) |
| Handle TX-side UART interrupt reasons. | |
| void | HandleUartInterrupt () |
| Dispatch pending UART interrupt reasons. | |
| void | OnTxTransferDone (bool in_isr, ErrorCode result) |
| Finalize one TX transfer result. | |
Static Private Member Functions | |
| static uint8_t * | AllocateTxStorage (size_t size) |
| Allocate DMA-capable backing storage for TX buffers. | |
| static ErrorCode | ResolveUartPeriph (uart_port_t uart_num, periph_module_t &out) |
| Map one UART index to its peripheral module. | |
| static bool | ResolveWordLength (uint8_t data_bits, uart_word_length_t &out) |
| Convert configured data bits into the HAL enum. | |
| static bool | ResolveStopBits (uint8_t stop_bits, uart_stop_bits_t &out) |
| Convert configured stop bits into the HAL enum. | |
| static uart_parity_t | ResolveParity (UART::Parity parity) |
| Convert configured parity into the HAL enum. | |
| static void | UartIsrEntry (void *arg) |
| UART ISR trampoline. | |
Private Attributes | |
| uart_port_t | uart_num_ |
| Selected UART peripheral index. | |
| int | tx_pin_ |
TX GPIO pin or PIN_NO_CHANGE. | |
| int | rx_pin_ |
RX GPIO pin or PIN_NO_CHANGE. | |
| int | rts_pin_ |
RTS GPIO pin or PIN_NO_CHANGE. | |
| int | cts_pin_ |
CTS GPIO pin or PIN_NO_CHANGE. | |
| UART::Configuration | config_ |
| Current UART framing configuration. | |
| uint8_t * | rx_isr_buffer_ = nullptr |
| Scratch buffer used by the RX ISR path. | |
| size_t | rx_isr_buffer_size_ = 0 |
Size of rx_isr_buffer_. | |
| uint8_t * | tx_storage_ = nullptr |
| Backing storage for the TX half-buffers. | |
| DoubleBuffer | tx_dma_buffer_ {} |
| TX double-buffer view for the DMA path. | |
| WriteInfoBlock | tx_active_info_ = {} |
| Metadata for the active TX request. | |
| size_t | tx_active_length_ = 0U |
| Active TX payload length in bytes. | |
| size_t | tx_active_offset_ = 0U |
| Bytes already emitted for the active request. | |
| bool | tx_active_valid_ = false |
| Whether the active TX metadata is valid. | |
| Flag::Plain | tx_busy_ |
| Hardware TX engine currently owns the request. | |
| Flag::Plain | in_tx_isr_ |
| Reentry guard while processing TX ISR work. | |
| bool | uart_hw_enabled_ = false |
| UART hardware block was initialized. | |
| uart_hal_context_t | uart_hal_ = {} |
| ESP-IDF UART HAL context. | |
| intr_handle_t | uart_intr_handle_ = nullptr |
| Registered UART interrupt handle. | |
| bool | uart_isr_installed_ = false |
| UART ISR installation state. | |
| bool | dma_requested_ = true |
| Constructor preference for DMA mode. | |
| ESP32UARTReadPort | _read_port |
Read-side queue bridge exposed to UART. | |
| WritePort | _write_port |
Write-side queue bridge exposed to UART. | |
| Flag::Atomic | rx_fifo_draining_ {} |
| RX FIFO drain reentry gate. | |
Friends | |
| class | ESP32UARTReadPort |
Additional Inherited Members | |
Public Types inherited from LibXR::UART | |
| enum class | Parity : uint8_t { NO_PARITY = 0 , EVEN = 1 , ODD = 2 } |
| 奇偶校验模式 / Parity mode More... | |
Data Fields inherited from LibXR::UART | |
| ReadPort * | read_port_ |
| 读取端口 / Read port | |
| WritePort * | write_port_ |
| 写入端口 / Write port | |
ESP32 UART backend with FIFO and optional GDMA fast paths.
ESP32 UART 后端,支持 FIFO 和可选 GDMA 快路径。
The object owns the UART hardware state, software queue plumbing, and the optional DMA resources used by the ESP-specific transmit and receive paths. 该对象持有 UART 硬件状态、软件队列连接,以及 ESP 专用收发路径使用的可选 DMA 资源。
Definition at line 75 of file esp_uart.hpp.
| LibXR::ESP32UART::ESP32UART | ( | uart_port_t | uart_num, |
| int | tx_pin, | ||
| int | rx_pin, | ||
| int | rts_pin = PIN_NO_CHANGE, | ||
| int | cts_pin = PIN_NO_CHANGE, | ||
| size_t | rx_buffer_size = 1024, | ||
| size_t | tx_buffer_size = 512, | ||
| uint32_t | tx_queue_size = 5, | ||
| UART::Configuration | config = {115200, UART::Parity::NO_PARITY, 8, 1}, | ||
| bool | enable_dma = true ) |
Create and initialize one ESP32 UART instance.
创建并初始化一个 ESP32 UART 实例。
Definition at line 104 of file esp_uart.cpp.
|
staticprivate |
Allocate DMA-capable backing storage for TX buffers.
为 TX buffer 分配可 DMA 访问的 backing storage。
Definition at line 66 of file esp_uart.cpp.
|
private |
Clear active TX state.
清除 active TX 状态。
Definition at line 451 of file esp_uart.cpp.
|
private |
Clear pending TX state.
清除 pending TX 状态。
Definition at line 461 of file esp_uart.cpp.
|
private |
Configure the selected GPIO pins.
配置选定的 GPIO 引脚。
Definition at line 399 of file esp_uart.cpp.
|
private |
Program RX interrupt thresholds and masks.
配置 RX 中断阈值和掩码。
Definition at line 170 of file esp_uart.cpp.
|
private |
Dequeue one TX payload into the selected buffer.
将一个 TX payload 出队到选定缓冲区。
Definition at line 684 of file esp_uart.cpp.
|
private |
Drain pending bytes from the hardware RX FIFO.
从硬件 RX FIFO 中取出待处理字节。
Definition at line 118 of file esp_uart_fifo.cpp.
|
private |
Drain active TX bytes into the UART FIFO backend.
将 active TX 字节排入 UART FIFO 后端。
Definition at line 68 of file esp_uart_fifo.cpp.
|
private |
Handle RX-side UART interrupt reasons.
处理 RX 侧 UART 中断原因。
Definition at line 170 of file esp_uart_fifo.cpp.
|
private |
Handle TX-side UART interrupt reasons.
处理 TX 侧 UART 中断原因。
Definition at line 195 of file esp_uart_fifo.cpp.
|
private |
Dispatch pending UART interrupt reasons.
分发待处理的 UART 中断原因。
Definition at line 211 of file esp_uart_fifo.cpp.
|
private |
Initialize UART hardware and base HAL state.
初始化 UART 硬件和基础 HAL 状态。
Definition at line 351 of file esp_uart.cpp.
|
private |
Install the UART interrupt handler.
安装 UART 中断处理函数。
Definition at line 38 of file esp_uart_fifo.cpp.
|
private |
Load one active TX request from the queue.
从队列装载一个 active TX 请求。
Definition at line 540 of file esp_uart.cpp.
|
private |
Preload one pending TX request for DMA mode.
为 DMA 模式预装一个 pending TX 请求。
Definition at line 578 of file esp_uart.cpp.
|
private |
Finalize one TX transfer result.
收尾一次 TX 传输结果。
Definition at line 807 of file esp_uart.cpp.
|
private |
Promote one preloaded DMA pending request into the active slot.
将一个已经预装的 DMA pending 请求提升到 active 槽位。
Definition at line 620 of file esp_uart.cpp.
|
private |
Push RX bytes into the software queue.
将 RX 字节推入软件队列。
Definition at line 771 of file esp_uart.cpp.
Queue-driven RX entry used by ReadPort.
ReadPort 使用的队列驱动 RX 入口。
Definition at line 289 of file esp_uart.cpp.
|
staticprivate |
Convert configured parity into the HAL enum.
将配置的校验位转换为 HAL 枚举。
Definition at line 333 of file esp_uart.cpp.
|
staticprivate |
Convert configured stop bits into the HAL enum.
将配置的停止位转换为 HAL 枚举。
Definition at line 316 of file esp_uart.cpp.
|
staticprivate |
Map one UART index to its peripheral module.
将一个 UART 序号映射到对应的外设模块。
Definition at line 81 of file esp_uart.cpp.
|
staticprivate |
Convert configured data bits into the HAL enum.
将配置的数据位转换为 HAL 枚举。
Definition at line 293 of file esp_uart.cpp.
|
overridevirtual |
Apply a new UART framing and baud configuration.
应用新的 UART 帧格式和波特率配置。
Implements LibXR::UART.
Definition at line 185 of file esp_uart.cpp.
| ErrorCode LibXR::ESP32UART::SetLoopback | ( | bool | enable | ) |
Toggle UART peripheral internal loopback mode.
切换 UART 外设内部环回模式。
Definition at line 267 of file esp_uart.cpp.
|
private |
Start the active request on the selected TX backend.
在选定 TX 后端上启动 active 请求。
Definition at line 734 of file esp_uart.cpp.
|
private |
Start the active request and report queue completion ownership.
启动 active 请求并上报队列完成所有权交接。
Definition at line 475 of file esp_uart.cpp.
|
private |
Start the current pending DMA request when TX is fully idle.
在 TX 完全空闲时启动当前 pending DMA 请求。
Definition at line 654 of file esp_uart.cpp.
|
private |
Try to start queued transmit work.
尝试启动排队的发送工作。
Definition at line 496 of file esp_uart.cpp.
|
staticprivate |
UART ISR trampoline.
UART 中断跳板函数。
Definition at line 24 of file esp_uart_fifo.cpp.
Queue-driven TX entry used by WritePort.
WritePort 使用的队列驱动 TX 入口。
Definition at line 280 of file esp_uart.cpp.
|
friend |
Definition at line 77 of file esp_uart.hpp.
|
private |
Read-side queue bridge exposed to UART.
Definition at line 374 of file esp_uart.hpp.
|
private |
Write-side queue bridge exposed to UART.
Definition at line 375 of file esp_uart.hpp.
|
private |
Current UART framing configuration.
Definition at line 354 of file esp_uart.hpp.
|
private |
CTS GPIO pin or PIN_NO_CHANGE.
Definition at line 352 of file esp_uart.hpp.
|
private |
Constructor preference for DMA mode.
Definition at line 372 of file esp_uart.hpp.
|
private |
Reentry guard while processing TX ISR work.
Definition at line 366 of file esp_uart.hpp.
|
staticconstexpr |
Sentinel for an unmapped GPIO.
Definition at line 80 of file esp_uart.hpp.
|
private |
RTS GPIO pin or PIN_NO_CHANGE.
Definition at line 351 of file esp_uart.hpp.
|
private |
|
private |
Scratch buffer used by the RX ISR path.
Definition at line 356 of file esp_uart.hpp.
|
private |
Size of rx_isr_buffer_.
Definition at line 357 of file esp_uart.hpp.
|
private |
RX GPIO pin or PIN_NO_CHANGE.
Definition at line 350 of file esp_uart.hpp.
|
private |
|
private |
Active TX payload length in bytes.
Definition at line 362 of file esp_uart.hpp.
|
private |
Bytes already emitted for the active request.
Definition at line 363 of file esp_uart.hpp.
|
private |
Whether the active TX metadata is valid.
Definition at line 364 of file esp_uart.hpp.
|
private |
Hardware TX engine currently owns the request.
Definition at line 365 of file esp_uart.hpp.
|
private |
|
private |
TX GPIO pin or PIN_NO_CHANGE.
Definition at line 349 of file esp_uart.hpp.
|
private |
Backing storage for the TX half-buffers.
Definition at line 359 of file esp_uart.hpp.
|
private |
|
private |
UART hardware block was initialized.
Definition at line 368 of file esp_uart.hpp.
|
private |
Registered UART interrupt handle.
Definition at line 370 of file esp_uart.hpp.
|
private |
UART ISR installation state.
Definition at line 371 of file esp_uart.hpp.
|
private |
Selected UART peripheral index.
Definition at line 348 of file esp_uart.hpp.