PA 8001 2015 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: Square Root

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

struct rootStruct {
  int rootInt;
  int rootFraction;
 }; 

 typedef struct rootStruct RootStruct;
 RootStruct * isqroot ( int ); 

This function is supposed to calculate the square root of its only parameter with one degree of precision and return it in a struct comprising its integer part, its fractional part (one digit after the ".", the decimal separator). We suggest that you use the simple Babylonian method with 1 as the start value for your implementation.

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 square root, 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 isqroot(int) and run all your tests.

Part 2: Square Root on Raspberry Pi

Write a program that shows the square root 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: 1.4, 
3: 1.7,
4: 2.0,
5: 2.2, 
.
.
.

Download the screen_2015.zip and complete the implementation for the functions specified in numbers.h, i.e.,

void writeChar(unsigned int pos, char ch);
void writeLong(unsigned int line, float i);
void cleanLine(unsigned int  pos);
void showSquareRoot(void);

The current screen resolution is 640X480, defiened in screen.h by SCREEN_WIDTH and SCREEN_HEIGHT. The resolution is set in the below lines (screen.c, init_screen() function):

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

Note: showSquareRoot() 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, modify it so that the time between each two blinking is constant.

Part 3.2. Take the blinking program from part 3.1, and the square root 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 LED blinks more slowly than it is supposed to as the square root of the number grows; devise a fair interleaving of the tasks such that the blinking speed remains constant.