Академический Документы
Профессиональный Документы
Культура Документы
3 Unit Course, Spring 2002 EECS Department, UC Berkeley Chapter 1: RTOS Concepts
Christoph Kirsch www.eecs.berkeley.edu/~fresco/giotto/course-2002
Embedded Programming
Software
2002 C. Kirsch -2-
Environment Processes
Software Processes
Software
2002 C. Kirsch -3-
Software
2002 C. Kirsch -4-
Software
2002 C. Kirsch -5-
Software
2002 C. Kirsch -6-
Software
2002 C. Kirsch -7-
Real-Time Scheduler
Software
2002 C. Kirsch -8-
t1
t2
t1
t3
t2
t1
Software
2002 C. Kirsch -10-
Coroutine/MMU
Behavioral Function
Coroutine
Triggered Function
Subroutine
Function
Stack/List
Memory Model
Environment Ports
actuates
Software Ports
2002 C. Kirsch -12-
Definition: Task
A task is a function from its input and state ports to its output and state ports A task runs to completion (cannot be killed) A task is preemptable A task does not use signals (except at completion) A task does not use semaphores (as a consequence) API (used by the RTOS): initialize {task: state ports} schedule {task} dispatch {task: function}
2002 C. Kirsch -13-
t1
t2
Task t2
2002 C. Kirsch -15-
t1
t2
Task t2
2002 C. Kirsch -16-
Definition: Trigger
A trigger is a predicate on environment, software, driver ports A trigger awaits events and/or signals A trigger is enabled if its predicate evaluates to true Trigger evaluation is atomic (non-preemptable) A trigger can be activated by the RTOS A trigger can be cancelled by the RTOS A trigger can be enabled by an event or a signal API (used by the RTOS): activate {trigger} cancel {trigger} evaluate {trigger: predicate}
2002 C. Kirsch -18-
My First RTOS
tasks t: initialize(t); triggers g: activate(g); while (true) { if active-trigger g: evaluate(g) == true then execute(); } execute() { scheduled-tasks := triggered-tasks t: schedule(t); scheduled-tasks t: dispatch(t); }
Software
2002 C. Kirsch -20-
Software
2002 C. Kirsch -21-
Definition: Thread
A thread is a behavioral function (with a trace semantics) A thread may be killed A thread is preemptable A thread may use signals A thread may use semaphores API (used by the RTOS or threads): initialize {thread: ports} schedule {thread} dispatch {thread: function} kill {thread}
2002 C. Kirsch -24-
t1 Kill t1 t2
Task t2
2002 C. Kirsch -26-
Signal API
A signal can be awaited by a thread A signal can be emitted by a thread Signal emission is atomic (non-preemptable) API (used by threads): wait {signal} emit {signal} Literature: emit: send(signal)
Definition: Semaphore
A semaphore consists of a signal and a port A semaphore can be locked by a thread A semaphore can be released by a thread Semaphore access is atomic (non-preemptable) API (used by threads): lock {semaphore} release {semaphore} Literature: lock: P(semaphore) release: V(semaphore)
2002 C. Kirsch -28-
must be atomic
Events react(): The Embedded Machine execute(): The Scheduler and Dispatcher Tasks
Software
2002 C. Kirsch -31-
Proposal
Environment
Human: Programming in terms of environment time Compiler: Implementation in terms of platform time
Software
2002 C. Kirsch -32-
Programming as if there is enough platform time Implementation checks whether there is enough of it
Software
2002 C. Kirsch -33-
Portability
Environment
Software
2002 C. Kirsch -34-
Predictability
Environment
Software
2002 C. Kirsch -35-
sense
actuate
start
end
Software
2002 C. Kirsch -36-
Preemptable
Environment
sense
actuate
start
end
Software
2002 C. Kirsch -37-
but Atomic
Environment
f(
1
1)
=
2
Software
2002 C. Kirsch -38-
Software
2002 C. Kirsch -39-
Non-preemptable, Synchronous
Environment
f(
)=
1 1 2
f(
)=
Software
2002 C. Kirsch -40-
Syntax
Environment
2
a
Software
2002 C. Kirsch -41-
A Trigger g
g g : c c
b: Program
b:
call(a) call(s)
2
schedule(t) future(g,b)
a
2
a
Software
2002 C. Kirsch -43-
b:
call(a) call(s)
2
schedule(t) future(g,b)
a
2
a
Software
2002 C. Kirsch -44-
c
b:
g
e
c:
INACTIVE schedules
RUN
READY
Environment-triggered Code
Environment
Software
2002 C. Kirsch -46-
Software-triggered Code
Environment
Software
2002 C. Kirsch -47-
b:
Time Safety
Environment
Software
2002 C. Kirsch -49-
2 1
2 1
Software
2002 C. Kirsch -50-
Environment-deterministic If Environment-triggered
Environment
2 1
a
2 1
a
2 1
a
Software
2002 C. Kirsch -51-
10 g g : c = c + 5 Control
i a
Actuator
5
Sensor
s
Navigation
mode Flight ( ) period 10ms { actfreq 1 do Servo ( actuating ) ; taskfreq 1 do Control ( input ) ; taskfreq 2 do Navigation ( sensing ) ; }
Environment Timeline
0ms 5ms 10ms
i Control
s Navigation
Block of synchronous code (nonpreemptable)
s Navigation
Scheduled tasks (preemptable)
E Code
0ms 5ms 10ms
i Control
b1:
s Navigation
E Code
0ms 5ms 10ms
b2:
s Navigation
s Navigation
Navigation Control
2ms 3ms
2ms 5ms
2002 C. Kirsch -59-
Time Safety
Environment
2
a
Software
2002 C. Kirsch -60-
Runtime Exceptions I
Environment
2
a
call(a_ctuating)
Software
2002 C. Kirsch -61-
Runtime Exceptions II
Environment
call(s_ensing)
2
a
Software
2002 C. Kirsch -62-
schedule(t)
2
a
Software
2002 C. Kirsch -63-
An Exception Handler e
Environment
b:
call(a) call(s)
schedule(t,e)
1 2
a
e:
a
call(a)
schedule(t) future(g,b)
Software
2002 C. Kirsch -64-
Navigation Control
2ms 4ms
2002 C. Kirsch -65-
terminate(t)
1 2
a
Software
2002 C. Kirsch -66-
2
a
Software
2002 C. Kirsch -67-
Dynamic Linking
E Machine
E Code
b: call(a) call(s) schedule(t) future(g,b)
Functionality Code t g
d
HeliCtr
HeliNet
HeliNav
t+5ms t+5ms
t+7ms
t+10ms t+10ms
HeliNav
t+5ms t+5ms
t+7ms
t+10ms t+10ms
Instructions
Scheduled Task:
schedule(t)
Triggering:
g
g : c c
b:
future(g,b)