Forum Discussion
Altera_Forum
Honored Contributor
15 years ago --- Quote Start --- Sorry, try this:
alt_u8 *uncached_buffer = (alt_u8 *)alt_remap_uncached(buffer,DEPTH); --- Quote End --- cool.. it works like a charm .. thank you Daixiwen here is the code (in case somebody else having the same problem): # define DEPTH 100
# 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;
alt_u8 * ubuffer = (alt_u8 *)alt_remap_uncached(buffer,DEPTH);
memset(ubuffer, 0x55, DEPTH * 2);
//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 *) ubuffer, 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,ubuffer);
}
printf("---using IORD---\n");
for(int x=0;x<DEPTH;x++)
{
printf("%d:%x\n",x,IORD_8DIRECT(MEM_SDRAM_BASE,0));
}
return 0;
}
i found that this line , memset(ubuffer, 0x55, depth * 2); is somehow also affect the output.. -if i comment this line the output is not correct. //seems like we have to initialize the ubuffer first -if i change it to memset(ubuffer, 0x0, depth * 2);, the output is incorrect -if i change it to memset(ubuffer, 0x0, depth); -- somehow the length which must be set has to be double the size of the buffer we need. :p so many mystery that i still dont understand about this dma controller provided by altera in sopc.. rite now im back to trying the transfer from memory to memory with dma controller provided with sopc. memcpy works best without bug for me. somehow the disadvantage is that i have to wait until memcpy operation finish b4 i can do other operation. With dma controller, i can tell it to copy a certain block of memory and do other operation. if the copy operation is done (can check it with flag) i can continue what i want todo with the copied data.