Reconfigurable computing
Small Embedded Systems
Unit 5.7 Real Time Systems
Introduction
What is a real time system?
Classification of real time systems
Challenges with only one thread of execution
Interrupt-driven systems
Multithreaded systems and thread scheduling
Real time operating systems
Real Time Systems
Real time system:
Result must be computed by a certain deadline
A late response is as bad as an incorrect response
Examples:
Heart pacemaker
Car airbag
Ignition system of a car
Classification of Real Time Systems
Hard real time
Late result is useless
Late result is system failure
Example: Car airbag
Weakly hard real time
Late results are useless
A proportion of the results are permitted to be late
If this proportion is exceeded, system fails
Example: control system which becomes unstable if output samples and system corrections are too infrequent/irregular
Classification of Real Time Systems
Firm real time
Late result is useless, but no system failure is caused
Late result causes loss of quality
Market forecasting system used to buy/sell stocks and shares
Video conferencing: a video frame delayed by so much that its successor frames have already been displayed is no use: the frame is dropped
Soft real time
Late result is useful, but less useful than if it had been delivered on time
Web service,
Online gaming system
Real Time Tasks
Tasks are normally characterised by
Triggering event
Deadline to be met (time D after the triggering event)
Triggering event
Deadline
Cost
Time
Hard real time system
Cost=∞
Triggering event
Deadline
Cost
Time
Soft real time system
Cost increasing
D
D
A Simple Example
Many embedded systems must carry out periodic tasks where
some data is read,
some computation is done on this data,
some output is applied
output must be applied before next reading is due
and repeat ….
If there is only one task, then it is easy
A Simple Example
The code would be organised something like this:
Here is a plot the activity of the microcontroller:
while(1){
take_a_reading();
compute_appropriate_response();
output_the_response();
wait_for_ms(100);
}
Time
Waiting
Active
The Example gets more Complicated
Real life is rarely that simple.
Suppose that our system grows:
We now have to produce responses to two sensors
The sensors produce their readings at different rates
Coding this in a single loop is awkward
Time
Waiting
Active
Task 1
Task 2
The Example gets more Complicated
This is horrible
We’d have to explicitly write a huge number of invocations
If timing of task2 changes, many lines of code must be changed
What if we grow to 3, 4, 5, … tasks?
The approach doesn’t scale
Time
Waiting
Active
Task 1
Task 2
while(1){
do_task1();
wait_for_ms(30);
do_task2();
wait_for_ms(70);
do_task1();
wait_for_ms(100);
do_task1();
wait_for_ms(5);
do_task2();
…
}
And so on for many line of code …
How about interrupts?
Interrupts establish the timing
Each ISR has clear code
This is much nicer
But …
Time
Waiting
Active
Task 1
Task 2
attach_timer_interrupt(ISR1, 100ms);
attach_timer_interrupt(ISR2, 175ms);
while(1){
// Empty main loop
}
ISR1(){
take_reading1();
compute_response1();
output_response1();
}
ISR2(){
take_reading2();
compute_response2();
output_response2();
}
Problems with Interrupts
ISRs need to be short and quick, but if the tasks are complicated they may not complete quickly
Sometimes both tasks will want to run at same time
What if one is far more important? Say Task1 controls the airbag and Task2 controls the CD player.
Time
Waiting
Active
Task 1
Task 2
ISR1(){
take_reading1();
compute_response1();
output_response1();
}
ISR2(){
take_reading2();
compute_response2();
output_response2();
}
Real Time Operating Systems
Doing this purely with interrupts can be made to work, and this is commonly done for simple embedded systems
However, it is tricky and doesn’t scale well
A nicer approach is to write code for separate tasks and use a real time operating system (RTOS) to manage the scheduling of which task gets the processor when
The RTOS will cause a task to yield the processor
when the task has completed its current job
when a higher priority task needs the processor
when it has had the processor for a long time, and another equally important task is awaiting attention
Summary
Real time systems must produce a correct response by a deadline
Multiple tasks (threads) running on one processor require careful scheduling to ensure all deadlines are met
Real time operating systems (RTOSs) are designed to perform scheduling of tasks to maximise chances of hitting deadlines
/docProps/thumbnail.jpeg