Introduction to State Machines
About Swift Act LLC Introduction to State Machine @ Swift Act LLC ❑ Established @ end of 2017 ❑ Legal representation in Egypt and Germany ❑ Experience in Automotive, Industrial Automation, IoT, consumer electronics … ❑ Safety critical experience: IEC 61508, ISO 26262 ... ❑ Process compliance: A-SPICE and CMMI ❑ Mission: Long-term partnership with stakeholders ❑ Vision: Maximizing value for stakeholders ❑ Values: Ethics, Empowerment, Professionalism, Team Work and Trust ❑ www.swift-act.com
What is a State Machine? Introduction to State Machine @ Swift Act LLC
Why a State Machine? Introduction to State Machine @ Swift Act LLC
State Machines are Hierarchical Introduction to State Machine @ Swift Act LLC
State Machines are Concurrent Introduction to State Machine @ Swift Act LLC
State Machine Elements Introduction to State Machine @ Swift Act LLC S/M Elements States Transitions Events Actions
States are ... Introduction to State Machine @ Swift Act LLC States Finite Distinct 1 or more initial states 0 or more end states 0 or more intermediate states
State Machine Graphical Representation Introduction to State Machine @ Swift Act LLC Stopped Playing Paused Play/Song is Playing from beginning Stop or Song Finished/Song is Stopped Pause/Song is Paused Play/Song is Resumed Stop/Song is Stopped
State Machine Tabular Representation Introduction to State Machine @ Swift Act LLC Current State Event Action Next State Stopped Play Play song from beginning Playing Stopped Pause Stopped Stopped Stop Stopped Stopped Song finished Stopped Playing Play Playing Playing Pause Song is paused Paused Playing Stop Song is stopped Stopped Playing Song finished Song is stopped Stopped Paused Play Song is resumed Playing Paused Pause Paused Paused Stop Song is stopped Stopped Paused Song finished Paused
State Machine Textual Representation Introduction to State Machine @ Swift Act LLC
State Machine from Design PoV Introduction to State Machine @ Swift Act LLC Events Timing events only? Input events only? Timing and input events
State Machine from Coding PoV Introduction to State Machine @ Swift Act LLC Function for every state? Similar? 1 function + Data Different? State type + State variable + function (switch-case) + function for every state (optional)
Data-Indexed State Machine Example Introduction to State Machine @ Swift Act LLC
Data-Indexed State Machine Example cont’d Introduction to State Machine @ Swift Act LLC
Execution-Indexed State Machine Example Introduction to State Machine @ Swift Act LLC
Execution-Indexed State Machine Example cont’d Introduction to State Machine @ Swift Act LLC
Remember: State Machines are Hierarchical Introduction to State Machine @ Swift Act LLC
Testing State Machine – Coverage Methods Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
Testing State Machine – Coverage Methods cont’d Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
Testing State Machine – Coverage Methods cont’d Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
Testing State Machine – Coverage Methods cont’d Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
Transition Coverage: n-switch (+ve Testing) Introduction to State Machine @ Swift Act LLC A B C D F E 1 2 9 8 10 3 14 11 4 13 5 12 7 6
Transition Coverage: 0-switch vs. 1-switch Introduction to State Machine @ Swift Act LLC 0-switch 1-switch A1 A2 A9 A1A1 A1A2 A1A9 A9B10 A9B8 A9B3 B10 B8 B3 B10C14 B10C11 B10C4 B8A1 B8A2 B8A9 C14 C11 C4 C14C14 C14C11 C14C4 C11D13 C11D12 C11D5 D13 D12 D5 D13D13 D13D12 D13D5 D12F6 D12F7 F6 F7 F7A1 F7A2 F7A9
0-switch: Systematic Way Introduction to State Machine @ Swift Act LLC 1 3 2 4 1 3 4 1212 13 13 12
n-switch: Systematic Way Introduction to State Machine @ Swift Act LLC (N-1)- switch Extra level in the tree N- switch
-ve Testing Introduction to State Machine @ Swift Act LLC -ve Testing Testing Invalid Transitions
Case Study: Digital Clock Introduction to State Machine @ Swift Act LLC Digital ClockSet Button + Button - Button Hours Units SSD Minutes Tens SSD Hours Tens SSD Minutes Units SSD
Case Study: Block Diagram Introduction to State Machine @ Swift Act LLC Digital Clock SW Time SSD Display
Case Study: SW Introduction to State Machine @ Swift Act LLC
Case Study: SSD Introduction to State Machine @ Swift Act LLC
Case Study: Time Introduction to State Machine @ Swift Act LLC Set Hours Set Minutes Normal Set is pressed Set is pressed Set is pressed
Case Study: Display Introduction to State Machine @ Swift Act LLC Blink Hours Blink Minutes Blink Seconds Time mode = Set Hours Time mode = Set Minutes Time mode = Normal
Introduction to State Machine @ Swift Act LLC

Introduction to state machines in Embedded Software Design

  • 1.
  • 2.
    About Swift ActLLC Introduction to State Machine @ Swift Act LLC ❑ Established @ end of 2017 ❑ Legal representation in Egypt and Germany ❑ Experience in Automotive, Industrial Automation, IoT, consumer electronics … ❑ Safety critical experience: IEC 61508, ISO 26262 ... ❑ Process compliance: A-SPICE and CMMI ❑ Mission: Long-term partnership with stakeholders ❑ Vision: Maximizing value for stakeholders ❑ Values: Ethics, Empowerment, Professionalism, Team Work and Trust ❑ www.swift-act.com
  • 3.
    What is aState Machine? Introduction to State Machine @ Swift Act LLC
  • 4.
    Why a StateMachine? Introduction to State Machine @ Swift Act LLC
  • 5.
    State Machines areHierarchical Introduction to State Machine @ Swift Act LLC
  • 6.
    State Machines areConcurrent Introduction to State Machine @ Swift Act LLC
  • 7.
    State Machine Elements Introductionto State Machine @ Swift Act LLC S/M Elements States Transitions Events Actions
  • 8.
    States are ... Introductionto State Machine @ Swift Act LLC States Finite Distinct 1 or more initial states 0 or more end states 0 or more intermediate states
  • 9.
    State Machine GraphicalRepresentation Introduction to State Machine @ Swift Act LLC Stopped Playing Paused Play/Song is Playing from beginning Stop or Song Finished/Song is Stopped Pause/Song is Paused Play/Song is Resumed Stop/Song is Stopped
  • 10.
    State Machine TabularRepresentation Introduction to State Machine @ Swift Act LLC Current State Event Action Next State Stopped Play Play song from beginning Playing Stopped Pause Stopped Stopped Stop Stopped Stopped Song finished Stopped Playing Play Playing Playing Pause Song is paused Paused Playing Stop Song is stopped Stopped Playing Song finished Song is stopped Stopped Paused Play Song is resumed Playing Paused Pause Paused Paused Stop Song is stopped Stopped Paused Song finished Paused
  • 11.
    State Machine TextualRepresentation Introduction to State Machine @ Swift Act LLC
  • 12.
    State Machine fromDesign PoV Introduction to State Machine @ Swift Act LLC Events Timing events only? Input events only? Timing and input events
  • 13.
    State Machine fromCoding PoV Introduction to State Machine @ Swift Act LLC Function for every state? Similar? 1 function + Data Different? State type + State variable + function (switch-case) + function for every state (optional)
  • 14.
    Data-Indexed State MachineExample Introduction to State Machine @ Swift Act LLC
  • 15.
    Data-Indexed State MachineExample cont’d Introduction to State Machine @ Swift Act LLC
  • 16.
    Execution-Indexed State MachineExample Introduction to State Machine @ Swift Act LLC
  • 17.
    Execution-Indexed State MachineExample cont’d Introduction to State Machine @ Swift Act LLC
  • 18.
    Remember: State Machinesare Hierarchical Introduction to State Machine @ Swift Act LLC
  • 19.
    Testing State Machine– Coverage Methods Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
  • 20.
    Testing State Machine– Coverage Methods cont’d Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
  • 21.
    Testing State Machine– Coverage Methods cont’d Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
  • 22.
    Testing State Machine– Coverage Methods cont’d Introduction to State Machine @ Swift Act LLC • States • Events • Actions • Paths
  • 23.
    Transition Coverage: n-switch(+ve Testing) Introduction to State Machine @ Swift Act LLC A B C D F E 1 2 9 8 10 3 14 11 4 13 5 12 7 6
  • 24.
    Transition Coverage: 0-switchvs. 1-switch Introduction to State Machine @ Swift Act LLC 0-switch 1-switch A1 A2 A9 A1A1 A1A2 A1A9 A9B10 A9B8 A9B3 B10 B8 B3 B10C14 B10C11 B10C4 B8A1 B8A2 B8A9 C14 C11 C4 C14C14 C14C11 C14C4 C11D13 C11D12 C11D5 D13 D12 D5 D13D13 D13D12 D13D5 D12F6 D12F7 F6 F7 F7A1 F7A2 F7A9
  • 25.
    0-switch: Systematic Way Introductionto State Machine @ Swift Act LLC 1 3 2 4 1 3 4 1212 13 13 12
  • 26.
    n-switch: Systematic Way Introductionto State Machine @ Swift Act LLC (N-1)- switch Extra level in the tree N- switch
  • 27.
    -ve Testing Introduction toState Machine @ Swift Act LLC -ve Testing Testing Invalid Transitions
  • 28.
    Case Study: DigitalClock Introduction to State Machine @ Swift Act LLC Digital ClockSet Button + Button - Button Hours Units SSD Minutes Tens SSD Hours Tens SSD Minutes Units SSD
  • 29.
    Case Study: BlockDiagram Introduction to State Machine @ Swift Act LLC Digital Clock SW Time SSD Display
  • 30.
    Case Study: SW Introductionto State Machine @ Swift Act LLC
  • 31.
    Case Study: SSD Introductionto State Machine @ Swift Act LLC
  • 32.
    Case Study: Time Introductionto State Machine @ Swift Act LLC Set Hours Set Minutes Normal Set is pressed Set is pressed Set is pressed
  • 33.
    Case Study: Display Introductionto State Machine @ Swift Act LLC Blink Hours Blink Minutes Blink Seconds Time mode = Set Hours Time mode = Set Minutes Time mode = Normal
  • 34.
    Introduction to StateMachine @ Swift Act LLC