pub struct ReadableRingBuffer<'a, W: Word> { /* private fields */ }
Expand description
Ringbuffer for receiving data using GPDMA linked-list mode.
Implementations§
Source§impl<'a, W: Word> ReadableRingBuffer<'a, W>
impl<'a, W: Word> ReadableRingBuffer<'a, W>
Sourcepub unsafe fn new(
channel: Peri<'a, impl Channel>,
request: Request,
peri_addr: *mut W,
buffer: &'a mut [W],
options: TransferOptions,
) -> Self
pub unsafe fn new( channel: Peri<'a, impl Channel>, request: Request, peri_addr: *mut W, buffer: &'a mut [W], options: TransferOptions, ) -> Self
Create a new ring buffer.
Transfer options are applied to the individual linked list items.
Sourcepub fn read(&mut self, buf: &mut [W]) -> Result<(usize, usize), Error>
pub fn read(&mut self, buf: &mut [W]) -> Result<(usize, usize), Error>
Read elements from the ring buffer Return a tuple of the length read and the length remaining in the buffer If not all of the elements were read, then there will be some elements in the buffer remaining The length remaining is the capacity, ring_buf.len(), less the elements remaining after the read Error is returned if the portion to be read was overwritten by the DMA controller.
Sourcepub async fn read_exact(&mut self, buffer: &mut [W]) -> Result<usize, Error>
pub async fn read_exact(&mut self, buffer: &mut [W]) -> Result<usize, Error>
Read an exact number of elements from the ringbuffer.
Returns the remaining number of elements available for immediate reading. Error is returned if the portion to be read was overwritten by the DMA controller.
Async/Wake Behavior: The underlying DMA peripheral only can wake us when its buffer pointer has reached the halfway point, and when it wraps around. This means that when called with a buffer of length ‘M’, when this ring buffer was created with a buffer of size ‘N’:
- If M equals N/2 or N/2 divides evenly into M, this function will return every N/2 elements read on the DMA source.
- Otherwise, this function may need up to N/2 extra elements to arrive before returning.
Sourcepub fn set_waker(&mut self, waker: &Waker)
pub fn set_waker(&mut self, waker: &Waker)
Set a waker to be woken when at least one byte is received.
Sourcepub fn request_pause(&mut self)
pub fn request_pause(&mut self)
Request the transfer to pause, keeping the existing configuration for this channel.
To resume the transfer, call request_resume
again.
This doesn’t immediately stop the transfer, you have to wait until is_running
returns false.
Sourcepub fn request_resume(&mut self)
pub fn request_resume(&mut self)
Request the transfer to resume after having been paused.
Sourcepub fn request_reset(&mut self)
pub fn request_reset(&mut self)
Request the DMA to reset.
The configuration for this channel will not be preserved. If you need to restart the transfer
at a later point with the same configuration, see request_pause
instead.
Sourcepub fn is_running(&mut self) -> bool
pub fn is_running(&mut self) -> bool
Return whether this transfer is still running.
If this returns false
, it can be because either the transfer finished, or
it was requested to stop early with request_pause
.