Forum Discussion
Altera_Forum
Honored Contributor
15 years agoI tried out some code from this forum. I cannot write the result from peripheral to SDRAM. my code is as follow:
--- Quote Start --- # include "io.h"# include <stdio.h># include <unistd.h># include <sys/alt_dma.h># include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "system.h"# include "sys/alt_timestamp.h" # ifndef datax # define datax 0x0# endif# ifndef datay # define datay 0x1# endif# ifndef datau # define datau 0x2# endif /* unsigned long add_h(unsigned long a, unsigned long b); unsigned long add_h(unsigned long a, unsigned long b) { long result; IOWR(AVALON_0_BASE,datax,a); IOWR(AVALON_0_BASE,datay,b); result = IORD(AVALON_0_BASE,datau); return result; } */ static volatile int rx_done = 0; static void transfer_done (void* handle, void* data) { rx_done++; } void mem2mem_DMA(unsigned int dst, int length, unsigned long a, unsigned long b) { void *rx_data = (void *) dst; alt_dma_rxchan rxchan; int ret_code; IOWR(AVALON_0_BASE,datax,a); // Data x IOWR(AVALON_0_BASE,datay,b); // Data y /* Create the receive channel */ if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == NULL) { printf("Failed to open receive channel\n"); exit (1); } ret_code = alt_dma_rxchan_ioctl(rxchan, ALT_DMA_SET_MODE_32, NULL); if (ret_code) { printf("Error: SET_MODE_32: %d.\n", ret_code); exit(1); } ret_code = alt_dma_rxchan_ioctl(rxchan, ALT_DMA_RX_ONLY_ON, (void*)(AVALON_0_BASE)); if (ret_code) { printf("Error: ALT_DMA_RX_STREAM_ON: %d.\n", ret_code); exit(1); } /* Post the receive request */ if ((ret_code = alt_dma_rxchan_prepare(rxchan, rx_data, length, transfer_done, NULL)) < 0) { printf("Failed to post read request, reason = %i\n", ret_code); exit (1); } /* wait for transfer to complete */ while (!rx_done); printf("Transfer successful!\n\n"); } int main(void) { printf("\nThis is 32bits addition operation \n\n"); unsigned int dst = SDRAM_BASE + 0x600000; unsigned long number[100]; //unsigned long output1[100]; int i=0; int w; printf("Please specify number of sets of random number:\t "); scanf("%d", &w); for (i=0;i<w;i++) { number= 300000000;mem2mem_dma(dst, w, number, number);
}
for(i=0; i<w; i++)
{
printf("%ld\t %ld\n",number, IORD(dst, i)); } return 0; } --- Quote End --- My peripheral address is AVALON_0_BASE. This peripheral will add up 2 number, x and y. In this case, I set both x and y to be number[i], that is 300000000. Please assist. Thanks! really headache dealing with DMA.