首页 新闻 会员 周边

请教一个dma传输问题

0
悬赏园豆:10 [待解决问题]

今天用黑金cyclone2测试了一下dma程序,从sdram到内部ram,代码是这样的,基本参照视频,运行后发现指针始终停留在while (!tx_done);进不了回调函数,哪位大侠帮帮忙,谢谢!
//存储器到存储器
#include <stdio.h>
#include <string.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;
//定义DMA传输的数据长度,数据长度不能超过DMA长度寄存器的范围。
#define TRANSFER_LENGTH 64

//回调函数
static void done (void* handle)
{
    tx_done++;
}

int main(void)
{
//定义源地址
char *source = (void*)(SDRAM_BASE+20000);
//定义目的地址
char *dest = (void*)(ONCHIP_MEMORY_BASE+256);
//初始化源数据,为0x88
    memset(source,0x88,TRANSFER_LENGTH);
//定义发送通道   
    alt_dma_txchan tx;
//创建DMA发送信道
    tx = alt_dma_txchan_open("/dev/dmaso");
//当信道创建成功
    if(tx == NULL)
    {
        printf("Failed to open transit channel.\n");
    }
    else
    {
        printf("Create the transit channel successfully.\n");
    }
   
//创建DMA接收通道  
alt_dma_rxchan  rx;
//创建DMA接收通道
    rx = alt_dma_rxchan_open("/dev/dmaso");
    //当信道创建成功
     if(rx == NULL)
    {
        printf("Failed to open receive channel.\n");
    }
    else
    {
        printf("Create the receive channel successfully.\n");
    }        
//往发送通道发送数据
     if(alt_dma_txchan_send(tx,
                            source,
                            TRANSFER_LENGTH,
                            NULL,
                            NULL)<0)
        {
        printf ("Error: failed to post transmit request\n");
        }                                   
   
//提交DMA接收请求 指定接收数据的位置(sdram)、传输数据长度和回调函数
    if(alt_dma_rxchan_prepare(rx,
                              dest,
                              TRANSFER_LENGTH,
                              done,
                              NULL) < 0)
        {
        printf ("Error: failed to post receive request\n");
        }
        
// 等待发送结束
while (!tx_done);
printf("DMA Transmit successful\n");
usleep(1000000);
int i,errorcount=0;
for(i=0;i<TRANSFER_LENGTH;i++)
{
    //对比缓冲区数据
    if(source[i]!=dest[i])
    {
        printf("Verify failed at location: 0x%X\n",(i+1));
        errorcount++;
    }
}
if(errorcount==0)
{
    printf("DMA Transfer successfully !\n");
}
else
{
    printf("DMA Transfer failed !\n");
}
return 0;
}

flyxiaoma的主页 flyxiaoma | 初学一级 | 园豆:192
提问于:2012-03-23 20:49
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册