[Main menu]

Interrupt Service Routine

Keyboard


Overview

When the Keyboard ISR is activated in performs the following steps:
  1. Test the Keyboard controller for waiting input. If none then exit the ISR, else continue.
  2. Retrieve full scancode from Keyboard controller. In case of extended scancode then a double read.
  3. Update the Keyboard layout.
  4. Putting the scancode on the ISR Keyboard Buffer.
  5. Test the Keyboard controller for more scancodes. If none then continue, else repeat step 2 and 3.
  6. Now it signals the higher level keyboard code, that some new data has been received.

Test the Controller

The initial test must determine whether or not the keyboard controller send the IRQ signal. If positive, then it must determine whatever the controller wanted. It may have been a service call request, or a request for the system to remove scancodes from its buffer.

In case of a service call, the ISR must know if it can do it itself, or if it has to active some higher code.

Retrieve Scancode and Update Keyboard Layout

When the ISR has determined that there are a scancode in the buffer, it retrieves the scancode. Then test if its a extended scancode (meaning one more scancode is already waiting). If positive, the ISR retrieve the next scancode. Then it take the scancode and update the Keyboard Layout. With this layout the ISR monitors which keys are pressed down and which are released.

Transferring to ISR Keyboard Buffer

When the Keyboard Layout has been updated, the scancode is put on the ISR Keyboard Buffer, and the control values (buffer_start_pointer, buffer_end_pointer) are updated.

Testing Again

Then the ISR test the keyboard buffer again to find out whether or not more scancodes are waiting. If none are waiting it continues to the next step, but if some are waiting it repeats step 2 trough 4, until the keybaord controller buffer is empty. If the ISR Keyboard Buffer is filled up first then the ISR would flush the buffer in the keyboard controller.

Signalling Higher Code

When nothing more has to be done, we active the high-level part of the Keyboard ISR code. This will process the received information when it gets dispatched. The high-level part will translate the scancode to an ASCII or Unicode character, through a specified Keyboard Layout table. The high-level code will also check for global short-cuts.


Assemble Code (NASM style)


function KeyboardISR() {
     get_controller_status()

     if (controller_doesnt_need_anything == true) {
          exit_isr()
          }

     if (controller_needs_service == true) {
          service_controller()
          }

     if (controller_has_data == true) {
          get_scancode()

          if (extended_scancode == true) {
               get_second_part_of_scancode()
               }

          update_keyboard_layout()

          put_scancode_on_isr_buffer()

          get_controller_status()

          if (controller_doesnt_need_anything == true) {
               activate_proces(proces_id)

               exit_isr()
               }

          if (controller_needs_service == true) {
               service_controller()
               }

          }

     }