关于NIOS II的DMA controller

来源:互联网 发布:用java输出正方形 编辑:程序博客网 时间:2024/06/07 01:28
不过,请人帮忙调通了API版的DMA,但是8bit和16bit的可以进行DMA传输,32bit的传输不成功~
#include <stdio.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "system.h"
static volatile int rx_done = 0;

void done (void* handle, void* data)
{
rx_done++;
}

void delay(int ms)
{
    while(ms--);
}

int main (int argc, char* argv[], char* envp[])
{
int rc,i,k = 0, m = 0;
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
void* tx_data = (void*) alt_uncached_malloc(1000);
void* rx_buffer = (void*)alt_uncached_malloc(1000);

memset(rx_buffer,0,1000);
for(i = 0;i<1000;i++)
{
    ((unsigned char*)tx_data)[i]= i;
}


if ((txchan = alt_dma_txchan_open("/dev/dma")) ==NULL)
{
printf ("Failed to open transmit channel\n");
exit (1);
}

if ((rxchan = alt_dma_rxchan_open("/dev/dma")) ==NULL)
{
printf ("Failed to open receive channel\n");
exit (1);
}

if(alt_dma_txchan_ioctl(txchan,ALT_DMA_SET_MODE_8,NULL)<0)
{
printf ("Failed to ioctrl transmit channel\n");
exit (1);
}

if(alt_dma_rxchan_ioctl(rxchan,ALT_DMA_SET_MODE_8,NULL)<0)
{
printf ("Failed to ioctrl transmit channel\n");
exit (1);
}


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);
}

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);
}

while(1)
{
    k =rx_done;
    if(k ==1)
     break;
    m++;
}
printf ("Transfer successful! %d\n",m);
return 0;
}
0 0
原创粉丝点击