lecture 2 finite automata & synccharts - uni … 2 finite automata & synccharts daniel...
TRANSCRIPT
Embedded Systems Development
Lecture 2Finite Automata & SyncCharts
Daniel KästnerAbsInt Angewandte Informatik GmbH
2
Some things I forgot to mention
Remember the HISPOS registration until 01.12.(Bachelor/Master CS+CuK).
My email address: [email protected]
Office in Science Park 1, AbsInt GmbH: 3rd floor, room 339 (with appointment).
3
Today
Finite State Automata (FSA)DefinitionDeterministic vs. non-deterministic FSADFA minimizationMealy/Moore automata
SyncCharts
4
Model-based Software Development
Lustre programs
Esterel programs
Esterel SCADE- SCADE language- SyncCharts
C Code
Binary Code
aiT WCET Analyzer- Timing Validation
SymTA/S- System-level Schedulability Analysis
CompilerGenerator
Compiler
5
Model-based Software Development
Esterel SCADE- SCADE language- SyncCharts
SyncCharts as Enhancement to FSA
6
Model-based Software Development
Esterel SCADE- SCADE language- SyncCharts
Lustre programs
Esterel programs C CodeGenerator Compiler
Compiler
Automata Minimization
7
Embedded Systems
Typically, embedded systems are reactive systems:
„A reactive system is one which is in continual interaction with is environment and executes at a pace determined by that environment“ [Bergé, 1995]
Behavior depends on input and current state.
automata model appropriate
8
Finite Automata
9
Finite Automata
Non-deterministic finite automaton (NFA):M = (Σ, Q, ∆, q0, F) where
Σ: finite alphabetQ: finite set of statesq0 ∈ Q: initial stateF ⊆ Q: final states
M is called a deterministic finite automaton, if ∆ is a partial function
QQ ×∪Σ×⊆∆ }){( ε
QQ →Σ×:δ
10
Simple State Transition DiagramUsed to represent a finite automatonNodes: statesq0 has special entry markFinal states are doubly circledAn edge from p to q is labelled by a ifExample: integer and real constants:
∆∈),,( qap
11
Language Accepted by an AutomatonM = (Σ, Q, ∆, q0, F)For q ∈ Q, w ∈ Σ*: (q,w) is a configuration.Binary step relation |− on configurations:
Reflexive transitive closure of is denoted byLanguage accepted by M:
QQpaqwpawq M →Σ×∆∈− :),,( iff ),(|),(
M−|*| M−
)},(|),(:||{)( *0
* εfMf qwqFqwwML −∈∃Σ∈=
12
Regular Languages / ExpressionsLet Σ be an alphabet. The regular languages are definedinductively over Σ by:
∅, {ε} are regular languages over ΣForall a ∈ Σ, {a} is a regular languageIf R1 and R2 are regular languages over Σ, then also R1∪R2, R1R2, R1
*.
Regular expressions over Σ are defined by:∅ is a regular expression and describes the language ∅ε is a regular expression and describes the language {ε}a (for a ∈ Σ) is a regular expression and denotes {a}(r1|r2) is a regular expression over Σ and denotes R1∪R2
(r1r2) is a regular expression over Σ and denotes R1R2
(r1)* is a regular expression over Σ and denotes R1*.
13
Regular Expressions and FAFor every regular language R, there exists an NFA M, such thatL(M)=R.Constructive Proof (Subset Construction):
A regular language is defined by a regular expression rConstruct an NFA with one final state, qf and the transition
Decompose r and develop the NFA according to thefollowing rules ->until only transitionsunder single charactersand ε remain.
14
Example: a(a|0)*
q0 q1 q2 q3 pa
a
0
εε
εε>
15
Nondeterminism
Sources of nondeterminism:
– many transitions may be possible under the samecharacter in a given state
– ε-moves (next character is not read) may compete withnon- ε-moves
1|}),,(|{| ≤∆∈′′ qaqq
DFA:– No ε-transition– At most one transition from every state under a given
character, ie for every q ∈ Q, a ∈ Σ:
16
NFA -> DFALet M=(Σ, Q, ∆, q0, F) be an NFA and let q ∈ Q. Theset of ε successor states of q, ε-SS, is
or the set of all states p, including q, for which thereexists an ε path from q to p in the transition diagramfor M. We extend ε-SS to sets of states S ⊆ Q:
)},(|),(|{)(- * εεε pqpqSS M−=
USq
qSSSSS∈
= )(-)(- εε
17
NFA -> DFA
If a language L is accepted by a NFA then there is also a DFAaccepting L.Let M=(Σ, Q, ∆, q0, F) be an NFA. The DFA associated with M, M'=(Σ, Q', δ, q0', F') is defined by:
Q' ⊆ P(Q)q0' = ε-SS(q0)
Thus, the successor state S under a character a in M' is obtainedby combining the sucessor states of all states q ∈ S under a and adding the ε sucessor states.
}|{' ∅≠∩⊆= FSQSFΣ∈∈∆∈−= aSqpaqpSSaS for })for ),,(|({),( εδ
18
Algorithm NFA->DFA
q'0:= ε-SS(q0); Q':={q0'};
marked(q0'):=false; δ :=∅;
while ∃ S∈Q' and marked(S)=false domarked(S):=true;
foreach a∈Σ do
T:= ε-SS({p∈Q| (q,a,p) ∈ ∆ and q ∈S});if T∉Q'
Q':=Q' ∪ {T}; // new statemarked(T):=false
δ := δ ∪ {(S,a)→T}; // new transition
19
Example: a(a|0)*
q1 q2 q3 q4 pa
a
0
εε
εε
0' 1' 2'a
a
0
a
0
∅a
0
0
20
DFA Minimization
After NFA->DFA the DFA need not have minimal size, ie minimal number of states and transitions.p and q are undistinguishable, iff for all words w both(q,w) and (p,w) lead by into either F' or Q'-F'.Undistinguishable states can be merged.
*| M−
21
DFA MinimizationInput: DFA M=(Σ, Q, δ, q0, F)Output: DFA Mmin=(Σ, Qmin, δmin, q0min, Fmin) with L(M)=L(Mmin) and Qmin minimal.Iteratively refine a partition of the set of states where each set S in the partition consists of states so far undistinguishableStart with the partition Π={F, Q-F}Refine the current Π by splitting sets S∈Π into S1, S2 if thereexist q1, q2 ∈ S such that
δ(q1,a) ∈ S1
δ(q2,a) ∈ S2
S1 ≠ S2
Merge sets of undistinguishable states into a single state.
22
Algorithm minDFAΠ := {F, Q-F}do changed := false
Π':= Π;foreach K in Π do
if n > 1 then changed := true fiΠ:= Π';
until not changed;Qmin= Π - (Dead ∪ Unreachable);
q0min Class of Π containing q0
Fmin Classes containing an element of Fδmin(K,a)=K' if δ(q,a)=p with a∈Σ and p∈K' for one (ie for all) q∈KK∈Dead if K is not final state and contains only transitions to itselfK Unreachable if there is no path from the initial state to K
''
1
1
),(: and
such that maximal with }}{{}){'(:'
iiini
i
inii
KaqKKqaKK
KKK
∈Π∈∃∈∀Σ∈∀=
∪−Π=Π
≤≤
≤≤
δU
23
Example: a(a|0)*
0' 1' 2'a
a
0
a
0
∅a
0
0
{0'} {1',2'}a
a
0
24
Mealy AutomataMealy automata are finite-state machines that act as transducers, or translators, taking a string on an input alphabetand producing a string of equal length on an output alphabet.A machine in state qj, after reading symbol sigma σk writessymbol λk; the output symbol depends on the state just reachedand the corresponding input symbol. A Mealy automaton is a six-tupleME=(Q, Σ, Γ, δ, λ, q0) where
Q is a finite set of statesΣ is a finite input alphabetΓ is a finite output alphabetδ: Q × Σ -> Q is the transition functionλ: Q × Σ -> Γ is the output functionq0 is the initial state
25
Moore AutomataMoore automata are finite-state machines that act as transducers, or translators, taking a string on an input alphabetand producing a string of equal length on an output alphabet.Symbols are output after the transition to a new state iscompleted; output symbol depends only on the state just reached.A Moore automaton is a six-tupleMO=(Q, Σ, Γ, δ, λ, q0) where
Q is a finite set of statesΣ is a finite input alphabetΓ is a finite output alphabetδ: Q × Σ -> Q is the transition functionλ: Q -> Γ is the output functionq0 is the initial state
26
State Transition DiagramsState transition: When event γ occurs in state A, if Condition P istrue at the time, the system executes action a and transfers to state C.State diagrams are directed graphs with nodes denoting states, and arrows (labelled with the triggering event, guardingconditions and action to be executed) denoting transitions.Example:
Problem: all combinations of states have to be representedexplicitly, leading to exponential blow-up.
A
C
Bγ(P)
δ
β
α
β
27
State Transition DiagramsDisadvantages:
No structure (no strategy for bottom-up of top-down development)State-transition diagrams are flat, ie without hierarchyUneconomical wrt transitions (eg interrupt): exponential blow-upUneconomical wrt states: exponential blow-upUneconomical wrt parallel composition: exponential blow-upInherently sequential; parallelism cannot be expressed in a natural way
28
SyncChartsVisual formalism for describing states and transitions of a system in a modular fashion.
Extension of state-transition diagrams (Mealy/Moore automata):HierarchyModularityParallelism
Is fully deterministic.
Tailored to control-oriented applications (drivers, protocols).
Implements sychronous principle.
29
Synchroneous Programming
Two simple ways of implementing reactive systems:Event-driven
Sampling
<Initialize Memory>Foreach input_event do
<Compute Outputs><Update Memory>
End
<Initialize Memory>Foreach period do
<Read Inputs><Compute Outputs><Update Memory>
End
30
Synchroneous ProgrammingProgram typically implements an automaton:
state: valuations of memorytransition: reaction, possibly involving manycomputations
Synchronous paradigm: reactions are considered atomic, ie theytake no time. (Computational steps execute like combinatorialcircuits.)Synchronous broadcast: instantaneous communication, ie eachautomaton in the system considers the outputs of others as being part of its own inputs.
31
Synchronous ProgrammingImportant requirement: guaranteeing deterministic behavior.
Time is divided into discrete ticks (also called cycles, steps, instants).
Implicit assumption: presence of a global clock. This makes application in distributed environments difficult.
In order to validate the timing behavior it is sufficient to prove that the worst-case execution time (WCET) of any reaction is smaller than the minimal time interval between two external events.
32
OverviewStateCharts:
First, and probably most popular formal language for the design of reactive systems.Focus on specification and design, not designed as a programminglanguage.Determinism is not ensured.No standardized semantics.
Programming languages for designing reactive systems:ESTEREL [Berry]: textual imperative language. SyncCharts / SSM: Graphical formalism for ESTEREL.LUSTRE [Caspi, Halbwachs]: textual declarative language. Tailoredto data-flow oriented systems (e.g. regulation systems).SCADE [Esterel Inc.]. Graphical formalism for (enhanced) LUSTRE.
33
Cyclic Evolution
Reactions consist of three phases:1. Read input signals (input event)2. Compute the reaction3. Perform outputs (output event)
All phases happen in one instant, ie have 0-duration.
34
SyncChartsT
T/C
off on
FDIV
States (circles and rectangles):can be namedtwo types:
simple state (circle)macrostate (rounded rectangle): contain a hierarchy of other states
are optionally labelled*: /<effect>
Transitions (arrows):are labelled*: <trigger>/<effect>
All components are optional.three types:
strong abortweak abortnormal termination
can have priorities (-> determinism)
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B1
signal C0
*Triggers and effects are signals, or combinations of signals usingboolean operations or, and andnot.
12
35
States & State Transition GraphsSpecial states:
Initial state: (alternative notation: )Terminal state:
State Transition Graph: connected labeled graph made of states connected by transitions, with an initial state.Two types of states:
Simple state: just carries a label.Macrostate: contains at least one state transition graph.
At each instant there is one and only one active state.An active state waits for the satisfaction of the trigger of one of its outgoing transitions, at an instant strictly posterior to its entering (activation).
S
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B1
signal C0
I S
36
State and Transition LabelsSignals are characterized by their presence status (+,-, ⊥).
Valued signal: signals conveys a value of a given type.Pure signal: no value conveyed.
tick: implicit signal present at every instant.A trigger is satisfied associated signal is present.Transition labels:
When the trigger is satisfied, the transition is said to be enabled.The transition is immediately taken and emits the associated signals.The firing of a transition is fully deterministic and takes no time.
Node labels:Signal emission depends on transition type (strong/weak abort)Signals are emitted when…
…entering …in …exiting
Weak abort Yes Yes Yes
Strong abort Yes Yes No
37
Example: Strong vs. Weak AbortTFF - SA
T
T/C
off on
/OFF /ON
TFF - WA
T
T/C
off on
/OFF /ON
Instant Input TFF-SA Output TFF-WA Output
1
2 T
3
4 T
5
6 T
7 T
8 T
9
38
Example: Strong vs. Weak AbortTFF - SA
T
T/C
off on
/OFF /ON
TFF - WA
T
T/C
off on
/OFF /ON
Instant Input TFF-SA Output TFF-WA Output
1 OFF
ON
ON
C, OFF
OFF
ON
C,OFF
ON
ON
2 T
3
4 T
5
6 T
7 T
8 T
9
39
Example: Strong vs. Weak AbortTFF - SA
T
T/C
off on
/OFF /ON
TFF - WA
T
T/C
off on
/OFF /ON
Instant Input TFF-SA Output TFF-WA Output
1 OFF
ON
ON
C, OFF
OFF
ON
C,OFF
ON
ON
OFF
2 T OFF,ON
3 ON
4 T ON,C,OFF
5 OFF
6 T OFF,ON
7 T ON,C,OFF
8 T OFF,ON
9 ON
40
ConcurrencyA macrostate can contain a parallelcomposition of separate concurrentSTGs. Graphical notation: dashedseparation line.STGs are coupled by shared signals.A local signal is declared by thekeyword signal and its scope is thecontaining macrostate.A set of (concurrent) active states iscalled a configuration.
Notation:Active state Taken transition Emitted signal
S+: presence of signal S S-: absence of signal S
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B1
signal C0
S
41
Example ReactionCnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B0
signal C0
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B0
signal C0
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B0
signal C0
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B0
signal C0
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B0
signal C0
Cnt2
C0/C
off1
C0
on1 /B1
T/C0
off0
T
on0 /B0
signal C0
T- T+
T+
T+ T+
42
Concurrency and Normal TerminationWhen each concurrent STG in a macrostate reaches a final state, then the macrostate is immediately exited by its normal termination transition.
WaitAandB
wA
A
dA
wB
B
dB
/O
done
ABO
43
Concurrency and Abort
R+ B+
WaitAandB
wA
A
dA
wB
B
dB
/O
done
ABO
R
ABRO
WaitAandB
wA
A
dA
wB
B
dB
/O
done
ABO
R
ABRO
44
Transitions
A strong abort prevents any execution in the preempted state.
For any stateevery outgoing transition has a different priorityany strong abort transition has priority over any weak aborttransitionany weak abort transition has priority over a normal termination transition
There are no inter-level transitions.