Altera_Forum
Honored Contributor
14 years agoProblem with SGDMA in ISR
I have a custom SOPC component that acquires 512 bytes of sample data and then signals to the Nios processor that the data is ready via its irq_n line. In the Nios ISR I call alt_avalon_sgdma_construct_mem_to_mem_desc() and alt_avalon_sgdma_do_sync_transfer() to DMA the sample data from the custom SOPC component to a USB peripheral.
This works fine most of the time and I can log the sample data over the USB interface to a PC data file. However occasionally the system hangs. This occurs because somewhere in the chain one or more 512 byte data packets are getting lost i.e. the PC application has requested N data packets and has received less than N so is waiting for more packets, the SOPC component has sent N packets and is waiting for another request from the PC. The packet loss problem is quite rare, approximately 1 in every million packets is getting lost. To eliminate some possible sources of the problem I ran the system with the Nios processor responding to requests by DMAing dummy data from RAM (i.e. the custom component was removed). This worked fine so I concluded that the problem was with either the hdl of the custom component or the ISR handling. I then put the SOPC component back in, added an incrementing variable in the ISR and ran the debugger. When the system hung I broke the code and checked the ISR count. This showed that the ISR had been called the expected number of times but somehow the DMA is occasionally failing so the PC application had received less packets than the ISR count. Is there a problem with calling alt_avalon_sgdma_construct_mem_to_mem_desc() or alt_avalon_sgdma_do_sync_transfer() in an ISR? Can anyone explain what is going wrong to me?