0
1
00:00:00,850 --> 00:00:06,460
In this lecture, I will explain the structure of the HLS code for the Home Alarm System project 
1

2
00:00:06,580 --> 00:00:08,020
explained in the previous lecture.
2

3
00:00:09,390 --> 00:00:15,000
The design code should contain a top-function. The top-function should check all the sensors for any 
3

4
00:00:15,000 --> 00:00:18,680
security breach and send the proper information to the display panel.
4

5
00:00:22,040 --> 00:00:28,470
Two separate sub-functions help to send window or motion sensors information to the 7-segment displays.
5

6
00:00:29,810 --> 00:00:32,390
We also need a testbench to test the design behaviour.
6

7
00:00:33,110 --> 00:00:35,930
The test starts with the C/C++ main function.
7

8
00:00:36,770 --> 00:00:40,280
The function generates the input data and applies them to the design 
8

9
00:00:40,550 --> 00:00:44,840
and the golden software model and compares the results.
9

10
00:00:48,500 --> 00:00:54,470
The design top-function receives two groups of input signals and generates three groups of output signals.
10

11
00:00:56,540 --> 00:01:03,290
Here, two 16-bit and  5-bit arbitrary precision call-by-value arguments are used to read the slide 
11

12
00:01:03,290 --> 00:01:09,590
switches and push-buttons. Also, three 16-bit, 8-bit and 4-bit arbitrary precision 
12

13
00:01:09,590 --> 00:01:10,250
call-by-reference 
13

14
00:01:10,250 --> 00:01:15,350
arguments are defined to provide data for LEDs and seven-segments.
14

15
00:01:16,920 --> 00:01:23,160
We define an array to represent the seven-segment code in the design. Later we refer to this array to
15

16
00:01:23,160 --> 00:01:25,560
extract the desired code for 7-segments.
16

17
00:01:28,780 --> 00:01:34,260
The data format in the 16-bit slide_switches argument was presented in the previous lecture.
17

18
00:01:35,660 --> 00:01:40,310
In the first step, the top-function splits these data into different variables.
18

19
00:01:40,640 --> 00:01:45,910
Also, it saves the push_button states into a 5-bit variable with a more descriptive name.
19

20
00:01:46,460 --> 00:01:50,210
Then it directly connects all the slide-switches to LEDs. 
20

21
00:01:53,490 --> 00:01:59,910
The top-function should check the value of the code to see if the system is ON or OFF. According to 
21

22
00:01:59,910 --> 00:02:01,050
the project definition 
22

23
00:02:01,050 --> 00:02:06,570
in the previous lecture, the binary code of 1011 turns on the system.
23

24
00:02:07,950 --> 00:02:13,380
If the system is OFF, then all the 7-segments should display the letter O or the number 0.
24

25
00:02:15,400 --> 00:02:22,060
If the system is ON, then the output of the sensors should be checked. If there is any activation 
25

26
00:02:22,060 --> 00:02:26,230
in sensors, then the security_breach function is called for more inspection. 
26

27
00:02:27,300 --> 00:02:31,050
Otherwise, all the 7-segment displays should show the letter A.
27

28
00:02:32,630 --> 00:02:38,950
Now let’s have a look at the security_breach sub-function.
Firstly, it sends the letter E to all 
28

29
00:02:38,990 --> 00:02:45,110
7-segments. Then, it checks the pattern on the show_fault variable (which represents the push-buttons 
29

30
00:02:45,110 --> 00:02:45,680
sates).
30

31
00:02:46,640 --> 00:02:52,460
If any of the push_buttons is pressed, then the code checks whether it is related to the window sensors 
31

32
00:02:52,490 --> 00:02:58,040
or the motion sensors. And call the corresponding function for displaying the proper number on 
32

33
00:02:58,040 --> 00:02:58,910
seven segments.
33

34
00:03:01,240 --> 00:03:06,700
Let’s have a look at the display_window function. Before that, it is helpful to remember the data format 
34

35
00:03:06,700 --> 00:03:09,730
of the show_fault variable explained in the previous lecture.
35

36
00:03:10,540 --> 00:03:13,670
This function sends the letter E to all 7-segments again. 
36

37
00:03:13,690 --> 00:03:19,630
This process is done to make sure that the 7-segments receive data for all paths inside
37

38
00:03:19,630 --> 00:03:20,190
the function.
38

39
00:03:20,440 --> 00:03:26,140
Otherwise, as some paths may not generate data for the 7-segments than the HLS code saves 
39

40
00:03:26,140 --> 00:03:27,210
the previous values, 
40

41
00:03:27,880 --> 00:03:30,370
that means it should instantiate some flip-flips. 
41

42
00:03:30,730 --> 00:03:33,900
Consequently, the resulted circuit won’t be combinational. 
42

43
00:03:35,080 --> 00:03:40,990
Then the function modifies the 7-segment data according to the value of show_fault variable and 
43

44
00:03:40,990 --> 00:03:42,010
the sensor outputs.
44

45
00:03:45,790 --> 00:03:51,100
The display_motion function also has a similar structure and generates the corresponding 7-segment 
45

46
00:03:51,100 --> 00:03:55,630
data base on the value of show_fault variable and the motion sensors outputs.
46

47
00:03:58,800 --> 00:04:05,580
The test bench, firstly, define the status variables which keeps the status of the test. And report that 
47

48
00:04:05,580 --> 00:04:06,150
properly.
48

49
00:04:09,820 --> 00:04:15,100
Then it declares a couple of variables for design and software implementation inputs and outputs.
49

50
00:04:18,980 --> 00:04:25,220
Then using four nested for-loops, it generates all the possible inputs and prepares the design input 
50

51
00:04:25,220 --> 00:04:25,570
data.
51

52
00:04:33,640 --> 00:04:37,360
Then it calls the design and the software model and compares the results. 
52

53
00:04:42,690 --> 00:04:48,780
The next lecture puts all the codes in a Vivado-HLS project and generates the bitstream and examine 
53

54
00:04:48,780 --> 00:04:50,040
the system on the Basys-3 board.
