首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[求助]如何在niosii中用DMA接收UART的数据?

[求助]如何在niosii中用DMA接收UART的数据?

问题描述:我想用DMA接收URAT发来的数据包,数据包的长度和速率是固定的;
在网上也找了相关的代码,但是只能接收一个数据包,不能循环的接收,我现在
不知道CPU如何知道要进行DMA数据传递了?niosii的系统中好像是外设不能发起
DMA传输,只有CPU能发起DMA的传输,那么它是怎么知道的呢?
希望高手给指点一下!谢谢了
下面是我的程序
#include <stdio.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "system.h"
//#include "altera_avalon_pio_regs.h"
#include "altera_avalon_uart_regs.h"
#include "alt_types.h"

#define RXBUFSIZE 5
static volatile int rx_done = 0;
volatile static alt_u8 RxBuf[RXBUFSIZE];

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


int main ()
{
int rc;

alt_dma_rxchan rxchan;

void* destination_buff_ptr = (void*)RxBuf;
void* source_buff_ptr = (void*)IOADDR_ALTERA_AVALON_UART_RXDATA(UART_BASE);

volatile int i;


/*打开接收通道*/
if((rxchan = alt_dma_rxchan_open("/dev/dma"))== NULL)
{
printf("Failed to open transmit channel\n");
exit(1);
}

alt_dma_rxchan_ioctl(rxchan,ALT_DMA_SET_MODE_8,NULL);

if((rc = alt_dma_rxchan_ioctl(rxchan,ALT_DMA_RX_ONLY_ON,source_buff_ptr))<0)
{
printf("Failed to set ioctl,reason = %i\n",rc);
exit(1);
}

if((rc = alt_dma_rxchan_prepare(rxchan,destination_buff_ptr,5,done,NULL))<0)
{
printf("Failed to pose transmit request ,reason = %i\n",rc);
exit(1);
}

while (1)
{

while (!rx_done);

for(i=0;i<5;i++)
{
printf("RxBuf[%d]= %x\n",i,RxBuf);
}
alt_dma_rxchan_close(rxchan);



}
return 0;
}

上面的这个程序在收完一个数据包后就停止了,不能连续的接收;我把 while (1) 加到 /*打开接收通道*/前面,可是每次都是

Failed to pose transmit reques!!
返回列表