Show
added a comment - - edited The following comments are related to my experimentation with NiFpga_ReadFifoU16() and NiFpga_AcquireFifoReadElementsU16() .
NiFpga_ReadFifoU16()
Here is the documentation for this function: here
A FIFO was created in the FPGA target, called daqFiFO , with a U16 data type defined, 9 elements to store, and configured as a target-to-host DMA FIFO, which means the elements will be written in the FPGA target and read by the Real Time target (host).
The data written in the FIFO is simulated in the FPGA VI as a sequence of numbers from 1 to 9, then 10 to 18, and so on. This simulated data is for debugging purposes only.
The FPGA Interface C API includes this Read FIFO function to read U16 elements:
NiFpga_ReadFifoU16(NiFpga_Session session, uint32_t fifo, uint16_t* data, size_t numberOfElements, uint32_t timeout, size_t* elementsRemaining)
where session handles a currently open session, fifo is the target-to-host FIFO from which to read, data outputs the data that was read, numberOfElements is the number of elements to read, timeout is the timeout in milliseconds, and elementsRemaining outputs the number of elements remaining in the host memory part of the DMA FIFO.
The variables declared will be:
uint16_t data[ 9 ] = { 0 }; //declare pointer to data
size_t numberOfElements;uint32_t timeout;
size_t elementsRemaining = 0 ;
NiFpga_Bool fifoStatus = 0 ;
The variable fifoStatus will read the value of an FPGA boolean indicator called dataFifoFull using the function NiFpga_ReadBool() . If its value is TRUE the daqFIFO is full and data is not written to the FIFO until space becomes available. The following data that is trying to write into the FIFO will be lost until there is new space available. The C/C++ developer can use this to determine if the code reads data slower than the FPGA adds elements into the FIFO, then make a decision.
The design used in this experiment was to define no elements to read (numberOfElements = 0) and use the NiFpga_ReadFifoU16() to read the elements remaining only. If this value is greater or equal to 9 the NiFpga_ReadFifoU16() is used again with the numberOfElements = 9.
I use the for loop to read the array of elements read from the FIFO.
The fifoReadExample.c shows the code that I used for this experiment.
NiFpga_AcquireFifoReadElementsU16()
Here is the documentation for this function: here
According to the documentation, this function prevents the need to copy the contents of elements from the host memory buffer to a separate user-allocated buffer before reading.
The FPGA Interface C API includes this Acquire FIFO Read Elements function:
NiFpga_AcquireFifoReadElementsU16(NiFpga_Session session, uint32_t fifo, uint16_t** elements, size_t elementsRequested, uint32_t timeout, size_t* elementsAcquired, size_t* elementsRemaining)
where session handles a currently open session, fifo is the target-to-host FIFO from which to read, data outputs a pointer to the elements acquired, elementsRequested is the requested number of elements, timeout is the timeout in milliseconds, elementsAcquired is the actual number of elements acquired, which may be less than the requested number, elementsRemaining outputs the number of elements remaining in the host memory part of the DMA FIFO.
The variables declared will be:
uint16_t* pData = NULL; //declare pointer to data
size_t numberOfElements;
uint32_t timeout;
size_t elementsRemaining = 0 ;
size_t elementsAcquired = 0 ;
NiFpga_Bool fifoStatus = 0 ;
The design used in this experiment was to define no elements to read (numberOfElements = 0) and use the NiFpga_AcquireFifoReadElementsU16() to read the elements remaining only. If this is greater or equal to 9 the NiFpga_AcquireFifoReadElementsU16() was used again with the numberOfElements = 9.
To get the values from FIFO I use a for loop, like this:
for ( int i= 0 ; i<numberOfElements; i++) {
printf( "%d\t" , *(pData+i));
}
An image (acqFunctionOutput.png) is attached with a printed output of the code used for this function.
The acqFifoExmple.c is the code I used for this experiment.
The following comments are related to my experimentation with NiFpga_ReadFifoU16() and NiFpga_AcquireFifoReadElementsU16().
NiFpga_ReadFifoU16()
NiFpga_ReadFifoU16(NiFpga_Session session, uint32_t fifo, uint16_t* data, size_t numberOfElements, uint32_t timeout, size_t* elementsRemaining)
where session handles a currently open session, fifo is the target-to-host FIFO from which to read, data outputs the data that was read, numberOfElements is the number of elements to read, timeout is the timeout in milliseconds, and elementsRemaining outputs the number of elements remaining in the host memory part of the DMA FIFO.
size_t numberOfElements;uint32_t timeout;
NiFpga_AcquireFifoReadElementsU16()
NiFpga_AcquireFifoReadElementsU16(NiFpga_Session session, uint32_t fifo, uint16_t** elements, size_t elementsRequested, uint32_t timeout, size_t* elementsAcquired, size_t* elementsRemaining)
where session handles a currently open session, fifo is the target-to-host FIFO from which to read, data outputs a pointer to the elements acquired, elementsRequested is the requested number of elements, timeout is the timeout in milliseconds, elementsAcquired is the actual number of elements acquired, which may be less than the requested number, elementsRemaining outputs the number of elements remaining in the host memory part of the DMA FIFO.
size_t numberOfElements;
uint32_t timeout;
}