Avoid Unwanted Recursion in a Chart
Recursion can be useful for controlling substate transitions among parallel states at the same level of the chart hierarchy. For example, you can send a directed event broadcast from one parallel state to a sibling parallel state to specify a substate transition. This type of recursive behavior is desirable and efficient. For details, see Broadcast Local Events to Synchronize Parallel States.
However, unwanted recursion can also occur during chart execution. To avoid unwanted recursion, do not use recursive function calls or undirected local event broadcasts.
Recursive Function Calls
Suppose that you have functions named
h in a chart. These functions can be any combination of graphical
functions, truth table functions, MATLAB® functions, or Simulink® functions.
To avoid recursive behavior, do not:
Undirected Local Event Broadcasts
An undirected event broadcast sends a local event to all states in which it is visible. The format of an undirected event broadcast is
event_name is a local event.
To avoid recursive behavior, replace undirected event broadcasts with directed event broadcasts by using the syntax
event_name is a local event in the chart and
state_name is a destination state.
If the local event broadcast occurs in a state action, ensure that the destination state is not an ancestor of the source state in the chart hierarchy.
If the local event broadcast occurs in a transition, ensure that:
The destination state is not an ancestor of the transition in the chart hierarchy.
The transition does not connect to the destination state.
For more information, see Broadcast Local Events to Synchronize Parallel States.
During simulation, Stateflow® charts can detect undirected local event broadcasts. To control the level of
diagnostic action, open the Configuration Parameters dialog box and, in the Diagnostics > Stateflow pane, set the Undirected event broadcasts parameter to
error. The default setting is
warning. For more information, see Undirected event broadcasts (Simulink).