Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

DMA transfer

Altera_Forum
Honored Contributor II
1,243 Views

I copied an example from the Altera Nios II Software Developer’s Handbook, chapter "Using DMA Devices" using memory to memory data transfer. I modified the code a bit ..... 

 

The good thing is that there are no error messages, but the dma-transfer does not complete by setting the rx_done flag.  

Perhaps a beginners fault? Can somebody help me? 

 

Freeck 

 

# 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/dma_0")) == NULL) 

printf ("Failed to open transmit channel\n"); 

exit (1); 

/* Create the receive channel */ 

if ((rxchan = alt_dma_rxchan_open("/dev/dma_0")) == 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; 

}
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
500 Views

I&#39;ve just tried to run your code on the 1C20 full design from the Nios II 1.1 kit. That worked fine. What hardware/version of the kit are you using?

0 Kudos
Altera_Forum
Honored Contributor II
500 Views

I use the same kit, and using web edition 4.2 of QII.  

Perhaps the problem has something to do with the SoPC design ? 

I have added a dma channel called dma_0 to the example project "my-first-nios". You too? 

 

PS: is it possible to add an attachment to this reply perhap I could sent the design to you.....
0 Kudos
Altera_Forum
Honored Contributor II
500 Views

I was just using the "full" example design that comes with the kit. The one change I did have to make to your code was to chane the device name to /dev/dma to match what was used in the example. 

 

Try comparing and contrasting these example with what you have to see if you can see the problem. It could be that you haven&#39;t connected the DMA read and write master ports so that it can access the memories you&#39;re tying to use.
0 Kudos
Altera_Forum
Honored Contributor II
500 Views

You are completely right!  

I compiled the full featured version and everything worked well; after adapting my own design everything seems to work well. I had indeed forget to connect the read/write-master to the avalon-slave port. 

 

Thanks for the hint.
0 Kudos
Reply