User Manual
12
To retrieve the original software, put the file where you want your Gertboard software to end up on
your Raspberry Pi computer, then extract the files by typing the following in one of the terminal
windows on your RPi (substituting the name of the actual file you have downloaded for the file name
we are using in this example):
unzip gertboard_sw_20120725.zip
A new directory, gertboard_sw, will be created. Change to this directory (by typing cd
gertboard_sw) and list the contents (ls). You will see a set of C files and a makefile. C files are
software files, but they need to be compiled to run on the processor on your system. In the case of
Raspberry Pi, this is an ARM11. The makefile tells the computer how to compile the code, so all
you need to do it type:
make all
This compiles the C code into executable programs. To run a program (for example the program
leds which tests the LEDs), type:
sudo ./leds
The sudo is there because accessing the GPIO ports requires special privileges, and so you need to
make an extra effort (by typing sudo) to execute it. The ./ before leds means that the program
leds is in the current directory.
Each functional block has at least one test program that goes with it. Each test program is compiled
from two or more C files. The file gb_common.c (which has an associated header file
gb_common.h) contains code used by all of the functional blocks on the board. Each test has a C
file that contains code specific to that test (thus you will find the main function here). Some of the
tests use a special interface (for example the SPI bus), and these tests have an additional C file that
provides code specific to that interface (these files are gb_spi.c for the SPI bus and gb_pwm for
the pulse width modulator).
In each of the sections about the individual functional blocks, the code specific to the tests for that
block is explained. Since all of the tests share the code in gb_common.c, an overview of that code
will be given here. In order to use the Gertboard via the GPIO, the test code first needs to call
setup_io. This function allocates various arrays and then calls mmap to associate the arrays with
the devices that it wants to control, such as the GPIO, SPI bus, PWM (pulse width modulator) etc.
The result of this is that it writes to these arrays control the devices or sends data to them, and reads
from these arrays get status bits or data from the devices. At the end of a test program, restore_io
should be called, which undoes the memory map and frees the allocated memory.
Macros
In gb_common.h, gb_spi.h, and gb_pwm.h there are a number of macros that give a more
intuitive name to various parts of the arrays that have been mapped. These macros are used to do
everything from setting whether a GPIO is used as input or output to controlling the clock speed of
the pulse width modulator.