Having introduced Direct Memory Access in my previous blog, this blog will focus upon creating a very simple example which demonstrates how to set up and use DMA. To demonstrate this I will transfer one memory location to another using one DMA controller channel.

The starting point for this is one which we have commonly used in this blog series: the inclusion of header files generated as part of the BSP. These header files provide macros and functions we can use to drive the DMA. For this example we will need to include:

#include "xscugic.h"

#include "xdmaps.h"

#include "xil_exception.h"



Xscugic.h and xil_exceptions.h allow use of the interrupt controller while xdmaps.h configures and allows use of the DMA.

Using parameters provided with xparamters.h, we can define the device identifications for the DMA and interrupt controller, the interrupts that will be used, and the length of the data we will be transferring:

#define DMA_DEVICE_ID XPAR_XDMAPS_1_DEVICE_ID

#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID

#define DMA_FAULT_INTR XPAR_XDMAPS_0_FAULT_INTR

#define DMA_DONE_INTR_0 XPAR_XDMAPS_0_DONE_INTR_0

#define DMA_LENGTH 1024

The next stage of the development is to write three functions to configure the DMA, to configure the interrupt controller, and to act as the interrupt service routine at the completion of the DMA transfer.

Within the DMA configuration function we first create a DMA command using the command structure provided by xdmaps.h. A DMA command consists of the channel control, block descriptor, a user-defined program, a pointer to the generated program and the result of the transfer. As this is a simple example we will not be requiring all of these components however we will be configuring the DMA controller as below:

DmaCmd. ChanCtrl.SrcBurstSize = 4;

DmaCmd. ChanCtrl.SrcBurstLen = 4;

DmaCmd. ChanCtrl.SrcInc = 1;

DmaCmd. ChanCtrl.DstBurstSize = 4;

DmaCmd. ChanCtrl.DstBurstLen = 4;

DmaCmd. ChanCtrl.DstInc = 1;

DmaCmd. BD.SrcAddr = (u32) Src;

DmaCmd. BD.DstAddr = (u32) Dst;

DmaCmd. BD.Length = DMA_LENGTH * sizeof ( int );

The next step is to initialize and configure the DMA controller before running the interrupt set up function to connect the DMA interrupts to the interrupt controller:

DmaCfg = XDmaPs_LookupConfig(DeviceId);

XDmaPs_CfgInitialize(DmaInst,DmaCfg,DmaCfg-> BaseAddress );

SetupInterrupt(&GicInstance, DmaInst);

Following this, the source memory location is seeded with data and the destination location is cleared before we connect the done handler and start the transfer, to track progress we also make one call to the DMA progress function:

DmaCfg = XDmaPs_LookupConfig(DeviceId);

XDmaPs_CfgInitialize(DmaInst,DmaCfg,DmaCfg->BaseAddress);

SetupInterrupt(&GicInstance, DmaInst);

XDmaPs_Print_DmaProg(&DmaCmd);

When the attached source code file was run on the MicroZed the following results were shown on the rs232 monitor output I was using to report the status.

Having looked at the DMA control and basic example, in my next blog I will be moving on to look at the MicroZed carrier card and how we can use this with the MicroZed as a system of modules.

Please see the previous entries in this MicroZed series by Adam Taylor:

The Zynq PS/PL, Part Eight: Zynq DMA – Adam Taylor’s MicroZed Chronicles Part 28

The Zynq PS/PL, Part Seven: Adam Taylor’s MicroZed Chronicles Part 27

The Zynq PS/PL, Part Six: Adam Taylor’s MicroZed Chronicles Part 26

The Zynq PS/PL, Part Five: Adam Taylor’s MicroZed Chronicles Part 25

The Zynq PS/PL, Part Four: Adam Taylor’s MicroZed Chronicles Part 24

The Zynq PS/PL, Part Three: Adam Taylor’s MicroZed Chronicles Part 23

The Zynq PS/PL, Part Two: Adam Taylor’s MicroZed Chronicles Part 22

The Zynq PS/PL, Part One: Adam Taylor’s MicroZed Chronicles Part 21

Introduction to the Zynq Triple Timer Counter Part Four: Adam Taylor’s MicroZed Chronicles Part 20

Introduction to the Zynq Triple Timer Counter Part Three: Adam Taylor’s MicroZed Chronicles Part 19

Introduction to the Zynq Triple Timer Counter Part Two: Adam Taylor’s MicroZed Chronicles Part 18

Introduction to the Zynq Triple Timer Counter Part One: Adam Taylor’s MicroZed Chronicles Part 17

The Zynq SoC’s Private Watchdog: Adam Taylor’s MicroZed Chronicles Part 16

Implementing the Zynq SoC’s Private Timer: Adam Taylor’s MicroZed Chronicles Part 15

MicroZed Timers, Clocks and Watchdogs: Adam Taylor’s MicroZed Chronicles Part 14

More About MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 13

MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 12

Using the MicroZed Button for Input: Adam Taylor’s MicroZed Chronicles Part 11

Driving the Zynq SoC's GPIO: Adam Taylor’s MicroZed Chronicles Part 10

Meet the Zynq MIO: Adam Taylor’s MicroZed Chronicles Part 9

MicroZed XADC Software: Adam Taylor’s MicroZed Chronicles Part 8

Getting the XADC Running on the MicroZed: Adam Taylor’s MicroZed Chronicles Part 7

A Boot Loader for MicroZed. Adam Taylor’s MicroZed Chronicles, Part 6

Figuring out the MicroZed Boot Loader – Adam Taylor’s MicroZed Chronicles, Part 5

Running your programs on the MicroZed – Adam Taylor’s MicroZed Chronicles, Part 4

Zynq and MicroZed say “Hello World”-- Adam Taylor’s MicroZed Chronicles, Part 3

Adam Taylor’s MicroZed Chronicles: Setting the SW Scene

Bringing up the Avnet MicroZed with Vivado