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++

why DMA not done?

Altera_Forum
Honored Contributor II
1,083 Views

Hi, 

I have problem to use DMA to transfer data from memory to memory, also memory to peripherals. Each time I start a DMA, it is not done, the DONE bit will not be set, and my problem keep in busy waiting the bit. Here is my program, I think there is no problem. Anyone can help? 

 

#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_cache.h" #include"sys/alt_alarm.h" #include"alt_types.h" static volatile int txrx_done = 0; //callback function when DMA transfer done static void txrxDone(void * handle, void * data) { txrx_done = 1; } void initMEM(void* base_addr,int len) { int i; for (i=0;i<len;i++) { IOWR_16DIRECT(base_addr,i,i); } } static alt_16 txbuff; static alt_16 rxbuff; int main() { int i; printf("testing sdram to sdram : DMA operation\n"); initMEM((void*)txbuff, 0x10); memset(rxbuff, 0, sizeof(rxbuff)); printf("content of txbuff:before DMA operation\n"); for (i=0;i<0x10;i++) { printf("%d: %x\n",i,IORD_16DIRECT(txbuff,i)); } printf("content of rxbuff:before DMA operation\n"); for (i=0;i<0x10;i++) { printf("%d: %x\n",i,IORD_16DIRECT(rxbuff,i)); } int rc; //request alt_dma_txchan txchan; alt_dma_rxchan rxchan; void* tx_data = (void*)alt_remap_uncached(txbuff, sizeof(txbuff)); /* pointer to data to send */ void* rx_data = (void*)alt_remap_uncached(rxbuff, sizeof(rxbuff)); /* pointer to rx buffer */ /* Create the transmit channel */ if ((txchan = alt_dma_txchan_open("/dev/dma_3")) == NULL) { printf ("Failed to open transmit channel\n"); exit(1); } /* Create the receive channel */ if ((rxchan = alt_dma_rxchan_open("/dev/dma_3")) == NULL) { printf ("Failed to open receive channel\n"); exit(1); } /* Post the transmit request */ if ((rc = alt_dma_txchan_send (txchan, tx_data, 0x20, 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_data, 0x20, txrxDone, NULL)) < 0) { printf ("Failed to post read request, reason = %i\n", rc); exit (1); } /* wait for transfer to complete */ while (!txrx_done); printf ("Transfer successful!\n"); printf("content of rxbuff:after DMA operation\n"); for (i=0;i<0x10;i++) { printf("%d: %x\n",i,IORD_16DIRECT(txbuff,i)); } printf("content of txbuff:after DMA operation\n"); for (i=0;i<0x10;i++) { printf("%d: %x\n",i,IORD_16DIRECT(rxbuff,i)); } alt_dma_rxchan_close (rxchan); alt_dma_txchan_close (txchan); return 0; }  

 

Also I attached the qsys file.
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
385 Views

Have you tried simulation?

0 Kudos
Reply