Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21336 Discussions

help with simple memory testing example on niosII

Altera_Forum
Honored Contributor II
1,322 Views

hi all, 

im just a beginner trying to run memory test example code provided in nios EDS. 

 

What ive wanted to do is simply running a test on SDRAM (with dma). Ive configure the SOPC with SDRAM & dma controller. The screenshot of my sopc is shown below: 

https://www.alteraforum.com/forum/attachment.php?attachmentid=2385  

 

While running the c code example, the program pass all the test but stay still when it comes to "testing memory using dma". I ran it again in debug mode and put breakpoints in certain places. What i found out is that it never get out of while(!rx_done). It seems like the dma transfer is never completed and rx_done is always 0

 

Here is the code snippet of the memory test (consist only the function called for dma test) 

 

/****************************************************************** * Function: dma_done * * Purpose: Called when a DMA recieve transaction is complete. * Increments rx_done to signal to the main program that * the transaction is done. * ******************************************************************/# ifdef DMA_NAME static void dma_done (void* handle, void* data) { rx_done++; }# endif /* DMA_NAME */ /****************************************************************** * Function: MemDMATest * * Purpose: Tests every bit in the memory device within the * specified address range using DMA. The DMA controller provides * a more rigourous test of the memory since it performs back-to- * back memory accesses at full system speed. * ******************************************************************/# ifdef DMA_NAME static int MemDMATest(unsigned int memory_base, unsigned int nBytes) { int rc; int ret_code = 0; int pattern, offset; alt_dma_txchan txchan; alt_dma_rxchan rxchan; void* data_written; void* data_read; /* Get a couple buffers for the test */ data_written = (void*)alt_uncached_malloc(0x1000); data_read = (void*)alt_uncached_malloc(0x1000); /* Fill write buffer with known values */ for (pattern = 1, offset = 0; offset < 0x1000; pattern++, offset+=4) { IOWR_32DIRECT((int)data_written, offset, pattern); } /* Create the transmit channel */ if ((txchan = alt_dma_txchan_open("/dev/dma")) == NULL) { printf ("Failed to open transmit channel\n"); exit (1); } /* Create the receive channel */ if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == NULL) { printf ("Failed to open receive channel\n"); exit (1); } for(offset = memory_base; offset < (memory_base + nBytes); offset += 0x1000) { /* Use DMA to transfer from write buffer to memory under test */ /* Post the transmit request */ if ((rc = alt_dma_txchan_send (txchan, data_written, 0x1000, NULL, NULL)) < 0) { printf ("Failed to post transmit request, reason = %i\n", rc); exit (1); } /* Post the receive request */ if ((rc = alt_dma_rxchan_prepare (rxchan, (void*)offset, 0x1000, dma_done, NULL)) < 0) { printf ("Failed to post read request, reason = %i\n", rc); exit (1); } /* Wait for transfer to complete */ while (!rx_done); rx_done = 0; /* Clear the read buffer before we fill it */ memset(data_read, 0, 0x1000); /* Use DMA to read data back into read buffer from memory under test */ /* Post the transmit request */ if ((rc = alt_dma_txchan_send (txchan, (void*)offset, 0x1000, NULL, NULL)) < 0) { printf ("Failed to post transmit request, reason = %i\n", rc); exit (1); } /* Post the receive request */ if ((rc = alt_dma_rxchan_prepare (rxchan, data_read, 0x1000, dma_done, NULL)) < 0) { printf ("Failed to post read request, reason = %i\n", rc); exit (1); } /* Wait for transfer to complete */ while (!rx_done); rx_done = 0; if (memcmp(data_written, data_read, 0x1000)) { ret_code = offset; break; } } alt_uncached_free(data_written); alt_uncached_free(data_read); return ret_code; }# endif /* DMA_NAME */ can u guys advice anything that ive done wrong?maybe setting in the sopc.the connection in sopc or something. im a little confuse right now because this is suppose to be a simple memory test which i only use an example provided code in niosIDE :confused:. Any help is appreciated. Thanks~ 

 

Im currently using  

Altera Quartus II v8.0, Nios IDE v8.0
0 Kudos
0 Replies
Reply