RTOS
Real Time Operating System

By:
VIVEK. P.PATKAR.
PRAKRUTI. JOSHI.

An example of RTOS implementation on Renesas
automotive dashboard platform.
What is RTOS?


An RTOS is multitasking operating system for
the applications needing meeting of :
a) time deadlines and
b)functioning in real time constraints
Block Diagram of RTOS
Architecture of RTOS
Architecture of RTOS
 An RTOS usually comprises only a kernel. For

more complex embedded systems, an RTOS
can be a combination of various modules,
including the kernel, networking protocol
stacks, and other components as illustrated
previously.
 An operating system generally consists of two
parts: kernel space (kernel mode) and user
space (user mode).
Kernel
The kernel of an RTOS
provides an abstraction
layer between the
application software
and hardware.
 This abstraction layer
comprises of six main
types of common
services provided by the
kernel to the
application software.

KERNEL
There are three broad categories of kernel models available

Monolithic Kernel
E.g.. Examples are Linux
and Windows

Microkernel
E.g. Examples are
AmigaOS and QNX

Exokernel
E.g.. library operating
systems (libOSes)
Classification Of RTOS
RTOS
Hard real time

Firm real time

Zero degree of
tolerance

Unacceptable
quality
reduction

E.g. Automobile engine
control system and anti
lock brake, video
transmission, each picture
frame and
audio must be transferred
at fixed rate.

Soft real time
Reduction in
quality
reduction is
acceptable.

E.g. a food processing
plant control system.
E.g. Mobile phone, digital
cameras and orchestra
playing robots.
Features Of RTOS

Task and
Multitask

Running

Scheduler

Timer
Function

Memory
Management

Dormant
Blocked

Ready

Pre emptive

Non Pre emptive

Inter Task
Communication
Task and Multitask
Context

Switch

E.g.20 MHz 68000 process
or task switch times are
roughly 20 microseconds.
In contrast, a
100 MHz ARM CPU
switches in less than 3
microseconds.
Advantages:

a)Can concentrate all the
talent at a particular task.
b)Debugging is simple.
c)Easy to understand.
Scheduler
Pre emptive Scheduler

It allows high priority task to
run first and move low
priority task which is in
running into ready state.
E.g. Solaris 2.0/SunOS
5.0, Windows NT, the Linux
kernel 2.6 and 3.x, AIX and
some BSD systems (NetBSD,
since version 5), Anroid.
Advantages:
High priority task executed
immediately.
Disadvantages:
Starvation.
Scheduler
Non Pre emptive

Scheduler

High priority task co
operate with low priority
task.
E.g. Windows3.1x, Mac
OS pre-9.

Advantages:
No starvation.
Easy to implement.
Disadvantages:
High priority task has to
wait for low priority task
to complete, thus, not
suitable for RTOS.
Timer Function
 Task delay.

E.g. In μC/OS-II, for a task to delay itself:
OSTimeDly(ticks), where ticks is the number of
clock ticks from the timer;
OSTimeDlyHMSM(H,M,S,M), with Hours, Minutes,
Seconds, Microseconds.


Task alert.

E.g. µC/OS-II use system clock, Vx Works use
watchdog timers
Memory Management
Memory allocated for
each task.
 Memory allocated for
each task control
block(TCB).
 Size of queue.
 Size of mailbox
 Size of pipe


TCB
Inter task Communication

Event

Queue Mailbox

Pipe

Shared Data Protected

Disabling
Task Switch

Semaphore

Disabling
Interrupts

Mutex
Counting
Semaphore Semaphore
Priority Inversion

Spinlock
Semaphore

Dead Lock
Event

Event objects are used when task synchronization is required without resource
sharing. They allow one or more tasks to
keep waiting for a specified event to occur.
Queue
Queue :
E.g. AVR microcontroller, Linux 2.4; Windows
NT/XP/Vista, Mac OS X uses a multilevel feedback
queue, uses a Multilevel feedback queue.
mailbox:
E.g. TI SYS/BIOS v6.33 RTOS, Keil RTX.
Pipe:
E.g. QNX RTOS, SMX RTOS.
Semaphores

E.g. ChibiOS/RT, VxWorks
Binary Semaphore









Whenever it is set, shared data is free.
whenever it is reset shared data is busy.
Whenever a task access shared data it takes
semaphore and the semaphore flag is reset.
Whenever a task exit from shared data it releases
semaphore and the flag is reset.
In this way shared data is protected.
Semaphores

E.g. VxWorks, UNIX
Counting Semaphore







It is semaphore in which value can be
incremented or decremented. it is unsigned
integer.
This semaphore can be taken multiple times.
Taking semaphore means decrementing the
integer.
Releasing the semaphore means incrementing
the integer.
Semaphores

