pub struct RingBuffer<'channel, 'buf, W: Word> { /* private fields */ }Expand description
A ring buffer for continuous DMA reception.
This structure manages a circular DMA transfer, allowing continuous reception of data without losing bytes between reads. It uses both half-transfer and complete-transfer interrupts to track available data.
§Example
use embassy_mcxa::dma::{DmaChannel, RingBuffer, TransferOptions};
static mut RX_BUF: [u8; 64] = [0; 64];
let dma_ch = DmaChannel::new(p.DMA_CH0);
let ring_buf = unsafe {
dma_ch.setup_circular_read(
uart_rx_addr,
&mut RX_BUF,
)
};
// Read data as it arrives
let mut buf = [0u8; 16];
let n = ring_buf.read(&mut buf).await?;Implementations§
Source§impl<'channel, 'buf, W: Word> RingBuffer<'channel, 'buf, W>
impl<'channel, 'buf, W: Word> RingBuffer<'channel, 'buf, W>
Sourcepub fn is_overrun(&self) -> bool
pub fn is_overrun(&self) -> bool
Check if the buffer has overrun (data was lost).
This happens when DMA writes faster than the application reads.
Sourcepub fn read_immediate(&self, dst: &mut [W]) -> usize
pub fn read_immediate(&self, dst: &mut [W]) -> usize
Read data from the ring buffer into the provided slice.
Returns the number of elements read, which may be less than
dst.len() if not enough data is available.
This method does not block; use read_async() for async waiting.
Sourcepub async fn read(&self, dst: &mut [W]) -> Result<usize, Error>
pub async fn read(&self, dst: &mut [W]) -> Result<usize, Error>
Read data from the ring buffer asynchronously.
This waits until at least one byte is available, then reads as much as possible into the destination buffer.
Returns the number of elements read.
Sourcepub fn stop(self) -> usize
pub fn stop(self) -> usize
Stop the DMA transfer and consume the ring buffer.
Returns any remaining unread data count.
Sourcepub unsafe fn enable_dma_request(&self)
pub unsafe fn enable_dma_request(&self)
Enable the DMA channel request.
Call this to start continuous reception. This is separated from setup to allow for any additional configuration before starting the transfer.