embassy-mcxa

Crates

git

Versions

mcx-a256

Flavors

RingBuffer

Struct RingBuffer 

Source
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>

Source

pub fn available(&self) -> usize

Returns the number of bytes available to read.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&self)

Clear the ring buffer, discarding all unread data.

Source

pub fn stop(self) -> usize

Stop the DMA transfer and consume the ring buffer.

Returns any remaining unread data count.

Trait Implementations§

Source§

impl<'a, W: Word> Drop for RingBuffer<'a, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.