CS452 - Real-Time Programming - Fall 2011
Lecture 2 - Introduction
Pubilc Service Annoucements
- Due date for assignment 0
- Combination to trains lab
- Ubuntu 10.10
- How to compile and run your first
program
Practical Details: pdf
Embedded Systems
Artifacts that use computation to manipulate the real-world, including
user interfaces, have a structure that can be described in one of two
different ways.
- Computation measures the response of sensors to determine the correct
state for its internal model of the world, and that model is used to
calculate appropriate activator responses.
- Actvators are manipulated according to the state of the artifacts
internal model of the world,after which computation reads sensors to
calculate the effect of their action on the world.
Most of the mediation between the internal representations and the
real-world is done by embedded systems
- invisible computing
- sense and control
- billions and billions sold
What is real-time programming?
Actually real-world programming, which means
- World is measured in seconds, metres, etc.
- Programs manipulate bits, bytes, words, which must be translated into
into real-world measures.
For example,
- formatted output: translate from int, which computers manipulate,
to decimal, which humans read
- out in the open: i2a( ), printf( )
- hidden: print, cout
- Banking: int translates into, e.g., number of cents
- program says dispense( 10000 ), which means `put five twemties
into the hopper'.
- microcontrollers start
- activating motors
- sensing forces
- reading digitized video
- etc.
- Train control: contents of messages map into change speed, switch
turn-out, sensor triggered
What is important for real-time?
- Throughput
- e.g., number of frames per second in a game
- e.g., frequency of sensor sampling in process control
- no solution except
- getting better hardware
- getting better algorithms
- restructuring the task
- Response time
In cs452 we take guaranteed response time as the defining quality of
real-time computation.
Assignment 0
Objective
Go beyond busy-waiting to maintain several synchronized activities
simultaneously.
To be specific
Output to the terminal
- Write the current time on the display of the terminal
- will need cursor addressing
- Display of the state of the train-set on the display of the
terminal
- Prompt and echo for input
Input from the terminal
- User commands for the train-set
Output to the train-set
- Give speed commands
- Switch turn outs
- Request sensor data
Input from the train-set
- Sensor reports
Output to the timer
- Initialization
Input from the timer
- Current count
Software Design
No operating system services available, including
- input output
- dynamic memory
- hardware abstractions
- file system
Polling loop design
Generalization of busy-waiting
Sending a byte onto a 115,200 bps serial line
- 10 bits per byte
- 11,520 = 10,000 bytes per second
- ready sets after 100 microseconds
- software could
- test the byte 200 times (busy wait), OR
- test the byte less frequently and do something else with the extra
time (polling loop).
The polling loop
while( true ) {
if( transmit ready bit set )
if( NOT output buffer empty )
write next byte
if( receive ready bit set )
read next byte into buffer
if( timer has counted down )
increment time
...
}
This generalizes to
while( true ) {
if( condition1 )
do action1
if( condition2 )
do action2
...
if( condition-n )
do action-n
...
}
Attractive feature of a polling loop
- You can calculate the worst case response time
Unattractive feature of polling loop
- The worst case response time is very pessimistic
Hardware Available
Timers
Generic timer
Three registers
- Command register
- Load register
- Read register
The generic timer
- counts down from the loaded value
- reloads and keeps counting when it hits zero
- sets an interrupt when it reaches zero
In a polling loop the interrupt is not used.
Find out the details in the EP9302 documentation. Of the five, or is it
six, timers on the EP9302 SoC use the 32-bit one.
UARTs
Generic UART
Three wires
- transmit (XMIT)
- receive (RCV)
- ground
(Transmit and receive must be crossed.)
Two registers
- Command/status register
- read to get the state of the UART
- write to give commands to the UART
- Data register
- read when receiving a byte
- write when sending a byte
Common added features
- Separate command & status registers
- Separate (readable) register for setting line parameters such as bps,
start bits, parity, etc
- Separate register for reading error conditions, of which the important
ones are
Generic UART with hardware flow control
Two extra wires, usually
- request to send (RTS) an output
- clear to send (CTS) an input
(Like XMIT and RCV, RTS and CTS must be crossed.)
Assert RTS when you are ready to receive a character. Read CTS to ensure
that the receiver is ready before you transmit a character.
Notes.
- Find the details in the EP9302 documentation.
- If you examine the TS-7200 circuit diagram you will see that there is a
third UART available. The connector called COM3 does not have this UART
attached to it, but rather some digital I/O bits and some other random
stuff.
Return to: