Difference between revisions of "PA 8001 2014 Practical 2"

From CERES
Jump to: navigation, search
Line 39: Line 39:
 
Now you can restart the Raspberry Pi and work on the PiFace!  
 
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.
+
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.
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 ===  
 
=== 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.
 
  
 +
The exercise is about two ticket machines, such as the one used in bakeries for taking turns. 
 +
Customers may arrive at each of the two ticket machines, they can press a button to take a turn (by which the latest number between the two ticket machines is determined) and
 +
after a small delay, they will get a ticket, which is the number from the previous step incremented by one .
 +
The tickets should be issued  uniquely, i.e., no two customers should get the same number, even if they got their tickets from different machines.
  
[[File:two_trains_2014.png|300px|thumb|super|Part 3: Train Controller.]]
+
You use the navigation switch to have a customer arrived at ticket machine 1.  
 +
Ticket machine 2 has customers arriving at a fixed period (3 seconds).
 +
Each ticket machine has a delay of 1 second between reading the last ticket from both machines and issuing the next one.  
  
+
The current tickets of ticket machines 1 and 2 are displayed on the left- and the right-hand-sides of the LCD display of PiFace, respectively.  
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.
+
The initial state of both ticket machines indicates number 0.  
Train1 is controlled by the navigation switch as specified in Part 2.  
+
Hence, by pressing right, releasing before 3 seconds, a customer arrives at ticket machine 1 and
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.  
+
1 second later will receive ticket number 1 displayed on the left-most corner of the LCD.  
The access to bridge has to be protected by a mutual exclusion mechanism.
+
Exactly after 3 seconds from the start of the system, a customer will arrive at ticket machine 2 and one second later will get the next available ticket
 +
displayed on the left-most corner.  
  
 +
If two customers arrive at the two ticket machines simultaneously, a mutual exclusion mechanism should ensure that they get different tickets.
 +
 +
 
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].   
 
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]] ==

Revision as of 05:16, 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!


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 exercise is about two ticket machines, such as the one used in bakeries for taking turns. Customers may arrive at each of the two ticket machines, they can press a button to take a turn (by which the latest number between the two ticket machines is determined) and after a small delay, they will get a ticket, which is the number from the previous step incremented by one . The tickets should be issued uniquely, i.e., no two customers should get the same number, even if they got their tickets from different machines.

You use the navigation switch to have a customer arrived at ticket machine 1. Ticket machine 2 has customers arriving at a fixed period (3 seconds). Each ticket machine has a delay of 1 second between reading the last ticket from both machines and issuing the next one.

The current tickets of ticket machines 1 and 2 are displayed on the left- and the right-hand-sides of the LCD display of PiFace, respectively. The initial state of both ticket machines indicates number 0. Hence, by pressing right, releasing before 3 seconds, a customer arrives at ticket machine 1 and 1 second later will receive ticket number 1 displayed on the left-most corner of the LCD. Exactly after 3 seconds from the start of the system, a customer will arrive at ticket machine 2 and one second later will get the next available ticket displayed on the left-most corner.

If two customers arrive at the two ticket machines simultaneously, a mutual exclusion mechanism should ensure that they get different tickets.


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