E.g. ChibiOS/RT, VxWorks, CHIP-RTOS-x86 RTX
Spin lock Semaphore








This semaphore will not make running task to
blocked immediately.
Spin lock is useful in following situation:
Suppose low priority task is running and only some
time is left for its completion.
Now high priority task wants to run
Now RTOS provides spin lock semaphore to the high
priority task and so it can spin for some time. During
that time low priority task is executed and by itself it
is moved into blocked state.
Now high priority task begins to run.
RTOS Design
 Size of ISR:
If ISR is long, then there are two drawbacks:



Highest priority task is blocked for more time.
ISR is sensitive to error and so it is difficult to debug long
ISR.
Conclusion:
Size of ISR should be small.
RTOS Design
 Number

of Task:

Advantages:
 Can concentrate all talent at a particular task.
 Debugging is simple.
 Very easy to understand.
Disadvantages:
 More memory needed because each task needs memory.
 Speed is less because task switching needs more time.

Conclusion:
Number of tasks should be moderate.
RTOS Design
 Avoid

creating and destroying task:

It is time consuming and thus speed becomes less.
Conclusion:
Must avoid this.

 Task

structure:

Task designing should be such that task is blocked at the most
only one place.
RTOS Design
 Keep time slicing off:
Task should not have equal priority.

 Techniques





to save memory:

For each task provide stack memory, TCB etc. only as much
needed.
Limit RTOS services.
Do not use same function that does nearly same action.
RTOS Design
 Techniques to save power:






Idle mode.
Power down mode.
Sleep mode.
Low power mode.
Standby mode.
RTOS Design
 Encapsulate








hardware with task:

This type of task is known as sever task.
If hardware is having many tasks, then we must have
separate task to encapsulate the hardware.
This separate task is known as server task.
Whenever task has to access hardware, they give
message in the queue to the server task.
Then server task makes accessing the hardware in
proper manner.
Advantages
 Run time facilities i.e. provision of kernel services.

 Provision for interrupts.
 Task can have priority.
 This architecture can suspend low priority task

and make high priority task run immediately
when need arises.
 Scalable.
 Portable.
Disadvantages
 Cost

is more.
 License.
 Supplier stability/ longevity.
 Availability of Development tools.
Examples
 LynxOS.

 OSE
 QNX
 RTLinux
 Windows
 VxWorks

CE
Applications
 Web

server
 Microwave oven
 MRI(Magnetic Resonance Machine)
 Aircraft control
 Automotive applications:
a) automatic breaking systems.
b) fuel injection.
c) path tracking.
REAL TIME OPERATING SYSTEM

