Skip to main content

SpscFrameRing

Struct SpscFrameRing 

Source
pub struct SpscFrameRing<const N: usize, const BYTES: usize> { /* private fields */ }
Expand description

A fixed-capacity SPSC FIFO of BYTES-sized frames for the ISR-to-pipeline capture hand-off. N slots live inline (no alloc); usable capacity is N - 1 (one slot separates a full ring from an empty one), so N >= 2, and N >= 3 gives a double-buffer plus one frame in flight.

Implementations§

Source§

impl<const N: usize, const BYTES: usize> SpscFrameRing<N, BYTES>

Source

pub const fn new() -> Self

Build an empty ring. const, so it lives in a static (the DMA-ring idiom) shared between the producer ISR and the consumer. N >= 2.

Source

pub const fn capacity(&self) -> usize

Slot count (the const N); usable capacity is N - 1.

Source

pub fn overruns(&self) -> u32

Full-ring events: produce calls that found no free slot. For the canonical ISR producer (one attempt per frame, no retry) this is the count of frames dropped to back-pressure.

Source

pub fn is_empty(&self) -> bool

True if the ring currently holds no published frames.

Source

pub fn produce( &self, fill: impl FnOnce(&mut [u8; BYTES]), ) -> Result<(), Overrun>

PRODUCER side (call from exactly one context, e.g. a DMA-completion ISR): fill the next free slot via fill and publish it to the consumer.

Returns Err(Overrun) if the ring is full (the consumer is behind): the frame is dropped and counted, never blocked on, because a producer in an interrupt cannot wait.

Source

pub fn borrow(&self) -> Option<SystemSlice>

CONSUMER side: borrow the oldest published frame zero-copy as a SystemSlice, or None if the ring is empty. The borrow aliases the ring slot (no copy); it stays valid until release advances past it.

Contract: borrow at most one frame at a time and [release] it before the next borrow, after the frame (and its slice) is dropped, the single-frame- in-flight discipline the static runners already follow (each frame is dropped before the next next()). Releasing a still-referenced slice would let the producer reuse the slot under the reader.

Not built under --cfg loom: the lend hands out a raw pointer that outlives any scoped cell access, which loom’s UnsafeCell cannot model. The loom consumer reads through [Self::loom_peek0] instead.

Source

pub fn release(&self)

CONSUMER side: reclaim the slot last returned by [borrow], freeing it for the producer to refill. Call once per consumed frame, after the frame is dropped. A release with nothing borrowed is a no-op.

Trait Implementations§

Source§

impl<const N: usize, const BYTES: usize> Debug for SpscFrameRing<N, BYTES>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, const BYTES: usize> Default for SpscFrameRing<N, BYTES>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize, const BYTES: usize> Sync for SpscFrameRing<N, BYTES>

Auto Trait Implementations§

§

impl<const N: usize, const BYTES: usize> !Freeze for SpscFrameRing<N, BYTES>

§

impl<const N: usize, const BYTES: usize> !RefUnwindSafe for SpscFrameRing<N, BYTES>

§

impl<const N: usize, const BYTES: usize> Send for SpscFrameRing<N, BYTES>
where [UnsafeCell<[u8; BYTES]>; N]: Send,

§

impl<const N: usize, const BYTES: usize> Unpin for SpscFrameRing<N, BYTES>
where [UnsafeCell<[u8; BYTES]>; N]: Unpin,

§

impl<const N: usize, const BYTES: usize> UnsafeUnpin for SpscFrameRing<N, BYTES>
where [UnsafeCell<[u8; BYTES]>; N]: UnsafeUnpin,

§

impl<const N: usize, const BYTES: usize> UnwindSafe for SpscFrameRing<N, BYTES>
where [UnsafeCell<[u8; BYTES]>; N]: UnwindSafe,

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> ElementBound for T
where T: Send,

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 = !

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.