CS452 - Real-Time Programming - Spring 2017
Lecture 1 - Introduction
Public Service Annoucements
-
Due date for assignment 0 is Wednesday 10 May at the beginning
of class. What we expect to see in nine days:
-
A description of your implementation, handed in at the
beginning of class.
-
Code on git accessible by the TAs, so that they can run
your program and see your code while marking the assignment.
-
Who your partner will be.
While working on the assignment you will learn how to communicate
with the trains, which is essential for the project.
-
Combination to trains lab
-
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.
-
Get a partner at the same skill level as you.
-
Get a partner with the same ambitions as you.
-
Get a partner with the same work habits as you.
-
Start talking to potential partners immediately, but not in class.
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.
Actually there are four boxes we care about
-
The box on which you edit, compile and link the code,
-
The box that executes the code,
-
The box that displays output from and provides input to a
serial port (com2) on the second box and
-
The box that transforms its inout and output (from the other
serial port (com1) on the second box into train commands and responses.
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 1 is the primary focus of the first half of the course. It
contains
-
A Cirrus 9304 system on chip, which contains among other
devices,
-
an ARM 920T cpu,
-
two UARTS (driving com1 and com2),
-
a variety of timers, and
-
an ethernet adapter.
-
thirty-two MBytes of DRAM,
-
flash memory containing a boot loader, and
-
various connectors.
Serial I/O
In order to do assignment zero your program, running on box 2, must
-
receive keyboard input from the terminal (box 3),
-
send monitor output to the terminal (box 3),
-
send commands to the train controller (box 4),
-
receive sensor reports from the train (box 4), and
-
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,
-
which is really just two shift registers,
-
one for receiving and
-
one for sending,
-
and a bus interface of two eight-bit read/write registers,
-
one for sending and receiving data and
-
one for writing commands and reading status.
For the purposes of assignment 0 this appears to your program as
several registers, magic locations in memory.
-
Read from the data register to get a byte from the UART.
-
Write to the data register and the UART will transmit the byte.
-
Read from the status register to discover if a byte has been
received or if the UART has finished transmitting the last byte
written.
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( ; ; )
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.,
-
collect bytes coming in a serial port
-
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: