CS452 - Real-Time Programming - Winter 2013

Lecture 3 - Timers, I/O, Pitfalls

Pubilc Service Annoucements

  1. Due date for assignment 0
  2. Caches, optimization, clock speed, FIFOs
  3. Libraries: memcpy in particular
  4. Some clean-up needed in course account

The Hardware/Software Provided

Provided and maintained by CSCF

TS-7200

Specific documentation from Technologic

System on Chip (SoC)

EP9302, designed and manufactured by Cirrus semiconductor

Memory

Byte addressable, word size 32 bits

Separate instruction and data caches

`COM' ports

Connected to UARTs

Only really two

Ethernet port

Busy wait ethernet code in RedBoot

Reset switch

EP-9302

Specific documentation from Cirrus

System on chip

Software

Compiler

GNU tool chain

RedBoot

Partial implementation

Returns when program terminates

Busy-wait IO

COM2 uses monitor; COM1 goes to train

  1. initialization
  2. output
  3. input

Timers

How does one keep time in a computer?

Timers normally count down

You interact with the timer through three registers

Timers available in the EP9302.

  1. Two sixteen bit
  2. One thirty-two bit
  3. One forty bit
  4. One watch-dog

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;
}

A Few Comments

Shallow computation

Worst case response time

What you put into an action matters a lot.

Suppose you put busy-wait I/O to the train controller into an action

Will you catch it in your testing?

When you Miss Deadlines

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( half-done ) { a2.2; half-done = FALSE; }
  ...
}

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


Return to:

Practical Details: pdf

Timers

How does one keep time in a computer?

Terminals

How does one produce a useful display on an ASCII terminal?

The only way to "refresh" the display is to rewrite it completely.

Make the model more like a window.

Cursor addressing makes this possible.

Polling Loops

Busy Waiting

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

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

or in another form

FOREVER {
   if ( ready( ) ) do-it( );
}

Sometimes you only want to do the thing once, as you do when putting a character on a serial line.

#define UART1_BASE        0x808c0000
#define UART_DATA_OFFSET        0x00    // low 8 bits
#define UART_FLAG_OFFSET        0x18    // low 8 bits
#define TXFF_MASK               0x20    // Transmit buffer full

        flags = (int *)( UART1_BASE + UART_FLAG_OFFSET );
        data = (int *)( UART1_BASE + UART_DATA_OFFSET );
        while( ( *flags & TXFF_MASK ) ) ;
        *data = c;

Note. The volatile keyword.

Worst case response time

From the time that the ready bit sets until the first instruction of do-it is executed

The problem with busy-waiting

What if the CPU has to two things at once?

E.g.,

  1. collect bytes coming in from one serial port
  2. collect bytes coming in from another serial port

You might think of doing something like:

FOREVER {
	while (!ready(port1) ;
	read( port1 );
	while (!ready(port2) ;
	read( port2 );
}

What must be true for this code to catch all the bytes?

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

What you put into an action matters a lot.

Suppose you put busy-wait I/O to the train controller into an action

Will you catch it in your testing?

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( half-done ) { a2.2; half-done = FALSE; }
  ...
}

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


Return to: