|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
在调试NIOS 两个onchip_memery DMA传输时,传输的数据只有部分对,好像是有规律,找了很多资料,还是没找到问题,新手。谢谢
附代码如下:
#include <stdio.h>
#include <string.h>
#include <alt_types.h>
#include "system.h"
#include "sys/alt_dma.h"
#include "unistd.h"
#include "io.h"
#include <sys/alt_cache.h>
static volatile int tx_done = 0;
//回调函数
static void done (void* handle)
{
tx_done++;
}
//#define TRANSFER_LENGTH 32
const int TRANSFER_LENGTH =16 ;
int main(void)
{
int data[TRANSFER_LENGTH] ;
//#pragma DATA_SECTION (data,".ONCHIP_RAM0_BASE");
int i=0;
for(i=0;i<TRANSFER_LENGTH;i++)
data=i+100;
int *source = ( int*)(data);
int *dest = ( int*)(ONCHIP_RAM1_BASE);
//memset(source,0x55,TRANSFER_LENGTH*sizeof(char));
alt_dma_txchan tx;
//创建DMA发送信道
tx = alt_dma_txchan_open("/dev/dma0");
//当信道创建成功
if(tx == NULL)
{
printf("Failed to open transit channel.\n");
}
else
{
printf("Create the transit channel successfully.\n");
}
//创建DMA接收通道
alt_dma_rxchan rx;
rx = alt_dma_rxchan_open("/dev/dma0");
//当信道创建成功
if(rx == NULL)
{
printf("Failed to open receive channel.\n");
}
else
{
printf("Create the receive channel successfully.\n");
}
// alt_dma_txchan_ioctl(tx,ALT_DMA_SET_MODE_32 ,NULL);
if(alt_dma_txchan_send(tx,
source,
TRANSFER_LENGTH,
NULL,
NULL)<0)
{
printf ("Error: failed to post transmit request\n");
}
else
printf ("ok: success to post transmit request\n");
//提交DMA接收请求指定接收数据的位置(sdram)以及传输数据量
// cwg = alt_dma_txchan_ioctl(rx,ALT_DMA_SET_MODE_8 ,NULL);
// alt_dma_rxchan_ioctl(rx,ALT_DMA_SET_MODE_32 ,NULL);
if(alt_dma_rxchan_prepare(rx,
dest,
TRANSFER_LENGTH,
done,
NULL) < 0)
{
printf ("Error: failed to post receive request\n");
}
else
printf ("ok: success to post receive request\n");
// 等待发送结束
while (!tx_done);
printf("Transmit successful\n");
usleep(5000000);
int loop,errorcount=0;
for(loop=1;loop<TRANSFER_LENGTH;loop++)
{
//对比缓冲区数据
if(source[loop]!=dest[loop])
{
printf("Verify failed at location: %d\n",loop);
errorcount++;
}
}
if(errorcount==0)
{
printf("Transfer successfully !\n");
}
else
{
printf("Transfer failed !\n");
}
for(i=0;i<TRANSFER_LENGTH;i++)
printf("dest[%d]: %d\n",i,*(dest+i));
return(0);
// while(1);
}
////////////////////////////////////////////////////运行结果如下
Create the transit channel successfully.
Create the receive channel successfully.
ok: success to post transmit request
ok: success to post receive request
Transmit successful
Verify failed at location: 8
Verify failed at location: 9
Verify failed at location: 10
Verify failed at location: 11
Verify failed at location: 12
Verify failed at location: 13
Verify failed at location: 14
Verify failed at location: 15
Transfer failed !
dest[0]: 100
dest[1]: 101
dest[2]: 102
dest[3]: 103
dest[4]: 104
dest[5]: 105
dest[6]: 106
dest[7]: 107
dest[8]: 0
dest[9]: 0
dest[10]: 0
dest[11]: 0
dest[12]: 0
dest[13]: 0
dest[14]: 0
dest[15]: 0 |
-
-
QSYS.rar
198.15 KB, 下载次数: 7
, 下载积分:
资产 -2 信元, 下载支出 2 信元
|