Forum Discussion
Altera_Forum
Honored Contributor
15 years agoI cleaned up my code (since it was a total mess).
DMA transfer code (I tried the alt_dma_txchan_ioctl), but it didn't help so it's commented out at the moment. I also tried out byte transfers in stead of word transfers, but that didn't make a difference either.
void dma_transfer_general (void* tx_data, void* rx_buffer, alt_u32 length)
{
int i;
int rc; //request
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
printf("Transfer size: 0x%X\n",(int)length);
char dma_name;
strcpy(dma_name, "/dev/dma_tester");
txrx_done=0;
/* Create the transmit channel */
if ((txchan = alt_dma_txchan_open(dma_name)) == NULL)
{
printf ("Failed to open transmit channel\n");
exit (1);
}
/* Create the receive channel */
if ((rxchan = alt_dma_rxchan_open(dma_name)) == NULL)
{
printf ("Failed to open receive channel\n");
exit (1);
}
// /* Configure transmit request */
// if ((rc = alt_dma_txchan_ioctl(txchan, ALT_DMA_SET_MODE_32, tx_data)) < 0)
// {
// printf ("Failed to set tx ioctl to mode_32, reason = %i\n", rc);
// exit (1);
// }
//
// /* Configure receive request */
// if ((rc = alt_dma_rxchan_ioctl(rxchan, ALT_DMA_SET_MODE_32, rx_buffer)) < 0)
// {
// printf ("Failed to set rx ioctl to mode_32, reason = %i\n", rc);
// exit (1);
// }
/* Post the transmit request */
if ((rc = alt_dma_txchan_send (txchan, tx_data, length, 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, rx_buffer, length, txrxDone, NULL)) < 0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}
/* wait for transfer to complete */
while (!txrx_done);
/* Close channels */
alt_dma_txchan_close(txchan);
alt_dma_rxchan_close(rxchan);
printf("Content of TX DDR2 SDRAM after DMA operation\n");
for (i=0x0;i<0x20;i+=4)
{
printf("Address 0x%X: %x\n",i+(int)tx_data,IORD_32DIRECT((int)tx_data,i));
}
printf("Content of RX DDR2 SDRAM after DMA operation\n");
for (i=0x0;i<0x20;i+=4)
{
printf("Address 0x%X: %x\n",i+((int)rx_buffer),IORD_32DIRECT((int)rx_buffer,i));
}
printf("Memory compare from starting addresses 0x%X and 0x%X \nwith 0x%X bytes gives 0x%X \n",(int)tx_data,(int)rx_buffer,(int)length,(memcmp(tx_data,rx_buffer,(int)length)));
}
In main (see my first post for the fill_ddr2 function):
alt_u32 transfer_size = 0x10;
fill_ddr2_memory_with_counter(memory_base,memory_size);
dma_transfer_general((void*)ALTMEMDDR_1_BASE,(void*)(ALTMEMDDR_1_BASE+0x1500004),transfer_size);
dma_transfer_general((void*)(ALTMEMDDR_1_BASE+0x1500004),(void*)(ALTMEMDDR_1_BASE+0x3000004),transfer_size);