21template <std::
size_t BufferSize = 512>
23 static_assert((BufferSize & (BufferSize - 1)) == 0,
"BufferSize must be a power of two.");
30 return _buffer.data();
34 [[nodiscard]]
const uint8_t*
dmaBuffer() const noexcept {
35 return _buffer.data();
39 [[nodiscard]]
static constexpr std::size_t
capacity() noexcept {
47 template <
typename Callback>
49 currentDmaWriteIndex = currentDmaWriteIndex & (BufferSize - 1);
51 if (currentDmaWriteIndex == _tail) {
55 if (currentDmaWriteIndex > _tail) {
57 std::size_t len = currentDmaWriteIndex - _tail;
58 onPacket(std::span<const uint8_t>(_buffer.data() + _tail, len));
59 _tail = currentDmaWriteIndex;
62 std::size_t firstPart = BufferSize - _tail;
64 onPacket(std::span<const uint8_t>(_buffer.data() + _tail, firstPart));
66 if (currentDmaWriteIndex > 0) {
67 onPacket(std::span<const uint8_t>(_buffer.data(), currentDmaWriteIndex));
69 _tail = currentDmaWriteIndex;
79 [[nodiscard]] std::size_t
tail() const noexcept {
84 alignas(4) std::array<uint8_t, BufferSize> _buffer{};
90template <
typename EventVariant, std::
size_t BufferSize = 512>
111 template <
typename TargetEvent>
113 _rxBuffer.processAvailableBytes(currentDmaWriteIndex, [
this, priority](std::span<const uint8_t> data) {
114 _sink.post(EventVariant{TargetEvent{data}}, priority);
Non-allocating type-erased fat pointer handle for lock-free event posting.
Bounded and multi-tier priority MPSC queueing policies.
Non-blocking hardware ISR adapter for DMA UART controllers.
Definition DmaUartAdapter.hpp:91
DmaUartRxBuffer< BufferSize > & rxBuffer() noexcept
Access underlying circular DMA RX buffer.
Definition DmaUartAdapter.hpp:98
DmaUartAdapter(EventSinkT< EventVariant > sink) noexcept
Definition DmaUartAdapter.hpp:93
void processFromIsr(std::size_t currentDmaWriteIndex, EventPriority priority=EventPriority::Normal)
Process newly received DMA bytes and post constructed event into sink.
Definition DmaUartAdapter.hpp:112
const DmaUartRxBuffer< BufferSize > & rxBuffer() const noexcept
Access const circular DMA RX buffer.
Definition DmaUartAdapter.hpp:103
Statically-allocated circular DMA UART RX buffer.
Definition DmaUartAdapter.hpp:22
std::size_t tail() const noexcept
Current tail index in the circular buffer.
Definition DmaUartAdapter.hpp:79
static constexpr std::size_t capacity() noexcept
Capacity of circular DMA buffer in bytes.
Definition DmaUartAdapter.hpp:39
const uint8_t * dmaBuffer() const noexcept
Const pointer to raw memory buffer.
Definition DmaUartAdapter.hpp:34
void processAvailableBytes(std::size_t currentDmaWriteIndex, Callback &&onPacket)
Update tail position based on hardware DMA counter and extract available bytes. Typically invoked fro...
Definition DmaUartAdapter.hpp:48
void reset() noexcept
Reset circular tail index.
Definition DmaUartAdapter.hpp:74
uint8_t * dmaBuffer() noexcept
Direct pointer to raw memory buffer for DMA peripheral configuration (e.g. HAL_UART_Receive_DMA).
Definition DmaUartAdapter.hpp:29
constexpr DmaUartRxBuffer()=default
Definition CanAdapter.hpp:16
EventPriority
Event priority levels for multi-priority queue policies.
Definition QueuePolicies.hpp:32