Set up the hardware for the project – Altera Nios II C2H Compiler User Manual

Page 27

Advertising
background image

Altera Corporation

9.1

2–5

November 2009

Nios II C2H Compiler User Guide

Getting Started Tutorial

f

You can download dma_c2h_tutorial.c from the Nios II literature page.
The file is located next to this document (Nios II C2H Compiler User
Guide)
on the Altera Nios II literature page at

http://www.altera.com/

literature/lit-nio2.jsp

.

The file dma_c2h_tutorial.c includes two functions:

do_dma()

– This is the function you accelerate. It performs a block

memory copy.

do_dma()

takes a source address pointer, a

destination address pointer, and an integer number of bytes to copy.
When implemented in hardware,

do_dma()

resembles DMA copy

logic. The prototype for

do_dma()

is as follows:

int do_dma( int * _ _ restrict_ _ dest_ptr,

int * _ _ restrict_ _ source_ptr, int length )

The

_ _ restrict_ _

qualifier informs the compiler that the

pointers

dest_ptr

and

source_ptr

point to mutually exclusive

address ranges. For further information about the

_ _ restrict_ _

qualifier, see

“Pointer Aliasing” on page 3–32

of

Chapter 3, C-to-

Hardware Mapping Reference

.

main()

main()

calls

do_dma()

and measures the amount of time

taken, so that you can compare the software implementation with the
hardware accelerator.

main()

performs the following actions:

1.

Allocates two 1 MB buffers in main memory

2.

Fills the source buffer with incrementing values

3.

Fills destination buffer with all 0x0.

4.

Calls the

do_dma()

function 100 times

5.

Checks the copied data to ensure there were no errors

6.

Frees the two allocated buffers

To measure the time it takes for the copy operations to complete, there are
timer routines around the loop that calls the

do_dma()

function. After

the application runs, the number of milliseconds that were spent
performing the copy operations is displayed to the Console view in the
Nios II IDE.

Set up the Hardware for the Project

To set up the hardware for the tutorial, perform the following steps:

1.

Connect your Nios development board to power, and connect the
board to your host computer with an Altera download cable.

Advertising