Altera_Forum
Honored Contributor
14 years agodma questions
Hey! I'm runing some test using the DMA controller. I started with the simplest one, trying to copy some datas from an onchip memory to another. I'm using this code.
static volatile int rx_done = 0;
static void done_rx (void* handle, void* data)
{
rx_done++;
printf ("Transfer RX successful!\n");
}
static void done_tx (void* handle, void* data)
{
printf ("Transfer TX successful!\n");
}
void char_tx_rx()
{
char *send="87654321";
int length=strlen(send);
printf ("length=%i\n", length);
int rc;
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
void* rx_buffer = (void*) (ONCHIP_MEMORY2_1_BASE); /* pointer to rx buffer */
/* Create the transmit channel */
if ((txchan = alt_dma_txchan_open("/dev/dma_0")) == NULL)
{
printf ("Failed to open transmit channel\n");
exit (1);
}
/* Create the receive channel */
if ((rxchan = alt_dma_rxchan_open("/dev/dma_0")) == NULL)
{
printf ("Failed to open receive channel\n");
exit (1);
}
/* Post the receive request */
if ((rc = alt_dma_rxchan_prepare (rxchan,rx_buffer,length,done_rx,NULL)) < 0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}
/* Post the transmit request */
if ((rc = alt_dma_txchan_send (txchan,send,length,done_tx ,NULL)) < 0)
{
printf ("Failed to post transmit request, reason = %i\n", rc);
exit (1);
}
/* wait for transfer to complete */
while (!rx_done);
printf("send: \n");
int i;
for(i=0;i<length;i++)
printf ("%c",send);
char *p;
p=rx_buffer;
printf("\nreceived: \n");
for(i=0;i<length;i++)
printf ("%c",*(p+i));
alt_dma_rxchan_close(rxchan);
alt_dma_txchan_close(txchan);
}
After some hard work(i've started with the integer function which is presented in the next post) i managed to make it work. The question here are : 1) why, if I transmit all the tx buffer( tx_length=length) and set the dma to receive, lets say, only half of the datas(rx_length=length/2) the done_functions are called in the same order as when I transmit and receive the whole buffer( done_tx and then done_rx). 2) And when I transmit half of the buffer(tx_length=length/2) and want to receive the whole buffer it works( i transmit what i want, but i also receive how much I want and I was expecting some problems here) ?