CS452 - Real-Time Programming - Spring 2008

Lecture 3 - Old-style RT Programming Methods

Busy Waiting

This is used to synchronize with an external event, with minimal response time.

#define FOREVER for( ; ; )
FOREVER {
   while( !ready( ) ) ;
   do-it( );
}

Aside: The nature of of I/O devices

Worst case response time

The NOP technique

Maybe this isn't fast enough for you. Here's an "improvement".

L1:
  NOP
L2:
  NOP
...
L1000:
  NOP
L1001:
  LDR  R0, [R3]
  STR  R0, [R4, #4]!
  BX   R5

Worst case response time

Polling Loops

Polling loops allow you to manage more than one condition/activity pair at the same time.

The basic polling loop

FOREVER {
  if( c1 ) a1;
  if( c2 ) a2;
  ...
  if( cN ) aN;
}

Worst case response time

Testing more than once

Suppose you want a better response time for a1. Then try the loop

FOREVER {
  if( c1 ) a1;
  if( c2 ) a2;
  if( c1 ) a1;
  if( c3 ) a3;
  ...
  if( c1 ) a1;
  if( cN ) aN;
}

Worst case response time for a1

Breaking into pieces

Suppose the response time is still too long, because the execution of one action, say a2, is too long. Then you can break a2 into two parts

FOREVER {
  if( c1 ) a1;
  if( c2 ) { a2.1; half-done = TRUE }
  if( c1 ) a1;
  if( halfdone ) a2.2;
  ...
}

This is strarting to get a little complicated and we haven't said anything about inter-action communication

Interrupt Service Routines (ISRs)

We can use interrupts to get rid of polling

Interrupts are exceptions

  1. Mask interrupts
  2. Set link register
  3. Save CSR
  4. Transfer control

Interrupt vectors

ISRs

Like function calls without arguments or return values.

  1. Save state of interrupted task
  2. Turn off source of interrupt
  3. Do the work
  4. Restore state of interrupted task
  5. Return to next instruction of interrupted task

Contrast RT to non-RT


Return to: