KEMBAR78
Chap 10Lesson11Emsys3ERTOSBasicDesign | PDF | Embedded System | Real Time Computing
0% found this document useful (0 votes)
21 views46 pages

Chap 10Lesson11Emsys3ERTOSBasicDesign

Uploaded by

Sasi Bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views46 pages

Chap 10Lesson11Emsys3ERTOSBasicDesign

Uploaded by

Sasi Bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

REAL TIME OPERATING SYSTEMS

Lesson-11:
Basic Design using an Real Time
Operating System

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 1
Design" , Raj Kamal, Publs.: McGraw-Hill Education
1. Basic Design

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 2
Design" , Raj Kamal, Publs.: McGraw-Hill Education
RTOS

 An embedded system with a single CPU can


run only one process at an instance.
 The process at any instance either may be
an ISR or kernel function or task

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 3
Design" , Raj Kamal, Publs.: McGraw-Hill Education
RTOS
 Provides running the user threads in kernel
space so that they execute fast.
 Provides effective handling of the ISRs,
device drivers, ISTs, tasks or threads
 Disabling and enabling of interrupts in user
mode critical section code
 Provides memory allocation and de-
allocation functions in blocks and in a fixed
blocks of memory

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 4
Design" , Raj Kamal, Publs.: McGraw-Hill Education
RTOS

 Provides for effectively scheduling and


running and blocking of the tasks in cases
of number of many tasks
 I/O Management with devices, files,
mailboxes, pipes and sockets becomes
simple using an RTOS
 provides for the uses of Semaphore (s) by
the tasks or for the shared resources
(cCritical sections) in a task or OS functions
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 5
Design" , Raj Kamal, Publs.: McGraw-Hill Education
RTOS

 Effective management of the multiple


states of the CPU and, internal and
external physical or virtual devices

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 6
Design" , Raj Kamal, Publs.: McGraw-Hill Education
1. Hard Real Time Design Considerations

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 7
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Hard real time
 Hard real time means strict about adherence
to each task deadline. When an event
occurs, it should be serviced within the
predictable time at all times in a given hard
real time system.
 The preemption period for the hard real
time task in worst case should be very small

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 8
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Hard real time
 A hard RT RTOS is one, which has
predictable performance with no deadline
miss, even in case of sporadic tasks (sudden
bursts of occurrence of events requiring
attention).
 Automobile engine control system and anti
lock brake are the examples of hard real
time systems

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 9
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Hard real time system design
 Disabling of all other interrupts of lower priority
when running the hard real time tasks
 Preemption of higher priority task by lower
priority tasks
 Some critical code in assembly to meet the real
time constraint (deadline) fast
 Task running in kernel space, [This saves the
time required to first check whether access is
outside the memory space allocated to the kernel
functions.]
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 10
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Hard real time system design

 Provision of asynchronous IOs


 Provision of locks or spin locks
 Predictions of interrupt latencies and
context switching latencies of the tasks
 Predictability is achieved by writing all
functions which execute always take the
same predefined time intervals in case of
varying rates of occurrences of the events.

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 11
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Hard real time system design

 Response in all the time slots for the given


events in the system and thus providing
the guaranteed task deadlines even in case
of sporadic and aperiodic tasks.
 Sporadic tasks means tasks executed on
the sudden-bursts of the corresponding
events at high rates, and
 Aperiodic tasks mean task having no
definite period of event occurrence.
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 12
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Hard real time system design

 Response in all the time slots for the given


events in the system and thus providing
the guaranteed task deadlines even in case
of sporadic and aperiodic tasks.
 Sporadic tasks means tasks executed on
the sudden-bursts of the corresponding
events at high rates, and
 Aperiodic tasks mean task having no
definite period of event occurrence.
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 13
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Example of hard real time system

 video transmission, each picture frame and


audio must be transferred at fixed rate

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 14
Design" , Raj Kamal, Publs.: McGraw-Hill Education
2. Soft Real Time Design Considerations

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 15
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Soft real time system

 One in which deadlines are mostly met.


 Soft real time means that only the
precedence and sequence for the task-
operations are defined, interrupt latencies
and context switching latencies are small
but there can be few deviations between
expected latencies of the tasks and observed
time constraints and a few deadline misses
are accepted
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 16
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Soft real time task

 The preemption period for the soft real time


task in worst case may be about a few ms.
 Mobile phone, digital cameras and orchestra
playing robots are examples of soft real
time systems.

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 17
Design" , Raj Kamal, Publs.: McGraw-Hill Education
3. Real Time Operating System based
System design Principles

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 18
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with using Interrupt Service
Threads or Interrupt Service tasks

 Certain RTOSes, for servicing the


interrupts, there are two levels, (i) fast level
ISRs and (ii) slow level ISTs, the priorities
are first for the ISRs, then for the ISTs and
then the task
 Certain RTOSes three levels

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 19
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with using Interrupt Service
Threads
 ISRs post the messages for the ISTs and
do the detailed computations.
 If RTOS is providing for only one level,
then use the tasks as interrupt service
threads

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 20
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design Each Task with an infinite loop
 Each task has a while loop which never
terminates.
 A task waits for an IPC or signal to start.
 The task, which gets the signal or takes the
