Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I will try it. Besides, I cant see the SOPC picture because it is too small. Can you please enlarge it? Thanks for the help.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    In SOPC, I have SDRAM is for read from and onchip_write is write data out. Connect to DMA. In Nios program, there are src and dst. src to SDRAM_BASE and dst is connected to ONCHIP_WRITE.

    Try this again. It should work. I also include the result from my output.

    rename main.doc to main.c

    You can see in SOPC, SDRAM base address memory is 0x1000000 and Onchip memory is 0x2020000.

    Sean
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Stop posting the same question multiple times. If someone can help you, you will get an answer.

    Multiple posts are removed by the administrators.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I assume your settings in SOPC builder and pins assigment are correct. I have a litte program in Nios to test SDRAM with DMA. Look through and let me know.

    Rename main.doc to main.c

    Sean