Yang Posted April 2, 2014 Report Posted April 2, 2014 Dear All, I have a question regarding to FPGA FIFO, specifically DMA from Host to Target (FPGA). As an Example, I have a 1D array containing 10x2000 elements stored inside the host side Buffer. At the FPGA side, I want to use 'host to target-read' to read fixed amount of elements from the host side buffer, for example exact 2000 elements. Moreover I want to hold onto the data (2000 elements) for a certain amount of time (example 10s) before reading again 2000 elements from the buffer. Does anyone have a clue how to do this? Thank you so much! Yang Quote
Tim_S Posted April 2, 2014 Report Posted April 2, 2014 Have you looked at the example "DMA Multichannel Acquisition - cRIO"? Quote
ned Posted April 2, 2014 Report Posted April 2, 2014 What do you want to do with those 2000 elements during the 10s? Storing a 2000-element array on the FPGA in logic may not be a good use of space. Also, you can only ever read one element at a time from the DMA FIFO on the FPGA, so you'll need a loop that iterates 2000 times to read all 2000 elements. Depending on what you want to do with that data, you may want to read from the DMA FIFO into a memory block, then read values out of the memory block in a separate loop. Quote
Jordan Kuehn Posted April 3, 2014 Report Posted April 3, 2014 Also, you can only ever read one element at a time from the DMA FIFO on the FPGA, so you'll need a loop that iterates 2000 times to read all 2000 elements. You can read multiple elements from a DMA FIFO. 1 Quote
Neil Pate Posted April 3, 2014 Report Posted April 3, 2014 Just to add to Jordan's post for those that don't know. His picture shows an efficient way of reading from the DMA FIFO, first check to see if there are enough elements by requesting zero with a zero timeout, this will return the number elements remaining. Then only perform the actual read if the number of available elements is equal to (or more than) what you want. My understanding of this necessity is that although the transfer occurs via DMA, if there are not enough elements yet then the CPU actually polls (using a lot of resource) until the number of elements is achieved, and this can really kill performance. 1 Quote
Tim_S Posted April 3, 2014 Report Posted April 3, 2014 My understanding of this necessity is that although the transfer occurs via DMA, if there are not enough elements yet then the CPU actually polls (using a lot of resource) until the number of elements is achieved, and this can really kill performance. You can request 0 elements from the DMA to obtain the number of elements waiting. Quote
Neil Pate Posted April 3, 2014 Report Posted April 3, 2014 You can request 0 elements from the DMA to obtain the number of elements waiting. Yes, I did mention something like that in the line before. Quote
Tim_S Posted April 3, 2014 Report Posted April 3, 2014 Yes, I did mention something like that in the line before. Oops... missed that. Sorry, need more caffeine this morning. Quote
Jordan Kuehn Posted April 3, 2014 Report Posted April 3, 2014 Just to add to Jordan's post for those that don't know. His picture shows an efficient way of reading from the DMA FIFO, first check to see if there are enough elements by requesting zero with a zero timeout, this will return the number elements remaining. Then only perform the actual read if the number of available elements is equal to (or more than) what you want. My understanding of this necessity is that although the transfer occurs via DMA, if there are not enough elements yet then the CPU actually polls (using a lot of resource) until the number of elements is achieved, and this can really kill performance. A picture says a thousand words , but yes I included both parts to demonstrate a good way to check if the elements exist before attempting to read them. Regarding your last point, I would suggest at least employing a timeout if someone isn't going to do the initial check. The host loop should be structured in such that it doesn't need data every iteration (if you are looking for a chunk of buffered data), or manually provide your own polling by placing something like what I have in the picture in a loop with a timing element. Quote
Neil Pate Posted April 3, 2014 Report Posted April 3, 2014 A picture says a thousand words , but yes I included both parts to demonstrate a good way to check if the elements exist before attempting to read them. Regarding your last point, I would suggest at least employing a timeout if someone isn't going to do the initial check. The host loop should be structured in such that it doesn't need data every iteration (if you are looking for a chunk of buffered data), or manually provide your own polling by placing something like what I have in the picture in a loop with a timing element. The point I was trying to get across (unsuccessfully it seems!) is that even with a timeout a lot of CPU is used up waiting for the DMA buffer to have enough elements. This is probably contrary to what most people would expect. Quote
Jordan Kuehn Posted April 3, 2014 Report Posted April 3, 2014 The point I was trying to get across (unsuccessfully it seems!) is that even with a timeout a lot of CPU is used up waiting for the DMA buffer to have enough elements. This is probably contrary to what most people would expect. I understood, but yes some might not. The point I was trying to get across is that in that situation a timeout is better than nothing, i.e. waiting/polling the entire time for the number of elements to become available. Either way, the picture is the better approach and allows the loop to do other things. Quote
Neil Pate Posted April 3, 2014 Report Posted April 3, 2014 Either way, the picture is the better approach and allows the loop to do other things. Absolutely! Quote
ned Posted April 3, 2014 Report Posted April 3, 2014 This is all fine and good, but the poster specifically said that they're using a "Host-to-Target" DMA FIFO, which means the DMA FIFO Read is on the FPGA side, where it is only possible to read a single element at a time, so yes, a loop is required. Quote
Jordan Kuehn Posted April 3, 2014 Report Posted April 3, 2014 This is all fine and good, but the poster specifically said that they're using a "Host-to-Target" DMA FIFO, which means the DMA FIFO Read is on the FPGA side, where it is only possible to read a single element at a time, so yes, a loop is required. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.