REAL TIME OPERATING SYSTEM

  • 1.
    RTOS Real Time OperatingSystem By: VIVEK. P.PATKAR. PRAKRUTI. JOSHI. An example of RTOS implementation on Renesas automotive dashboard platform.
  • 2.
    What is RTOS?  AnRTOS is multitasking operating system for the applications needing meeting of : a) time deadlines and b)functioning in real time constraints
  • 3.
  • 4.
  • 5.
    Architecture of RTOS An RTOS usually comprises only a kernel. For more complex embedded systems, an RTOS can be a combination of various modules, including the kernel, networking protocol stacks, and other components as illustrated previously.  An operating system generally consists of two parts: kernel space (kernel mode) and user space (user mode).
  • 6.
    Kernel The kernel ofan RTOS provides an abstraction layer between the application software and hardware.  This abstraction layer comprises of six main types of common services provided by the kernel to the application software. 
  • 7.
    KERNEL There are threebroad categories of kernel models available Monolithic Kernel E.g.. Examples are Linux and Windows Microkernel E.g. Examples are AmigaOS and QNX Exokernel E.g.. library operating systems (libOSes)
  • 8.
    Classification Of RTOS RTOS Hardreal time Firm real time Zero degree of tolerance Unacceptable quality reduction E.g. Automobile engine control system and anti lock brake, video transmission, each picture frame and audio must be transferred at fixed rate. Soft real time Reduction in quality reduction is acceptable. E.g. a food processing plant control system. E.g. Mobile phone, digital cameras and orchestra playing robots.
  • 9.
    Features Of RTOS Taskand Multitask Running Scheduler Timer Function Memory Management Dormant Blocked Ready Pre emptive Non Pre emptive Inter Task Communication
  • 10.
    Task and Multitask Context Switch E.g.20MHz 68000 process or task switch times are roughly 20 microseconds. In contrast, a 100 MHz ARM CPU switches in less than 3 microseconds. Advantages: a)Can concentrate all the talent at a particular task. b)Debugging is simple. c)Easy to understand.
  • 11.
    Scheduler Pre emptive Scheduler Itallows high priority task to run first and move low priority task which is in running into ready state. E.g. Solaris 2.0/SunOS 5.0, Windows NT, the Linux kernel 2.6 and 3.x, AIX and some BSD systems (NetBSD, since version 5), Anroid. Advantages: High priority task executed immediately. Disadvantages: Starvation.
  • 12.
    Scheduler Non Pre emptive Scheduler Highpriority task co operate with low priority task. E.g. Windows3.1x, Mac OS pre-9. Advantages: No starvation. Easy to implement. Disadvantages: High priority task has to wait for low priority task to complete, thus, not suitable for RTOS.
  • 13.
    Timer Function  Taskdelay. E.g. In μC/OS-II, for a task to delay itself: OSTimeDly(ticks), where ticks is the number of clock ticks from the timer; OSTimeDlyHMSM(H,M,S,M), with Hours, Minutes, Seconds, Microseconds.  Task alert. E.g. µC/OS-II use system clock, Vx Works use watchdog timers
  • 14.
    Memory Management Memory allocatedfor each task.  Memory allocated for each task control block(TCB).  Size of queue.  Size of mailbox  Size of pipe  TCB
  • 15.
    Inter task Communication Event QueueMailbox Pipe Shared Data Protected Disabling Task Switch Semaphore Disabling Interrupts Mutex Counting Semaphore Semaphore Priority Inversion Spinlock Semaphore Dead Lock
  • 16.
    Event Event objects areused when task synchronization is required without resource sharing. They allow one or more tasks to keep waiting for a specified event to occur.
  • 17.
    Queue Queue : E.g. AVRmicrocontroller, Linux 2.4; Windows NT/XP/Vista, Mac OS X uses a multilevel feedback queue, uses a Multilevel feedback queue. mailbox: E.g. TI SYS/BIOS v6.33 RTOS, Keil RTX. Pipe: E.g. QNX RTOS, SMX RTOS.
  • 18.
  • 19.
    Binary Semaphore      Whenever itis set, shared data is free. whenever it is reset shared data is busy. Whenever a task access shared data it takes semaphore and the semaphore flag is reset. Whenever a task exit from shared data it releases semaphore and the flag is reset. In this way shared data is protected.
  • 20.
  • 21.
    Counting Semaphore     It issemaphore in which value can be incremented or decremented. it is unsigned integer. This semaphore can be taken multiple times. Taking semaphore means decrementing the integer. Releasing the semaphore means incrementing the integer.
  • 22.
  • 23.
    Spin lock Semaphore       Thissemaphore will not make running task to blocked immediately. Spin lock is useful in following situation: Suppose low priority task is running and only some time is left for its completion. Now high priority task wants to run Now RTOS provides spin lock semaphore to the high priority task and so it can spin for some time. During that time low priority task is executed and by itself it is moved into blocked state. Now high priority task begins to run.
  • 24.
    RTOS Design  Sizeof ISR: If ISR is long, then there are two drawbacks:   Highest priority task is blocked for more time. ISR is sensitive to error and so it is difficult to debug long ISR. Conclusion: Size of ISR should be small.
  • 25.
    RTOS Design  Number ofTask: Advantages:  Can concentrate all talent at a particular task.  Debugging is simple.  Very easy to understand. Disadvantages:  More memory needed because each task needs memory.  Speed is less because task switching needs more time. Conclusion: Number of tasks should be moderate.
  • 26.
    RTOS Design  Avoid creatingand destroying task: It is time consuming and thus speed becomes less. Conclusion: Must avoid this.  Task structure: Task designing should be such that task is blocked at the most only one place.
  • 27.
    RTOS Design  Keeptime slicing off: Task should not have equal priority.  Techniques    to save memory: For each task provide stack memory, TCB etc. only as much needed. Limit RTOS services. Do not use same function that does nearly same action.
  • 28.
    RTOS Design  Techniquesto save power:      Idle mode. Power down mode. Sleep mode. Low power mode. Standby mode.
  • 29.
    RTOS Design  Encapsulate     hardwarewith task: This type of task is known as sever task. If hardware is having many tasks, then we must have separate task to encapsulate the hardware. This separate task is known as server task. Whenever task has to access hardware, they give message in the queue to the server task. Then server task makes accessing the hardware in proper manner.
  • 30.
    Advantages  Run timefacilities i.e. provision of kernel services.  Provision for interrupts.  Task can have priority.  This architecture can suspend low priority task and make high priority task run immediately when need arises.  Scalable.  Portable.
  • 31.
    Disadvantages  Cost is more. License.  Supplier stability/ longevity.  Availability of Development tools.
  • 32.
    Examples  LynxOS.  OSE QNX  RTLinux  Windows  VxWorks CE
  • 33.
    Applications  Web server  Microwaveoven  MRI(Magnetic Resonance Machine)  Aircraft control  Automotive applications: a) automatic breaking systems. b) fuel injection. c) path tracking.