Title: IT-606 Embedded Systems (Software)
1IT-606Embedded Systems(Software)
- S. Ramesh
- Kavi Arya
- Krithi Ramamritham
- KReSIT/ IIT Bombay
2Esterel Basic Features and Constructs S.
Ramesh
3Layered OrganizationConventional View
Application Tasks
Scheduling, IP Communication
OS
I/O Handlers
Hardware
4Layered OrganizationEsterel View
Esterel Program Data Handler
Esterel Application
I/O Handlers
Bare Machine
5Layer Interaction
6An Esterel program
- Describes the behavior of the reactive kernel
- Has rich set of constructs for programming the
kernel - Kernel is typically finite state
- Interacts with its environment through an
abstract interface - Signals and Sensors are the means of
communication - Input, Output and Local signals
- Sensors are inputs only
7An Esterel program (contd.)
- Has minimal data processing functions
- Uses the data handling part for major data
processing - Functions and Tasks are the means of
communication. - Global and Local variables are used for
communication - Host language support - C,C, Ada
8Signals and sensors
- Signals are the novel means of communication
- idea from hardware systems
- software abstractions of the interface
- Signals can be pure or valued
- pure signals have two status 'presence' or
'absence - valued signals when present carry values
- values are typed, like integer, boolean,
string,float - Signals are transient! - reset at the end of a
reaction
9Signals and sensors
- environment communicates by setting input signals
- program communicates back via output signals
- local signals are used for communication between
concurrent modules - has a no. of constructs for handling signals
- emit S, await S, present S then
- tick is a special signal always present
- sensors are special signals used as input only
10Variables and Expressions
- Esterel is an imperative language and hence uses
variables - variables can store different types of values
- integer, boolean, string, float
- variables retain values until updated (across
reactions) - variables can be local to a block of statements,
a procedure or function or global - no sharing of variables with the environment
11Variables and Expressions
- No sharing of variables between concurrent
threads - Variables are means of communication along a
single sequential thread - The 'race problem' is absent!
- Expressions can be formed out of variables
12Types and Functions
- Esterel is meant for controller applications
- Has minimal number of types
- Integer, boolean, float and string
- All other types used should be defined in the
host language - Functions and Procedures called during execution
13Functions and Procedures
- Their type specifications given in the program
- their definition is written in the host language
- value and reference parameters (like Pascal)
14Modules
- Basic programming unit
- Declarations
- types, variables, functions and procedures
(Pascal syntax) - input and output signals
- relation constraints
- Body of a module
- the statement executed
- sequential and concurrent flow of control
- preemption and exceptions
15Declaration
- module TIMER
- declaration
- type TIME
- var t0integer
- procedure dec(TIME)()
- function zorn()(TIME)boolean
- input SECOND, SET(TIME), RESET
- output ALARM
- relation SECOND RESET
16Modules
- loop abort await SET(t) trap T in
loop if zorn(t) then exit T
else nothing
await SECOND call dec(t)
end end emit ALARM
when RESET - end
- end module.
17Execution Model
- execution is a series of reactions
- invoked from an external 'main' program
repeatedly at discrete points of time - one reaction per invocation
- control returns after each reaction
18Reaction
- Considered instantaneous!
- Control flows from one statement to its next
- Concurrent control flows
- Input signals do not change in status nor in
their values. - Output and local signals may change
- Signal presence tested and variables updated
- Reaction proceeds until pause is encountered
19Reaction
- Reaction stops when pause is encountered in all
active threads - Next reaction starts from the next statement
- Status and values of input signals are reset at
the end of reaction - New values are set by the environment
20Statements
- Rich set of high level constructs
- Basic Statements
- Derived Statements
- Basic statements
- Nothing
- does nothing, terminates instantaneously
- Pause
- special control statement
- stops the current reaction
- does not terminate in the current reaction
- terminates in the next reaction
21Basic Statements
- xexpr
- classical assignment statement
- terminates instantaneously
- emit S
- terminates instantaneously generating a pure
signal S
22Basic Statements (contd.)
- emit S(exp)
- evaluate exp' and emit S with the expression
value - sustain S
- sustains the signal S, i.e. emits the signal in
each instant
23Classical control structures
- stat1 stat2
- when stat1 terminates stat2 start instantaneously
- if expr then stat1 else stat2
- evaluation of the expression and the execution of
the branch done in the same instance
24Classical control structures (contd.)
- call A(arg1)(arg2)
- procedure call statement
- transfer of control to the procedure, execution
of the body and the return all done
instantaneously! - var x in stat
- block statement
- x is local in this block
25Loop statement
- loop stat end
- repeated execution of stat
- when stat terminates it is restarted
- stat should not terminate instantaneously
- one or more pause should be there
- Consider
- loop pause end
- What is the behavior of this?
- halt is a derived statement that stands for this
26Signal testing
- present S then stat1 else stat2
- Similar to conditional statement
- tests the presence of a signal at the current
reaction - testing, branching and executing are
instantaneous - one of the branches could be absent
27Synchronous Parallelism
- stat1 stat2 stat3
- simultaneous (not concurrent) execution of all
the statements - signals are used for communication
- signal emitted by one thread is broadcast to all
other threads - terminates when every stati terminates
- no sharing of variables
- compare with asynchronous parallelism
28Synchronous Parallelism
- Example
- emit S
- present S then emit O1 else emit O2
-
- present S then emit O3 else emit O4
-
- What is the behaviour of this program?
29Preemption Statements
- Strong abort primitive - watchdog
- abort
- stat
- when S
- The body stat is executed only when S is not
present - Presence of S instantaneously kills the body
- No statement in stat is executed when S is
present - terminates either when either stat terminates or
when S is present
30Example
abort pause emit S1 pause
emit S2 when S
- emits S1 in the second instant and S2 in third
instant if S is not present during these
instants. - if S is present in second instant then nothing
happens the whole statement exits.
31Example
- if S is not present in the second instant but
present in third instant then - S1 is emitted in the second instant, terminates
in the third instant no S2 is emitted in the
third instant - S in the first instant is ignored
- S in the first instant is not ignored if you
write - abort stat when immediate S
32Await statements
Consider abort halt when
S This can be abbreviated as await S
- await tick
- waits for the special signal tick
- tick is present in every instant
- equivalent to pause
33A generalized await statement
- awaitcase S1 do stat1case S2 do stat2case S3
do stat3 - end
- waits for one of the signals to be present
- selects one of stati for execution
- selects stati only if Si is present
- selection is deterministic
34Nesting of aborts
Consider abort abort
stat1 when S1 stat2
when S2
- when S1 is present, stat1 is killed and stat2 is
started - when S2 is present, what happens?
- when both S1,S2 are present, the outer abort
statement is exited
35Weak Abort
weak abort stat when S
- A weaker form of watchdog
- The strong abort statement prevented the
execution of body in the instant when it was
aborted - many time the body would like to write the last
will at the time of aborting-some book keeping
activity - weak abort statement allows computation of the
body at the instant of aborting
36Example
- weak abort
- pause
- emit S1
- pause
- emit S2
- when S
- What is the difference?Â
- Weak abort statements can be nested.Â
- weak and strong statements can be nested
37Traps and exits
- trap T in
- stat1
- handle T do
- stat2
- end trap
- Another weak preemption primitive
- The body stat1 may contain exit statement
- exit T
38Traps and exits
- execution starts with execution of stat1Â
- when exit T is encountered the control jumps to
the handle statement - handle statement is optional - control then
returns to the statement following the trap
statement - if stat1 is terminated then the whole trap
statement is exited - stat2 is not executed
39Traps and exits (contd.)
- Concurrent traps
- trap T,U,V in
- stat1
- handle T do
- stat2
- handle U do
- stat3
- handle V do
- stat4
- end trap
40Traps and exits (contd.)
- Nested traps
- Â trap T in
- trap U in
- stat1
- handle U do
- stat2
- end trap U
- stat3
- handle T do
- stat4
- end trap T
41Process Suspension
- Abort statements are like ctrl-C of Unix
- Suspension inspired by ctrl-Z
- suspend
- stat
- when S
- behaves like stat so long as S is not present if
stat terminates then the whole terminates
42Process Suspension (contd.)
- stat is not executed in the instants when S is
present - execution is resumed at the suspended point,
when S is present - S in the first instant is ignored use immediate
S to avoid this
43Local Signal Declarations
- signal S in
- stat
- end signal
- signal S is local in stat
- stat does not react to any external S
- S emitted in stat not visible outside
44Module Instantiation
- A program is a collection of modules
- Any module can be main module, defined by the
user at the time of compilation - modules can be instantiated in other modules
- module instantiation is a macro expansion
45Module Instantiation (contd.)
-
- run M
- is the simplest instantiation.
- during compilation, this statement is replaced by
the body - all signal declarations discarded
- data declarations exported to the parent module
46A More General Instantiation
- run MX1/Y1, X2/Y2, . . . , Xn/Yn
- X/Y means that X renames Y'
- X can be a type, constant, function
- X can be a variable or a signal
- X should be declared in the module