Göm meny

TSEA81 - Datorteknik och realtidssystem

Notera att dessa sidor enbart finns i engelsk version

TSEA81 - Computer Engineering and Real-time Systems

Assignment 1 : Introduction, Shared Resources

Introduction

In this assignment, a selection of small real-time programs are compiled, executed, and to some extent modified. The following activities are included:

  • Compilation, execution, and modification of a C-program
  • Mutual exclusion using a semaphore
The purpose of the assignment is to give an introduction to real-time programming by performing the above mentioned activities, and also to give an introduction to mutual exclusion.

Requirements to pass

The requirements to pass this assignment are:

Preparations

As a preparation for the assignment, the lecture 1 - Introduction and 2 - Shared Resources should be studied. You also need to install Simple_OS in order to access the GUI which we will use in the assignments. Instructions regarding this are found in Section Required software.

Besides the GUI which we will use, Simple_OS contains a small real-time kernel. Feel free to study it, but you will not use it at this point in the course.

Required software

The assignment requires access to a C compiler. It is also required that java is available so that you can run the GUI in Simple_OS.

The assignments use POSIX API:s such as pthreads. These are natively available in Linux which is used in ISY:s computer labs. If you want to prepare the labs at home you shouldn't have any problems doing the labs at home either, as long as you have the right development packages installed. If you have Windows installed, you could probably run the labs under Cygwin, although this has not been tested by us. (Let us know if it works though!)

Installation instructions for Simple_OS are available in the Simple_OS documentation. (You will need to download the Simple OS zip file from that page.) Note that you only need the Java GUI of Simple OS. That is, you do not need to run the command ./prog_x86_host in this course.

Assignment tasks

Compilation, execution, and modification of a C program

Download the file assignment1_20231031.tar.gz. You can unpack this file using the console command tar xvf filename, where filename is the path to the downloaded archive. For example, to create a TSEA81 directory and unpack the file in this directory, run the following commands: mkdir TSEA81;cd TSEA81; tar xvf ~/Downloads/assignment1_20231031.tar.gz. Compile and link the program set_clock by changing your working directory to the assignment1 directory and running the command make set_clock.

Figure 1. Compiling and linking set_clock.

If everything works, that should produce a runnable program named set_clock.

To test the program you need to first start the SimpleOS GUI. You can do this by opening another terminal and changing the current directory to the simple_os_2020_11_04/java_gui/java directory and run the command java GUISimpleOS

Figure 2. Starting java GUI from the terminal.

At this point you can run the set_clock command as follows (preferably from yet another terminal window): ./set_clock (the ./ in the beginning is to ensure that you can execute the command in the current directory as you typically should not have the current directory (.) in your command search path).

Figure 3. Starting set_clock from the terminal.

When connection is established, a window should open up displaying the clock.

Figure 4. The set_clock GUI.

You should now modify the program according to the following instructions and testrun it again:

  • Change the clock so that its hours and minutes are shown in the interval 1:00-12:59.
  • Double the speed of the clock.

Mutual exclusion using a semaphore

The file odd_even.c in the assignment 1 directory contains a program which periodically displays a number, together with information showing whether the number is odd or even. The task which displays this information reads the number, together with information indicating if the number is odd or even, from shared variables. Before the number is displayed, it is checked if the information indicating an odd or even number is consistent with the actual number. If this is not the case, an error message is displayed.

Study the program code, in order to verify that the program behaves according to this description.

Compile, link and execute the program. (Use the command make odd_even to do this.) Use the Java graphical user interface as in the previous task.

Does the program display any error messages? If so, how often?

  • Introduce, in the function increment_number, a call of the function long_calculation. Insert the call directly after the line

        Number += inc_value;
    

Does the program display any error messages? If so, how often?

  • Introduce a mutex for mutual exclusion, so that no error messages are displayed.

Even though the program after that works correctly, that is for a functioning program with no error messages, the numbers displayed may sometimes be negative. Why is that?
(You may have to rerun the program to get negative numbers)


Informationsansvarig: Kent Palmkvist
Senast uppdaterad: 2023-10-31