NIOS2 DMA Memory to Peripheral Trnasfer

image

(1)

dma_1:  memory to periheral

read_master:  sdram中的数组的地址

write_master:  uart txdtxddata地址

 

image

(2)uart ip 定制

 

image

(3)

 

dma ip 定制

根据 dma 的ds,至少得read_master 两倍的深度,不然会出错(此处准备1024,故增大一位11:bit)

次数是数据寄存器的长度,即数量,不是宽度。

image

image

image

下面是dma ip定制的允许传输的字节使能选项,理论上uart 只要byte就可以了,但实际上却不行,会导致传输失败,我不理解,随意只能全选,不会出错误了

image

image

 image

代码如下,仿造了cactor的原创:

http://blog.ednchina.com/chactor/185802/message.aspx

 

#include <stdio.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "system.h"
#include "alt_types.h"

#include "../inc/mcu_uart.h"

#define CHAR_LENGTH    1024

static volatile int tx_done = 0;
volatile static alt_u8 chr[CHAR_LENGTH];

 

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

int main()
{
    //串口输出目标地址空间的数据
    int i;
    for(i = 0; i < CHAR_LENGTH; i++)
    {
       *(chr + i) = i;
    }

    //创建DMA接收信道
    alt_dma_txchan txchan;
    //源地址
    void* source_buff_ptr = (void*) chr;
    //目标地址UART_BASE+2,因为UART的txdata寄存器在rxdata之后,偏移量为一个rxdata的长度(16位,2个字节)
    void* destination_buff_ptr = (void*)(UART_BASE + 2);

    //-----------------------------------------------------------
    /* 打开发送通道 */
    if ((txchan = alt_dma_txchan_open("/dev/dma_1")) == NULL)
    {
        printf ("Failed to open transmit channel\n");
        exit (1);
    }
    else
        printf("打开发送通道.\n");

    //-----------------------------------------------------------
    //设置每次发送一个字节,即8位,因为UART每次只发送8位
    if(alt_dma_txchan_ioctl(    txchan,
                                ALT_DMA_SET_MODE_8 ,
                                NULL) <0 )
    {
        printf("Failed to set mode 8\n");
        exit(1);
    }
    else
        printf("设置8字节发送模式.\n");

    //-----------------------------------------------------------
    /* 设置目标地址固定 */
    if (alt_dma_txchan_ioctl(    txchan,
                                ALT_DMA_TX_ONLY_ON,
                                destination_buff_ptr) < 0)
    {
        printf ("Failed to set ioctl.\n");
        exit (1);
    }
    else
        printf("设置目标地址固定.\n");

    //-----------------------------------------------------------
    /* 开始发送 */
    if (alt_dma_txchan_send(    txchan,
                                source_buff_ptr,
                                CHAR_LENGTH,
                                done,
                                NULL) < 0)
    {
        printf ("Failed to post transmit request.\n");
        exit (1);
    }
    else
        printf("开始发送.\n");

    //-----------------------------------------------------------
    /* 等待发送结束 */
    while (!tx_done);
    printf ("Transfer successful!\n");

    //-----------------------------------------------------------
    //关闭DMA接收信道
    alt_dma_txchan_close(txchan);


    return 0;
}

image

 

总结问题:

(1)dma ip定制的允许传输的字节使能选项,理论上uart 只要byte就可以了,但实际上却不行,会导致传输失败,我不理解,随意只能全选,不会出错误了,不知道这是为什么,不管我在代码中重新使能9为mode还是否

(2)void* destination_buff_ptr = (void*)(UART_BASE + 2); 此处不能写IOADDR_ALTERA_AVALON_UART_TXDATA(UART_BASE);,因为一个是字对齐的,一个地址是地址,我也解释不清楚,但是chactor就是这里搞错了。 谁能帮我解释清楚。

 

(3)解决所以基本架构,继续我的video_capture

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值