下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 道法安全记心上课件
- 2026年甘肃省陇南市高职单招职业适应性测试题库试题附答案
- 2025胸腔镜肺结节日间手术围手术期健康教育专家共识解读课件
- 车险新人培训
- 木材加工设备安装计划主要内容
- 军队文职面试考生回忆版试题(软件工程工程技术)
- 车间节后返岗安全培训课件
- 酒店客户服务标准流程制度
- 2025年学校教学管理与核心教学制度落实工作心得(2篇)
- 2025年儿科护士儿童疾病护理与心理安抚工作年度总结(3篇)
- 别墅浇筑施工方案(3篇)
- 2026年关于汽车销售工作计划书
- 肿瘤放射治疗的新技术进展
- 2024外研版四年级英语上册Unit 4知识清单
- 视频会议系统施工质量控制方案
- 2025年高二数学建模试题及答案
- 2025年党的二十届四中全会精神宣讲稿及公报解读辅导报告
- 压力管道安装单位压力管道质量安全风险管控清单
- 停车场道闸施工方案范本
- 2025年实验室安全事故案例
- 卫生院关于成立消除艾滋病、梅毒、乙肝母婴传播领导小组及职责分工的通知
评论
0/150
提交评论