IAR Information Center

GETTING STARTED

GETTING STARTED

USER GUIDES

USER GUIDES

TUTORIALS

TUTORIALS

SUPPORT

SUPPORT

RELEASE NOTES

RELEASE NOTES

SUB STATE MACHINES

Submachine states and sub state machines are an efficient way to capture common design patterns or fragments for reuse both within a design and across different designs. This page briefly describes the submachine state and the sub state machine features.


FEATURES

The idea with sub state machines is that you can create a state machine once and then reuse it in every place where a similar state and transition structure is needed, even if it's a different project. When you need to instantiate such a state machine you draw a special submachine state and associate the state with the sub state machine. This can be all that's needed to reuse an arbitrarily complex state machine; but you can just as well design a reusable state machine where things like event names, action function names, variable names etc can be associated with entities that match the point of use.

HOW TO CREATE A SUB STATE MACHINE

There are three ways to create a reusable state machine:

The created sub state machine can be edited in the sam way as any other part of the design. Note that transitions that need to go out of or in to the sub state machine should be drawn to connection points. Corresponding connection point references will be automatically added on the submachine states associated with the sub state machine.

Look at the picture above. It depicts a simple state machine that utilizes the same sub state machine in two submachine states. The sub state machine is a simple counter that counts an event and on hitting a limit it emits a signal that can trigger a transition in the state machine instantiating the sub state machine. The sub state machine is designed so that the event, the counter variable and the counter limit constant are all declared so that they can be bound to elements of the instantiating state machine.
One of the submachine states will count button events and the other will count timer events. Each state machine has a separare count limit and it's own counter variable, as specified by the bindings. You can look at the picture below to examine the bindings for SubmachineState1.

If you want to be able to remap names of action functions, event names, variables names, signals or constants you must make sure the corresponding element is declared in the sub state machine and not defined. If it is defined in the sub state machine it is treated as a local name that is not supposed to be remapped and it will not show in the Bindings tab. All elements are automatically declared when converting an existing state to a sub state machine.


USING A SUB STATE MACHINE

It's straightforward to reuse an existing state machine: