|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
使用循环接收 DMA 和双缓冲发送的 STM32 串口 / STM32 UART with circular RX DMA and double-buffered TX. More...
#include <stm32_uart.hpp>
Public Member Functions | |
| STM32UART (UART_HandleTypeDef *uart_handle, RawData dma_buff_rx, RawData dma_buff_tx, uint32_t tx_queue_size=5) | |
| 构造串口并关联 DMA 缓冲区 / Construct a UART with DMA buffers. | |
| ErrorCode | SetConfig (UART::Configuration config, bool in_isr=false) override |
| 提交串口配置请求 / Submit a UART configuration request. | |
| void | SetRxDMA (bool in_isr=false) |
| 初始化循环接收 DMA 并检查启动结果 / Initialize circular RX DMA and check startup. | |
| void | TxCompleteIRQHandler () |
| 通知发送完成,交给后端释放半区 / Notify TX completion to release the active half. | |
| void | RxEventIRQHandler () |
| 通知接收位置变化 / Notify RX position changes. | |
| void | ErrorIRQHandler () |
| 通知错误,由后端处理器启动中止 / Report an error; the service initiates the abort. | |
| void | AbortCompleteIRQHandler () |
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 | |
| 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. | |
| UART_HandleTypeDef * | uart_handle_ |
| Flag::Plain | tx_busy_ |
| 发送半区是否在使用,仅后端处理器访问 / TX half in use; service-only access. | |
| stm32_uart_id_t | id_ = STM32_UART_ID_ERROR |
Public Attributes inherited from LibXR::UART | |
| ReadPort * | read_port_ |
| 读取端口 / Read port | |
| WritePort * | write_port_ |
| 写入端口 / Write port | |
Static Public Attributes | |
| static STM32UART * | map [STM32_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 和双缓冲发送的 STM32 串口 / STM32 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 137 of file stm32_uart.hpp.
| STM32UART::STM32UART | ( | UART_HandleTypeDef * | uart_handle, |
| RawData | dma_buff_rx, | ||
| RawData | dma_buff_tx, | ||
| uint32_t | tx_queue_size = 5 ) |
构造串口并关联 DMA 缓冲区 / Construct a UART with DMA buffers.
| uart_handle | 已初始化的 HAL 句柄 / Initialized HAL handle. |
| dma_buff_rx | 接收 DMA 缓冲区 / RX DMA buffer. |
| dma_buff_tx | 双缓冲发送存储,每半区容纳一个请求 / TX storage, one request per half. |
| tx_queue_size | 写请求队列容量,启用发送时须大于零 / Positive TX request capacity. |
Definition at line 398 of file stm32_uart.cpp.
| void STM32UART::AbortCompleteIRQHandler | ( | ) |
通知 HAL 中止完成,由后端恢复收发 / Notify HAL abort completion for backend recovery.
Definition at line 653 of file stm32_uart.cpp.
| void STM32UART::ErrorIRQHandler | ( | ) |
通知错误,由后端处理器启动中止 / Report an error; the service initiates the abort.
Definition at line 647 of file stm32_uart.cpp.
| void STM32UART::RxEventIRQHandler | ( | ) |
通知接收位置变化 / Notify RX position changes.
Definition at line 641 of file stm32_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 435 of file stm32_uart.cpp.
| void STM32UART::SetRxDMA | ( | bool | in_isr = false | ) |
初始化循环接收 DMA 并检查启动结果 / Initialize circular RX DMA and check startup.
Definition at line 553 of file stm32_uart.cpp.
| void STM32UART::TxCompleteIRQHandler | ( | ) |
通知发送完成,交给后端释放半区 / Notify TX completion to release the active half.
Definition at line 635 of file stm32_uart.cpp.
|
static |
通知后端处理已提交的写请求 / Notify the backend of released writes.
Definition at line 219 of file stm32_uart.cpp.
| ReadPort LibXR::STM32UART::_read_port |
接收字节队列与读请求 / RX byte queue and read requests.
Definition at line 181 of file stm32_uart.hpp.
| WritePort LibXR::STM32UART::_write_port |
写请求及发送字节队列 / Write requests and TX byte queue.
Definition at line 183 of file stm32_uart.hpp.
| RawData LibXR::STM32UART::dma_buff_rx_ |
调用者提供的接收 DMA 缓冲区 / Caller-provided RX DMA buffer.
Definition at line 186 of file stm32_uart.hpp.
| DoubleBuffer LibXR::STM32UART::dma_buff_tx_ |
当前与待发送的 DMA 半区 / Active and pending TX DMA halves.
Definition at line 188 of file stm32_uart.hpp.
| stm32_uart_id_t LibXR::STM32UART::id_ = STM32_UART_ID_ERROR |
Definition at line 198 of file stm32_uart.hpp.
| size_t LibXR::STM32UART::last_rx_pos_ = 0 |
上次已处理的 DMA 接收位置 / Last processed RX DMA position.
Definition at line 191 of file stm32_uart.hpp.
|
static |
Definition at line 200 of file stm32_uart.hpp.
| Flag::Plain LibXR::STM32UART::tx_busy_ |
发送半区是否在使用,仅后端处理器访问 / TX half in use; service-only access.
Definition at line 196 of file stm32_uart.hpp.
| UART_HandleTypeDef* LibXR::STM32UART::uart_handle_ |
Definition at line 193 of file stm32_uart.hpp.