Professional Documents
Culture Documents
06ec6035 - Advanced Microcontrollers and Real Time Operating Systems
06ec6035 - Advanced Microcontrollers and Real Time Operating Systems
06ec6035 - Advanced Microcontrollers and Real Time Operating Systems
Compiled by
Jagadeesh Kumar P
jagadeeshkumarp@mec.ac.in
Module2 Part1
2
Reference Book
3
What is an RTOS?
A Real Time Operating System, commonly known as an RTOS, is a software
component that rapidly switches between tasks,
- giving the impression that multiple programs are being executed at the
same time on a single processing core.
In actual the processing core can only execute one program at any one time, and
what the RTOS is actually doing is rapidly switching between individual
programming threads (or Tasks)
4
OS or RTOS?
The difference between an OS (Operating System) such as Windows or Unix and an RTOS
(Real Time Operating System) found in embedded systems,
OS’s typically provide a non-deterministic, soft real time response, where there are no
guarantees as to when each task will complete, but they will try to stay responsive to
the user.
An RTOS differs in that it typically provides a hard real time response, providing a fast,
highly deterministic reaction to external events.
The difference between the two can be highlighted through examples – compare, for
example, the editing of a document on a PC to the operation of a precision motor control.
5
RTOS
Inconsistent terminology - when we discuss real-time operating systems.
Many people use the acronym RTOS (which they pronounce “are toss").
Others use the terms kernel, real-time kernel, or the acronym for this, RTK.
Some use all of these terms synonymously; others use kernel to mean some subcollection
containing the most basic services offered by the larger RTOS.
These latter people consider things like network support software, debugging tools, and
even memory management to be part of the RTOS but not part of the kernel.
Since there is no general agreement about where the kernel stops and the RTOS begins, the
reference book ignores these distinctions and use the term RTOS indiscriminately.
6
RTOS vs OS
The First Place --
Despite the similar name, most real-time operating systems are rather different from
desktop machine operating systems such as Windows or Unix
On a desktop computer, the OS takes the control of the machine as soon as it is turned on
and lets start the application.
- During boot-up time the application usually gets the control first, and then it starts the
RTOS.
- Thus the application and the RTOS are much more tightly tied to one another than an
application and its OS.
7
RTOS vs OS
The Second Place --
Many RTOS do not protect themselves as carefully from the application as do desktop
OS.
Eg. Most desktop OSs check any pointer we pass into a system function is valid, but many
RTOSs skip this step in the interest of better performance.
if the application is doing something like passing a bad pointer into the RTOS, the
application is probably about to crash anyway;
- for many embedded systems, it may not matter if the application takes the RTOS down
with it - the whole system will have to be rebooted anyway.
8
RTOS vs OS
The Third Place --
In the third place, to save memory RTOSs typically include just the services, that we need for
our embedded system and no more.
Most RTOSs allow us to configure them extensively before we link them to the application,
letting us leave out any functions we don't plan to use
Unless we need them, we can configure away such common operating system functions as
file managers, I/O drivers, utilities, and perhaps even memory management,
9
RTOS vs OS
The Third Place --
10
Architectures for Embedded Software
The most important factor that determines which architecture will be the most
appropriate for any given system is how much control we need to have over
system response.
How hard it will be to achieve good response depends not only on the absolute
response time requirements but also
11
Architectures for Embedded Software
A system with little to do whose response-time requirements are few and not
particularly stringent can be written with a very simple architecture.
A system that must respond rapidly to many different events and that has
various processing requirements, all with different deadlines and different
priorities, will require a more complex architecture.
12
Architectures for Embedded Software
Will discuss four architectures,
- starting with the simplest one, which offers us practically no control of our
response and priorities, and moving onto others that give us greater control
but at the cost of increased complexity.
13
Round -Robin
Simplest architecture
No interrupts
No shared data
No latency concerns
14
Round -Robin
Adequate for simple jobs – Digital
Multimeter
15
Round -Robin
Round –robin works well for this
system
16
Round -Robin
17
Round -Robin
18
Round -Robin
19
Round-Robin with Interrupts
Interrupt routines deals with very urgent needs of h/d and set flags
Main loop polls the flags and does the follow-up processing required by the
interrupts
Gives a little bit more control over priorities – possible to assign priorities for
various interrupts
Interrupt routines can get good response – μC stops what ever it is doing in main
fn.
20
Round-Robin with Interrupts
21
Round-Robin with Interrupts
22
Round-Robin with Interrupts
Disadvantage
fDeviceA, fDeviceB…. fDeviceZ and other data are shared between the ISR and
the task code in main
23
Round-Robin with Interrupts
24
Round-Robin with Interrupts
25
Round-Robin with Interrupts
Disadvantage
26
Round-Robin with Interrupts
Whenever a character is received on one of the ports – it
causes an interrupt – μC must read from the I/O h/d - it must
be serviced reasonably quickly
27
Round-Robin with Interrupts
The encryption routine can encrypt characters one at a
time and
28
Round-Robin with Interrupts
29
Round-Robin with Interrupts
30
Round-Robin with Interrupts
31
Round-Robin with Interrupts
μC executes the ISRs vGotCharacterOnLinkA and vGotCharacterOnLinkB
whenever the h/d receives a character
The ISR reads the characters from the h/d and put them into the queues
qDataFromLinkA and qDataFromLinkB
The task code in the main routine calls vEncrypt and vDecrypt which
32
Round-Robin with Interrupts
The variables fLinkAReadyToSend and fLinkBReadyToSend keep track of
whether I/O h/d is ready to send characters on the two communication links
33
Round-Robin with Interrupts
When the task code writes to the h/d or to these varaibles – interrupt is disabled
– to avoid the shared data problem
The ISRs receives the characters and write them to the queues
This process get priority over the process of moving characters among the
queues,
This way a sudden burst of characters will not overrun the system – even if
encryption & decryption process are time consuming
34
Characteristics of Round-Robin-with-Interrupts
All task codes execute at the same priority
Let the task codes that deal with devices A, B, and C take 200ms each
If devices A, B, and C all interrupt when the controller is executing the statements
at the top of the loop
Then task code for C may have to wait 400 milliseconds before it starts to execute.
35
Function Queue Scheduling
The interrupt routines add function pointers to a queue of function pointers
– for the main function to call
The main routine just reads pointers from the queue and calls the functions
No rules says that main has to call the function in the order that the routines
occurred
36
Function Queue Scheduling
37
Function Queue Scheduling
With a little clever coding that queue up the function parameters
- any task code that need quicker response can be executed earlier
The worst wait for the highest priority task code function is the length of the
longest task code function
- this happens if the longest task code function has just started when the
interrupt for the highest-priority device occurs
38
Function Queue Scheduling
The trade-off for this better response –
The response for the lower priority task functions may get worse
Under round-robin-with-interrupts all of the task code gets a chance to run each
time main goes around the loop
But here, lower priority functions may never execute if the interrupt routines
schedule the higher priority functions frequently
39
Real Time Operating System Architecture
Interrupt routines take care of most urgent operations
Then they signal that there is work for the task code to do
!!Set signal X }
{ while (True)
{ while (True)
} ………
41
Real Time Operating System Architecture
Features
The signaling between the interrupt routines and the task code is handled by the RTOS
Code inside the RTOS decides which of the task code function to run
RTOS knows about the various task code routines and run based on urgency
RTOS can suspend one task code routine in the middle of its processing to run another
42
Real Time Operating System Architecture
In the previous example
If task1 is of higher priority than task2 and If task2 is in the middle of processing and If interrupt routine
vHandleDeviceA sets the signal X, then
The worst case wait time for the highest priority task code is zero
changes to lower priority tasks do not generally affect the response of higher priority ones
43
Real Time Operating System Architecture
Disadvantage of using RTOS
Selecting an architecture
Select the simplest architecture that will meet the response requirements
If the system has requirements that necessitate an RTOS then lean toward using it
Select an appropriate RTOS which has a collection of useful tools to test and debug the system
Priorities available
- None
- Poor
Simplicity
- Very simple
45
Characteristics of various architectures
Round Robin with interrupts
Priorities available
- Interrupt routines in priority order – then all task code at the same priority
Simplicity
Priorities available
- Relatively Good
Simplicity
- Must deal with data sharing problem and write function queue code
47
Characteristics of various architectures
Real Time OS
Priorities available
- Zero
- Very Good
Simplicity
48
Characteristics of various architectures
49