1. NIOS2 DMA controller Structural block diagram
650) this.width=650; "alt=" NIOS2 essay--DMA (1)-Shugenyin-shugenyin's Blog "src=" Http://img2.ph.126.net/UvG2chFB2mYwE7kHy_ B9nq==/6631693387816559267.jpg "style=" border:0px;height:auto;margin:0px 10px 0px 0px;width:500px; "/>
Like other IP peripherals, the DMA controller also implements the register configuration and data reading and writing functions via the Avalon mm bus.
2. NIOS2 DMA three modes of transmission
650) this.width=650; "alt=" NIOS2 essay--DMA (1)-Shugenyin-shugenyin's Blog "src=" http://img0.ph.126.net/ Xoplqockjc1tpsov8kbygg==/6631719776095607640.jpg "style=" border:0px;height:auto;margin:0px 10px 0px 0px;width : 500px; "/>
3. NIOS2 DMA API function
The API function prototypes of the NIOS2 Dam are defined in the ALT_DMA.H header file. The usual API functions are as follows:
Alt_dma_txchan alt_dma_txchan_open (const char* name);
static alt_inline int alt_dma_txchan_send (Alt_dma_txchan DMA,
Const void* from,
Alt_u32 length,
Alt_txchan_done* Done,
void* handle)
{
Return DMA? Dma->dma_send (DMA,
From
Length
Done
HANDLE):-enodev;
}
static alt_inline int alt_dma_txchan_ioctl (Alt_dma_txchan DMA,
int req,
void* Arg)
{
Return DMA? DMA->IOCTL (DMA, req, arg):-enodev;
}
Alt_dma_rxchan alt_dma_rxchan_open (const char* dev);
static Alt_inline intAlt_dma_rxchan_prepare(Alt_dma_rxchan DMA,
void* data,
Alt_u32 Len,
Alt_rxchan_done* Done,
void* handle)
{
Return DMA? Dma->prepare (DMA, data, Len, done, handle):-enodev;
}
static alt_inline int alt_dma_rxchan_ioctl (Alt_dma_rxchan DMA,
int req,
void* Arg)
{
Return DMA? DMA->IOCTL (DMA, req, arg):-enodev;
}
4. Reference Design--onchipmenmory to SDRAM
1) Qsys Settings
The NIOS2 code runs in SDRAM, and onchipmemory acts as an on-chip storage peripheral.
The following two figures are the IP settings in the Qsys, which shows that DMA supports burst read-write mode, which can greatly improve efficiency.
In the second picture, the blogger checked the show signals option to see the signal interface defined by the DMA component, a Avalon mm slave port for the configuration register, two Avalon mm Masters to read and write, and an IRQ interrupt output, Generates an interrupt signal to the CPU.
650) this.width=650; "alt=" NIOS2 essay--DMA (1)-Shugenyin-shugenyin's Blog "src=" http://img0.ph.126.net/ Bhyqhvtc-ew4oohvfnkhxg==/6631485580118913474.jpg "style=" border:0px;height:auto;margin:0px 10px 0px 0px;width : 500px; "/>
650) this.width=650; "alt=" NIOS2 essay--DMA (1)-Shugenyin-shugenyin's Blog "src=" http://img1.ph.126.net/ Auywkyd5yu3lnjnrqrj4kw==/6631524063025883605.jpg "style=" border:0px;height:auto;margin:0px 10px 0px 0px;width : 500px; "/>
2) Software source code
File name:main.c
Date:2016.8.15
Author:shugen.yin
Function:DMA, onchip memory to SDRAM/DDR2
Log
#include <stdio.h>
#include <string.h>
#include <sys/alt_irq.h>
#include "system.h"
#include "Alt_types.h"
#include "Sys/alt_dma.h"
#define Dat_len 32
unsigned int BUFFER0[DAT_LEN/4];
unsigned int *point=onchip_memory1_0_base;
static void Dma_init (void); Initializing DMA
unsigned int dma_end_flag = 0;
Alt_dma_txchan TX;
Alt_dma_rxchan Rx;
void Dma_done ()
{
dma_end_flag++;
}
static void Dma_init (void)
{
tx = Alt_dma_txchan_open ("/dev/dma_0");
if (tx! = NULL)
{
printf ("DMA transition start\n");
}
Alt_dma_txchan_ioctl (Tx,alt_dma_set_mode_32,null);
Point is the source address, the length of the transmit block is Dat_len
Alt_dma_txchan_send (TX, point, Dat_len, NULL, NULL);
Rx = Alt_dma_rxchan_open ("/dev/dma_0");
Alt_dma_rxchan_ioctl (Rx,alt_dma_set_mode_32,null);
BUFFER0 is the destination address, the length of the transmitted data block is Dat_len, Dma_done () is the callback function called after the DMA is completed
Alt_dma_rxchan_prepare (Rx, Buffer0, Dat_len, Dma_done, NULL);
}
int main ()
{
int i;
for (i=0;i<dat_len/4;i++)
Buffer0[i] = 0;
for (i=0;i<dat_len/4;i++)
* (point+i) = i+1;
Initializing DMA
Dma_init ();
Wait for end of interrupt, indicating transfer complete
while (Dma_end_flag = = 0)
{
}
Print data from a receiving address
for (i=0;i<dat_len/4;i++)
{
printf ("Buffer0[%d]=%d\t", I,buffer0[i]);
}
Alt_dma_txchan_close (TX);
Alt_dma_rxchan_close (RX);
return 0;
}
This article is from the "Shugenyin blog" blog, make sure to keep this source http://shugenyin.blog.51cto.com/4259554/1838704
NIOS2 essay--DMA (1)