CS452 - Real-Time Programming - Winter 2018

Lecture 1 - Introduction

Public Service Annoucements

  1. Due date for assignment 0 is Wednesday January 11. What we expect to see in a week: While working on the assignment you will learn how to communicate with the trains, which is essential for the project.
  2. Combination to trains lab
  3. How to compile and run your first program.

Practical Details: pdf

Finding a partner

Doing this well matters a lot for you learning this term, not to mention your stress and your enjoyment of being in this course. Here is what you should be considering.

Two Box Development

Two box development separates editing, compiling and linking from executing. One box runs an editor, cross-compiler, so-called because it compiles for a different machine architecture than the one on which it runs, and link-editor, which binds together the various parts of your program.

After compilation the program is loaded from the first box to the second which executes it. To make this possible the box on which the program executes has a boot loader that runs automatically whenever it is rebooted. The boot loader, called RedBoot, is an offshoot of a real-time development environment called ecos.

Actually there are four boxes we care about

  1. The box on which you edit, compile and link the code
  2. The box that executes the code
  3. The box that displays output from and provides keyboard input to a serial port (com2) on the second box.
  4. The box that transforms its inout and output (from the other serial port (com1) on the second box into train commands

Box 1 is connected to box 2 by ethernet.

Box 2 is connected to box 3 by three-wire RS-232.

Box 2 is connected to box 4 by five-wire RS-232.

Box 2 is the primary focus of the first half of the course. It contains

Serial I/O

All four boxes are used in assignment 0, the focus of which is getting box 2 communicating with the other three boxes.

In order to do assignment zero your program, running on box 2, must

  1. receive keyboard input from the terminal (box 3),
  2. send monitor output to the terminal (box 3),
  3. send commands to the train controller (box 4),
  4. receive sensor reports from the train (box 4), and
  5. read the timer (box 2) to update the clock.
The first four use serial I/O for communication, so you must start assignment zero by mastering the hardware and software that provides getc and putc in a Unix environment.

Uses a device called a UART,

For the purposes of assignment 0 this appears to your program as several registers, magic locations in memory.

Busy Waiting

Busy waiting is the simplest and most reliable way of timing an action, and is the technique used in the hello-world program. In addition it gives the shortest possible response time. (Except when more than one response time matters.)

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

The above program is written in an easy-to-understand form. Real programs, not to mention real-time ones, are not easy to understand. A more realistic version looks more like this

    #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

    #define  FLAGS	(int *)( UART1_BASE | UART_FLAG_OFFSET )
    #define DATA	(int *)( UART1_BASE | UART_DATA_OFFSET );

    void transmit( byte c ) {
      while( ( FLAGS & TXFF_MASK ) ) ;
      DATA = c;

The problem with busy-waiting

What if the CPU has to two things at once?


  1. collect bytes coming in a serial port
  2. maintain a clock

Unless the rate of bytes coming in and rate of clock ticks are identical you are guaranteed to lose something sooner or later. If this is not obvious work out an example in detail.

Return to: