NIOS2 DMA Memory to Memory Transfer
http://blog.ednchina.com/chactor/185802/message.aspx
#include <stdio.h>
#include <stdlib.h>
#include <sys/alt_dma.h>
#include "system.h"
static volatile int rx_done = 0;
int rc;
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
static char buff[256]; /* 待传数据 */
void* tx_data = (void*) buff; /* 源地址 */
void* rx_buffer = (void*) ONCHIP_MEMORY_BASE; /* 目标地址*/
//DMA传输结束回调函数
static void done_t(void* handle, void* data)
{
rx_done++;
}
int main (void)
{
/* 打开发送通道 */
if ((txchan = alt_dma_txchan_open("/dev/dma_1")) == NULL)
{
printf ("Failed to open transmit channel\n");
exit (1);
}
else
printf("打开发送通道.\n");
/* 打开接收通道 */
if ((rxchan = alt_dma_rxchan_open("/dev/dma_1")) == NULL)
{
printf ("Failed to open receive channel\n");
exit (1);
}
else
printf("打开接收通道.\n");
/* 开始发送数据 */
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);
}
else
printf("开始发送数据.\n");
/* 开始接收数据*/
if ((rc = alt_dma_rxchan_prepare (rxchan,
rx_buffer,
128,
done_t,
NULL)) < 0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}
else
printf("开始接收数据.\n");
/* 等待传输结束 */
while (!rx_done);
printf ("Transfer successful!\n");
return 0;
}
不是很理解回调函数,代码是参照EDN那个前辈的,先测试,目前没时间求甚解
(1)DMA长度寄存器设为8 bit了, Onchip_Menory Data_Width为32位了,怎么可以传输的好好的???
posted on 2011-04-06 13:53 CrazyBingo 阅读(941) 评论(0) 编辑 收藏 举报