Forum Discussion
Direct Memory Access (DMA)
hello, i am having a problem with using dma. my dma seems like never finish the transaction because it cannot call the done function and keep on looping in the while(!rx_done). I dont know why. can anyone please help? i posted a lot on the forum but seem like no one is helping. thanks!
my code: --- Quote Start --- # include <stdio.h># include <stdlib.h># include <stddef.h># include <string.h># include <system.h># include <io.h># include <alt_types.h># include "sys/alt_dma.h"# include "sys/alt_dma_dev.h"# include "sys/alt_cache.h"# include "sys/alt_alarm.h"# include "alt_types.h" static volatile int rx_done = 0; /* * Callback function that obtains notification that the data * is received. */ static void done (void* handle, void* data) { rx_done++; } /* * */ int main (int argc, char* argv[], char* envp[]) { int rc,i; alt_dma_txchan txchan; alt_dma_rxchan rxchan; void* tx_data = (void*) SDRAM_BASE+0x200000; /* pointer to data to send */ void* rx_buffer = (void*) SDRAM_BASE+0x201000; /* pointer to rx buffer */ for(i=0;i<1024;i++) { IOWR(tx_data, i, i); } for(i=0;i<1024;i++) { printf("%d\n", IORD(tx_data, i)); } /* Create the transmit channel */ if ((txchan = alt_dma_txchan_open(DMA_NAME)) == NULL) { printf ("Failed to open transmit channel\n"); exit (1); } /* Create the receive channel */ if ((rxchan = alt_dma_rxchan_open(DMA_NAME)) == NULL) { printf ("Failed to open receive channel\n"); exit (1); } /* Post the transmit request */ if ((rc = alt_dma_txchan_send (txchan, tx_data, 128, NULL, NULL)) < 0) { printf ("Failed to post transmit request, reason = %i\n", rc); exit (1); } /* Post the receive request */ if ((rc = alt_dma_rxchan_prepare (rxchan, rx_buffer, 128, done, NULL)) < 0) { printf ("Failed to post read request, reason = %i\n", rc); exit (1); } /* wait for transfer to complete */ while (!rx_done); printf ("Transfer successful!\n"); return 0; } --- Quote End ---15 Replies
- Altera_Forum
Honored Contributor
[email protected] (http://www.alteraforum.com/forum/member.php?u=35844): Hi, really thank a lot! now it is done successfully. really thank you so much. i did it for months and finally it is done... really thank you very much! a great help!
- Altera_Forum
Honored Contributor
You're welcome.
- Altera_Forum
Honored Contributor
Hi, I have a question here. I tried to use DMA to transfer data within the same SDRAM, src = SDRAM + 0x200000 and dst = SDRAM_BASE + 0x300000. However, the data in the src and dst is different after transmission. the receive channel seems like cannot write into dst.
- Altera_Forum
Honored Contributor
If you have a data cache on the CPU it's possible that the start and/or destination block are cached, and therefore the CPU reads and writes data from it's cache rather than the SDRAM. You have several ways around this:[list]
[*]Disable the data cache, or use the Nios II/e core [*]Do a cache flush on the source block before the dma transfer, and a cache invalidate on the destination block after [*]Bypass the cache when accessing the source and destination block, either though the IORD/IOWR macros, or by modifying the pointers with alt_remap_uncached()[/list] - Altera_Forum
Honored Contributor
could anyone repost the picture bigger? or write what are the names of those components?