NIOS2 DMA Memory to Memory Transfer

本文提供了一个DMA(直接内存访问)传输的代码实例,包括发送和接收通道的设置、数据传输过程及回调函数的使用。作者通过该例程展示了如何利用DMA进行数据传输,并提出了关于DMA长度寄存器设置的问题。

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

image

image

image

#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;

}

 

image

不是很理解回调函数,代码是参照EDN那个前辈的,先测试,目前没时间求甚解

 

(1)DMA长度寄存器设为8 bit了, Onchip_Menory Data_Width为32位了,怎么可以传输的好好的???

转载于:https://www.cnblogs.com/crazybingo/archive/2011/04/06/2006746.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值