Skip to content

Commit 3b1f7c1

Browse files
committed
Updated version of all labs
Updates for style and clarity; changed to misc method of specifying kernel modules; updated C coding standard to match industry.
1 parent f6e974e commit 3b1f7c1

File tree

148 files changed

+2973
-3001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+2973
-3001
lines changed

lab1/design_files/DE1-SoC/README.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
The file part2 is an ARM executable program. It is a sample solution to Part II. This sample
2-
solution exits after 12 seconds.
1+
The file part2 is an ARM executable program. It is a sample solution to Part II.
2+
This sample solution exits after 12 seconds.
33

4-
The file part3.ko is a kernel module. It is a sample solution using the HEX0 display for Part III.
5-
6-
The file part3_ASCII.ko is a kernel module. It is a sample solution using the Terminal window
4+
The file part3.ko is a kernel module. It is a sample solution using the HEX0 display
75
for Part III.
6+
7+
The file part3_ASCII.ko is a kernel module. It is a sample solution using the
8+
Terminal window for Part III.
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
The file part2 is an ARM executable program. It is a sample solution to Part II. This sample
2-
solution exits after 12 seconds.
1+
The file part2 is an ARM executable program. It is a sample solution to Part II.
2+
This sample solution exits after 12 seconds.
33

4-
The file part3.ko is a kernel module. It is a sample solution using the HEX0 display for Part III.
5-
6-
The file part3_ASCII.ko is a kernel module. It is a sample solution using the Terminal window
4+
The file part3.ko is a kernel module. It is a sample solution using the HEX0 display
75
for Part III.
6+
7+
The file part3_ASCII.ko is a kernel module. It is a sample solution using the
8+
Terminal window for Part III.

lab1/doc/lab1.tex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
devices. This discussion assumes that the reader is using the DE1-SoC development and
1919
education board, but the lab instructions apply equally well if other boards are being used,
2020
such as the DE10-Standard or DE10-Nano. The DE-series boards are described on the
21-
FPGAcademy.org website. Linux runs on the ARM* processor that is part
21+
{\it FPGAcademy.org} website. Linux runs on the ARM* processor that is part
2222
of the Cyclone V SoC device. During the operating system boot process, Linux programs the
2323
Cyclone V FPGA with the \textit{DE1-SoC Computer} system (or similar system for other
2424
boards). This system instantiates components inside the FPGA to make it easy to use the
2525
peripherals built into the DE1-SoC board, such as the LEDs, seven-segment displays, switches,
2626
and pushbuttons. For a detailed description of the computer system, please refer to
27-
a document such as \textit{DE1-SoC Computer System with ARM}, available from FPGAcademy.org.
27+
a document such as \textit{DE1-SoC Computer System with ARM}, available as part of the
28+
{\it Computer Organization} materials on {\it FPGAcademy.org}.
2829

2930
\section*{Part I}
3031
\noindent
3132
Read and complete Sections 1, 2, and 3 of the tutorial \textit{Using Linux on DE-series Boards}.
33+
This tutorial is available as part of the {\it Embedded Systems} material on {\it FPGAcademy.org}.
3234
These sections will guide you through setting up the Linux microSD card, running the
3335
Linux OS on the DE-series board, and communicating with the board from a host computer.
3436

@@ -47,7 +49,8 @@ \section*{Part II}
4749
right-to-left, then left-to-right, and so on.
4850
Use a delay so that the light moves at some reasonable speed. To implement the delay, you
4951
can use a Linux system function, such as \texttt{nanosleep($\ldots$)}. Documentation for
50-
the \texttt{nanosleep} function can be found by searching for it on the Internet.
52+
the \texttt{nanosleep} function can be found by typing \texttt{man nanosleep} in a
53+
Linux terminal, or by searching for it on the Internet.
5154

5255
\section*{Part III}
5356
\noindent
@@ -62,7 +65,7 @@ \section*{Part III}
6265
augment this code to display the count of pushbutton presses as a decimal digit, either on
6366
the seven-segment display {\it HEX0} or on the Linux Terminal window. You only need to
6467
display the decimal value corresponding to the four
65-
least-significant bits of the count, and wrap around to 0 when it reaches 9. Always
68+
least-significant bits of the count, and wrap around to 0 when it exceeds 9. Always
6669
leave the leftmost LEDR light set to 1 as a visual indicator that the device driver
6770
is present in the kernel. The count values displayed on the LEDR port should cycle through
6871
$\red{1}000000000, \red{1}00000000\red{1}, \red{1}00000000\red{1}0,
@@ -95,7 +98,8 @@ \section*{Part III}
9598
\end{lstlisting}
9699

