In this project the Raspberrypi board is loaded with Ubuntu and is remotely accessed using VNC. The Raspberrypi board is also connected to the internet. There are 26 connectors which can be taken out from the connector port of the Raspberrypi board. All the connector pins are taken out using 13*2 pin female connectors and at the other end of their wire 26 pin Burg stick male connectors are attached. The Burg stick male connectors allow each pin out from the Raspberrypi board to be plugged into the holes of a breadboard. To access the pins that coming out of the Broadcom controller of the Raspberrypi board using C language, a C library is available called “bcm2835” which has been downloaded and installed.
A signal is sent for the purpose of notifying the process about something that required immediate attention. Different signals are used to notify different events and the signals are differentiated by their signal numbers. The list of all the available signals in the OS and their signal numbers can be obtained using the following command;
The following table gives a list of the most common signals that a process might encounter in an Operating System;
Linux sends a process this signal when it becomes disconnected from a terminal.
Linux sends a process this signal when the user tries to end it by
Linux sends a process this signal when it attempts to execute an illegal instruction.
Linux sends a process this signal to the process when the process calls the ‘abort ()’ function
Linux sends a process this signal when it has executed an invalid floating-point math instruction
Linux sends a process this signal to end it immediately
User programs can send this signal to other process
User programs can send this signal to other process
Linux sends a process this signal when the program has attempted an invalid memory access
Linux sends a process this signal when the program has attempted to access a broken data stream, such as a socket connection that has been already closed
A process can receive this signal from the Linux using the function alarm(), after a time period mentioned in its argument.
Linux sends a process this signal requesting it to terminate
Linux sends a process this signal when a child process exits
Linux sends a process this signal when it exceeds the limit of
CPU time that it can consume.
A process can receive this signal from the Linux using the function setitimer (), after a time period mentioned in its argument.
This particular project is based on continuously receiving and handling the signal number 14, the SIGALRM. A process can receive the SIGALRM signal from the OS by calling a function named ‘alarm ()’, the prototype of which is defined in the header file <signal.h>.
The OS will send the SIGALRM to the process after a time period mentioned in the parameter passed to the function during the function call. A single call to the alarm () will receive a single SIGALRM signal only. To receive a SIGALRM at continuous interval of time, the same function needs to be called after receiving each SIGALRM. The better method is to use set a timer which can continuously generate the SIGALRM signals at specified intervals of time.
The ‘set interval timer’ function can be used to set a timer which can continuously generate the SIGALRM signals at specified intervals of time. The details of the function ‘setitimer ()’ which is used for this purpose is discussed below;
Using this function a timer can be set which will down count from the specified value and generates an interrupt as it reaches zero and then resets to the previous value. The function ‘setitimer ()’ is defined in the header file <sys/time.h> as given below;
int setitimer (
const struct itimerval *new_value,
struct itimerval *old_value
The first argument asks for the type of the timer that needs to be enabled. The OS provides each process to enable timers in three different modes. The timer sends different signals when operating in each modes and the signal SIGALRM is send only when the timer is operating as Real Time timer. To enable the timer as Real Time timer, the function ‘setitimer ()’ should be called with the first parameter as ‘ITIMER_REAL’. The parameters ITIMER_VIRTUAL, or ITIMER_PROF can also be passed to the function to enable the timer as a virtual timer (which runs only when the process is in execution) or when it is required for the process profiling (to find out how much time the process spends in CPU) respectively.
The ‘setitimer ()’ function sets a new the timer specified by values inside the structure which is passed as the second parameter in the function call. The third parameter can be used to read the values of an already existing timer. Timer values are defined by the following structures:
struct timeval it_interval; /* value of the required interval between signals */
struct timeval it_value; /* value of time period to generate the first signal */
time_t tv_sec; /* interval value when it is in seconds range */
suseconds_t tv_usec; /* interval value when it is in microseconds range */
The following statements show how to set up a timer for 2 seconds using the function setitimer ().
struct itimerval timer1;
timer1 . it_interval . tv_usec = 0;
timer1 . it_interval . tv_sec = 2;
timer1 . it_value . tv_usec = 0;
timer1 . it_value . tv_sec = 2;
setitimer ( ITIMER_REAL, &timer1, NULL );
The setitimer () function is used in the coding done for this particular project which continuously toggles LEDs with a delay of 2 seconds.
***Note that in this project the latest version of library “bcm2835” is used with an old version of Raspberrypi board. It is not possible to access the pin number 13 of the old board with the latest library version and hence in the the pin number 24 is used to blink the 3rd LED. The circuit diagram is also drawn accordingly. Those who have the latest version of the board can use the pin 13 without any trouble.
To find the ‘Revision’ and other important details about the Raspberrypi board, use the following command;
In this project the Raspberrypi board version 2 is used, but a previous version of the “bcm2835” library is installed. Accessing the GPIO pin 13 is not possible with this library and hence the 3rd IO pin is selected as pin24 of the P1 port of the Raspberrypi. The circuit and the code are modified accordingly. Those who have the version 2 of the Raspberrypi and the latest version of the “bcm2835” library can use the GPIO pin 13 using “RPI_V2_GPIO_P1_13” instead of “RPI_GPIO_P1_13” in the pin definition.
For example to define a ‘PIN’ as 13th pin of P1 port of Raspberrypi board version2, use the following statement in the code;
#define PIN RPI_V2_GPIO_P1_13