Execution of a Stateflow Chart

When a Stateflow® chart wakes up, the chart follows a workflow and executes actions. A Stateflow chart wakes up:

  • At each time step according to the Simulink® solver.

  • When the Stateflow chart receives an event.

When a chart wakes up for the first time, the chart is initialized and becomes active. See Chart Entry. Once the chart is active but with no more actions to take, the chart goes to sleep until it is triggered by a new time step or an event.

Workflow for Stateflow Chart Execution

This flow chart shows the progression of events that Stateflow takes for executing a chart or state. In this flow chart, the current state refers to the state in which a decision or a process is taking place.

During Actions

During actions for a state execute when:

  • The state is active, a new time step occurs, and no valid transition to another state is available.

  • The state is active, an event occurs, and no valid transition to another state is available.

During actions are preceded by the prefix during or du, and then followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,). If you do not specify the state action type explicitly for a statement, the chart treats that statement as an entry,during action.

A state performs its during actions (if specified) when the chart wakes up. The preceding flow chart depicts the process of state execution and shows when during actions occur.

If your Stateflow chart does not contain states, each time the chart is executed, Stateflow always evaluates the default transition path.

Outgoing Transition

Stateflow marks outgoing transitions for evaluation as a part of the execution of a Stateflow chart. Once an outgoing transition is marked for evaluation, follow the Workflow for Evaluating Transitions. For more information about how Stateflow evaluates outgoing transitions, see Evaluate Transitions.

Inner Transitions

Stateflow marks inner transitions for evaluation as a part of the execution of a Stateflow chart. Once an inner transition is marked for evaluation, follow the Workflow for Evaluating Transitions. For more information about how Stateflow evaluates inner transitions, see Evaluate Transitions.

Chart Execution with a Valid Transition

In this example, the Stateflow chart is initialized and the entry actions are performed for StateA and StateA1. A new time step occurs and the chart wakes up.

At this time step, x = 5, y = 2, and z = 0.

By following the Workflow for Stateflow Chart Execution, the execution steps for chart execution are in this order:

  1. The chart has an active substate, StateA.

  2. StateA has an outgoing transition to StateB. By following the Workflow for Evaluating Transitions, the transition is determined to be valid.

  3. StateB is marked for entry and StateA is marked for exit.

To complete the time step, follow the Workflow for Exiting a State for StateA and the Workflow for Entering a Chart or State for StateB.

Chart Execution Without a Valid Transition

In this example, the Stateflow chart is initialized and the entry actions are performed for StateA and StateA1. A new time step occurs and the chart wakes up.

At this time step, x = 3, y = 0, and z = 0.

By following the Workflow for Stateflow Chart Execution until the chart goes to sleep, the execution steps for chart execution are in this order:

  1. The chart has an active substate, StateA.

  2. StateA has an outgoing transition to StateB. By following the Workflow for Evaluating Transitions, the transition is determined to be invalid.

  3. Perform the during actions for StateA. Now y = 1.

  4. StateA does not have any inner transitions.

  5. The active substate of StateA is StateA1.

  6. StateA1 has an outgoing transition to StateA2. By following the Workflow for Evaluating Transitions, the transition is determined to be invalid.

  7. Perform the during actions for StateA1. Now x = 4.

  8. StateA1 does not have any active substates.

  9. The chart goes to sleep.

Steps 1 through 9 take place in the second time step.

Related Topics