DT 8025 2016 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: Exponential Function

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

struct expStruct {
  int expInt;
  int expFraction;
 }; 

 typedef struct expStruct ExpStruct;
 ExpStruct * iexp ( int ); 

This function is supposed to calculate the value of e^n (n = the input parameter) with two degrees of precision and return it in a struct comprising its integer part, its fractional part (two digit after the ".", the decimal separator). We suggest that you use the Taylor series of the exponential function (at point a=0) and consider the first (n+1) terms to calculate e^n.

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 the exponential function, 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 iexp(int) and run all your tests.

Part 2: Exponential Function on Raspberry Pi

Write a program that shows the values of the exponential function for natural numbers, starting from 1 and moving upwards, on the PiFace's display connected to the GPIO pins of your Raspberry Pi.

The output of the program should look like the following:

1: 2.00,
2: 5.00, 
3: 13.00,
4: 34.34,
.
.
.

Download the lab1_2016.zip and complete the implementation of the following functions specified in the file piface.c, i.e.,

void piface_putc(char c);
void piface_puts(char s[]);
void piface_clear(void);

The HD44780 LCD of the PiFace sits on top of a MCP23S17 general purpose I/O expander, which operates in sequential mode to communicate with the Raspberry Pi's SPI interface. It operates in 4-bit mode and has two communication channels; one channel used to transmit commands and another channel to send data. Showing some characters on the PiFace's display requires to write the respective value into the expander's data register. This can be done using the following provided methods:

static void lcd_write_cmd(uint8_t cmd)
static void lcd_write_data(uint8_t data)

Respective commands for clearing the display and moving the cursor can be found inside the LCD's specification.

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 kernel.img into it. You should now be able to see the outcome of the exponential function on the screen.

Part 3: Manual 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 exponential function program from Part 2. Make an interleaving of the two programs.

Part 3.2. Observe that the LED blinks more slowly than it is supposed to as the exponential value of the number grows; devise a fair interleaving of the tasks such that the blinking speed remains constant.


Back to Course Page