|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
使用循环接收 DMA 和双缓冲发送的 CH32 串口 / CH32 UART with circular RX DMA and double-buffered TX. More...
#include <ch32_uart.hpp>
Public Member Functions | |
| 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. | |
| ErrorCode | SetConfig (UART::Configuration config, bool in_isr=false) override |
| 提交串口配置请求 / Submit a UART configuration request. | |
| void | TxDmaIRQHandler () |
| 处理发送 DMA 完成通知 / Handle TX DMA completion. | |
| void | RxDmaIRQHandler () |
| 处理接收 DMA 进展通知 / Handle RX DMA progress. | |
| void | UartIRQHandler () |
| 处理接收空闲和发送完成中断 / Handle RX idle and TX complete interrupts. | |
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 void | WriteFun (WritePort &port, bool in_isr) |
| 通知后端处理已提交的写请求 / Notify the backend of released writes. | |
Public Attributes | |
| ch32_uart_id_t | id_ |
| uint16_t | uart_mode_ |
| ReadPort | _read_port |
| 接收字节队列与读请求 / RX byte queue and read requests. | |
| WritePort | _write_port |
| 写请求及发送字节队列 / Write requests and TX byte queue. | |
| RawData | dma_buff_rx_ |
| 调用者提供的接收 DMA 缓冲区 / Caller-provided RX DMA buffer. | |
| DoubleBuffer | dma_buff_tx_ |
| 当前与待发送的 DMA 半区 / Active and pending TX DMA halves. | |
| size_t | last_rx_pos_ = 0 |
| 上次已处理的 DMA 接收位置 / Last processed RX DMA position. | |
| USART_TypeDef * | instance_ |
| DMA_Channel_TypeDef * | dma_rx_channel_ |
| DMA_Channel_TypeDef * | dma_tx_channel_ |
| Flag::Plain | tx_busy_ |
| 发送半区是否在使用,仅后端处理器访问 / TX half in use; service-only access. | |
Public Attributes inherited from LibXR::UART | |
| ReadPort * | read_port_ |
| 读取端口 / Read port | |
| WritePort * | write_port_ |
| 写入端口 / Write port | |
Static Public Attributes | |
| static CH32UART * | map_ [CH32_UART_NUMBER] = {nullptr} |
Additional Inherited Members | |
Public Types inherited from LibXR::UART | |
| enum class | Parity : uint8_t { NO_PARITY = 0 , EVEN = 1 , ODD = 2 } |
| 奇偶校验模式 / Parity mode More... | |
使用循环接收 DMA 和双缓冲发送的 CH32 串口 / CH32 UART with circular RX DMA and double-buffered TX.
写请求完整复制到发送缓冲半区后完成,DMA 完成仅释放半区。接收持续运行, 按 DMA 位置变化向 ReadPort 发布数据;软件队列放不下的部分作为接收溢出丢弃。 Writes complete once copied into a TX half; DMA completion only releases that half. RX runs continuously and publishes observed DMA bytes to ReadPort, discarding any overflow beyond available software capacity.
Definition at line 32 of file ch32_uart.hpp.
| CH32UART::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.
| id | 串口编号 / UART identifier. |
| dma_rx | 接收 DMA 缓冲区 / RX DMA buffer. |
| dma_tx | 双缓冲发送存储,每半区容纳一个请求 / TX storage, one request per half. |
| tx_gpio_port | 发送引脚端口 / TX GPIO port. |
| tx_gpio_pin | 发送引脚 / TX GPIO pin. |
| rx_gpio_port | 接收引脚端口 / RX GPIO port. |
| rx_gpio_pin | 接收引脚 / RX GPIO pin. |
| pin_remap | 引脚重映射配置,默认零 / Pin remapping, zero by default. |
| tx_queue_size | 写请求队列容量,启用发送时须大于零 / Positive TX request capacity. |
| config | 初始串口配置 / Initial UART configuration. |
Definition at line 35 of file ch32_uart.cpp.
| void CH32UART::RxDmaIRQHandler | ( | ) |
处理接收 DMA 进展通知 / Handle RX DMA progress.
清除接收 DMA 中断标志并通知后端 / Clear RX DMA flags and notify the backend.
Definition at line 573 of file ch32_uart.cpp.
|
overridevirtual |
提交串口配置请求 / Submit a UART configuration request.
| config | 目标配置 / Requested configuration. |
| in_isr | 当前调用是否在中断中 / Whether this call is in an ISR. |
Implements LibXR::UART.
Definition at line 210 of file ch32_uart.cpp.
| void CH32UART::TxDmaIRQHandler | ( | ) |
处理发送 DMA 完成通知 / Handle TX DMA completion.
Definition at line 555 of file ch32_uart.cpp.
| void CH32UART::UartIRQHandler | ( | ) |
处理接收空闲和发送完成中断 / Handle RX idle and TX complete interrupts.
Definition at line 517 of file ch32_uart.cpp.
|
static |
通知后端处理已提交的写请求 / Notify the backend of released writes.
Definition at line 299 of file ch32_uart.cpp.
| ReadPort LibXR::CH32UART::_read_port |
接收字节队列与读请求 / RX byte queue and read requests.
Definition at line 81 of file ch32_uart.hpp.
| WritePort LibXR::CH32UART::_write_port |
写请求及发送字节队列 / Write requests and TX byte queue.
Definition at line 83 of file ch32_uart.hpp.
| RawData LibXR::CH32UART::dma_buff_rx_ |
调用者提供的接收 DMA 缓冲区 / Caller-provided RX DMA buffer.
Definition at line 86 of file ch32_uart.hpp.
| DoubleBuffer LibXR::CH32UART::dma_buff_tx_ |
当前与待发送的 DMA 半区 / Active and pending TX DMA halves.
Definition at line 88 of file ch32_uart.hpp.
| DMA_Channel_TypeDef* LibXR::CH32UART::dma_rx_channel_ |
Definition at line 94 of file ch32_uart.hpp.
| DMA_Channel_TypeDef* LibXR::CH32UART::dma_tx_channel_ |
Definition at line 95 of file ch32_uart.hpp.
| ch32_uart_id_t LibXR::CH32UART::id_ |
Definition at line 77 of file ch32_uart.hpp.
| USART_TypeDef* LibXR::CH32UART::instance_ |
Definition at line 93 of file ch32_uart.hpp.
| size_t LibXR::CH32UART::last_rx_pos_ = 0 |
上次已处理的 DMA 接收位置 / Last processed RX DMA position.
Definition at line 91 of file ch32_uart.hpp.
|
static |
Definition at line 100 of file ch32_uart.hpp.
| Flag::Plain LibXR::CH32UART::tx_busy_ |
发送半区是否在使用,仅后端处理器访问 / TX half in use; service-only access.
Definition at line 98 of file ch32_uart.hpp.
| uint16_t LibXR::CH32UART::uart_mode_ |
Definition at line 78 of file ch32_uart.hpp.