Types of Chart Execution
Life Cycle of a Stateflow Chart
Stateflow® charts go through several stages of execution:
|Chart has no active states
|Chart has active states
|Chart has active states, but no events to process
When a Simulink® model first triggers a Stateflow chart, the chart is inactive and has no active states. After the chart executes and completely processes its initial trigger event from the Simulink model, it transfers control back to the model and goes to sleep. At the next Simulink trigger event, the chart changes from the sleeping to active stage.
Execution of an Inactive Chart
When a chart is inactive and first triggered by an event from a Simulink model, it first executes its set of default flow charts (see Order of Execution for a Set of Flow Charts). If this action does not cause an entry into a state and the chart has parallel decomposition, then each parallel state becomes active (see Enter a Chart or State).
If executing the default flow paths does not cause state entry, a state inconsistency error occurs.
Execution of an Active Chart
After a chart has been triggered the first time by the Simulink model, it is an active chart. When the chart receives another event from the model, it executes again as an active chart. If the chart has no states, each execution is equivalent to initializing a chart. Otherwise, the active substates execute. Parallel states execute in the same order that they become active.
Execution of a Chart at Initialization
By default, the first time a chart wakes up, it executes the default transition paths. At this time, the chart can access inputs, write to outputs, and broadcast events.
If you want your chart to begin executing from a known configuration, you can enable the Execute (enter) Chart At Initialization chart property. When you turn on this option, the state configuration of a chart initializes at time 0 instead of the first occurrence of an input event. The default transition paths of the chart execute during the model initialization phase at time 0, corresponding to the mdlInitializeConditions() (Simulink) phase for S-functions. For more information, see Execute (enter) chart at initialization.
If an output of this chart connects to a SimEvents® block, do not select this check box. To learn more about using Stateflow charts and SimEvents blocks together in a model, see the SimEvents documentation.
Due to the transient nature of the initialization phase, do not perform certain actions in the default transition paths of the chart — and associated state entry actions — which execute at initialization. Follow these guidelines:
Do not access chart input data, because blocks connected to chart input ports might not have initialized their outputs yet.
Do not call exported graphical functions from other charts, because those charts might not have initialized yet.
Do not broadcast function-call output events, because the triggered subsystems might not have initialized yet.
To control the level of diagnostic action for invalid access to chart input data,
open the Configuration Parameters dialog box and, in the Diagnostics > Stateflow pane, set the Invalid input data access in chart
initialization parameter to
error. The default
warning. For more information, see Invalid input data access in chart initialization (Simulink).
Execute at initialization is ignored in Stateflow charts that do not contain states.