# Practical Details

• Combination
• Due date for assignment 1

# Polling Loops

## What is important for real-time?

1. Throughput
2. 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

• \sum_n execution time of if( c<n> ) + execution time of a<n>

#### 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

• execution time for if( c1 ) + \max_n execution time for if( cn ) an

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

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

3. Save CSR
4. Transfer control

#### 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

Contrast RT to non-RT

# RS-232

Communication protocol existing since forever.

• description of a wire, and the signals on it.

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

• simple
• inexpensive
• robust
• easy to implement

## Very simple RS-232

Three wires

• ground
• transmit

Wired like this

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

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

What could be simpler?

• BUT, ...
• This is actually called a null modem.
• To see why we need to look at the pins on the connector.

### 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?

• Wait for mechanical sensors.
• High electrical noise

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