pub struct DmaRxStreamBuf { /* private fields */ }
unstable
only.Expand description
DMA Streaming Receive Buffer.
This is a contiguous buffer linked together by DMA descriptors, and the buffer is evenly distributed between each descriptor provided.
It is used for continuously streaming data from a peripheral’s FIFO.
It does so by maintaining sliding window of descriptors that progresses when you call DmaRxStreamBufView::consume.
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) -> NULL
A (full) -> B (empty) -> C (empty) -> D (empty) -> NULL
A (full) -> B (full) -> C (empty) -> D (empty) -> NULL
A (full) -> B (full) -> C (full) -> D (empty) -> NULL
As you call DmaRxStreamBufView::consume the list (approximately) progresses like so:
A (full) -> B (full) -> C (full) -> D (empty) -> NULL
B (full) -> C (full) -> D (empty) -> A (empty) -> NULL
C (full) -> D (empty) -> A (empty) -> B (empty) -> NULL
D (empty) -> A (empty) -> B (empty) -> C (empty) -> NULL
If all the descriptors fill up, the DmaRxInterrupt::DescriptorEmpty interrupt will fire and the DMA will stop writing, at which point it is up to you to resume/restart the transfer.
Note: This buffer will not tell you when this condition occurs, you should check with the driver to see if the DMA has stopped.
When constructing this buffer, it is important to tune the ratio between the chunk size and buffer size appropriately. Smaller chunk sizes means you receive data more frequently but this means the DMA interrupts (DmaRxInterrupt::Done) also fire more frequently (if you use them).
See DmaRxStreamBufView for APIs available whilst a transfer is in progress.
Implementations§
Source§impl DmaRxStreamBuf
impl DmaRxStreamBuf
Sourcepub fn new(
descriptors: &'static mut [DmaDescriptor],
buffer: &'static mut [u8],
) -> Result<Self, DmaBufError>
pub fn new( descriptors: &'static mut [DmaDescriptor], buffer: &'static mut [u8], ) -> Result<Self, DmaBufError>
Creates a new DmaRxStreamBuf evenly distributing the buffer between the provided descriptors.
Sourcepub fn split(self) -> (&'static mut [DmaDescriptor], &'static mut [u8])
pub fn split(self) -> (&'static mut [DmaDescriptor], &'static mut [u8])
Consume the buf, returning the descriptors and buffer.