6#include "libxr_assert.hpp"
51 template <
typename Backend>
71 template <
typename Backend>
74 uint8_t*
const buffer =
Buffer();
76 const size_t remaining = backend.GetCircularDmaRxRemaining();
77 if (remaining > capacity)
83 const size_t current_position = capacity - remaining;
84 backend.PrepareCircularDmaRxForCpu(buffer, capacity);
86 if (current_position == last_position_)
91 if (current_position > last_position_)
94 current_position - last_position_);
99 capacity - last_position_);
103 last_position_ = current_position;
117 [[nodiscard]] uint8_t*
Buffer()
const {
return static_cast<uint8_t*
>(storage_.
addr_); }
133 size_t last_position_ = 0U;
可写原始数据视图 / Mutable raw data view
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address
ReadPort class for handling read operations.
SPSCQueue< uint8_t > * queue_data_
RX payload queue. 接收数据字节队列。
void ProcessPendingReads(bool in_isr)
Processes pending reads.
ErrorCode PushBatch(const Data *data, size_t size)
批量推入多个 payload。
UART 基于位置的循环 DMA 接收模型 / Position-based circular DMA RX model for UART.
uint8_t * Buffer() const
获取 DMA 可写缓冲区起始地址 / Get the DMA-writable buffer start address
size_t BufferSize() const
获取循环 DMA 缓冲区容量 / Get the circular DMA buffer capacity
size_t LastPosition() const
获取上次已消费的 DMA 写入位置 / Get the last consumed DMA write position
void OnDataAvailable(Backend &backend, ReadPort &port, bool in_isr)
消费上次 DMA 事件后新产生的数据 / Consume bytes produced since the previous DMA event
void ResetPosition()
将软件读取位置复位到 DMA 缓冲区起点 / Reset the software read position to the start of the DMA buffer
UartCircularDmaRxModel(RawData storage)
使用平台提供的 DMA 存储区构造接收模型 / Construct the RX model with platform-provided DMA storage
void Start(Backend &backend)
复位读取位置并启动循环 DMA / Reset the read position and start circular DMA