--- Quote Start ---
originally posted by mumford@Apr 2 2007, 02:08 AM
thanks ellis,
i will try my design with the macros and avoid the api and see how it goes.
dma should be pretty easy, but the lack of complete documentation and design examples is slowing me down a lot.
peter
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22714)
--- quote end ---
--- Quote End ---
Hi Peter,
yes, I know what you mean. I add my code with some comments, maybe this helps a bit. Sorry, but I can't remember where I found it, it was somewhere here in the forum.
Purpose of this code: Write one line of a picture from memory to peripheral.
------------------------------------------------------# define ARRAY_SIZE 1280 // pixel(=byte) amount of one picture line# define SDRAM_MEM_ADD 0x00080000 // base address of picture memory part# define DMA_BASE DMA_0_BASE // this time the dma component is named dma_0
alt_u32 pic_mem_offset = 0x00000000; // address offset of actual line in memory
int do_dma(int counter)
{
int mode;
alt_u32 wadd;
wadd = SDRAM_MEM_ADD | pic_mem_offset; // offset changes after every picture line
// status bit must be reset
IOWR_ALTERA_AVALON_DMA_STATUS(DMA_BASE, 0);
// set read address (memory address in this case)
IOWR_ALTERA_AVALON_DMA_RADDRESS(DMA_BASE, (int)wadd);
// set write address (peripheral address in this case)
IOWR_ALTERA_AVALON_DMA_WADDRESS(DMA_BASE, STREAMING_OUTPUT_REGISTER_0_BASE);
// set dma length (dma component in SOPC builder allows byte, halfword and word, but byte should be enough and "width of DMA length register" is 11 => 2047 > 1280(=ARRAY_SIZE) fits!)
IOWR_ALTERA_AVALON_DMA_LENGTH(DMA_BASE, sizeof(unsigned char) * ARRAY_SIZE);
// meaning of registers is explained in Quartus II Handbook, Volume V: Embedded Peripherals, Chapter 4: DMA Controller Core with Avalon Interface
mode =
ALTERA_AVALON_DMA_CONTROL_BYTE_MSK |
ALTERA_AVALON_DMA_CONTROL_GO_MSK |
ALTERA_AVALON_DMA_CONTROL_LEEN_MSK |
ALTERA_AVALON_DMA_CONTROL_WCON_MSK |
0;
IOWR_ALTERA_AVALON_DMA_CONTROL(DMA_BASE,mode);
return 0;
}
//function call in interrupt handling routine:
...
do_dma(*count_ptr);
pic_mem_offset += 0x500; // ARRAY_SIZE
...
------------------------------------------------------
Any comments welcome!
<edit> sorry, thought the "*count_ptr" parameter isn't important for function "do_dma", but it is indeed.