IPC for which it is waiting, runs from the
point where it was blocked or preempted.
 In preemptive scheduler, the high priority
task can be delayed for some period to let
the low priority task execute

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 21
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design in the form of tasks for the Better
and Predictable Response Time Control
 provide the control over the response time
of the different tasks.
 The different tasks are assigned different
priorities and those tasks which system
needs to execute with faster response are
separated out.

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 22
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Response Time Control

 For example, in mobile phone device there


is need for faster response to the phone call
receiving task then the user key input.
 In digital camera, the task for recording the
image needs faster response than the task
for down loading the image on computer
through USB port

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 23
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design in the form of tasks Modular Design

 System of multiple tasks makes the design


modular.
 The tasks provide modular design

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 24
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design in the form of tasks for Data
Encapsulation
 System of multiple tasks encapsulates the
code and data of one task from the other by
use of global variables in critical sections
getting exclusive access by mutex

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 25
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with taking care of the time spent in
the system calls
 expected time in general depends on the
specific target processor of the embedded
system and the memory access times.
 Some IPCs takes longer than the other

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 26
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with Limited number of tasks

 Limit the number of tasks and select the


appropriate number of tasks to increase
the response time to the tasks, better
control over shared resource and reduced
memory requirement for stacks
 The tasks, which share the data with
number of tasks, can be designed as one
single task.

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 27
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Use appropriate precedence assignment
strategy and Use Preemption
 Use appropriate precedence assignment
strategy and Use Preemption in place of
Time Slicing

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 28
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Avoid Task Deletion

 Create tasks at start-up only and avoid


creating and then deleting tasks later at the
later times.
 Deleting only advantage─ availability of
additional memory space

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 29
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Use CPU idle CPU time for internal
functions
 Read the internal queue.
 Manage the memory.
 Search for a free block of memory.

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 30
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with Memory Allocation and De-
Allocation By the Task
 If memory allocation and de-allocation are done
by the task then the number of functions required
as the RTOS functions is reduced.
 This reduces the interrupt-latency periods. As
execution of these functions takes significant time
by the RTOS whenever the RTOS preempts a
task.
 Further, if fixed sized memory blocks are
allocated, then the predictability of time taken in
memory allocation is there
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 31
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with taking care of the Shared
Resource or Data among the Tasks
 The ISR coding should be as like a reentrant
function or should take care of problems
from the shared resources or data such as
buffer or global variables
 if possible, instead of disabling the
interrupts only the task-switching flag
changes should only be prevented. [It is by
using the semaphore.]

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 32
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Design with limited RTOS functions

 Use an RTOS, which can be configured.


RTOS provides during execution of the
codes enabling the limited RTOS functions.
For example, if queue and pipe functions
are not used during execution, then disable
these during run
 Scalable RTOS
 Hierarchical RTOS

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 33
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Use an RTOS, which provides for creation
of scalable code
 Only the needed functions include in the
executable files, and those functions of
kernel and RTOS not needed do not include
in the executable files

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 34
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Use an RTOS, which is hierarchical

 The needed functions extended and


interfaced with the functionalities
 Configured with specific processor and
devices

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 35
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Encapsulation Using the Semaphores

 Semaphores, queues, and messages should


not be not globally shared variables, and let
each should one be shared between a set of
tasks only and encapsulated from the rest
 A semaphore encapsulates the data during a
critical section or encapsulates a buffer
from reading task or writing into the buffer
by multiple tasks concurrently

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 36
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Encapsulation Using Queues
 A queue can be used to encapsulate the messages
to a task at an instance from the multiple tasks.
 Assume that a display task is posted a menu for
display on a touch screen in a PDA
 Multiple tasks can post the messages into the
queue for display.
 When one task is posting the messages and these
messages are displayed, another task should be
blocked from posting the messages.
 We can write a task, which takes the input
messages from other tasks and posts these
messages to the display task only after querying
whether the queue is empty
Chapter-10 L11: "Embedded Systems - Architecture, Programming and
2015 37
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Summary

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 38
Design" , Raj Kamal, Publs.: McGraw-Hill Education
We learnt
• There are certain design principles observed
when using the RTOS

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 39
Design" , Raj Kamal, Publs.: McGraw-Hill Education
End of Lesson 12 of Chapter 8

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 40
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Summary

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 41
Design" , Raj Kamal, Publs.: McGraw-Hill Education
We learnt
• Soft real time systems can accept few
deadline misses and
• Hard real time systems adhere to the
predicted latencies, deadlines and time
constraints of the processes

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 42
Design" , Raj Kamal, Publs.: McGraw-Hill Education
End of Lesson 13 of Chapter 8

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 43
Design" , Raj Kamal, Publs.: McGraw-Hill Education
Summary

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 44
Design" , Raj Kamal, Publs.: McGraw-Hill Education
We learnt
• RTOS is an OS for effective real time
scheduling of the concurrent processes
• User priority allocations
• Preemptive scheduling
• Fixed memory blocks allocation and de-
allocation
• IPCs

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 45
Design" , Raj Kamal, Publs.: McGraw-Hill Education
End of Lesson 11 of Chapter 10

Chapter-10 L11: "Embedded Systems - Architecture, Programming and


2015 46
Design" , Raj Kamal, Publs.: McGraw-Hill Education

You might also like