Difference between revisions of "PA 8001 2014 Practical 2"

From CERES
Jump to: navigation, search
Line 36: Line 36:
 
=== Part 2: I/O on PiFace ===
 
=== Part 2: I/O on PiFace ===
  
In this exercise, we familiarize ourselves with the [http://www.piface.org.uk/products/piface_control_and_display/ PiFace Control and Display] hardware and its [https://github.com/piface/libpifacecad software library].
+
In this exercise, we familiarize ourselves with the [http://www.piface.org.uk/products/piface_control_and_display/ PiFace Control and Display] hardware and its [https://github.com/piface software library]: you need both libmcp23s17 and libpifacecad.
 
Use the [http://piface.github.io/libpifacecad/pifacecad_8h.html documentation] of the library or the example code on the internet to find your way through the different functionalities and implement the following exercise:  
 
Use the [http://piface.github.io/libpifacecad/pifacecad_8h.html 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
 +
then press Esc and type :wq
 +
Now you can restart the pi work on the piface!
  
 
The exercise is about a train that is moving on different tracks, until it reaches a bridge.  
 
The exercise is about a train that is moving on different tracks, until it reaches a bridge.  

Revision as of 01:43, 29 September 2014

Objectives

There are three main objectives for this practical:

  • Learn about and implement the basic ingredients for concurrency,
  • Implement the mutual exclusion primitives,
  • Use them in implementing a simple access control protocol

Instructions

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: Yield

Restore Raspbian on Raspberry Pi.

Download the tiny threads library and run the sample program test1 using GCC on Linux. Notice that only one thread in the sample program gets to execute. This is so because there is no way of switching context: there is no invocation to yield() in the program and furthermore, there is no implementation for yield(). In this exercise you will implement the function

yield() 

in tinythreads.c. The function should


  • enqueue the current thread in the ready queue (as you can see in the source file tinythreads.c there are functions already implemented for enqueuing and dequeuing).
  • pick the first element in the queue, dequeue it and dispatch it! It is dispatch that makes the context-switch trick! (check the definition of dispatch).

Part 2: 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 then press Esc and type :wq Now you can restart the pi 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 3: 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.


Back to Embedded Systems Programming