Forum Discussion
Altera_Forum
Honored Contributor
15 years agoOk, so I'm using a DMA core now (not a SGDMA). I want to use the DMA configuration "peripheral to memory", so I implement the receive channel with the API functions:
static volatile int dma_done = 0;
/*
* Callback function that obtains notification that the data
* is received.
*/
static void done (void* handle, void* data)
{
dma_done = 1;
}
...
INT8U tx_buf;
INT32U rc;
alt_dma_rxchan rxchan;
INT8U * rx_data = (INT8U *)IOADDR_ALTERA_AVALON_PIO_DATA(DMA_READ_MASTER_AD_DATA_BASE); /* pointer to data to send */
/* Create the receive channel */
if ((rxchan = alt_dma_rxchan_open(DMA_NAME)) == NULL)
{
printf ("Failed to open receive channel\n");
}
alt_dma_rxchan_ioctl(rxchan, ALT_DMA_RX_ONLY_ON, rx_data); // continuously read from fixed address rx_data
...
// The rest will execute in a loop:
/* Post the receive request */
if ((rc = alt_dma_rxchan_prepare (rxchan, tx_buf, SSS_TX_BUF_SIZE, done, NULL)) < 0)
{
printf ("Failed to post read request, reason = %d\n", rc);
}
/* wait for transfer to complete */
while (!dma_done);
dma_done = 0;
printf ("Transfer successful!\n");
send(conn.fd, tx_buf, SSS_TX_BUF_SIZE, 0); // creates the MAC frames ect. and send tx_buf content to the PC
...
This is all happening in a thread. The functions are not garantied to be thread safe. When I debug it, the while loop never stops! Why? I'm also not quite sure about my rx_data. In the example 6-13 on page 156 of the Nios Software Developers Handbook (http://www.altera.com/literature/hb/nios2/n2sw_nii5v2.pdf) it doesn't show where the data is read from. Is the data automatically read from the avalon slave address connected to the read master of the DMA ?