Professional Documents
Culture Documents
Real Time Systems
Real Time Systems
Real Time Systems
Part 1
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 1
This is the first in the series of short seminars that will introduce you to concepts of
real-time systems. In this seminar, we shall discuss the fundamental concept of
“task” and relevant topics. The expected length of this seminar is 15 minutes.
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 2
So what is a system?
A system is something that solves a problem.
For example, to solve the problem of dirty dishes, we can design a system of a
dishwasher.
As we know, when we start a dishwasher, many things happen; for example, water
intake, motor operation that swirls water to clean dishes, water drain, etc.
Dishwashers also provide a variety of wash-cycles to handle different types of
utensils and the amount of cleaning they need. Also, if you open the door of a
dishwasher in the middle of its operation, it most likely will sense that the door is
opened and will stop its operation. And the latest high-end dishwashers may even
have an LCD display that shows various status and control information on the front-
panel.
z Group of
Motor
Display Manager instructions
Manager
performing a
PIC® MCU function of a system
Water
Manager z Dishwasher system
Door may have following
Manager
tasks:
− Water Manager
− Motor Manager
− Door Manager
− Display Manager
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 3
So what is a task?
A task is a group of instructions that executes on a microcontroller to solve a
portion of the problem. This group of instructions performs a function of a
system.
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 4
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 5
Now let’s talk about the most essential aspect of a real-time system, the “deadline”.
In our dishwasher system, say the Water Manager task is currently filling the water in the chamber.
When the dishwasher is full with water, the Water Manager task should IMMEDIATELY shut the
water intake. Otherwise, the water may spill out of the dishwasher.
Every task in a real-time system is characterized by its deadline. A task is expected to perform its
function by the time allocated to it (meaning before a deadline). The time allocation, or the deadline,
may be absolute or relaxed. For example, if a task MUST perform its function within one second,
then the deadline is an absolute deadline. On the other hand, if the task SHOULD perform its
function in about one second or so, then the deadline is relaxed.
When the deadlines are absolute, the real-time system is called a hard real-time system. The tasks in
a hard real-time system are governed by rigid time constraints.
When the deadlines are relaxed, the real-time system is called a soft real-time system. The tasks in a
soft real-time system do not have rigid time constraints.
The deadline for the Water Manager task in the scenario mentioned above should be absolute;
otherwise the probability of spilling water would be quite high resulting in many unhappy
dishwasher owners with frequent wet floors! On the other hand, a Display Manager task may have a
relaxed deadline.
Obviously, if a real-time system task fails to meet its deadline, it may have dire consequences.
Since there is only one microcontroller performing many different tasks of varied importance, it is
imperative to determine task deadlines and their relative importance in the system.
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 6
So in our dishwasher system, we may assign higher priority to the Water Manager
than the Display Manager. This ensures that when water needs to be shut-off, the
on-going display update will not unduly delay the Water Manager from performing
its job on time. No water spills, no wet floors, happy owners!
But how does the priority actually help coherent functioning of the system?
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 7
Using priorities of each task in a system, we can devise a scheme that allows
coherent operation of the system.
Simply by preventing the low priority tasks from doing their work, when a higher
priority task wants to do work, we can maintain coherency of operation. In other
words, by virtue of its priority, a task can PRE-EMPT lower priority tasks.
This prerogative of a higher priority task, to perform its job even when other lower
priority tasks are performing their job, is known as preemption.
Higher
priority
Lower
priority
time
0 Time T1 Time T2 Time T3 Time T4
- Display - Dishwasher - Water Shut-off - Display update
update chamber is full - Display update Completed
started paused
Priority
Lower
priority Display Manager Display Manager Paused Display Manager
time
Time T1 Time T2 Time T3 Time T4
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 8
As shown in this slide, consider two tasks in the dishwasher system, the higher
priority Water Manager, and the lower priority Display Manager. There are two
figures shown on this slide: the upper figure shows visual of the two tasks in form of
their function, while the lower figure shows the time-continuum of tasks executing
on the microcontroller embedded in the dishwasher.
At time T1, the water tap is ON and the dishwasher chamber is being filled with
water. Exactly at this time, the Display Manager is updating the display and has
printed “Goo” on the display, which is part of the complete message “Good Status”
that it wants to show on the display.
Next, at time T2, the dishwasher chamber is full so that there is a need to shut-off
the water tap.
At time T3, immediately after time T2, the Display Manager is paused (i.e.
preempted), and the Water Manager swings into action and shuts-off the water tap.
Notice that the display at time T3 is still showing “Goo”.
Only after the water is shut-off, at time T4, that the Display Manager is able to
complete its work and the display is showing “Good Status”. Notice on the lower
figure that the Display Manager is preempted by the Water Manager between Time
T2 and Time T4.
z Maintains ‘ranked
list’ of tasks based
on priority
z Enforces ‘ranked
list’ of tasks by
allowing or
disallowing tasks to
perform their job
z Real-time systems
have a Priority
Based Preemptive
Scheduling scheme
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 9
But which authority in the system decides which task runs at what time?
Well, that’s the job of the Scheduler.
A Scheduler in the system lines-up tasks in accordance with their priority. It works
as an arbitrator. At any given time, it decides which task must perform its job and
which task should be paused.
Thus, when the water needs to be shut-off in a dishwasher, the Scheduler decides
that the lower priority task, the Display Manager, must give way to the higher
priority task, the Water Manager. It’s only after the Water Manager finishes its job
that the Scheduler allows the Display Manager to continue its work.
Hence, the typical scheme employed for a Scheduler in the real-time system is
called Priority Based Preemptive Scheduling. Quite a mouthful! Huh!
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 10
That brings us to the end of this seminar. Let’s summarize the concepts we just
covered:
-A basic unit of operation in a system is a task
-A system may have multiple tasks running at any given time
-Tasks in real-time systems have deadlines. If tasks fail to meet deadlines, dire
consequences may follow.
-According to their importance, tasks get assigned priorities. The higher the priority,
the higher the importance.
-Higher priority tasks can do their job while pausing the lower priority tasks. This is
called preemption.
-A Scheduling scheme enforces priority based preemption to maintain coherency of
the system.
z Wikipedia (www.wikipedia.com)
− Search for the word “RTOS”
− Happy browsing
z MicroC OS II: The Real Time Kernel by
Jean J. Labrosse
− ISBN-13: 978-1578201037
z Modern Operating Systems by Andrew S.
Tanenbaum
− ISBN-13: 978-0136006633
© 2008 Microchip Technology Incorporated. All Rights Reserved. Concepts of Real Time Systems – Part 1 Slide 11
Lastly, if this seminar has incited enough interest, please do read more on the topic
at the references shown on this slide.
The easiest to find and have fun with, is the Wikipedia at www.wikipedia.com. On
this website search for the word “RTOS” and cruise-on from there on.
Another very helpful resource on real-time system and operating system concepts is
a book written by Jean Labrosse, who is also the author of MicroC OS. This real-
time operating system is ported on all Microchip microcontrollers. His book has
abundant reading material for novice as well as experienced programmer.
With that I shall say good-bye, and please don’t forget to provide your feedback on
this seminar. Thanks for your time today!