Beruflich Dokumente
Kultur Dokumente
miro@quantum-leaps.com
Miro Samek
Outline
slide 3
slide 4
slide 5
Function 1 Function 2
Function 3 Function 4
slide 6
event loop ISR1() ISR2() event queue (FIFO) event dispatcher event dispatching based on event type queue empty
...
application code
event eventN_handler();
...
event2_handler();
event1_handler();
idle_handler();
slide 7
slide 8
(b)
else event A arrived process A
(c)
process_A()
process_B()
while () { ...
else
process_C()
wait4eventB(); /* process B */ }
wait4eventC(); /* process C */
slide 9
slide 10
Outline
Event-driven programming Hierarchical state machines Hierarchical state machines Real-time frameworks Q&A
slide 11
on
OFF / powerOff();
slide 12
(b)
else event A arrived process A
(c)
wait 4A
A / process A
while () { ...
[else]
process B
B / process B
slide 13
(a)
s1 E1 / action1(); s2 E2 / action2(); s3 E3 / action3();
(b)
do X
do Y
do Z
do W
slide 14
State-transition explosion
C operand1 OPER C C OPER DIGIT_0_9, POINT result OFF opEntered DIGIT_0_9, POINT OFF EQUALS operand2 OFF C OFF
slide 15
operand1
EQUALS
OFF
Programming by difference
Behavioral inheritance
slide 16
TIMEOUT
TIMEOUT
slide 17
/ me->foo = 0; s
TERMINATE
slide 18
... ...
QState Calc::on(Calc *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { // entry action BSP_message("on-ENTRY"); return Q_HANDLED(); } case Q_EXIT_SIG: { // exit action BSP_message("on-EXIT"); return Q_HANDLED(); } C case Q_INIT_SIG: { // initial transition BSP_message("on-INIT"); return Q_TRAN(&Calc::ready); } case C_SIG: { // state transition OFF BSP_clear(); // clear the display return Q_TRAN(&Calc::on); } case OFF_SIG: { // state transition return Q_TRAN(&Calc::final); } } return Q_SUPER(&QHsm::top); // superstate Quantum Leaps, LLC } slide 19 www.state-machine.com
Outline
Event-driven programming Hierarchical state machines Real-time frameworks Real-time frameworks Q&A
slide 20
...
application code
event eventN_handler();
...
event2_handler();
event1_handler();
idle_handler();
slide 21
slide 22
priority = n
...
e = Queue_get(a); FSM_dispatch(a, e); e = Queue_get(a); FSM_dispatch(a, e);
... ...
idle processing
slide 23
(a)
ISR1
ISR2
(b)
events
e = Queue_get(me);
...
FSM_dispatch(me, e);
slide 24
QTimeEvt
Star Wars application Ship Missile n Mine1 n Mine2 ObjectPosEvt ObjectImageEvt Tunnel
slide 25
Summary
State machines complement imperative languages (C, C++, Java, C#, etc.) State machines explode without state hierarchy State machines are impractical without a framework
Once you try an event-driven, state machine framework you will not want to go back to spaghetti and raw RTOS/OS
slide 26
Outline
Event-driven programming Hierarchical state machines Real-time frameworks Q&A Questions & Answers
slide 27