NIOS2 DMA Memory to Peripheral Trnasfer

(1)

dma_1:  memory to periheral

read_master:  sdram中的数组的地址

write_master:  uart txdtxddata地址

 

NIOS2 DMA Memory to Peripheral Trnasfer

(2)uart ip 定制

 

NIOS2 DMA Memory to Peripheral Trnasfer

(3)

 

dma ip 定制

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

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

NIOS2 DMA Memory to Peripheral Trnasfer

NIOS2 DMA Memory to Peripheral Trnasfer

NIOS2 DMA Memory to Peripheral Trnasfer

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

NIOS2 DMA Memory to Peripheral Trnasfer

NIOS2 DMA Memory to Peripheral Trnasfer

 NIOS2 DMA Memory to Peripheral Trnasfer

代码如下,仿造了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;
}

NIOS2 DMA Memory to Peripheral Trnasfer

 

总结问题:

(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

相关文章: