PA 8001 2014 Practical 1

From CERES
Jump to: navigation, search

Objectives

There are three objectives for this practical:

  • Experiment with concurrency (without any underlying support) and observe its issues
  • Experiment with a unit testing framework (such as CUnit)
  • Get more insight into the working of the Raspberry Pi, particularly with respect to input and output


Instructions

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

For each function in the code, you need to write evidence of test-driven development, both in terms of comments (description, pre- and post-condition and properties) and unit testing test suites (e.g., in CUnit, see below). To show the successful execution of your test suite, also include the XML file resulting from its execution.


Part 1: Prime Factorization

Part 1.1. Write the specification (description, pre- and post-condition, test-cases) for the function factorize() with the following signature:

struct factorization {
  int factor;
  struct factorisation *next;
 }; 

 factorization * factrorize ( int ); 


Part 1.2. Implement its test suite using a unit testing framework such as CUnit.

Note that different development environments come with their built in unit testing framework and you can use any of those instead of CUnit.

If you decide to use CUnit, please download it from its sourceforge repository, unpack it and install it in your local directory. Here is a useful discussion about installing CUnit.

Review the examples provided at the CUnit repository or the tutorial by Nielsen and Skou.

Implement a test suite for factorization, based on the description provided in part 1.1. In the implementation, you may use your own helper functions, but for each function, you need to provide evidence of test-driven development.

Part 1.3 Implement factorize(int) and run all your tests.

Part 2: Prime Factorization on Raspberry Pi

Write a program that shows the prime factorization of natural numbers, starting from 1 and moving upwards, on the monitor screen connected through the HDMI port to Raspberri Pi. The output of the program should look like the following:

1: 1,
2: 2, 
3: 3,
4: 2 2,
5: 5, 
6: 2 3, 
.
.
.

Download the screen.zip and complete the implementation for the functions specified in numbers.c, i.e.,

void writeChar(unsigned int pos, char ch);
void cleanPos(unsigned int  pos);
void writeLong(long i);
void showPrimeFactorization(void);

The current screen resolution is 64X48. To change the resolution modify the below lines (screen.c, init_screen() function):

   PUT32(0x40040000, 64); /* #0 Physical Width */
   PUT32(0x40040004, 48); /* #4 Physical Height */
   PUT32(0x40040008, 64); /* #8 Virtual Width */
   PUT32(0x4004000C, 48); /* #12 Virtual Height */

Note: showPrimeFactorization() function does not have to stop printing. When you get to the last line of the screen, go to the first line and replace it with the prime factorization of the next integer.

After you finish implementing the above-mentioned functions, insert the SD-card into a computer using the USB reader, empty the SD card, and copy the files from boot.zip into it, then perform the following sequence of actions:

  1. power off the Raspberry Pi
  2. remove the SD card
  3. insert the SD card into a computer using the usb reader
  4. open GCC Command Prompt (click start and go to GNU Tools ARM Embedded 4.7 2013q3)
  5. go to your working path (screen folder)
  6. run build.bat
  7. copy kernel.img to the SD card
  8. remove the SD card and insert it into the Raspberry Pi
  9. power on the Raspberry Pi.

You should now be able to see the outcome of prime factorization on the screen.

Part 3: Interleaving

Part 3.1. Take the blinking program from Lab0, and the factorization program from Part 2. Make an interleaving of the two programs. Load the interleave on Raspberry Pi using a similar procedure as in Part 3.

Part 3.2. Observe that the LEDs blink more and more slowly as the factorized number grows; devise a fair interleaving of the tasks such that the blinking speed remains constant.