6#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
8#include "ch32_uart_def.hpp"
9#include "double_buffer.hpp"
10#include "libxr_def.hpp"
11#include "libxr_rw.hpp"
12#include "serialized_service.hpp"
50 uint16_t tx_gpio_pin, GPIO_TypeDef* rx_gpio_port, uint16_t rx_gpio_pin,
51 uint32_t pin_remap = 0, uint32_t tx_queue_size = 5,
93 USART_TypeDef* instance_;
94 DMA_Channel_TypeDef* dma_rx_channel_;
95 DMA_Channel_TypeDef* dma_tx_channel_;
100 static CH32UART* map_[CH32_UART_NUMBER];
104 enum class ConfigState : uint32_t
111 static constexpr uint32_t TX_EVENT_WRITE = 1U << 0U;
112 static constexpr uint32_t TX_EVENT_DMA_DONE = 1U << 1U;
113 static constexpr uint32_t TX_EVENT_CONFIG = 1U << 2U;
114 static constexpr uint32_t TX_EVENT_TC = 1U << 3U;
115 static constexpr uint32_t TX_EVENT_RX_WORK = 1U << 4U;
118 void HandleTxService(uint32_t events,
bool in_isr);
120 void FillTx(
bool in_isr);
122 void HandleTxDone(
bool in_isr);
124 void StartTxDma(
bool in_isr);
128 void TryApplyConfig(
bool in_isr);
130 void HandleRxData(
bool in_isr);
135 std::atomic<ConfigState> config_state_{ConfigState::EMPTY};
138 UART::Configuration pending_config_{};
使用循环接收 DMA 和双缓冲发送的 CH32 串口 / CH32 UART with circular RX DMA and double-buffered TX.
void RxDmaIRQHandler()
处理接收 DMA 进展通知 / Handle RX DMA progress.
ErrorCode SetConfig(UART::Configuration config, bool in_isr=false) override
提交串口配置请求 / Submit a UART configuration request.
size_t last_rx_pos_
上次已处理的 DMA 接收位置 / Last processed RX DMA position.
void TxDmaIRQHandler()
处理发送 DMA 完成通知 / Handle TX DMA completion.
DoubleBuffer dma_buff_tx_
当前与待发送的 DMA 半区 / Active and pending TX DMA halves.
ReadPort _read_port
接收字节队列与读请求 / RX byte queue and read requests.
CH32UART(ch32_uart_id_t id, RawData dma_rx, RawData dma_tx, GPIO_TypeDef *tx_gpio_port, uint16_t tx_gpio_pin, GPIO_TypeDef *rx_gpio_port, uint16_t rx_gpio_pin, uint32_t pin_remap=0, uint32_t tx_queue_size=5, UART::Configuration config={115200, UART::Parity::NO_PARITY, 8, 1})
构造串口并关联 DMA 缓冲区 / Construct a UART with DMA buffers.
WritePort _write_port
写请求及发送字节队列 / Write requests and TX byte queue.
void UartIRQHandler()
处理接收空闲和发送完成中断 / Handle RX idle and TX complete interrupts.
Flag::Plain tx_busy_
发送半区是否在使用,仅后端处理器访问 / TX half in use; service-only access.
RawData dma_buff_rx_
调用者提供的接收 DMA 缓冲区 / Caller-provided RX DMA buffer.
双缓冲区管理类 / Double buffer manager class
普通标志位(非原子)/ Non-atomic flag
可写原始数据视图 / Mutable raw data view
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
事件合并与回调串行化服务 / Event-coalescing serialized-callback service.
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
@ NO_PARITY
无校验 / No parity
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
void(* WriteFun)(WritePort &port, bool in_isr)
写入进度通知函数类型 / Write progress notification function type.
UART 配置结构体 / UART configuration structure.