97100
~\\
98-
\noindent More Terminal window commands can be found by searching on the Internet for
101+
\noindent Documentation for the {\it printk} library function can be found by searching on
102+
the Interet. Also, more Terminal window commands can be found by searching on the Internet for
99103
\texttt{VT100 escape codes}.
100104

101105
~\\

lab10/doc/figures/gaussian.pdf

1.74 KB
Binary file not shown.

lab10/doc/figures/gaussian.svg

Lines changed: 475 additions & 31 deletions
Loading

lab10/doc/lab10.tex

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
\newcommand{\LabNum}{10}
44
\newcommand{\CommonDocsPath}{../../common/docs}
55
\input{\CommonDocsPath/preamble.tex}
6+
\usepackage{amsmath}
67

78
\begin{document}
89

@@ -24,10 +25,10 @@
2425
\noindent
2526
~\\
2627
In this laboratory exercise, we will implement two versions of an image processing application
27-
that detects the edges of an image. The first version will run entirely on the CPU. We
28-
will assume that the reader is using the DE1-SoC board to run their programs. If a
29-
different board is being used, the same instructions will mostly apply, but we will point
30-
out any differences as needed. The second version of the application will
28+
that detects the edges of an image. The first version will run entirely on the CPU. This
29+
discussion assumes that you are using the ARM processor in the DE1-SoC Computer to run your
30+
programs. If a different board is being used, the same instructions will mostly apply, but we
31+
will point out any differences as needed. The second version of the application will
3132
make use of hardware acceleration, by offloading most of the image processing operations to
3233
a hardware accelerator implemented inside an FPGA. We will assume that image files are
3334
represented in the {\it bitmap} (BMP) file format, using {\it 24-bit true color}.
@@ -40,11 +41,8 @@ \section*{The Canny Edge-Detection Technique}
4041
a widely-used edge-detection scheme. Figures~\ref{fig:tracks} and \ref{fig:tracks_edges}
4142
show a sample image that is provided as the input to a Canny edge detector, as well as the
4243
resulting edge-detected output image.
43-
44-
~\\
45-
\noindent
46-
As illustrated in Figure~\ref{fig:canny} the Canny edge-detection algorithm involves five
47-
stages, which are applied to the input image in succession. The following
44+
As illustrated in Figure~\ref{fig:canny}, the Canny edge-detection algorithm involves five
45+
stages that are applied to the input image in succession. The following
4846
sections describe each stage of the algorithm and show how the sample image from
4947
Figure~\ref{fig:tracks} is transformed as it passes through each stage.
5048

@@ -109,9 +107,10 @@ \section*{Stage 2: Gaussian Smoothing}
109107
\noindent
110108
Smoothing, or blurring, of the image is accomplished by using a {\it Gaussian filter}, which
111109
modifies noisy pixels (pixels that are unlike their neighbouring pixels) to be more like
112-
their neighbours. An example of a Gaussian function is illustrated in Figure~\ref{fig:gaussian}$a$.
113-
By choosing different values for the parameters $\sigma$ and $\mu$, the amplitude and shape of the
114-
function can be selected. For this exercise we are using a digital version of the Gaussian,
110+
their neighbours. An example of a 2-D Gaussian function is illustrated in
111+
Figure~\ref{fig:gaussian}$a$. The shape of this function can be selected by choosing different
112+
values for the standard deviation $\sigma$. For this exercise we are using a
113+
digital version of the Gaussian,
115114
specified as a $5 \times 5$ filter, or {\it kernel}. This kernel corresponds to a Gaussian function
116115
with standard deviation $\sigma = 1$ and mean $\mu = 0$. Part~($b$) of Figure~\ref{fig:gaussian}
117116
shows how the kernel is applied to the image. The * operator denotes {\it convolution}, $A$ is
@@ -410,7 +409,11 @@ \section*{Part I}
410409
hardware-accelerated version developed later in this exercise. The code in
411410
Figure~\ref{fig:skeleton} is provided along with this exercise. Some additional functionality not
412411
shown in the figure is also included, such as code that can draw the images on an
413-
output video display.
412+
output video display. To view the images generated by your program, you can connect
413+
a video monitor to your DE1-SoC board. Alternatively, you can view the images by using the
414+
VGA emulator that is provided along with Lab Exercise 6. This emulator allows video output
415+
to be displayed in a window within a VNC Viewer tool.
416+
414417

415418
\lstset{language=C,numbers=none,escapechar=|,basicstyle=\small\ttfamily,}
416419
\begin{figure}[h]
@@ -658,7 +661,7 @@ \section*{Part II}
658661
(for the DE10-Nano board you would need to use the Onchip memory instead of SDRAM).
659662
The functions {\it open\_physical} and {\it map\_physical} use the {\it /dev/mem} mechanism
660663
and the Linux system function {\it mmap} to provide virtual memory mappings of physical
661-
addresses. More details are provided in the tutorial {\it Using Linux on DE-series Boards}.
664+
addresses. More details are provided in the tutorial {\it Using Linux on DE-series Boards}.
662665

663666
\item
664667
You are to write the function {\it memcpy\_consecutive\_to\_padded} to complete the code in
@@ -668,8 +671,10 @@ \section*{Part II}
668671
\item
669672
Compile and test your code. Some sample images that have the correct dimensions are provided with
670673
this lab exercise ($640 \times 480$ pixels for the DE1-SoC and DE10-Standard boards, and $320
671-
\times 240$ for the DE10-Nano). You should see the bitmap image, upside down, on the video
672-
display.
674+
\times 240$ for the DE10-Nano). With a video monitor connected to your DE-series board, you
675+
should see the bitmap image, upside down, on the video display. (Note that you cannot
676+
view your images using the video emulator (provided with Lab Exercise 6) that was mentioned in
677+
Part I, as this emulator does not work with the system in Figure~\ref{fig:edge_detect_system}.)
673678

674679
\item
675680
Write a function called {\it flip} that flips the image vertically before writing it into

lab2/design_files/DE1-SoC/README.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
The file part1 is an ARM executable program that provides a sample solution for Part I. The
2-
program automatically exits after 12 seconds.
1+
The file part1 is an ARM executable program that provides a sample solution for
2+
Part I. The program automatically exits after 12 seconds.
33

4-
The files physical.c and physical.h provide sample source code for handling virtual-to-physical
5-
memory mapping. These files are useful for Part I
4+
The files physical.c and physical.h provide sample source code for handling
5+
virtual-to-physical memory mapping. These files are useful for Part I
66

7-
The file timer.ko is a kernel module that provides a sample solution for Part II
7+
The file timer.ko is a kernel module providing a sample solution for Part II.
88

9-
The file stopwatch.ko is a kernel module that provides a sample solution for Part III. It can
10-
be controlled by the KEY pushbuttons and SW switches. The stopwatch can be stopped/started by
11-
pressing pushbutton KEY0. When the stopwatch is stopped, it can be set to a starting time by
12-
using KEY1, KEY2, and KEY3. Pressing KEY1 causes the hundredth to be set using the SW switches,
13-
pressing KEY2 sets the seconds, and pressing KEY3 sets the minutes. The maximum values possible
14-
are 59 for minutes, 59 for seconds, and 99 for hundredths. The SW values are interpreted as a
15-
10-bit binary number.
9+
The file stopwatch.ko is a kernel module that provides a sample solution for
10+
Part III. It can be controlled by the KEY pushbuttons and SW switches. The
11+
stopwatch can be stopped/started by pressing pushbutton KEY0. When the
12+
stopwatch is stopped, it can be set to a starting time by using KEY1, KEY2,
13+
and KEY3. Pressing KEY1 causes the hundredth to be set using the SW switches,
14+
pressing KEY2 sets the seconds, and pressing KEY3 sets the minutes. The
15+
maximum values possible are 59 for minutes, 59 for seconds, and 99 for
16+
hundredths. The SW values are interpreted as a 10-bit binary number.

lab2/design_files/DE1-SoC/physical.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,44 @@
44
#include <sys/mman.h>
55

