CS452 - Real-Time Programming - Winter 2017

Lecture 3 - Odds and Ends

Public Service Annoucements

  1. Due date for assignment 0
  2. Remember to get a partner
  3. Caches, optimization, clock speed, FIFOs
  4. Libraries: memcpy in particular
  5. Questions about using a timer

Estimating time

In a real-time system finding the correct algorithm requires us to think about how long things take. Mostly this means doing mental or back of the envelope calculations where we care only about getting the right order of magnitude.

Digression: How many bits in a byte?

End of digression.

Practical questions

Can we put busy-wait I/O into the polling loop? Acutally, four questions.

  1. How long does it take to transmit/receive a byte to/from the train controller?
  2. How long does it take to transmit/receive a byte to/from the terminal?
  3. How often do you need to read the timer?
  4. Is there a problem?

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;

A few odds and ends about UARTs

Error conditions in UARTs

There is a receive status register that tells you something about receive errors. Its bits are:

The data register

At most 8 of the bits in the integer you read have genuine content. Masking is usual.

A few odds and ends about trains

Talking to the train controller

This is the hardest part of Ass. 0. If nothing happens to the train the problem can be

Putting a terminal into the line between the ARM box and the train controller will help you to eliminate possible sources or error more easily. In fact, old dumb terminals had an extra connector on the back and passed everything coming in on one connector out the other while displaying it on the screen, just to make debugging communications easier.

Today you can achieve the same thing using the two COM parts of a simple PC.

This is an important problem solving technique that you use all the time, possibly without noticing it: break a complex problem into two or more simple ones.

Turning a train headlight on and off is an easy way to see if you are communicating with the train controller successfully.

States of Three-way Switches

The three way switches are actually a pair of switches so they have four states
States of three-way switches
Switch 1 Switch 2 Result
Straight Straight Straight
Straight Curved Curve Right
Curved Straight Curve Left
Curved Curved Probable Derailment

UART Flow Control

All hardware & software has buffers somewhere

Three-wire RS-232

We need what's called a null modem. Without the crossover it's called straight through.

connects to
signal ground signal ground
transmit (XMIT) receive (RCV)
receive (RCV) transmit (XMIT)

Five-wire RS-232

Two extra wires are added to provide flow control

connects to
signal ground signal ground
transmit (XMIT) receive (RCV)
receive (RCV) transmit (XMIT)
clear to send (CTS) request to send (RTS)
request to send (RTS) clear to send (CTS)

The train controller asserts RTS, which is read as CTS by the UART. The train controller ignores the RS-232 input if you send when CTS is not asserted. Of course, nothing is sent to you saying that a byte has been lost.

A few interesting things about RedBoot

What's in the flash ROM of the board is a partial implementation of Redboot.

The program you have written so far is allocating local memory on a stack? This enables you to get a clean return to RedBoot when your program terminates.

When your program crashes Redboot catches the exception, and puts out some information for gcc to hook into your program. (ecos and RedHat are strongly connected to the GNU project. (Don't bother trying to use gdb!) You see it on the bottom two lines of output. It's useless except for one 8 digit number starting 00218 or 00219. This is the address of the last instruction the CPU attempted to execute. Using the load map and the assembly code you can find exactly how far the program got before crashing. Unfortunately, the error may have occurred long before execution stopped.

Return to: