Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Direct Memory Access (DMA)

hello, i am having a problem with using dma. my dma seems like never finish the transaction because it cannot call the done function and keep on looping in the while(!rx_done). I dont know why. can anyone please help? i posted a lot on the forum but seem like no one is helping. thanks!

my code:

--- Quote Start ---

# include <stdio.h># include <stdlib.h># include <stddef.h># include <string.h># include <system.h># include <io.h># include <alt_types.h># include "sys/alt_dma.h"# include "sys/alt_dma_dev.h"# include "sys/alt_cache.h"# include "sys/alt_alarm.h"# include "alt_types.h"

static volatile int rx_done = 0;

/*

* Callback function that obtains notification that the data

* is received.

*/

static void done (void* handle, void* data)

{

rx_done++;

}

/*

*

*/

int main (int argc, char* argv[], char* envp[])

{

int rc,i;

alt_dma_txchan txchan;

alt_dma_rxchan rxchan;

void* tx_data = (void*) SDRAM_BASE+0x200000; /* pointer to data to send */

void* rx_buffer = (void*) SDRAM_BASE+0x201000; /* pointer to rx buffer */

for(i=0;i<1024;i++)

{

IOWR(tx_data, i, i);

}

for(i=0;i<1024;i++)

{

printf("%d\n", IORD(tx_data, i));

}

/* 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);

}

/* Post the transmit request */

if ((rc = alt_dma_txchan_send (txchan,

tx_data,

128,

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,

128,

done,

NULL)) < 0)

{

printf ("Failed to post read request, reason = %i\n", rc);

exit (1);

}

/* wait for transfer to complete */

while (!rx_done);

printf ("Transfer successful!\n");

return 0;

}

--- Quote End ---

15 Replies