CS452 - Real-Time Programming - Winter 2015

Lecture 1 - Introduction

Public Service Annoucements

  1. Due date for assignment 0. What we expect to see in a week
  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

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

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

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

The Two Box Program Development Cycle

Most important, you must assume that the program you are running will 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 magic locations in memory

Busy Waiting

This is used to synchronize with an external event, minimizing response time.

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

Sometimes you only want to do the thing once, as you do when putting a character on a serial line.

#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

        flags = (int *)( UART1_BASE + UART_FLAG_OFFSET );
        data = (int *)( UART1_BASE + UART_DATA_OFFSET );
        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: