PA 8001 2014 Practical 2

Jump to: navigation, search


There are three main objectives for this practical:

  • Implement the mutual exclusion primitives,
  • Use a concurrency library,
  • Learn to perform typical I/O operations using PiFace,
  • Use all the ingredients to implement a simple access control protocol


Submit a single .zip file on blackboard with four folders, each containing the solutions to the below-specified parts.

For each function in the code, you need to write a piece of comment, describing its pre- and post-condition and a few test-cases.

Part 1: I/O on PiFace

In this exercise, we familiarize ourselves with the PiFace Control and Display hardware and its software library: you need both libmcp23s17 and libpifacecad. Use the documentation of the library or the example code on the internet to find your way through the different functionalities and implement the following exercise:

Download both libmcp23s17 and libpifacecad and rename them as libmcp23s17 and libpifacecad. To build the library run the flowing command,

$ cd libmcp23s17/ && make && cd -

$ cd libpifacecad/ && make

Enable the SPI interface

$ sudo vi /etc/modprobe.d/raspi-blacklist.conf

-press insert, then add a # add before blacklist spi-bcm2708

-press Esc and type :wq

Now you can restart the Raspberry Pi and work on the PiFace!

The exercise is about a train that is moving on different tracks, until it reaches a bridge. We model hence three states of this train: away, approaching and on-bridge. When it is away, it is moving on tracks that are not directly connected to the bridge, when it is approaching, it is on a track that is immediately connected to the bridge and on-bridge status is self-explanatory.

You use the navigation switch to move between these three states back and forth, by moving the switch to right and left, respectively. The current status of the switch is displayed on the LCD display of PiFace. The initial state of the train is away. Hence, pressing right, releasing, pressing right, releasing and then pressing left and releasing will result in showing the following sequence of strings on PiFace Screen: away, approaching, on-bridge, away.

Part 2: Train Controller

The final part of the assignment consists of implementing a sample of a train controller with two trains and a bridge, depicted below.

Part 3: Train Controller.

The status of Train1 and Train2 are to be displayed on the PiFace Screen on the left-most and right-most side of the LCD Screen, respectively. Train1 is controlled by the navigation switch as specified in Part 2. Train2 is controlled by a timer that moves the train from one state to other within 5 seconds, unless blocked by the unavailability of the bridge. The access to bridge has to be protected by a mutual exclusion mechanism.

Use the POSIX Thread (pthread) library to implement concurrency. More information about pthread with some examples can be found here.

Back to Embedded Systems Programming