Altera_Forum
Honored Contributor
14 years agoSerious Problem with DMA transfer.
Guys,
I have a desperate problem on my hand. Using DMA to do burst transfers from DDR to on-chip RAM. Using the reference code as shown below. Searched all the forums and confirmed people using the same NIOS code and succesfully making the transfer. Please help Code: int main() { int i,rc; unsigned int On_chip_SRAM_base_dma= 0x41030000; unsigned int DDR_write_OFFSET_ADDRESS_dma=0x00000500; int data_dma[4]={2882343476,4020983416, 9867509251, 6945207616}; unsigned long *sram_ptr2=(unsigned short*)On_chip_SRAM_base_dma; printf("Hello from Nios II!\n"); printf("Testing DMA transfer from DDR to SRAM\n"); for (i=0;i<4;i++){ IOWR(ALTMEMDDR_BASE,DDR_write_OFFSET_ADDRESS_dma + i, data_dma);printf("data: %08x is correctly written to memory offset on ddr: %08x \n",data_dma,DDR_write_OFFSET_ADDRESS_dma+i); } for(i=0;i<4;i++){ read_data1=iord(altmemddr_base,ddr_write_offset_address_dma+i);
printf("read %08x from address %08x on ddr\n",read_data1,(DDR_write_OFFSET_ADDRESS_dma+ i)); } // DMA code alt_dma_txchan txchan; alt_dma_rxchan rxchan; void *tx_data= (void*)DDR_write_OFFSET_ADDRESS_dma; void *rx_buffer= (void*)On_chip_SRAM_base_dma; /* Create the transmit channel */ if ((txchan = alt_dma_txchan_open("/dev/dma_0")) == NULL) { printf ("Failed to open transmit channel\n"); exit (1); } else { printf("Transmit channel setup successful\n"); } /* Create the receive channel */ if ((rxchan = alt_dma_rxchan_open("/dev/dma_0")) == NULL) { printf ("Failed to open receive channel\n"); exit (1); } else { printf("Receive channel setup successful\n"); } /* Post the transmit request */ if ((rc = alt_dma_txchan_send (txchan, tx_data, 4 ,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 , 4, done, NULL)) < 0) { printf ("Failed to post read request, reason = %i\n", rc); exit (1); } /*while(1){ unsigned int status[32]= IOWR_ALTERA_AVALON_DMA_STATUS(0x41000000,0X00); if(status[0]=1){ prontf("VIOLA!!"); break; } } /* wait for transfer to complete */ while (!rx_done); printf ("Transfer successful!\n"); alt_dma_rxchan_close ("/dev/dma_0"); alt_dma_txchan_close ("/dev/dma_0"); //sram_ptr=On_chip_SRAM_base_dma; for(i=0;i<4;i++){ read_data3=*sram_ptr2;
printf("read %08x from address %08x ,read_data3,(On_chip_SRAM_base_dma+ i)); sram_ptr2++; } The results: Hello from Nios II! Testing DMA transfer from DDR to SRAM Data: abcd1234 is correctly written to memory offset on DDR: 00000500 Data: efab5678 is correctly written to memory offset on DDR: 00000501 Data: 4c263e03 is correctly written to memory offset on DDR: 00000502 Data: 9df77540 is correctly written to memory offset on DDR: 00000503 Read abcd1234 from address 00000500 on DDR Read efab5678 from address 00000501 on DDR Read 4c263e03 from address 00000502 on DDR Read 9df77540 from address 00000503 on DDR Transmit channel setup successful Receive channel setup successful Transfer successful! Read 08080808 from address 41030000 //WORING RESULTS!:( Read 00000000 from address 41030001 Read 00000000 from address 41030002 Read 00000000 from address 41030003 Altera Gurus, Please come to the rescue!!!!!!!! Many Thanks. Appreciate your response!