Introduction To Embedded Systems: Melaku M
Introduction To Embedded Systems: Melaku M
Introduction To Embedded Systems: Melaku M
EMBEDDED SYSTEMS
By Melaku M.
Definition
sonar - A device that uses hydrophones (in the same manner as radar) to locate
objects underwater.
Typical Embedded Systems
Single-functioned
Executes a single program, repeatedly
Tightly-constrained
Low cost, low power, small, fast, etc.
11
Design Metrics
• Common metrics
• Unit cost: the monetary cost of manufacturing
each copy of the system, excluding NRE cost
• NRE cost (Non-Recurring Engineering
cost): The one-time monetary cost of designing
the system
• Size: the physical space required by the system
• Performance: the execution time or
throughput of the system
• Power: the amount of power consumed by the
system
Cont…d
• Time-to-prototype: the time needed to
build a working version of the system
• Time-to-market: the time required to
develop a system to the point that it can be
released and sold to customers
• Maintainability: the ability to modify the
system after its initial release
• Correctness, safety, many more
Input and output technology
Examples of sensor
Photo-voltaic sensor
Temperature sensor
Pressure sensor
Actuators
Examples of actuators
Motors
Heaters
Hydraulic and pneumatic actuators
Processors
Microprocessors and Micro-Controller
Key requirement:
Energy Efficiency
Data Bus
CPU
General I/O Serial
purpose RAM ROM Timer
Port port
Micropro
cessor
Address Bus
Microcontroller
Programmable
Re-programmable
Single purpose
Microcontroller architecture
PIC16F877A
INTERFACING
Interfacing is nothing but connecting an
Data Memory
Program Memory
14 bits.
Program memory space divided
into 4 pages of 2k each.
Memory Map
29
Stack
30
& Control
cont…d
37
a context switch.
Interrupt Assignment
45
Use PIC16F877A
Simulate it.
What language to use?
In the process of making a better embedded
Readability
Multiline Comments . . . . . Denoted using /*……*/
Single Line Comments . . . . . Denoted using //
Preprocessor Directives . . . . . #include<…> or #define
Global Variables . . . . . Accessible anywhere in the program
Function Declarations . . . . . Declaring Function
Main Function . . . . . Main Function, execution begins here
{
Local Variables . . . . . Variables confined to main function
Function Calls . . . . . Calling other Functions
Infinite Loop . . . . . Like while(1) or for(;;)
Statements . . . . .
….
}
Function Definitions . . . . . Defining the Functions
{
Local Variables . . . . . Local Variables confined to this Function
Statements . . . . .
….….
}
Configuring PIC16F877A
Pin declaration:
TRISB.B6=1/0;
PORTB.B6 = 1/0;
54
Real-Time Operating
System
Why we have OS in an embedded
device 55
Support for
• Multitasking, scheduling, & synchronization
• Timing aspects
• Memory management
• File system
• Networking
• Interfacing wide range of I/O devices
• Security and power management
Introduction
56
Application Program
Hardware
INTERMEDIATE
HARDWARE
Introduction
58
Time-Sharing Systems
Distributed System
Batch Processing System
60
BATCH
MONITOR JOB 1 JOB 2 ... JOB N
Start End
Job under of of
execution Batch Batch
Disadvantage
61
Dispatch
READY RUNNING
Admit Time Out Release
Event
NEW Occurs Event EXIT
Wait
BLOCKED
No Priority
Round robin fashion
Time slice
Advantage
64
in nature.
Characteristics of Subtasks
66
event
Real-Time Operating System
67
T1
T2
T3
0 2 4 6 8 10 12 14 16 18 20 22 24
Built-In Hardware Feature to
support RTOS
70
Programmable Timer
• Generate timing signal
Register Banks
72
Real-time Task
Definition
73
Start time
ai si fi t
Finishing time
Definition
74
dispatching Termination
activation
READY RUNNING
Preemption
Ready Queue
77
ri si fi di t
Periodic
• Periodic tasks repeats after a certain fixed
time interval
Sporadic
• Sporadic tasks recurs at random instant
Aperiodic
• Same as sporadic except that minimum
separation b/n two instant can be 0.
Activation modes
83
Scheduling Polices
Tasks (Recap.)
86
#1 #2
Clock- Even
Driven Driven
Clock-driven scheduling
89
Popular Examples
• Table-driven scheduler
• Cyclic scheduler
Also called offline scheduler and
or more frames
Major Cyclic
98
Scheduling points:
• Defined by task completion & event arrival
Preemptive Scheduler
• On arrival of higher priority task, the
running task may be preempted.
These are greedy schedulers:
• Never keep the processor idle if a task is
ready.
Event-Driven Static Schedulers
104
by the programmer
• Do not change during runtime.
• RMA (Rate Monotonic Algorithm) is the
optimal static priority scheduling algorithm.
Event-Driven Dynamic Schedulers
105
Algorithm
• Each time a new ready task arrives:
• It is inserted in to a queue of ready tasks,
sorted by their deadlines.
• If a newly arrived task is inserted at the
head of the queue, the currently executing
task is pre-empted.
Earliest Deadline First (EDF)
107
Scheduling is complex
• Processes to be sorted according to deadline
at each scheduling instant.
• Sorted list maintained as a heap.
• Each update requires O(log n).
Example
108
T1
T2
T3
0 2 4 6 8 10 12 14 16 18 20 22 24
Accumulated Utilization
109
n
ci
Accumulated Utilization:
i 1 pi
of the laxity
Laxity = relative deadline – time
T1
T2
T3
0 2 4 6 8 10 12 14 16 18 20 22 24
l(T1)=33-4-6=23 l(T1)=33-5-6=22 l(T1)=33-15-6=10
l(T2)=28-4-3=21 l(T2)=28-5-2=21 l(T2)=28-15-2=9
l(T3)=29-5-10=14
Rate monotonic (RM) Scheduling
120
Assumption:
• All tasks have hard deadlines are periodic
• All tasks are independent
• di = pi for all tasks
• ci is constant and known for all tasks
• The time required for context switching is
negligible
Rate monotonic (RM) Scheduling
122
Scheduling policy
• The priority of a task is a monotically
decreasing function of its period.
The higher the frequency (or lower the period)
Priority
Frequency
Rate monotonic (RMA) Scheduling
124
Missing computation
scheduled in the next
Missed period
deadline
T1
T2
0 2 4 6 8 10 12 14 16 18 20 t
RMA Schedulability(utilization
bound) 126
1971)
u i
n 2 1n
1
using RMA
T1: e1 = 1, p1 = 4, d1 = 4
T2: e2 = 2, p2 = 6, d2 = 6
T3: e3 = 3, p3 = 20, d3 = 20
Solution
129
3
ei 1 1 3 11
i 1 pi
ui 1
4 3 20 15
n 21 n 1 3 21 3 1 0.778
11
ui 15 0.733 0.778
Therefore, the task set is schedulable
Completion Time Theorem
(Liu & Lehoczky)
130
task:
• Occurs when it is in phase with its higher
priority task
Completion Time Theorem: Basic
premise
132
T1 = 10, 30, Ф = 0
T1 is in phase with T2 T2 = 60, 120, Ф = 0
T1 T2 T1 T2 T1 T2
10 30 40 60 70 90
T1 = 10, 30, Ф = 20
T1 has 20ms phase lag with T2 T2 = 60, 120, Ф = 0
T2 T1 T2 T1 T2
20 30 50 60 80
Completion Time Theorem
(Liu & Lehoczky)
133
i 1
p
e i e p
i j 1 p j j i
where pi is the period of Ti and
p1 ≤ p 2 ≤ p3 . . . ≤ pn
Example
134
using RMA
using RMA
Searching O(n)
Searching O(1)
Deadline Monotonic
Algorithm(DMA)137
different
• RMA is not an optimal scheduling algorithm
• DMA is optimal for such tasks
Assign priority based of task
deadline
RMA will always fails if DMA fails.
Overhead due to context
switching 138
running task
2) When it completes
Overhead due to context
switching139
schedulable
Self Suspension
142
Self-suspension introduces an
additional scheduling point.
• The OS removes the self-suspended task
from the queue and places it in the blocked
queue.
• The OS then dispatches the next eligible
task.
Self Suspension
144
i 1
p
e bt i e p
i i
j 1 p j
j
i
i 1
bti bi mine j , b j
j 1
schedulable
For T3: 50 + (3 + 3 + 6) +10*4 + 25*2 =
T1
T2
EDF
T1
T2
0 2 4 6 8 10 12 14 16 18 20 t
Slack Stealing-to improve average
response time
149