CS452 - Real-Time Programming - Spring 2009

Lecture 4 - Polling Loops, RS-232

Practical Details

Polling Loops

What is important for real-time?

  1. Throughput
  2. Response time

Busy Waiting

Polling Loops

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

The basic polling loop

  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

  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

  if( c1 ) a1;
  if( c2 ) { a2.1; half-done = TRUE }
  if( c1 ) a1;
  if( half-done ) 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


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

Worst case reponse time

Interrupt vectors


Communication protocol existing since forever.

Why do we still use it in the age of USB, etc.

Very simple RS-232

Three wires

Wired like this

GND ---------- GND

XMIT --\ /---- XMIT
RCV----/ \---- RCV

What could be simpler?

Real Hardware

Distinguish Data Terminal Equipment (DTE) from Data Circuit-terminating Equipment (DCE)

On the DE-9 connector we have for DTE

5 -- GND
3 -- XMIT
2 -- RCV

and for DCE

5 -- GND
3 -- RCV
2 -- XMIT

A very simple `straight through' cable connects these perfectly. But when we conect DTE to DTE we need the cable above, which is called a `null modem'.

Train RS-232

Three wire works fine as long as both ends of the wire are much faster than the wire itself. But the train controller is very slow. Why?

The train controller needs to be able to say STOP. How is this done?

Software Flow Control

Hardware Flow Control

What Happens if You Omit Flow Control

Return to: