Altera_Forum
Honored Contributor
15 years agoChanging DMA stread read to stream write
Hello, I have the following fully functional code that gives as output:
Content of TX DDR2 SDRAM after DMA operation Address 0xC000000: 1 Address 0xC000004: 2 Address 0xC000008: 3 Address 0xC00000C: 4 Address 0xC000010: 5 Address 0xC000014: 6 Address 0xC000018: 0 Address 0xC00001C: 0 Content of RX DDR2 SDRAM after DMA operation Address 0xD000008: 1 Address 0xD00000C: 1 Address 0xD000010: 1 Address 0xD000014: 1 Address 0xD000018: 1 Address 0xD00001C: 1 Address 0xD000020: 0 Address 0xD000024: 0 I would now like to change this to a stream write. So swap it around. But how exactly should I change the code in the two boxes below, because I've tried but it doesn't seem to work :S: The following datasheet http://www.altera.com/literature/hb/...w_nii52004.pdf (http://www.altera.com/literature/hb/nios2/n2sw_nii52004.pdf) states the following If you are using the Avalon Memory-Mapped® (Avalon-MM) DMA device to transmit to hardware (not memory-to-memory transfer), call the alt_dma_txchan_ioctl()function with the request argument set to ALT_DMA_TX_ONLY_ON. the following is what i now use for stream reads.
alt_dma_txchan_ioctl(txchan, ALT_DMA_SET_MODE_32, NULL);
alt_dma_txchan_ioctl(txchan, ALT_DMA_TX_ONLY_OFF, NULL);
alt_dma_txchan_ioctl(txchan, ALT_DMA_RX_ONLY_OFF, NULL);
and
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_SET_MODE_32, NULL);
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_RX_ONLY_ON, rx_buffer);
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_TX_ONLY_OFF, NULL);
void dma_transfer_stream_read (void* tx_data, void* rx_buffer, alt_u32 length, int dma_picked)
{
int i;
int rc; //request
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
printf("Transfer size: 0x%X\n",(int)length);
char dma_name;
// printf("Please enter your dma name /dev/dma_tester .\n"); ///dev/dma_write or /dev/dma_read
// scanf("%s",dma_name);
if(dma_picked == 1)
strcpy(dma_name, "/dev/dma_tester");
else if(dma_picked == 2)
strcpy(dma_name, "/dev/dma_write");
else if(dma_picked ==3)
strcpy(dma_name, "/dev/dma_read");
else
{printf("No DMA controller picked!");
exit(1);}
// strcpy(dma_name, "/dev/dma_read");
txrx_done=0;
if((txchan = alt_dma_txchan_open(dma_name)) == NULL)
{
printf("Failed to open transmit channel\n");
exit (1);
}
else
{
alt_dma_txchan_ioctl(txchan, ALT_DMA_SET_MODE_32, NULL);
alt_dma_txchan_ioctl(txchan, ALT_DMA_TX_ONLY_OFF, NULL);
alt_dma_txchan_ioctl(txchan, ALT_DMA_RX_ONLY_OFF, NULL);
}
if((rxchan = alt_dma_rxchan_open(dma_name)) == NULL)
{
printf("Failed to open receive channel\n");
exit (1);
}
else
{
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_SET_MODE_32, NULL);
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_RX_ONLY_ON, rx_buffer);
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_TX_ONLY_OFF, NULL);
/*If you are using the Avalon-MM DMA device to receive from hardware(not memory-to-memory transfer), call the alt_dma_rxchan_ioctl() function with the request argument set to ALT_DMA_RX_ONLY_ON.*/
}
/* 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);
}
//printf("DMA_CONTROL_REG: 0X%8X\n", IORD_32DIRECT(DMA_TESTER_BASE, 24));
/* wait for transfer to complete */
printf("Waiting on DMA...");
while (!txrx_done)
printf(".");
printf(" Done!\n");
/* 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)
//for (i=0xFFFFD4;i<0x1000000;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)
//for (i=0xFFFFD4;i<0x1000000;i+=4)
{
printf("Address 0x%X: %x\n",i+((int)rx_buffer),IORD_32DIRECT((int)rx_buffer,i));
}
}
In main: dma_transfer_stream_read((void*)ALTMEMDDR_1_BASE,(void*)(ALTMEMDDR_1_BASE+0x1000008),transfer_size,1); //read Thanks in advance.