程序代码如下: BYTE strR[1024]; volatile BYTE strW[1024]; static volatile int rx_done = 0;
/* * Callback function that obtains notification that the data has * been received. */ static void done (void* handle, void* data) { rx_done++; } void InitDMA() { DWORD st; for(int i=0;i<512;i++) { strR=i&0xff; strW=0; } int rc; alt_dma_txchan txchan; alt_dma_rxchan rxchan; void* tx_data = (void*) strR; /* pointer to data to send */ void* rx_buffer = (void*) strW; /* pointer to rx buffer */ /* Create the transmit channel */
if ((txchan = alt_dma_txchan_open("/dev/dma")) == NULL) { printf ("Failed to open transmit channel\r\n"); exit (1); }
/* Create the receive channel */
if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == NULL) { printf ("Failed to open receive channel\r\n"); exit (1); }
/* Post the transmit request */
if ((rc = alt_dma_txchan_send (txchan, tx_data, 1024, NULL, NULL)) < 0) { printf ("Failed to post transmit request, reason = %i\r\n", rc); exit (1); } /* Post the receive request */
if ((rc = alt_dma_rxchan_prepare (rxchan, rx_buffer, 1024, done, NULL)) < 0) { printf ("Failed to post read request, reason = %i\r\n", rc); exit (1); } /* wait for transfer to complete */
while (!rx_done); printf ("Transfer successful!\r\n");
ShowData(strR,512); TRACE("strWP=%p\r\n",strW); ShowData((PUINT8)strW,512); } |