0% found this document useful (0 votes)
499 views

Embedded Systems Design With UML State Machines

1. Hierarchical state machines (HSMs) allow states to be nested within other states, reducing complexity and redundancy compared to flat state machines. 2. Tools like Quantum Platform provide a framework for designing HSMs, promoting code reusability, improved readability, and scalability. 3. Hierarchical event processing tools simplify development and maintenance of complex state machines, especially for real-time systems.

Uploaded by

tom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
499 views

Embedded Systems Design With UML State Machines

1. Hierarchical state machines (HSMs) allow states to be nested within other states, reducing complexity and redundancy compared to flat state machines. 2. Tools like Quantum Platform provide a framework for designing HSMs, promoting code reusability, improved readability, and scalability. 3. Hierarchical event processing tools simplify development and maintenance of complex state machines, especially for real-time systems.

Uploaded by

tom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

EMBEDDED SYSTEM DESIGN USING

UML STATE MACHINES

INTRODUCTION

What is a State Machine ?

A state machine is a software model of computation and it


,

comprises finite number of states


of a . Thus, any state machine

with a finite number of states is called a Finite state


machine (FSM)

Since a FSM has a finite number of states there is also


,
a

finite number of transitions among the states. Transitions are

triggeredby the input events feel to the state machine . Thus


,
a FSM is an event-driven system
.

A state machine also produces an .


output The output produced
depends on the current state of the state machine and the

input events fee to the state machine .

Benefits of using State Machines (FSMs)

·
FSM's can be used to describe situations or scenarios of your
application ,
like for example, modelling the life
cycle of a

reactive object through the interconnections of states.

·
FSMs are helpful to model complex applications that involve
lots of decision making producing different outputs or actions
, ,
and
processing various events .

Zager Altrai
Moore Machine

In this state machine , the output is determined ONLY by the

present active state of the state machine and NOT by any

input events
.

Thus, there are NO outputs during state transitions


Regardless of weather input is D or & ,


the output occurs as
long
as we enter state 3, thus the output is often called "Entry
"
action"

Zager Altrai
<behavior-type-label>[‘/’ <behavior-expression>]
{<trigger>}['[' <guard>']'] [/<behavior-expression>]
1. Nested Switch Approach:

• Structure:
This approach uses nested switch-case statements. The outer switch
statement typically handles the current state, and the inner switch or
if-else statements handle the events or inputs.

• Implementation:
Each case within the outer switch corresponds to a state. Inside each
case, another switch or series of if-else statements determine the
action to take based on the current input or event.

• Advantages:
• Easy to implement and understand, especially for simple state machines.
Directly maps the state machine diagram to code.

• Disadvantages:
• Can become complex and hard to manage with a large number of states and
transitions.
• Modifying the state machine can be error-prone, as changes might need to
be made in multiple places.

• Use Case:
Best for simple state machines with a limited number of states and
transitions.

2. State Table Approach:

• Structure:
This approach uses a table (array) to represent states and transitions.
Each row in the table represents a state, and each column represents an
event or input.

• Implementation:
The table entries typically store information about the next state and
the action to take. When an event occurs, the system looks up the
current state and event in the table to determine the next state and
action.

• Advantages:
• Scalable for complex state machines with many states and transitions.
• Easier to read and modify, as the state transition logic is centralized
in the table.
• Can be data-driven, allowing for dynamic changes to the state machine.

• Disadvantages:
• Can consume more memory, especially with a large number of states and
events.
• Might be less intuitive for simple state machines or for developers
unfamiliar with the approach.

• Use Case:
Ideal for complex state machines where scalability and maintainability
are important.
3. State Handler Approach:

• Structure:
This approach uses a function (or method) for each state. Each function
handles the events or inputs for its specific state and returns the next
state.

• Implementation:
The state machine has a current state variable. Based on this state, the
corresponding state handler function is called. The function executes
the actions for its state and returns the next state based on the inputs
or events.

• Advantages:
• Provides clear separation of the logic for each state.
• Easy to add or modify states, as each state has its own function.
• Can improve readability and maintainability, especially with well-named
state functions.

• Disadvantages:
• Might involve more overhead in terms of function calls, especially with
deeply nested states.
• The overall flow can be less visible compared to the nested switch or
state table approaches.

• Use Case:
Suitable for medium to complex state machines where clarity and
maintainability of state-specific logic are priorities.

In summary, the choice of implementation depends on factors like the


complexity of the state machine, the number of states and transitions,
maintainability requirements, and the familiarity of the development team with
these approaches. The nested switch approach is simple and straightforward but
can become unwieldy with complex state machines. The state table approach
centralizes the state transition logic, making it more scalable and easier to
modify. The state handler approach offers clear separation and encapsulation
of state-specific logic, favoring maintainability and readability.
Hierarchical event processing software modeling tools like Quantum Platform
(QP) provide a framework for designing complex state machines using a
hierarchical nesting of states. They are used instead of flat state machines
because they simplify the design of complex systems, improve maintainability,
and reduce code redundancy.

Detailed Explanation:

1. Quantum Platform (QP) Overview:

• Framework: QP is a set of lightweight, open-source software frameworks


for building responsive and modular real-time embedded applications.
• Hierarchical State Machines: QP supports UML (Unified Modeling Language)
compliant hierarchical state machines (HSMs) or statecharts, allowing
states to be nested within other states.

2. Hierarchical vs. Flat State Machines:

• Flat State Machines: In a flat state machine, all states are on the same
level. This can lead to complexity and redundancy, especially in large
systems where many states share similar behaviors.
• Hierarchical State Machines (HSMs): HSMs introduce the concept of nested
states. States can inherit behavior from their parent states, leading to
a more organized and manageable structure.

3. Advantages of Hierarchical Event Processing

• Reduced Complexity: HSMs can significantly reduce the complexity of state


machines, particularly in complex systems with many states and
transitions.
• Code Reusability and Maintenance: Common behaviors and actions can be
defined in parent states, promoting code reuse and easier maintenance.
• Improved Readability: The hierarchical organization mirrors real-world
systems more closely, making the state machine easier to understand and
modify.
• Scalability: HSMs are better suited for scaling, as adding new states or
modifying behaviors is more straightforward than in a flat model.

4. Why Use Hierarchical Modeling Tools like QP:

• Efficiency in Design: Tools like QP automate and facilitate the design of


HSMs, making it more efficient than manually coding state machines.
• Error Reduction: Automated tools can reduce errors that might occur in
manual coding, especially in complex nested states.
• Visual Representation: QP and similar tools often provide visual
representations of state machines, aiding in design and debugging.
• Integration with Other Tools: These tools often integrate with other
development tools, offering features like code generation, simulation,
and debugging.
5. Use Cases:

• Complex Systems: Ideal for systems where state behavior is complex or


when states share common actions.
• Real-Time Systems: Useful in real-time systems where predictability and
responsiveness are critical, and where system complexity can be high.

In conclusion, hierarchical event processing tools like QP offer a structured


and efficient way to design complex state machines. They simplify development
and maintenance, enhance scalability, and are particularly advantageous in
complex, real-time embedded systems as compared to traditional flat state
machine design.

You might also like