阅读DMA Controller Core 官方手册

阅读DMA Controller Core 官方手册-LMLPHP

DMA控制器框架图

阅读DMA Controller Core 官方手册-LMLPHP怎样去设定一个DMA控制器

阅读DMA Controller Core 官方手册-LMLPHP

实例化DMA控制器

参数配置界面如下图所示:

阅读DMA Controller Core 官方手册-LMLPHP

对于width of the DMA length register的配置尝试如下:

阅读DMA Controller Core 官方手册-LMLPHP

阅读DMA Controller Core 官方手册-LMLPHP

阅读DMA Controller Core 官方手册-LMLPHP

正如官方文档中描述的那样:

阅读DMA Controller Core 官方手册-LMLPHP

DMA Length register的位宽决定了DMA Length的最大值,决定了可以用这个DMA控制器传递数据的个数。

DMA的工作模式:

阅读DMA Controller Core 官方手册-LMLPHP

搭建一个系统:

数据从ROM里面,经过DMA控制器传送到RAM里面,软件程序单独在RAM_Pro内存空间里面运行。

阅读DMA Controller Core 官方手册-LMLPHP

注意:片上ROM与片上RAM可以不与Nios II 处理器相连,这样会导致处理器监控不到ROM和RAM里面的数据,在Eclipse里面的debug界面中没法查找到相应的内存空间,但是连上处理器之后,可以查询得到,建议连上

阅读DMA Controller Core 官方手册-LMLPHP顶层例化:

阅读DMA Controller Core 官方手册-LMLPHP DMA控制器软件程序的编写:

需要根据用户手册来指导编写:

阅读DMA Controller Core 官方手册-LMLPHP

阅读DMA Controller Core 官方手册-LMLPHP

阅读DMA Controller Core 官方手册-LMLPHP

在Eclipse中编写代码如下:

/*
* "Hello World" example.
*
* This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
* the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
* designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
* device in your system's hardware.
* The memory footprint of this hosted application is ~69 kbytes by default
* using the standard reference design.
*
* For a reduced footprint version of this template, and an explanation of how
* to reduce the memory footprint for a given application, see the
* "small_hello_world" template.
*
*/ #include <stdio.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "system.h"
static volatile int rx_done = ;
static void done(void* handle, void* data)
{
rx_done++;
} int main(int argc, char* argv[], char* envp[])
{
int rc;
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
void* tx_data = (void*) 0x2000;
void* rx_data = (void*) 0x1000;
if((txchan = alt_dma_txchan_open("/dev/dma")) == NULL)
{
printf ("Failed to open transmit channel\n");
exit();
} if((rxchan = alt_dma_rxchan_open("/dev/dma")) == NULL)
{
printf ("Failed to open receive channel\n");
exit();
} if((rc = alt_dma_txchan_send(txchan,tx_data,,NULL,NULL)) < )
{
printf ("Failed to post transmit request,reason = %i\n",rc);
exit();
} if ((rc = alt_dma_rxchan_prepare(rxchan,rx_data,,NULL,NULL)) < )
{
printf ("Failed to post read request,reason = %i\n",rc);
exit();
} while(!rx_done)
{
printf ("Transfer successful!\n");
}
printf ("Hello from Nios II!\n");
return ;
}

由于数据存储在片上的ROM和RAM中,因此可以用In-System Memory Content Editor来进行查看:

首先给ROM初始化数据文件和Instance ID:

阅读DMA Controller Core 官方手册-LMLPHP

阅读DMA Controller Core 官方手册-LMLPHP 然后,同样需要给RAM分配Instance ID:

阅读DMA Controller Core 官方手册-LMLPHP

最后在In-System Memory Content Editor里面进行查看:

阅读DMA Controller Core 官方手册-LMLPHP

经过核对:数据传输无误。

05-11 15:34
查看更多