基于Nios II的DMA传输总结_第1页
基于Nios II的DMA传输总结_第2页
基于Nios II的DMA传输总结_第3页
基于Nios II的DMA传输总结_第4页
基于Nios II的DMA传输总结_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、最近练了一段时间的DMA传输,现做如下的总结,分享自己获得心得以及遇到的一些问题。    在系统运行时,当需要传输大量数据时,可以采用DMA的方式进行传输,以解脱出CPU来处理其他命令。Nios II中的DMA传输有以下三种形式:1、 存储器到存储器这种情况下需要同时打开发送通道和接收通道,而且源地址和目标地址都是自增的。tx = alt_dma_txchan_open("/dev/dma_0");/打开发送通道dma_res = alt_dma_txchan_send(tx, tx_buf, 32, NULL, NULL); / tx_buf

2、是源地址rx = alt_dma_rxchan_open("/dev/dma_0");/打开接收通道dma_res = alt_dma_rxchan_prepare(rx, rx_buf, 32, dma_done, NULL); / rx_buf是目标地址,dma_done()是DMA完成后被调用的回调函数。2、 存储器到外设这种情况下只要打开发送通道,而且源地址是自增的,目标地址是固定的。tx = alt_dma_txchan_open("/dev/dma_0"); / 打开发送通道alt_dma_txchan_ioctl(tx, ALT_DMA_T

3、X_ONLY_ON, (void *)dst_addr); / dst_addr是目标地址dma_res = alt_dma_txchan_send(tx, tx_buf, 32, dma_done, NULL); / tx_buf是源地址3、 外设到存储器这种情况下只要打开接收通道,而且源地址是固定的,目标地址是自增的。rx = alt_dma_rxchan_open("/dev/dma_0"); / 打开接收通道alt_dma_rxchan_ioctl(rx, ALT_DMA_RX_ONLY_ON, (void *)source_addr); / source_addr

4、是源地址dma_res = alt_dma_rxchan_prepare(rx, rx_buf, 32, dma_done, NULL); / rx_buf是目标地址其中通过alt_dma_txchan_ioctl,alt_dma_rxchan_ioctl还可以设置每次发送和接收的字节数。下面给出两个实例,说明DMA传输的过程。1、 存储器到存储器下面程序为SDRAM到onchip-memory的数据传输。硬件连接图示:程序如下:#include <stdio.h>#include <stdlib.h>#include <sys/alt_dma.h>#inc

5、lude "system.h"static volatile int rx_done = 0;int rc;alt_dma_txchan txchan;alt_dma_rxchan rxchan;static char buff256;void* tx_data = (void*) buff; /* 源地址 */void* rx_buffer = (void*) 0x01801000; /* 目标地址,从上图看到0x01801000为onchip-memory的地址*/DMA传输结束回调函数static void done_t(void* handle, void* dat

6、a)        rx_done+;    int main (int argc, char* argv, char* envp)/* 打开发送通道 */if (txchan = alt_dma_txchan_open("/dev/dma") = NULL)    printf ("Failed to open transmit channeln");    exit (1);/* 打开接收通道 */if

7、 (rxchan = alt_dma_rxchan_open("/dev/dma") = NULL)    printf ("Failed to open receive channeln");    exit (1);/* 开始发送数据 */if (rc = alt_dma_txchan_send (txchan,               &

8、#160;                 tx_data,                               

9、0; 128,                                 NULL,                

10、;                 NULL) < 0)    printf ("Failed to post transmit request, reason = %in", rc);    exit (1);/* 开始接收数据*/if (rc = alt_dma_rxchan_prepare (rxchan,   &#

11、160;                                rx_buffer,                

12、60;                   128,                              

13、0;     done_t,                                    NULL) < 0)    printf ("Failed to

14、 post read request, reason = %in", rc);    exit (1);/* 等待传输结束 */while (!rx_done);printf ("Transfer successful!n");return 0;程序运行结束后在Nios IDE的console界面中显示:Transfer successful!表明传输成功。2、 存储器到UART下面程序为SDRAM到UART的数据传输硬件连接图:程序如下:#include <stdio.h>#include <stdlib.h>

15、;#include "sys/alt_dma.h"#include "altera_avalon_uart_regs.h"#include "system.h"#include "alt_types.h"static volatile int tx_done = 0;volatile static alt_u8 chr20 = 1,2,3,4,6,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ;/待发送的数据/回调函数static void done (void* handle)

16、tx_done+;int main()int rc;alt_dma_txchan txchan;void* source_buff_ptr = (void*) chr; /* 源地址 */void* destination_buff_ptr = (void*)IOADDR_ALTERA_AVALON_UART_TXDATA(UART_BASE); /* 目标地址IOADDR_ALTERA_AVALON_UART_TXDATA(UART_BASE)函数读出txdata的地址 */* 打开发送通道 */if (txchan = alt_dma_txchan_open("/dev/dma&

17、quot;) = NULL)printf ("Failed to open transmit channeln");exit (1);/* 设置目标地址固定 */if (rc = alt_dma_txchan_ioctl(txchan, ALT_DMA_TX_ONLY_ON, destination_buff_ptr) < 0)printf ("Failed to set ioctl, reason = %in", rc);exit (1);/设置每次发送一个字节,即8位,因为UART每次只发送8位if(rc = alt_dma_txchan_ioctl(txchan,ALT_DMA_SET_MODE_8 ,NULL)<0)    printf("Failed to set mode 8n");    exit(1);/* 开始发送 */if (rc = alt_dma_txchan_send(txchan, sour

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论