6#include "stm32_uart_gpdma.hpp"
8#ifdef HAL_UART_MODULE_ENABLED
14#include "double_buffer.hpp"
16#include "libxr_def.hpp"
17#include "libxr_rw.hpp"
18#include "serialized_service.hpp"
114stm32_uart_id_t stm32_uart_get_id(USART_TypeDef* addr);
153 uint32_t tx_queue_size = 5);
193 UART_HandleTypeDef* uart_handle_;
198 stm32_uart_id_t id_ = STM32_UART_ID_ERROR;
200 static STM32UART* map[STM32_UART_NUMBER];
204 enum class ConfigState : uint32_t
211 static constexpr uint32_t TX_EVENT_WRITE = 1U << 0U;
212 static constexpr uint32_t TX_EVENT_DONE = 1U << 1U;
213 static constexpr uint32_t TX_EVENT_CONFIG = 1U << 2U;
214 static constexpr uint32_t TX_EVENT_RX_WORK = 1U << 3U;
215 static constexpr uint32_t TX_EVENT_ABORT = 1U << 4U;
216 static constexpr uint32_t TX_EVENT_ERROR = 1U << 5U;
217#if defined(LIBXR_STM32_UART_GPDMA)
218 static constexpr uint32_t TX_EVENT_START_RX = 1U << 6U;
219 static void DmaAbortCallback(DMA_HandleTypeDef* dma_handle);
224 void BeginAbort(
bool in_isr);
227 void HandleTxService(uint32_t events,
bool in_isr);
229 void FillTx(
bool in_isr);
231 void HandleTxDone(
bool in_isr);
233 void StartTxDma(
bool in_isr);
237 void TryApplyConfig(
bool in_isr);
239 void HandleRxData(
bool in_isr);
246 bool abort_pending_ =
false;
248 std::atomic<ConfigState> config_state_{ConfigState::EMPTY};
251 UART::Configuration pending_config_{};
252#if defined(LIBXR_STM32_UART_GPDMA)
253 STM32GpdmaUartAdapter gpdma_adapter_;
双缓冲区管理类 / Double buffer manager class
普通标志位(非原子)/ Non-atomic flag
可写原始数据视图 / Mutable raw data view
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
使用循环接收 DMA 和双缓冲发送的 STM32 串口 / STM32 UART with circular RX DMA and double-buffered TX.
RawData dma_buff_rx_
调用者提供的接收 DMA 缓冲区 / Caller-provided RX DMA buffer.
void ErrorIRQHandler()
通知错误,由后端处理器启动中止 / Report an error; the service initiates the abort.
void SetRxDMA(bool in_isr=false)
初始化循环接收 DMA 并检查启动结果 / Initialize circular RX DMA and check startup.
DoubleBuffer dma_buff_tx_
当前与待发送的 DMA 半区 / Active and pending TX DMA halves.
Flag::Plain tx_busy_
发送半区是否在使用,仅后端处理器访问 / TX half in use; service-only access.
void AbortCompleteIRQHandler()
WritePort _write_port
写请求及发送字节队列 / Write requests and TX byte queue.
void TxCompleteIRQHandler()
通知发送完成,交给后端释放半区 / Notify TX completion to release the active half.
size_t last_rx_pos_
上次已处理的 DMA 接收位置 / Last processed RX DMA position.
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.
void RxEventIRQHandler()
通知接收位置变化 / Notify RX position changes.
ErrorCode SetConfig(UART::Configuration config, bool in_isr=false) override
提交串口配置请求 / Submit a UART configuration request.
ReadPort _read_port
接收字节队列与读请求 / RX byte queue and read requests.
事件合并与回调串行化服务 / Event-coalescing serialized-callback service.
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
基于 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.