CS452 - Real-Time Programming - Spring 2011

Lecture 10 - Hardware Interrupts

Pubilic Service Announcement

  1. Kernel 1 marks

Servers

What is a server?

How are servers implemented?


Name Server

What is a name server?

Why Do We Need a Name Server

Names constant across applications & executions interface Associated with a set of services (an API)
Task Ids vary across applications & executions implementation Associated with a particular set of instructions and data (an execution)

How do You Get the Task Id of the Name Server?

  1. Make it a constant across executions

Name Server API

int RegisterAs( char *name );
int WhoIs( char *name );

Name Server Semantics

RegisterAs

WhoIs

Comments

Name Server Implementation

User Code

E.g., RegisterAs

typedef struct {
    int type;
    char *name;
} NSstruct;
int RegisterAs( char *name ) {
    int result;
    NSstruct req;
    req.type = REGISTERAS;
    req.name = name;
    bytes = Send( NSTid, &req, sizeof(NSstruct), (char *) result, sizeof(int) );
    if ( bytes != sizeof(int) ) {
        // Do something error-like
    } else return result;
}

There are lots of possible variations, and this one is by no means the best.

Server Code

typedef struct {
    int type;
    char name[MaxNameSize];
} NSstruct;
int bytes, tid, result;
NSstruct req;
// initialize tables
FOREVER {
    bytes = Receive( &tid, &req, sizeof(NSstruct) );
    if ( detectError( ... ) ) {
        // Reply with error
    } else {
        switch( req.type ) {
        case REGISTERAS:
            insert( req.name, tid );
            Reply( tid, SUCCESS, sizeof(int) );
            break;
        case WHOIS:
            result = lookup( name );
            Reply( tid, result, sizeof(int) );
            break;
        default:  // This should never happen
            Reply( tid, ERROR, sizeof(int) );
            break;
        }
    }
}

Comments

  1. How much will this code run?
  2. How would you implement insert & lookup?

What should be allowable as a name?


Hardware Interrupts

What is a Hardware Interrupt?

In the CPU

  1. Test interrupt signal before fetching the next instruction
  2. If asserted, change mode to IRQ
  3. Disable interrupt in CPSR
  4. Execute instruction at 0x18

In the Interrupt Control Unit (ICU)

In the Peripheral Hardware

When two interrupts are present

May have been two present when interrupt processing started

May have occurred since interrupt processing started

What happens next?

  1. Kernel executes with interrupts disabled
  2. Context switch into user task turns on interrupts
  3. Before fetching the first user task instruction test interrupt signal
  4. If asserted, re-initiate interrupt processing

Context Switches for Interrupts

Difference from Software Interrupts

It is impossible to predict where they occur

Assymmetry between User Task and Kernel

Scratch Registers must be saved

Two Link Registers

  1. One to return from interrupt
  2. One to move to the caller's stack frame

Helpful Features of the ICU

  1. Several places where you can read state
  2. Several places where you can block interrupt flow
  3. Trigger hardware interrupt from software

Kernel Provision for Interrupts

  1. Initialize the kernel with interrupts disabled
  2. Turn on interrupts by having user PSW with interrupts enabled
  3. Find source of interrupt
  4. Turn off source of interrupt
  5. Handle interrupt
  6. Reschedule and activate

Three Free Choices

  1. Rescheduling
  2. Volatile Data
  3. Re-enabling interrupts

The Hardware in the Trains Lab

Timer

Interrupt Control Unit (ICU)

All input signals are

Base addresses

Basic Operation

VIC powers up with

Procedure

Initialization

  1. leave protection off
  2. enable in VICxIntEnable when you are ready to handle the interrupt

On an interrupt

  1. Read VICxIRQStatus
  2. Choose which interrupt you wish to handle
  3. Clear the interrupt source in the device

For debugging

  1. Use VICxSoftInt and VICxSoftIntClear to turn interrupt sources off and on in software

Hardware Definitions

Registers for Basic Operation
Register Name Offset R/W Description
VICxIRQStatus 0x00 RO One bit for each interrupt source

1 if interrupt is asserted and not masked

VICxFIQStatus 0x04 RO As above for FIQ
VICxRawIntr 0x08 RO As above but not masked
VICxIntSelect 0x0c R/W 0: IRQ, 1: FIQ
VICxIntEnable 0x10 R/W 0: Masked, 1: Enabled
VICxIntEnClear 0x14 WO Clears bits in VICxIntEnable
VICxSoftInt 0x18 R/W Asserts interrupt from software
VICxSoftIntClear 0x1c WO Clears interrupt from software
VICxProtection 0x20 R/W Bit 0 enables protection from user mode access
VICxVectAddr 0x30 R/W Enables priority hardware

See documentation.

Vectored Operation

Procedure

Initialization

  1. Write kernel entry point into VICxDefVectAddr
  2. If desired write special entry point into VICxVectAddry
  3. When ready to accept interrupts write source and enable into VICxVectCntly

When an interrupt occurs

  1. Read VICxVectAddr to find address
  2. Move result to PC
  3. When service is complete write VICxVectAddr to start priority hardware
Register Name Offset R/W Description
VICxVectAddr 0x030 R/W Read: address of vector for highest priority interrupt

Write: service complete, enable priority hardware

VICxDefVectAddr 0x034 R/W Default vector address
VICxVectAddry 0x100+4y R/W Vector address for interrupt y
VICxVectCntly 0x200+4y R/W Control register for interrupt y

Bit[0-4]: interrupt source for interrupt y

Bit[5]: enable vectored interrupt y


Return to: