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 Example HAL

Altera_Forum
Honored Contributor II
1,078 Views

Have anyone a good sample how works with DMA in HAL mode? I need something  

like to project Streaming with irq and streaming transfer. Thank you so much for any help http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
374 Views

I&#39;ve made it next: 

 

unsigned int *p = (unsigned int*)(SDRAM_BASE + 0xF4240); 

void *pdma = (void*) SD_DMA_BASE; 

 

void isr_dma(void* context, alt_u32 id) 

if ((IORD_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE))&&0x01) { 

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); 

 

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); 

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); 

............... 

}
0 Kudos
Altera_Forum
Honored Contributor II
374 Views

Just to clarify, that&#39;s _not_ an example of the use of the DMA HAL - it&#39;s a demonstration of how to do a DMA transaction with direct register reads and writes. 

 

By the way, instead of  

 

if ((IORD_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE)) && 0x01) 

 

you want: 

 

if ((IORD_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE)) & 0x01) 

 

even better: 

 

if ((IORD_ALTERA_AVALON_DMA_STATUS(SD_DMA_BASE))&  

ALTERA_AVALON_DMA_STATUS_DONE_MSK)
0 Kudos
Reply