Altera_Forum
Honored Contributor
21 years agoDMA transfer
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; }