Forum Discussion
About DMA problem..please help me
hi all
I have try the altera memory test project with Nios II IDE.. but always display "-Testing memory using DMA"... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif the dma might be already open.. and didn`t display "Memory at 0x%X Okay"....... so...I found the code at nios forum...it should be work but it always display"wait for transfer to complete"...why? look like the same problem with memory test !? I use Quartus II 5.1 SP2 & Nios II IDE 5.1 SP1 the exception address is sram_0 at SOPC Builder the program memory & .rodata & .rwdata & heap memory & stack memory are sdram_0 and I sure I have connect the DMA read & write master with sdram_0 & avalon tristate bridge in the SOPC builder this is the code...please help me thanks.... # include <stdio.h># include "system.h"# include "sys/alt_dma.h"# include "alt_types.h" /* Create the transmit channel */ static volatile int rx_done = 0; /* ready handler*/ static void done (void* handle, void* data) { rx_done++; } int main (int argc, char* argv[], char* envp[]) { int rc; alt_u8 Inbuf[1024], Outbuf[1024]; alt_dma_txchan txchan; alt_dma_rxchan rxchan; void* tx_data = (void*) &Inbuf[0]; /* pointer to data to send */ void* rx_buffer = (void*) &Outbuf[0]; /* pointer to rx buffer */ if ((txchan = alt_dma_txchan_open("/dev/avalon_dma")) == NULL) { printf ("Failed to open transmit channel\n"); exit (1); } /* Create the receive channel */ if ((rxchan = alt_dma_rxchan_open("/dev/avalon_dma")) == NULL) { printf ("Failed to open receive channel\n"); exit (1); } /* Post the transmit request */ if ((rc = alt_dma_txchan_send (txchan,tx_data,1024,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,1024,done,NULL)) < 0) { printf ("Failed to post read request, reason = %i\n", rc); exit (1); } /* wait for transfer to complete */ printf ("wait for transfer to complete\n"); while (!rx_done); printf("Transfer successful!\n"); return 0; }30 Replies
- Altera_Forum
Honored Contributor
thank you so much for the code.
- Altera_Forum
Honored Contributor
Hello aprado, do you know how to configure DMA using VHDL in Quartus before we can run the code in NiosII? thanks!
- Altera_Forum
Honored Contributor
Hello, using the Quartus you can instantiate it inside SOPC builder and set all the parameters you need
- Altera_Forum
Honored Contributor
thanks. may i know how? if possible, can you pls provide a simple example? thanks!
- Altera_Forum
Honored Contributor
Look at the first post of this thread, it is very detailed.
click on the icon in the left side of the ? at quartus to open sopc builder - Altera_Forum
Honored Contributor
i had done the sopc part. but i am stuck with the vhdl code in Quartus II. i thought we have to write the VHDL in Quartus II in order to be compatible with the sopc. only then, we can run the C code in nios2 ide. am i right? pls advise if i am wrong.
- Altera_Forum
Honored Contributor
--- Quote Start --- i had done the sopc part. but i am stuck with the vhdl code in Quartus II. i thought we have to write the VHDL in Quartus II in order to be compatible with the sopc. only then, we can run the C code in nios2 ide. am i right? pls advise if i am wrong. --- Quote End --- SOPC Builder will generate the VHDL for the entire system which you then compile using Quartus II (as apposed to writing the logic manually). Once you have a programming file created by Quartus II you download the file to the FPGA and then you can communicate with the Nios II processor inside your SOPC Builder system. - Altera_Forum
Honored Contributor
Hi BadOmen, thanks for the reply! really? this is nice! i always thought i have to write the code manually. May I know how to generate the VHDL for the entire system? Thanks!
- Altera_Forum
Honored Contributor
I recommend reading this tutorial, it'll explain all the steps:
http://www.altera.com/literature/tt/tt_nios2_hardware_tutorial.pdf http://www.altera.com/literature/tt/niosii_hw_dev_tutorial.zip - Altera_Forum
Honored Contributor
why my system stuck at:
--- Quote Start --- while (!txrx_done); printf ("Transfer successful!\n"); --- Quote End ---