Forum Discussion
Altera_Forum
Honored Contributor
21 years agoDMA transfer length problem
http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/wink.gif There is a problem in transferring data from SDRAM to my device ( avalon slave device ) . I use the DMA component p...
Altera_Forum
Honored Contributor
21 years agoTry to use io.h's functions IOWR and IORD as next:
unsigned int *p = (unsigned int*)(SDRAM_BASE + 0xF4240); void *pdma = (void*) SD_DMA_BASE; //Interrupt function if need void isr_dma(void* context, alt_u32 id) { if ((IORD_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE))&&ALTERA_AVALON_DMA_STATUS_DONE_MSK) { IOWR_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE, 0); IOWR_ALTERA_AVALON_DMA_RADDRESS(SD_DMA_BASE, (int)p); IOWR_ALTERA_AVALON_DMA_WADDRESS(SD_DMA_BASE, SD_BASE); IOWR_ALTERA_AVALON_DMA_LENGTH(SD_DMA_BASE, 40); IOWR_ALTERA_AVALON_DMA_CONTROL(SD_DMA_BASE, 0x02DC); } } int main(void) { unsigned int *p = (unsigned int*)(SDRAM_BASE + 0xF4240); ............. //Write to memory something (in this case 10 words) for (i=0, pattern=0xFFAAFFAA; i<10; i++) { IOWR_32DIRECT(p+i, 0, pattern); } //Registration of interrupt function if it need alt_irq_register(SD_DMA_IRQ, pdma, isr_dma); //Send to some device 10 words IOWR_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE, 0); IOWR_ALTERA_AVALON_DMA_RADDRESS(SD_DMA_BASE, (int)p); //Pointer to memory IOWR_ALTERA_AVALON_DMA_WADDRESS(SD_DMA_BASE, SD_BASE); //Pointer to your device IOWR_ALTERA_AVALON_DMA_LENGTH(SD_DMA_BASE, 40); //Sending 10 words (1 word == 4 bytes) IOWR_ALTERA_AVALON_DMA_CONTROL(SD_DMA_BASE, 0x02DC); //See description of dma control register ............... }