CS452 - Real-Time Programming - Winter 2016

Lecture 1 - Introduction

Public Service Annoucements

  1. Due date for assignment 0. 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 and cross-compiler, so-called because it compiles for a different machine architecture than the one on which it runs. After compilation the program is loaded from the first box to the second and executed.

Actually there are four boxes we care about

  1. The box that executes the code
  2. The box on which you edit, compile and link the code
  3. The box that displays output from serial port
  4. The box that transforms output from serial port 1 into train commands

Box 1 is connected to box 2 by ethernet.

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

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

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

The Two Box Program Development Cycle

Most important, Most real-time programs run forever. Thus the following define is in every program --

    #define FOREVER while( 1 )
and the first executed statement once initialization is complete is --
It's the user who decides when it terminates.

This philosophy also governs program development, which takes the form

  1. Access box 2 from a terminal; edit, compile and link your program.
  2. Get the executable into the memory of box 1 using tftp. You are typing commands to the boot loader in box 1 using the terminal of box 3, which is running a terminal emulator.
  3. Box 3 should have a prompt from the boot loader showing on its display. Start box 1 executing at the start of your program.
  4. Look at the display of box 3 and at the train to see if they're doing what you expect.
  5. Return to step 1.

Serial I/O

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 ...).

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

Return to: