Forum Discussion

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

The problem of DMA

I want to use the DMA to transfer data from SDRAM to SDRAM,but the code does not work.

# include<stdio.h># include"system.h"# include"sys/alt_dma.h"# include "alt_types.h"# include<string.h>

alt_u8 rx_done=0,tx_done=0;

void tdone()

{

tx_done++;

}

void rdone()

{

rx_done++;

}

int main()

{

alt_dma_txchan tx;

alt_dma_rxchan rx;

void *tx_addr=(void *)0x00FFFF60;

void *rx_addr=(void *)0x01000000;

tx=alt_dma_txchan_open("/dev/dma");

rx=alt_dma_rxchan_open("/dev/dma");

alt_dma_txchan_ioctl(tx,ALT_DMA_SET_MODE_8,NULL);

alt_dma_txchan_ioctl(tx,ALT_DMA_TX_ONLY_ON,NULL);

alt_dma_rxchan_ioctl(rx,ALT_DMA_SET_MODE_8,NULL);

alt_dma_rxchan_ioctl(rx,ALT_DMA_RX_ONLY_ON,tx_addr);

if(alt_dma_txchan_send(tx,tx_addr,128,tdone,NULL)<0)

{

printf("failed to transfer.\n");

}

if(alt_dma_rxchan_prepare(rx,rx_addr,128,rdone,NULL)<0)

{

printf("failed to receive.\n");

}

printf("the data is %d\n",tx_done);

printf("the data is %d\n",rx_done);

printf("successful.\n");

alt_dma_rxchan_close(rx);

alt_dma_txchan_close(tx);

return 0;

}

http://b31.photo.store.qq.com/http_imgload.cgi?/rurl4_b=b579f8b54f494fc69149a5de70a1aee95d585274539b9182cb8db26ee2e41438c99f78eab67eb7ee2a85545cfd423537a01317cb63ecdc91f849d6a588fc502a7430bb2372c3ea3633badf8963f8c5987a34603e&a=31&b=31

the result of the code:

http://b32.photo.store.qq.com/http_imgload.cgi?/rurl4_b=b579f8b54f494fc69149a5de70a1aee967573de951864407f046aab315d4d7e2cea226222d83c2343a5b88545e5203f0e4b5f65c02d005f9fee3ea3180359dd2cf533045d22252f709d5e911776428a254457545&a=32&b=32

thank you very much.
No RepliesBe the first to reply