CS452 - Real-Time Programming - Spring 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


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( ; ; )
    FOREVER {
       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?

E.g.,

  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: