This workshop is designed to help you learn C. The aim is to make it as advanced or simple as you want.
These are to try and get you used to writing C for embedded devices.
- No using
int
. Use fixed-width types, e.g.uint16_t
. - No using
malloc
- In the
src
folder, make a file calledworkshop.c
. Make this file printHello World!
to the command line. - Edit the
main
method to read a string from the command line and then print it. This can either be passed as a command line argument or taken as input within the function. - Create a header file with a
struct
for a person. This should have fields for name and age. - In your
main
method, use user input to populate an instance of yourstruct
. - Make a function that takes a pointer to a
struct
and prints each field to the command line - Using the GPIO library (
gpio.h
), create a GPIO pin then continuously take a user value and write it to the pin. - Create another GPIO pin and run your function which prints a
struct
to print the GPIO pinstruct
whenever the value of the pin is above 128. - If you get this far, look at multithreading (
pthreads
) and synchronisation in C. Run two functions at once, one which addsstruct
s to an array (a queue), then one which reads from the counter and prints thestruct
to the terminal. (Hint: this is a producer-consumer synchronisation problem.)
This project uses CMake to generate the build file. This is a common way to make building software easier.
- Make a folder called
build
and change to it - Run
cmake ..
- Run
make -s
Once you've run make
(or any other build tool), you should have an executable in the build folder that you can run.
You will need a C compiler installed (probably either gcc
or clang
; I'd recommend gcc
). This should be easy on Linux or Mac. On Windows, please use WSL otherwise it will be a pain.
The commands will probably be something like this.
$ mkdir build
$ cd build
$ cmake ..
$ make -s
$ ./workshop