Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-36940

Document interface for readDaq in ts_m2fpga project in Phase 2

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: ts_main_telescope
    • Labels:

      Description

      Experiment with LabVIEW FPGA code and C programming using the FPGA C API Interface created after the FPGA compilation. Experiment with the NiFpga_ReadFifoU16() and with the NiFpga_AcquireFifoReadElementsU16().

        Attachments

        1. acqFifoExample.c
          6 kB
        2. acqFunctionOutput.png
          acqFunctionOutput.png
          71 kB
        3. fifoReadExample.c
          5 kB

          Issue Links

            Activity

            Hide
            pcortes Patricio Cortes added a comment - - edited

            The following comments are related to my experimentation with NiFpga_ReadFifoU16() and NiFpga_AcquireFifoReadElementsU16().

            NiFpga_ReadFifoU16()

            1. Here is the documentation for this function: here
            2. 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).
            3. 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.
            4. 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.

            5. 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;
              

            6. 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.
            7. 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.
            8. I use the for loop to read the array of elements read from the FIFO.
            9. The fifoReadExample.c shows the code that I used for this experiment.

            NiFpga_AcquireFifoReadElementsU16()

            1. Here is the documentation for this function: here
            2. 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.
            3. 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.

            4. 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;
              

            5. 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.
            6. 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));
                 }

            7.  An image (acqFunctionOutput.png) is attached with a printed output of the code used for this function.
            8. The acqFifoExmple.c is the code I used for this experiment.
            Show
            pcortes Patricio Cortes 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.
            Hide
            ttsai Te-Wei Tsai added a comment -

            This ticket looks good.

            1. There is some mistakes in the code snippet comments. But it does not matter at this moment.
            2. Please help to clarify the returned memory region in "acquire" function is in stack or heap. And the OS can reallocate the memory after the releasing or not. There is the problem of memory leakage or not. I would like to have the clear demonstration or experiment for this. But you can do this in other ticket as well.

            Show
            ttsai Te-Wei Tsai added a comment - This ticket looks good. 1. There is some mistakes in the code snippet comments. But it does not matter at this moment. 2. Please help to clarify the returned memory region in "acquire" function is in stack or heap. And the OS can reallocate the memory after the releasing or not. There is the problem of memory leakage or not. I would like to have the clear demonstration or experiment for this. But you can do this in other ticket as well.

              People

              Assignee:
              pcortes Patricio Cortes
              Reporter:
              pcortes Patricio Cortes
              Reviewers:
              Te-Wei Tsai
              Watchers:
              Patricio Cortes, Te-Wei Tsai
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Jenkins

                  No builds found.