66
// Open /dev/mem, if not already done, to give access to physical addresses
7-
int open_physical (int fd)
8-
{
9-
if (fd == -1)
10-
if ((fd = open( "/dev/mem", (O_RDWR | O_SYNC))) == -1)
11-
{
12-
printf ("ERROR: could not open \"/dev/mem\"...\n");
13-
return (-1);
14-
}
15-
return fd;
7+
int open_physical (int fd) {
8+
if (fd == -1)
9+
if ((fd = open( "/dev/mem", (O_RDWR | O_SYNC))) == -1) {
10+
printf ("ERROR: could not open \"/dev/mem\"...\n");
11+
return (-1);
12+
}
13+
return fd;
1614
}
1715

1816
// Close /dev/mem to give access to physical addresses
19-
void close_physical (int fd)
20-
{
21-
close (fd);
17+
void close_physical (int fd) {
18+
close (fd);
2219
}
2320

2421
/*
2522
* Establish a virtual address mapping for the physical addresses starting at base, and
2623
* extending by span bytes.
2724
*/
28-
void* map_physical(int fd, unsigned int base, unsigned int span)
29-
{
30-
void *virtual_base;
25+
void* map_physical(int fd, unsigned int base, unsigned int span) {
26+
void *virtual_base;
3127

32-
// Get a mapping from physical addresses to virtual addresses
33-
virtual_base = mmap (NULL, span, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, base);
34-
if (virtual_base == MAP_FAILED)
35-
{
36-
printf ("ERROR: mmap() failed...\n");
37-
close (fd);
38-
return (NULL);
39-
}
40-
return virtual_base;
28+
// Get a mapping from physical addresses to virtual addresses
29+
virtual_base = mmap (NULL, span, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, base);
30+
if (virtual_base == MAP_FAILED) {
31+
printf ("ERROR: mmap() failed...\n");
32+
close (fd);
33+
return (NULL);
34+
}
35+
return virtual_base;
4136
}
4237

4338
/*
4439
* Close the previously-opened virtual address mapping
4540
*/
46-
int unmap_physical(void * virtual_base, unsigned int span)
47-
{
48-
if (munmap (virtual_base, span) != 0)
49-
{
50-
printf ("ERROR: munmap() failed...\n");
51-
return (-1);
52-
}
53-
return 0;
41+
int unmap_physical(void * virtual_base, unsigned int span) {
42+
if (munmap (virtual_base, span) != 0) {
43+
printf ("ERROR: munmap() failed...\n");
44+
return (-1);
45+
}
46+
return 0;
5447
}

lab2/design_files/DE10-Nano/physical.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,44 @@
44
#include <sys/mman.h>
55

66
// Open /dev/mem, if not already done, to give access to physical addresses
7-
int open_physical (int fd)
8-
{
9-
if (fd == -1)
10-
if ((fd = open( "/dev/mem", (O_RDWR | O_SYNC))) == -1)
11-
{
12-
printf ("ERROR: could not open \"/dev/mem\"...\n");
13-
return (-1);
14-
}
15-
return fd;
7+
int open_physical (int fd) {
8+
if (fd == -1)
9+
if ((fd = open( "/dev/mem", (O_RDWR | O_SYNC))) == -1) {
10+
printf ("ERROR: could not open \"/dev/mem\"...\n");
11+
return (-1);
12+
}
13+
return fd;
1614
}
1715

1816
// Close /dev/mem to give access to physical addresses
19-
void close_physical (int fd)
20-
{
21-
close (fd);
17+
void close_physical (int fd) {
18+
close (fd);
2219
}
2320

2421
/*
2522
* Establish a virtual address mapping for the physical addresses starting at base, and
2623
* extending by span bytes.
2724
*/
28-
void* map_physical(int fd, unsigned int base, unsigned int span)
29-
{
30-
void *virtual_base;
25+
void* map_physical(int fd, unsigned int base, unsigned int span) {
26+
void *virtual_base;
3127

32-
// Get a mapping from physical addresses to virtual addresses
33-
virtual_base = mmap (NULL, span, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, base);
34-
if (virtual_base == MAP_FAILED)
35-
{
36-
printf ("ERROR: mmap() failed...\n");
37-
close (fd);
38-
return (NULL);
39-
}
40-
return virtual_base;
28+
// Get a mapping from physical addresses to virtual addresses
29+
virtual_base = mmap (NULL, span, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, base);
30+
if (virtual_base == MAP_FAILED) {
31+
printf ("ERROR: mmap() failed...\n");
32+
close (fd);
33+
return (NULL);
34+
}
35+
return virtual_base;
4136
}
4237

4338
/*
4439
* Close the previously-opened virtual address mapping
4540
*/
46-
int unmap_physical(void * virtual_base, unsigned int span)
47-
{
48-
if (munmap (virtual_base, span) != 0)
49-
{
50-
printf ("ERROR: munmap() failed...\n");
51-
return (-1);
52-
}
53-
return 0;
41+
int unmap_physical(void * virtual_base, unsigned int span) {
42+
if (munmap (virtual_base, span) != 0) {
43+
printf ("ERROR: munmap() failed...\n");
44+
return (-1);
45+
}
46+
return 0;
5447
}

0 commit comments

Comments
 (0)