|
Background:
Handel-C is a high level programming language designed to enable compilation of programs directly in to hardware, which is implemented on Field Programmable Gate Array (FPGA). Handel-C is based on the syntax of
conventional C (ANSI C), with additional extensions to take advantage of the features of hardware. As Handel-C is high level it is possible to convert a Software Algorithm in to a hardware implementation with the
greatest of ease. Handel-C provides an alternative method to hardware design, compared to other methods of hardware design such as Schematic Capture methods and Hardware Definition Languages (HDL). If Hardware
Definition Languages are thought of as the Assembly Language equivalent in Hardware Design. Then Handel-C represents the equivalent of a High Level Language in Hardware Design.
To aid the Handel-C programmer it provides macros, similar in concept to the#define directives used by C pre-processors, but which perform more than just textual manipulation of the source. Macros fall into two categories, expressions and procedures.
Macro expressions
Macro expressions themselves are divided into two categories, shared and non-shared expressions. The syntax for both is similar, and is as follows:
macro expr normal_expr(x) = x + 2; shared expr shared_expr(x) = x + 3; int 8 var1, var2; var1 = normal_expr(var2); var2 = shared_expr(var1);
Either form of macro expression can take any number of parameters. Shared expressions generate hardware only once, the compiler producing the necessary multiplexors for the inputs if there are any, whereas non-shared
expressions generate hardware each time they are used, and consequently do not need any multiplexors.
Macro expressions are allowed to be recursive, and complex functions can be built up using select expressions, that direct the compiler to choose one of two expressions, depending on a value that must be a compile time constant. This allows single macro expressions to be used with different width expressions without having to be parametrised on variable width, for example.
It is the responsibility of the programmer to ensure that shared macro expressions with parameters are not used by different sections of code in the same clock cycle. Non-shared expressions, as they generate hardware
for each invocation, can be used without restrictions.
Macro procedures
Macro procedures are declared and used with the following syntax:
macro proc macro_proc(n) { par { x = x + n; y = y - n;
}} unsigned 8 x, y; void main() { macro_proc(6); }
Hardware is generated for each time the procedure is used. Any number of parameters is allowed, but macro procedures cannot be recursive. However they are allowed to use recursive expressions if required. Macro
procedures are a useful device to divide Handel-C code up into sections.
Introduction:
This tutorial is to give you a brief introduction into how Handel-C works through the use of a program called bounce. Bounce is a program that was written in Handel-C to display a square that bounces off the wall of
the monitor. There are 3 include files that we will not be concerned with, but I will tell you a little bit about each of them. As with C or C++ you need to include a stdlib.h file and for this program you also need
syncgen.h, which is the Sync generator and the dlabunm.h, which is the macro and pin definition file for the digilab board. The file that we will be dealing with is the source file called bounce.c. You will be
saving the files into directory. Once you have saved this file you will then be able to make changes to the square size and speed. Your ultimate goal is create a netlist that will be dropped down onto
the FPGA and then from there your bouncing square will appear on the monitor.
This is the directory that we were talking about so that the students could destroy the original.
Lab
First step:
On the desktop open the DK1 Design Suite. If you cannot find it on the desktop, then go to "START", select "PROGRAMS", DK1 Design Suite. You should get a blank workspace area that looks like image 1. Go to the "FILE"
dropdown menu, select "OPEN WORKSPACE" and select "BOUNCE."
|