pub struct RingBuffer<'a, 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<'a, W: Word> RingBuffer<'a, W>
impl<'a, W: Word> RingBuffer<'a, 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.
Trait Implementations§
Auto Trait Implementations§
impl<'a, W> !Freeze for RingBuffer<'a, W>
impl<'a, W> RefUnwindSafe for RingBuffer<'a, W>where
W: RefUnwindSafe,
impl<'a, W> !Send for RingBuffer<'a, W>
impl<'a, W> !Sync for RingBuffer<'a, W>
impl<'a, W> Unpin for RingBuffer<'a, W>
impl<'a, W> !UnwindSafe for RingBuffer<'a, W>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more