ni_fpga_interface/session/
fifo_control.rs

1//! Provides the low level interface to the FPGA FIFOs.
2//!
3//! In general we recommend using the [`crate::fifos`] module for a higher level interface.
4
5use crate::error::{to_fpga_result, Result};
6use crate::nifpga_sys::*;
7use libc::size_t;
8
9use super::Session;
10
11impl Session {
12    /// Specify the depth of the host memory part of the FIFO.
13    ///
14    /// Returns the actual size configured which may be larger than the request.
15    pub fn configure_fifo(&self, fifo: FifoAddress, requested_depth: usize) -> Result<usize> {
16        let mut actual_depth: size_t = 0;
17        let result = unsafe {
18            NiFpga_ConfigureFifo2(
19                self.handle,
20                fifo,
21                requested_depth,
22                &mut actual_depth as *mut size_t,
23            )
24        };
25        to_fpga_result(actual_depth, result)
26    }
27
28    /// Start the FIFO.
29    pub fn start_fifo(&self, fifo: FifoAddress) -> Result<()> {
30        let result = unsafe { NiFpga_StartFifo(self.handle, fifo) };
31        to_fpga_result((), result)
32    }
33
34    /// Stop the FIFO.
35    pub fn stop_fifo(&self, fifo: FifoAddress) -> Result<()> {
36        let result = unsafe { NiFpga_StopFifo(self.handle, fifo) };
37        to_fpga_result((), result)
38    }
39
40    /// Releases previously acquired FIFO elements.
41    /// The FPGA target cannot read elements acquired by the host.
42    /// Therefore, the host must release elements after acquiring them.
43    ///
44    /// Always release all acquired elements before closing the session.
45    /// Do not attempt to access FIFO elements after the elements are released or the session is closed.
46    pub fn release_fifo_elements(
47        &self,
48        fifo: FifoAddress,
49        number_of_elements: usize,
50    ) -> Result<()> {
51        let result = unsafe { NiFpga_ReleaseFifoElements(self.handle, fifo, number_of_elements) };
52        to_fpga_result((), result)
53    }
54
55    /// Gets the endpoint number of a peer-to-peer FIFO.
56    pub fn get_peer_to_peer_fifo_endpoint(&self, fifo: FifoAddress) -> Result<PeerToPeerEndpoint> {
57        let mut endpoint: PeerToPeerEndpoint = 0;
58        let result = unsafe { NiFpga_GetPeerToPeerFifoEndpoint(self.handle, fifo, &mut endpoint) };
59        to_fpga_result(endpoint, result)
60    }
61}