Exercise 2: Programmable Interrupt Controller.

Write a program that changes the priorities of the keyboard and system timer interrupts and demonstrates the effects of that change.

Normally system timer (IRQ0) has the highest priority. IRQ0 is generated repeatedly about 18 times a second. System timer standard interrupt handler updates system time, refreshes RAM memory and does other useful things. Keyboard interrupt (IRQ1) is generated when a key stroke occurs. Standard keyboard interrupt handler checks what key is pressed and stores its (ASCII) code in an internal buffer for later usage of a main program. Normally system timer interrupt has a higher priority than a keyboard interrupt. So if a system timer interrupt occurs while keyboard interrupt handler processes a key stroke the latter will be interrupted by
a system timer interrupt handler and after processing system clock operations the processor returns to a keyboard handler to finish key stroke processing. If we change priorities of those two interrupts so that a system timer interrupt will have a lower priority than a keyboard interrupt then if the system timer interrupt occurs while keyboard interrupt handler processes a key stroke it will wait until keyboard interrupt handler finishes.

The goal of the exercise is to change those two interrupts priorities and somehow present that the priorities are indeed changed.

The proposed method of the presentation is to override keyboard interrupt and system interrupt handlers with our own procedures. The new system timer interrupt handler might call a standard handler and additively scroll a single letter on a screen. Since it’s called 18 times per second it would give a fast scrolling effect. The new keyboard interrupt handler might call a standard keyboard handler and then wait for example a one second doing nothing.

Now consider what would happen in case of normal priorities. Since a clock interrupt has normally a higher priority if one presses a key on a keyboard the keyboard handler will be interrupted multiple times by a clock handler while it waits a second doing nothing. The letter will than be scrolled smoothly on the screen. However if we change priorities the keyboard handler won’t be interrupted by a clock handler causing the latter to wait until the keyboard handler finishes. Since the keyboard handler waits a second doing nothing the scrolling, which takes place in a clock handler, will suspend for a second every time a key is pressed on a keyboard. Those two effects allow to distinguish weather the clock or keyboard interrupt has a higher priority.

A program should allow to change priorities for example by pressing a space key on a keyboard. Before finishing it should restore original priorities (IRQ0 for the highest priority).

A program should be written in a C++ language using Borland C++ 3.1 compiler using
a program template available in a lecture4.zip file.