You are on page 1of 22

Real-Time and Embedded

Systems

Nam Ho
Dr. Anh-Vu Dinh-Duc
Module Outline

 Introduction to Real-Time Systems


 Real-Time Task Scheduling
 Real-Time Operating Systems (RTOS)
 Measuring Execution Time and Real-Time
Performance
 Development of Embedded Systems
 Our Research Results in Embedded
Systems
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 2
What is a Real-Time
Operating Systems (RTOS)?
 OS provides
 Task management (scheduling, communication, synchronization)
 Hardware abstract (device drivers)
 Resource allocation (memory management)
 Time control
 Error control
 …
 RTOS
 Provides some basic functionalities like regular OS
 But, involves real-time task scheduling
 The need for "deterministic" timing behavior
 A ideal platform for developing applications that require precise
timing (time bonded)
 Allows the designer to manage both soft and/or hard real time
requirements
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 3
Components in RTOS

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 4


RTOS supports Multitasking
Memory Map

FLASH

TASK1’s TASK2’s
Segments Segments

Code Code
Data kernel system call Data
Stack Stack
SRAM
Heap Heap
Shared Data Shared Data
Shared Code Shared Code

kernel

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 5


RTOS supports Multitasking
 Task uses Task Control
Block (TCB) to remember its
context
 Task ID
 Task Name
 Status
 Priority (if part of a preemptive
scheduling plan)
 Task Stack
 Task Program Counter
 …
 RTOS updates TCB when
task is switched
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 6
RTOS supports Multitasking
Stack Stack

TASK 1 TASK n

TCB TCB
Task_Rountine() Task_Rountine()
status {
status {
while(1)
pc while(1) pc
{ {

sp ….. sp …..

} }
priority priority }
}

Memory … … …

CPU
sp
Context
pc

CPU register
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 7
Task Context Switch

Affect the schedulability test

The entire task set is feasible by RMS if and only if


( e j 2. )
L max{1 i n} min{t S } j 1 i . t / pj 1,
i t
where Si {k . p j | j 1, ..., i; k 1, ..., p / p }
i j

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 8


Non – preemptive RTOS
 Higher priority
tasks only gain
control of the CPU
when the current
tasks gives up
control of the CPU
 Most important
drawback is low
responsiveness

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 9


Preemptive RTOS
 Used when system
responsiveness is
important
 The highest priority task
ready to run is always
given control of the
CPU. The lower priority
task is suspended
 Most commercial real-
time kernels are
preemptive

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 10


Task State – Clock-Driven
Based

k Task Start time


(T(tk)) (tk)
0 T1 1
1 T2 2
2 T1 4
3 I 5
4 T2 6
5 T1 7
6 T2 8
9 I 9
10 T1 10
11 T2 11
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 11
Task State – Event-Driven
Based

 Blocked state: The task is waiting for an event to occur.


 A semaphore/mutex token for which a task is waiting is released
 An Arriving message from message queue
 A time delay imposed on the task expires

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 12


Scheduler Implementation
pre-computed schedule
 Table-driven scheduler k Task Start time
(T(tk)) (tk)
Input: stored schedule (tk, T(tk)) for k = 0, 1, n – 1.
Task SCHEDULER: 0 T1 1
set the next scheduling point i = 0 and table entry k = 0; 1 T2 2
set the timer to expire at tk; 2 T1 4
do forever: 3 I 5
accept timer interrupt;
4 T2 6
if an aperiodic task is executing, preempt the task;
current task T = T(tk); 5 T1 7
increment i by 1; Idle 6 T2 8

Timer compute the next table entry k = i mod n; 9 I 9


set the timer to expire at [i / n] * M + tk;
interrupt if the current task T is I,
10 T1 10
11 T2 11
let the task at the head of the aperiodic queue
execute;
else
let the task T execute;
sleep;
end do.
End SCHEDULER.
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 13
Scheduler Implementation

 Cyclic Scheduler ?
 The concept implementation is the same
as table-driven scheduler„s
 Priority-Based Scheduler ?
 Complex
 Using several queues or link lists in each
of task states
 Case study: cOS-II
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 14
Scheduler Implementation –
Priority Scheduler

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 15


Inter-Task Communication and
Synchronization
 Semaphore
 Controls access to a
shared resource
 Signal the occurrence of
an event
 Allows two tasks to
synchronize their
activities
 Mutex
 Event
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 16
Inter-Task Communication and
Synchronization
 Message Queue
 A message queue is
used to send one or
more messages to a
task
 Reader gets
message in FIFO or
LIFO order
 Mailbox
 Pipe
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 17
Interrupt Timing Issues
 Interrupt
 An interrupt is a hardware mechanism used to inform the
CPU that an asynchronous event has occurred.
 ISR involve in disabling interrupts and enabling interrupts.
In a real-time environment, interrupts should be disabled
as little as possible
 Interrupt Latency
 Maximum amount of time interrupts are disabled + time to
start executing the first instruction in the ISR
 Lower latency is desired
 Interrupt Response
 Interrupt Recovery
 ISR Processing Time
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 18
Interrupt Timing Issues

8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 19


Timer Services
 In developing real-time applications, clearly it is desirable to have
facilities to “set” and “get” the time
 Time services are among some of the basic facilities provided to
programmers by every RTOS
 Embedded processors are usually equipped with a timer circuit (on-
chip timer)
 RTOS maintains a number of “ticks” or system clocks based on the
interrupt received from hardware timers
 The finer the resolution of the clock, the more frequent need to be the
time service interrupts and larger is the amount of processor time the
kernel spends in responding to these interrupts (low performance)
 Timer services supported by cOS-II
 OSTimeDly()
 OSTimeDlyHMSM()
 OSTimeDlyResume()
 OSTimeGet()
 OSTimeSet()
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 20
Requirement for a good RTOS

 Short Interrupt Latency


 Fast Context Switch
 Proper scheduling
 Fine granularity Timer Services
 Rich set of Inter-Task Communication
Mechanism
 Small size (Footprint)
 …
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 21
Reference
 Qing Li and Carolyn Yao, Real-Time Concepts for
Embedded Systems, CMP Books, 2003
 http://nptel.iitm.ac.in/courses/Webcourse-
contents/IIT%20Kharagpur/Embedded%20systems/
New_index1.html
 http://csperkins.org/teaching/rtes/
 Phillip A. Laplante, Real-Time System Design and
Analysis An Engineers Handbook, John Wiley &
Sons, Inc., Third Edition, 2004
 Jean Labrosse, μC/OS, The Real-Time Kernel,
Newnes Publisher, Second Edition
8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 22

You might also like