Difference between revisions of "PA 8001 2014 Practical 2"

From CERES
Jump to: navigation, search
(Created page with "== Objectives == There are three main objectives for this practical: * Learn about and implement the basic ingredients for concurrency, * Implement the mutual exclusion pr...")
 
(Undo revision 5560 by Ceres (talk))
 
(10 intermediate revisions by one user not shown)
Line 2: Line 2:
  
 
There are three main objectives for this practical:  
 
There are three main objectives for this practical:  
 
* Learn about and implement the basic ingredients for concurrency,
 
  
 
* Implement the mutual exclusion primitives,  
 
* Implement the mutual exclusion primitives,  
  
* Use them in implementing a simple access control protocol
+
* Use a concurrency library,
 +
 
 +
* Learn to perform typical I/O operations using PiFace, 
 +
 
 +
* Use all the ingredients to  implement a simple access control protocol
  
 
== Instructions ==
 
== Instructions ==
Line 15: Line 17:
 
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.  
 
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 ===
+
=== Part 1: 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 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:
 +
 
 +
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
  
Restore Raspbian on Raspberry Pi.
+
Now you can restart the Raspberry Pi and work on the PiFace!
  
Download the [[media:tiny_threads.zip|tiny threads library]] and run the sample program test1 using GCC on Linux.  
+
The exercise is about a train that is moving on different tracks, until it reaches a bridge.  
Notice that only one thread in the sample program gets to execute.
+
We model hence three states of this train: away, approaching and on-bridge.  
This is so because there is no way of switching context: there is no invocation to yield() in the program and  
+
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  
furthermore, there is no implementation for yield().
+
on-bridge status is self-explanatory.
In this exercise you will implement the function
+
  
yield()
+
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.
  
in tinythreads.c.  The function should
 
  
 +
=== Part 2: Train Controller ===
  
* 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).
+
The final part of the assignment consists of implementing a sample of a train controller with two trains and a bridge, depicted below.
  
* 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 ===
+
[[File:two_trains_2014.png|300px|thumb|super|Part 3: Train Controller.]]
  
=== 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. 
  
The final part of the assignment consists of implementing a sample of a train controller with two trains and a bridge.  
+
Use the POSIX Thread (pthread) library to implement concurrency. More information about pthread with some examples can be found [http://www.cs.cmu.edu/afs/cs/academic/class/15492-f07/www/pthreads.html here].
  
 
== [[PA 8001 Ed 2013|Back to Embedded Systems Programming]] ==
 
== [[PA 8001 Ed 2013|Back to Embedded Systems Programming]] ==

Latest revision as of 05:18, 28 September 2015

Objectives

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

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