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
I assume your settings in SOPC builder and pins assigment are correct. I have a litte program in Nios to test SDRAM with DMA. Look through and let me know.
Rename main.doc to main.c Sean - Altera_Forum
Honored Contributor
Stop posting the same question multiple times. If someone can help you, you will get an answer.
Multiple posts are removed by the administrators. - Altera_Forum
Honored Contributor
[email protected] (http://www.alteraforum.com/forum/member.php?u=35844): Hi. I tried your code but still the same. It manages to run until "Before DMA" part, then, it stops. Should it be the problem with my setting in SOPC Builder? I attached my SOPC here.
- Altera_Forum
Honored Contributor
In SOPC, I have SDRAM is for read from and onchip_write is write data out. Connect to DMA. In Nios program, there are src and dst. src to SDRAM_BASE and dst is connected to ONCHIP_WRITE.
Try this again. It should work. I also include the result from my output. rename main.doc to main.c You can see in SOPC, SDRAM base address memory is 0x1000000 and Onchip memory is 0x2020000. Sean - Altera_Forum
Honored Contributor
I will try it. Besides, I cant see the SOPC picture because it is too small. Can you please enlarge it? Thanks for the help.
- Altera_Forum
Honored Contributor
I don't know why. You should download it and open with Microsoft Picture.
- Altera_Forum
Honored Contributor
Yeah, did it but still cannot see. What is the clock rate for your DMA? is there any setting to do before using DMA? I just 32-bit and the rest is default for DMA. then i connect the dma_write and read to sdram and onchip. for me, i connect both dma_write and read to sdram and onchip. but yours is connecting read to sdram and write to onchip.
- Altera_Forum
Honored Contributor
besides, where do you set your reset vector and exceptional vector? and in the Nios IDE > System Library Properties, what do you set for Program Memory, Read-only data memory, read/write data memory, heap memory and stack memory? thanks and sorry for the trouble.
- Altera_Forum
Honored Contributor
To do this way, because you need to verify the data from sdram (read) to onchip (write) is working or not. memory to memory.
- Altera_Forum
Honored Contributor
Ok, I am trying now. Hopefully it works.