How to write a C/C++ code describing our simple LED controller? In this lecture, I am going to answer 1
this question. As our first coding experience, 2
I will try to keep everything simple. 3
A typical hardware module has four main components: A couple of input signals to read data or receive, 4
control commands. A few output signals to send out data or control commands. Some input/output or 5
inout signals to send and receive data or control commands. 6
Finally, functional and timing behaviour 7
We use a C/C++ software function to describe the hardware designs. 8
A C/C++ function has four main parts: Return value: it can be used to send data out. Function name: to 9
distinguish the function. Arguments: to send or receive data. Body: 10
to define the functionality of an algorithm. There are two types of arguments: call-by-value and 11
call-by-reference. 12
The call-by-value arguments are used only for reading data in the function. 13
The call-by-reference arguments are used for reading and returning data in the function. The pointer 14
operators or C++ reference operators can be used to define call-by-reference arguments. 15
This table shows the analogy between the components in a hardware design and a software function. 16
The function-return value can represent the output signals in the hardware. 17
The call-by-value arguments resemble the input signals in the hardware. 18
The call-by-reference arguments correspond to the output or inout signals in the hardware. And finally, 19
the function 20
body characterises the hardware design functionality and timing. 21
Our LED controller hardware design contains a few output signals corresponding to the LEDs to be 22
controlled. 23
Therefore, the software function implementing this controller should return a value. As mentioned 24
in the previous slide, 25
there are three ways to do so: 26
Using the function return statement. Using a pointer argument. Using a reference argument (C++ feature) 27
If we assume that our controller is going to control 8 LEDs, then an unsigned char C/C++ data type can 28
be used to represent the output signals. 29
This function uses the first approach to return the binary value of 11110000, 30
which means four lower LEDs are off, and four upper LEDs are on. 31
In the second approach, The function uses a pointer argument to return the same value. 32
And finally, the third version of the function returns the same value using the C++ reference argument. 33
One of the common mistakes among newbies is using the call-by-value argument to return a value. As 34
we know, this type of arguments adds input signals to the design instead of outputs. 35
How can we add port interfaces to the arguments in our C description? Assigning a proper interface 36
to each function argument plays a crucial role in synthesising the software code into an efficient hardware 37
module. In the following video, 38
I will briefly unlock some of the secrets behind this interface assignment and how to use compiler directives 39
to add them to the code. 40
Takeaway messages from this lecture are: 41
1- A software function can describe a hardware module 2- The function arguments model the hardware ports 3- The 42
function body implements the hardware behaviour and timing 43
Now the quiz question: How to describe a 16-LED controller in HLS that turns on the lower 44
8 LEDs and keeps the rest OFF.