|
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 | |
| void | OnConfigRequested () |
| bool | ApplyPendingConfig (bool in_isr) |
| bool | OnConfigApplied (bool in_isr) |
| 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. | |
| bool | StartDmaTx (uint8_t *data, size_t size, int block) |
| 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 | DequeueFifoTx (size_t &size, WriteInfoBlock &info) |
| Claim one queued request for the FIFO TX backend. | |
| 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 | 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. | |
| LatestSnapshot< UART::Configuration > | requested_config_ |
| UartRxConfigGate | rx_config_gate_ |
| 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. | |
| 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. | |
| UartDmaTxModel< ESP32UART > | tx_dma_model_ |
| One-shot DMA TX execution model. | |
Friends | |
| class | ESP32UARTReadPort |
| class | UartDmaTxModel< ESP32UART > |
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 78 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 |
Definition at line 212 of file esp_uart.cpp.
|
private |
Clear active TX state.
清除 active TX 状态。
Definition at line 511 of file esp_uart.cpp.
|
private |
Configure the selected GPIO pins.
配置选定的 GPIO 引脚。
Definition at line 459 of file esp_uart.cpp.
|
private |
Program RX interrupt thresholds and masks.
配置 RX 中断阈值和掩码。
Definition at line 170 of file esp_uart.cpp.
|
private |
Claim one queued request for the FIFO TX backend.
为 FIFO TX 后端认领一个排队请求。
Definition at line 596 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 173 of file esp_uart_fifo.cpp.
|
private |
Handle TX-side UART interrupt reasons.
处理 TX 侧 UART 中断原因。
Definition at line 198 of file esp_uart_fifo.cpp.
|
private |
Dispatch pending UART interrupt reasons.
分发待处理的 UART 中断原因。
Definition at line 214 of file esp_uart_fifo.cpp.
|
private |
Initialize UART hardware and base HAL state.
初始化 UART 硬件和基础 HAL 状态。
Definition at line 411 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 574 of file esp_uart.cpp.
|
private |
Definition at line 297 of file esp_uart.cpp.
|
private |
Definition at line 210 of file esp_uart.cpp.
|
private |
Finalize one TX transfer result.
收尾一次 TX 传输结果。
Definition at line 686 of file esp_uart.cpp.
|
private |
Push RX bytes into the software queue.
将 RX 字节推入软件队列。
Definition at line 650 of file esp_uart.cpp.
Queue-driven RX entry used by ReadPort.
ReadPort 使用的队列驱动 RX 入口。
Definition at line 349 of file esp_uart.cpp.
|
staticprivate |
Convert configured parity into the HAL enum.
将配置的校验位转换为 HAL 枚举。
Definition at line 393 of file esp_uart.cpp.
|
staticprivate |
Convert configured stop bits into the HAL enum.
将配置的停止位转换为 HAL 枚举。
Definition at line 376 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 353 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 317 of file esp_uart.cpp.
|
private |
Start the active request on the selected TX backend.
在选定 TX 后端上启动 active 请求。
Definition at line 626 of file esp_uart.cpp.
|
private |
Start the active request and report queue completion ownership.
启动 active 请求并上报队列完成所有权交接。
Definition at line 523 of file esp_uart.cpp.
|
private |
Definition at line 311 of file esp_uart.cpp.
|
private |
Try to start queued transmit work.
尝试启动排队的发送工作。
Definition at line 544 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 330 of file esp_uart.cpp.
|
friend |
Definition at line 80 of file esp_uart.hpp.
|
friend |
Definition at line 80 of file esp_uart.hpp.
|
private |
Read-side queue bridge exposed to UART.
Definition at line 361 of file esp_uart.hpp.
|
private |
Write-side queue bridge exposed to UART.
Definition at line 362 of file esp_uart.hpp.
|
private |
Current UART framing configuration.
Definition at line 340 of file esp_uart.hpp.
|
private |
CTS GPIO pin or PIN_NO_CHANGE.
Definition at line 338 of file esp_uart.hpp.
|
private |
Constructor preference for DMA mode.
Definition at line 359 of file esp_uart.hpp.
|
private |
Reentry guard while processing TX ISR work.
Definition at line 353 of file esp_uart.hpp.
|
staticconstexpr |
Sentinel for an unmapped GPIO.
Definition at line 84 of file esp_uart.hpp.
|
private |
Definition at line 341 of file esp_uart.hpp.
|
private |
RTS GPIO pin or PIN_NO_CHANGE.
Definition at line 337 of file esp_uart.hpp.
|
private |
Definition at line 342 of file esp_uart.hpp.
|
private |
Scratch buffer used by the RX ISR path.
Definition at line 344 of file esp_uart.hpp.
|
private |
Size of rx_isr_buffer_.
Definition at line 345 of file esp_uart.hpp.
|
private |
RX GPIO pin or PIN_NO_CHANGE.
Definition at line 336 of file esp_uart.hpp.
|
private |
|
private |
Active TX payload length in bytes.
Definition at line 349 of file esp_uart.hpp.
|
private |
Bytes already emitted for the active request.
Definition at line 350 of file esp_uart.hpp.
|
private |
Whether the active TX metadata is valid.
Definition at line 351 of file esp_uart.hpp.
|
private |
Hardware TX engine currently owns the request.
Definition at line 352 of file esp_uart.hpp.
|
private |
One-shot DMA TX execution model.
Definition at line 363 of file esp_uart.hpp.
|
private |
TX GPIO pin or PIN_NO_CHANGE.
Definition at line 335 of file esp_uart.hpp.
|
private |
Backing storage for the TX half-buffers.
Definition at line 347 of file esp_uart.hpp.
|
private |
|
private |
UART hardware block was initialized.
Definition at line 355 of file esp_uart.hpp.
|
private |
Registered UART interrupt handle.
Definition at line 357 of file esp_uart.hpp.
|
private |
UART ISR installation state.
Definition at line 358 of file esp_uart.hpp.
|
private |
Selected UART peripheral index.
Definition at line 334 of file esp_uart.hpp.