0
1
00:00:00,760 --> 00:00:07,930
How to write a C/C++ code describing our simple LED controller? In this lecture, I am going to answer 
1

2
00:00:07,930 --> 00:00:10,800
this question. As our first coding experience,
2

3
00:00:10,810 --> 00:00:12,520
I will try to keep everything simple. 
3

4
00:00:14,950 --> 00:00:21,610
A typical hardware module has four main components: 
A couple of input signals to read data or receive,
4

5
00:00:21,610 --> 00:00:28,420
control commands. A few output signals to send out data or control commands. Some input/output or
5

6
00:00:28,420 --> 00:00:31,870
inout signals to send and receive data or control commands. 
6

7
00:00:32,050 --> 00:00:34,930
Finally, functional and timing behaviour
7

8
00:00:36,510 --> 00:00:40,530
We use a C/C++ software function to describe the hardware designs. 
8

9
00:00:42,210 --> 00:00:51,630
A C/C++ function has four main parts: Return value: it can be used to send data out. Function name: to 
9

10
00:00:51,630 --> 00:00:56,520
distinguish the function. Arguments: to send or receive data. 	Body:
10

11
00:00:57,590 --> 00:01:03,650
to define the functionality of an algorithm.  There are two types of arguments: call-by-value and 
11

12
00:01:03,650 --> 00:01:04,400
call-by-reference.  
12

13
00:01:05,120 --> 00:01:09,590
The call-by-value arguments are used only for reading data in the function.
13

14
00:01:10,960 --> 00:01:17,380
The call-by-reference arguments are used for reading and returning data in the function. The pointer
14

15
00:01:17,380 --> 00:01:22,960
operators or C++ reference operators can be used to define call-by-reference arguments.
15

16
00:01:23,890 --> 00:01:29,080
This table shows the analogy between the components in a hardware design and a software function.
16

17
00:01:30,160 --> 00:01:34,150
The function-return value can represent the output signals in the hardware.
17

18
00:01:34,300 --> 00:01:38,040
The call-by-value arguments resemble the input signals in the hardware.
18

19
00:01:38,560 --> 00:01:44,260
The call-by-reference arguments correspond to the output or inout signals in the hardware. And finally, 
19

20
00:01:44,410 --> 00:01:44,980
the function 
20

21
00:01:44,980 --> 00:01:48,070
body characterises the hardware design functionality and timing.
21

22
00:01:50,060 --> 00:01:56,540
Our LED controller hardware design contains a few output signals corresponding to the LEDs to be 
22

23
00:01:56,540 --> 00:01:57,200
controlled.
23

24
00:01:57,680 --> 00:02:03,950
Therefore, the software function implementing this controller should return a value.  As mentioned
24

25
00:02:03,950 --> 00:02:05,010
in the previous slide, 
25

26
00:02:05,030 --> 00:02:06,500
there are three ways to do so:
26

27
00:02:06,860 --> 00:02:12,680
Using the function return statement. Using a pointer argument. Using a reference argument (C++ feature)
27

28
00:02:14,410 --> 00:02:22,270
If we assume that our controller is going to control 8 LEDs, then an unsigned char C/C++ data type can 
28

29
00:02:22,270 --> 00:02:24,370
be used to represent the output signals. 
29

30
00:02:26,270 --> 00:02:33,350
This function uses the first approach to return the binary value of 11110000, 
30

31
00:02:33,470 --> 00:02:38,000
which means four lower LEDs are off, and four upper LEDs are on.
31

32
00:02:38,510 --> 00:02:43,470
In the second approach, The function uses a pointer argument to return the same value.
32

33
00:02:43,910 --> 00:02:50,330
And finally, the third version of the function returns the same value using the C++ reference argument. 
33

34
00:02:52,020 --> 00:02:58,530
One of the common mistakes among newbies is using the call-by-value argument to return a value. As
34

35
00:02:58,530 --> 00:03:03,180
we know, this type of arguments adds input signals to the design instead of outputs.
35

36
00:03:05,450 --> 00:03:11,300
How can we add port interfaces to the arguments in our C description? Assigning a proper interface 
36

37
00:03:11,300 --> 00:03:17,330
to each function argument plays a crucial role in synthesising the software code into an efficient hardware 
37

38
00:03:17,330 --> 00:03:19,140
module. In the following video, 
38

39
00:03:19,760 --> 00:03:26,210
I will briefly unlock some of the secrets behind this interface assignment and how to use compiler directives 
39

40
00:03:26,330 --> 00:03:27,730
to add them to the code. 
40

41
00:03:29,490 --> 00:03:31,910
Takeaway messages from this lecture are:
41

42
00:03:34,460 --> 00:03:41,330
1- A software function can describe a hardware module 2- The function arguments model the hardware ports 3- The 
42

43
00:03:41,330 --> 00:03:44,240
function body implements the hardware behaviour and timing
43

44
00:03:46,360 --> 00:03:52,480
Now the quiz question: How to describe a 16-LED controller in HLS that turns on the lower 
44

45
00:03:52,480 --> 00:03:54,610
8 LEDs and keeps the rest OFF. 
