pub struct ReadFifo<T: NativeFpgaType> { /* private fields */ }
Expand description
A FIFO that can be read from.
Implementations§
Source§impl<T: NativeFpgaType + 'static> ReadFifo<T>
impl<T: NativeFpgaType + 'static> ReadFifo<T>
pub const fn new(address: u32) -> Self
Sourcepub fn read(
&mut self,
session: &impl FifoInterface<T>,
timeout: Option<Duration>,
data: &mut [T],
) -> Result<usize, FPGAError>
pub fn read( &mut self, session: &impl FifoInterface<T>, timeout: Option<Duration>, data: &mut [T], ) -> Result<usize, FPGAError>
Read from the FIFO into the provided buffer. The size of the read is determined by the size of the data slice.
The timeout can be None
to indicate an infinite timeout or a Duration
to indicate a timeout.
Returns the number of elements still to be read.
§Example
use std::time::Duration;
let session = Session::new("main.lvbitx", "sig", "RIO0").unwrap();
let mut fifo = ReadFifo::<u64>::new(1);
let mut buffer = [0u64; 10];
let remaining = fifo.read(&session, Some(Duration::from_millis(100)), &mut buffer).unwrap();
Sourcepub fn get_read_region<'d, 's: 'd>(
&'d mut self,
session: &'s impl FifoInterface<T>,
elements: usize,
timeout: Option<Duration>,
) -> Result<(FifoReadRegion<'s, 'd, T>, usize), FPGAError>
pub fn get_read_region<'d, 's: 'd>( &'d mut self, session: &'s impl FifoInterface<T>, elements: usize, timeout: Option<Duration>, ) -> Result<(FifoReadRegion<'s, 'd, T>, usize), FPGAError>
Provides a mechanism to read from the FIFO without copying the data.
This function returns a read region. This contains a view of the data in the DMA driver. It also returns the number of elements remaining in the buffer.
The timeout can be None
to indicate an infinite timeout or a Duration
to indicate a timeout.
To write to the FPGA you must overwrite the elements in the region and then drop it.
§Example
let session = Session::new("main.lvbitx", "sig", "RIO0").unwrap();
let mut fifo = ReadFifo::<u64>::new(1);
let (read_region, remaining) = fifo.get_read_region(&session, 1000, None).unwrap();
// Do something with the data in the read region.
println!("{:?}", read_region.elements);
// Drop the read region to commit the data back to the DMA driver.
drop(read_region);
Sourcepub fn elements_available(
&self,
session: &impl FifoInterface<T>,
) -> Result<usize, FPGAError>
pub fn elements_available( &self, session: &impl FifoInterface<T>, ) -> Result<usize, FPGAError>
Returns the number of elements available to read.
Warning: This achieves this by reading zero elements from the FIFO so it will start the FIFO if stopped.