Forum Discussion
Altera_Forum
Honored Contributor
15 years agoI manage to get DMA transfer complete. but rewrite the code, and it only copy from a single address to buffer.(more like a streaming).
I read from the documentation that this method is supposed to be for peripheral to memory copy..however i give the input to it my 2nd SDRAM base address - which i name it mem_sdram (im using de2-70). So im assuming that it supposed to be copying only the first data to buffer which i declare earlier. However after the transfer finish..i check the value inside buffer.Its not the same as in mem_sdram. here is the output:
Testing DMA!
readaddress =4000000, length =0, status =0, control =1f9
dma transfer: 1ms
Transaction complete
0:3
1:0
2:0
3:0
it shows there '3' and followed by 0.Im expecting the buffer to be filled with '78'. because at the first 32bits of mem_sdram i have already write it with this command : iowr_32direct(mem_sdram_base,0,0x12345678); Here is my code: # define DEPTH 4
# include <stdio.h># include <stddef.h># include <stdlib.h># include "string.h"# include "system.h"
# include "sys/alt_dma.h"# include "altera_avalon_dma_regs.h"# include "altera_avalon_dma.h"
# include "sys/alt_cache.h"# include "sys/alt_alarm.h"# include "alt_types.h"
volatile int dma_complete = 0;
void dma_done (void * handle, void * data)
{
dma_complete = 1;
}
void check(void)
{
alt_u32 control, status, readaddress, length;
readaddress = IORD_ALTERA_AVALON_DMA_RADDRESS(DMA_BASE);
printf ("readaddress =%x, ", readaddress);
length = IORD_ALTERA_AVALON_DMA_LENGTH (DMA_BASE);
printf ("length =%x, ", length);
status = IORD_ALTERA_AVALON_DMA_STATUS (DMA_BASE);
printf ("status =%x, ", status);
control = IORD_ALTERA_AVALON_DMA_CONTROL (DMA_BASE);
printf ("control =%x \n", control);
}
int main()
{
printf("Testing DMA!\n");
alt_u8 buffer;
//memset(buffer, 0x55, 2024);
alt_dcache_flush_all();
alt_dma_rxchan_dev * rx;
alt_u32 start,end;
IOWR_32DIRECT(MEM_SDRAM_BASE,0,0x12345678);
start = alt_nticks();
if ((rx = alt_dma_rxchan_open ("/dev/dma")) == NULL)
{
printf ("Error: failed to open device");
exit(1);
}
else
{
alt_dma_rxchan_ioctl(rx, ALT_DMA_SET_MODE_8, NULL);
alt_dma_rxchan_ioctl(rx, ALT_DMA_TX_ONLY_OFF, NULL);
alt_dma_rxchan_ioctl(rx, ALT_DMA_RX_ONLY_ON, (void *)MEM_SDRAM_BASE);
check();
}
int ret;
if ((ret = alt_dma_rxchan_prepare (rx,(void *) buffer, DEPTH , dma_done, NULL)) <0)
{
printf ("Error: failed to post receive request\n");
exit (1);
}
while (!dma_complete);
end = alt_nticks();
printf("dma transfer: %dms\n",(end-start));
/*start = alt_nticks();
memcpy(buffer,(void *)MEM_SDRAM_BASE,DEPTH);
end = alt_nticks();
printf("memcpy transfer: %dms\n",(end-start));*/
printf ("Transaction complete \n");
alt_dma_rxchan_close(rx);
for(int x=0;x<DEPTH;x++)
{
printf("%d:%x\n",x,buffer);
}
printf("---using IORD---\n");
for(int x=0;x<DEPTH;x++)
{
printf("%d:%x\n",x,IORD_8DIRECT(MEM_SDRAM_BASE,0));
}
return 0;
}