pub struct DmaRxStreamBuf { /* private fields */ }unstable only.Expand description
DMA Streaming Receive Buffer.
This is a contiguous buffer linked together by DMA descriptors.
It is used for continuously streaming data from a peripheral’s FIFO.
It maintains a sliding window of descriptors that progresses when DmaRxStreamBufView::consume is called.
The list starts out like so A (empty) -> B (empty) -> C (empty) -> D (empty) -> NULL.
As the DMA writes to the buffers the list progresses like so:
A (empty) -> B (empty) -> C (empty) -> D (empty) -> NULLA (full) -> B (empty) -> C (empty) -> D (empty) -> NULLA (full) -> B (full) -> C (empty) -> D (empty) -> NULLA (full) -> B (full) -> C (full) -> D (empty) -> NULL
As DmaRxStreamBufView::consume is called, the list (approximately) progresses like so:
A (full) -> B (full) -> C (full) -> D (empty) -> NULLB (full) -> C (full) -> D (empty) -> A (empty) -> NULLC (full) -> D (empty) -> A (empty) -> B (empty) -> NULLD (empty) -> A (empty) -> B (empty) -> C (empty) -> NULL
If all the descriptors fill up, the DmaRxInterrupt::DescriptorEmpty interrupt fires and the DMA stops writing. The transfer must then be resumed or restarted.
This buffer does not indicate when this condition occurs. Check with the driver to see if the DMA has stopped.
When constructing this buffer, tune the ratio between the chunk size and buffer size appropriately. Smaller chunk sizes mean data is received more frequently, but the DMA interrupts (DmaRxInterrupt::Done) also fire more frequently when they are used.
See DmaRxStreamBufView for APIs available while a transfer is in progress.
Implementations§
Source§impl DmaRxStreamBuf
impl DmaRxStreamBuf
Sourcepub fn new(
descriptors: DmaAlignedMut<'static, [DmaDescriptor]>,
buffer: DmaAlignedMut<'static, [u8]>,
) -> Result<Self, DmaBufError>
pub fn new( descriptors: DmaAlignedMut<'static, [DmaDescriptor]>, buffer: DmaAlignedMut<'static, [u8]>, ) -> Result<Self, DmaBufError>
Creates a new DmaRxStreamBuf and splits buffer across descriptors.
Each descriptor’s size is a multiple of the alignment that a receive transfer needs. In PSRAM, that alignment is the default 16-byte block. The sizes differ by at most one alignment unit.
§Errors
DmaBufError::InvalidAlignment when the address or the length of buffer is not a
multiple of the alignment.
DmaBufError::InsufficientDescriptors when any of the following is true:
descriptorshas fewer than four entriesbufferhas fewer alignment blocks than descriptors- a descriptor would hold more than 4095 bytes
Sourcepub fn new_with_min_burst(
descriptors: DmaAlignedMut<'static, [DmaDescriptor]>,
buffer: DmaAlignedMut<'static, [u8]>,
min: BurstSize,
) -> Result<Self, DmaBufError>
pub fn new_with_min_burst( descriptors: DmaAlignedMut<'static, [DmaDescriptor]>, buffer: DmaAlignedMut<'static, [u8]>, min: BurstSize, ) -> Result<Self, DmaBufError>
Creates a new DmaRxStreamBuf that guarantees an alignment of at least min.
§Errors
DmaBufError::InvalidAlignment if the address of the buffer, or the size of a
descriptor’s part of it, is not a multiple of min.
Sourcepub fn split(
self,
) -> (DmaAlignedMut<'static, [DmaDescriptor]>, DmaAlignedMut<'static, [u8]>)
pub fn split( self, ) -> (DmaAlignedMut<'static, [DmaDescriptor]>, DmaAlignedMut<'static, [u8]>)
Consumes the buf, returning the descriptors and buffer.