Main Content

Undirected Broadcast Events in Parallel States

Broadcast Events in State Actions

This example shows the behavior of event broadcast actions in parallel states. The chart uses implicit ordering of parallel states (see Implicit Ordering of Parallel States).

Stateflow chart with a top-level state called A. A has two parallel substates called A1 and A2. A1 has substates A1a and A1B. A2 has substates A2a and A2b.

Initially, the chart is asleep. Parallel substates A.A1.A1a and A.A2.A2a are active. Event E_one occurs and awakens the chart, which processes the event from the root down through the hierarchy:

  1. The chart root checks to see if there is a valid transition at the root level as a result of E_one. No valid transition exists.

  2. State A during actions (durA()) execute and complete.

  3. The children of state A are parallel (AND) states. Because implicit ordering applies, the states are evaluated and executed from left to right and top to bottom. State A.A1 is evaluated first. State A.A1 during actions (durA1()) execute and complete. State A.A1 executes and completes the on E_one action and broadcasts event E_two. The during and on event_name actions are processed based on their order of appearance in the state label:

    1. The broadcast of event E_two awakens the chart a second time. The chart root checks to see if there is a valid transition as a result of E_two. No valid transition exists.

    2. State A during actions (durA()) execute and complete.

    3. State A checks its children for valid transitions. No valid transitions exist.

    4. State A evaluates its children starting with state A.A1. State A.A1 during actions (durA1()) execute and complete. State A.A1 is evaluated for valid transitions. There are no valid transitions as a result of E_two within state A1.

    5. The during actions for state A1a (durA1a()) execute.

    6. State A.A2 is evaluated. State A.A2 during actions (durA2()) execute and complete. State A.A2 checks for valid transitions. State A.A2 has a valid transition as a result of E_two from state A.A2.A2a to state A.A2.A2b.

    7. State A.A2.A2a exit actions (exitA2a()) execute and complete.

    8. State A.A2.A2a is marked inactive.

    9. State A.A2.A2b is marked active.

    10. State A.A2.A2b entry actions (entA2b()) execute and complete.

  4. The processing of E_one continues once the on event broadcast of E_two has been processed. State A.A1 checks for any valid transitions as a result of event E_one. A valid transition exists from state A.A1.A1a to state A.A1.A1b.

  5. State A.A1.A1a executes and completes exit actions (exitA1a).

  6. State A.A1.A1a is marked inactive.

  7. State A.A1.A1b is marked active.

  8. State A.A1.A1b entry actions (entA1b()) execute and complete.

  9. Parallel state A.A2 is evaluated next. State A.A2 during actions (durA2()) execute and complete. There are no valid transitions as a result of E_one.

  10. State A.A2.A2b during actions (durA2b()) execute and complete.

    State A.A2.A2b is now active as a result of the processing of the on event broadcast of E_two.

  11. The chart goes back to sleep.

This sequence completes the execution of this Stateflow® chart associated with event E_one and the on event broadcast to a parallel state of event E_two. The final chart activity is that parallel substates A.A1.A1b and A.A2.A2b are active.

Tip

Avoid using undirected local event broadcasts. Undirected local event broadcasts can cause unwanted recursive behavior in your chart. Instead, send local events by using directed broadcasts. 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 none, warning, or error. The default setting is warning. For more information, see Undirected event broadcasts (Simulink).

Broadcast Events in Transition Actions

This example shows the behavior of an event broadcast transition action that includes a nested event broadcast in a parallel state. The chart uses implicit ordering of parallel states (see Implicit Ordering of Parallel States).

Stateflow chart with a top-level state called A. A has two parallel substates called A1 and A2. A1 has substates A1a and A1B. A2 has substates A2a and A2b.

Start of Event E_one Processing

Initially, the chart is asleep. Parallel substates A.A1.A1a and A.A2.A2a are active. Event E_one occurs and awakens the chart, which processes the event from the root down through the hierarchy:

  1. The chart root checks to see if there is a valid transition as a result of E_one. There is no valid transition.

  2. State A during actions (durA()) execute and complete.

  3. The children of state A are parallel (AND) states. Because implicit ordering applies, the states are evaluated and executed from left to right and top to bottom. State A.A1 is evaluated first. State A.A1during actions (durA1()) execute and complete.

  4. State A.A1 checks for any valid transitions as a result of event E_one. There is a valid transition from state A.A1.A1a to state A.A1.A1b.

  5. State A.A1.A1a executes and completes exit actions (exitA1a).

  6. State A.A1.A1a is marked inactive.

Event E_two Preempts E_one

  1. The transition action that broadcasts event E_two executes and completes:

    1. The broadcast of event E_two now preempts the transition from state A1a to state A1b that event E_one triggers.

    2. The broadcast of event E_two awakens the chart a second time. The chart root checks to see if there is a valid transition as a result of E_two. No valid transition exists.

    3. State A during actions (durA()) execute and complete.

    4. State A evaluates its children starting with state A.A1. State A.A1during actions (durA1()) execute and complete. State A.A1 is evaluated for valid transitions. There are no valid transitions as a result of E_two within state A1.

    5. State A.A2 is evaluated. State A.A2 during actions (durA2()) execute and complete. State A.A2 checks for valid transitions. State A.A2 has a valid transition as a result of E_two from state A.A2.A2a to state A.A2.A2b.

    6. State A.A2.A2a exit actions (exitA2a()) execute and complete.

    7. State A.A2.A2a is marked inactive.

    8. State A.A2.A2b is marked active.

    9. State A.A2.A2b entry actions (entA2b()) execute and complete.

Event E_one Processing Resumes

  1. State A.A1.A1b is marked active.

  2. State A.A1.A1b entry actions (entA1b()) execute and complete.

  3. Parallel state A.A2 is evaluated next. State A.A2 during actions (durA2()) execute and complete. There are no valid transitions as a result of E_one.

  4. State A.A2.A2b during actions (durA2b()) execute and complete.

    State A.A2.A2b is now active as a result of the processing of event broadcast E_two.

  5. The chart goes back to sleep.

This sequence completes the execution of this Stateflow chart associated with event E_one and the event broadcast on a transition action to a parallel state of event E_two. The final chart activity is that parallel substates A.A1.A1b and A.A2.A2b are active.

Tip

Avoid using undirected local event broadcasts. Undirected local event broadcasts can cause unwanted recursive behavior in your chart. Instead, send local events by using directed broadcasts. 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 none, warning, or error. The default setting is warning. For more information, see Undirected event broadcasts (Simulink).

Broadcast Events in Condition Actions

This example shows the behavior of a condition action event broadcast in a parallel (AND) state. The chart uses implicit ordering of parallel states (see Implicit Ordering of Parallel States).

Stateflow chart with a top-level state called A. A has two parallel substates called A1 and A2. A1 has substates A1a and A1B. A2 has substates A2a and A2b.

Initially, the chart is asleep. Parallel substates A.A1.A1a and A.A2.A2a are active. Event E_one occurs and awakens the chart, which processes the event from the root down through the hierarchy:

  1. The chart root checks to see if there is a valid transition as a result of E_one. No valid transition exists.

  2. State A during actions (durA()) execute and complete.

  3. The children of state A are parallel (AND) states. Because implicit ordering applies, the states are evaluated and executed from top to bottom, and from left to right. State A.A1 is evaluated first. State A.A1 during actions (durA1()) execute and complete.

  4. State A.A1 checks for any valid transitions as a result of event E_one. A valid transition from state A.A1.A1a to state A.A1.A1b exists. A valid condition action also exists. The condition action event broadcast of E_two executes and completes. State A.A1.A1a is still active:

    1. The broadcast of event E_two awakens the Stateflow chart a second time. The chart root checks to see if there is a valid transition as a result of E_two. There is no valid transition.

    2. State A during actions (durA()) execute and complete.

    3. State A evaluates its children starting with state A.A1. State A.A1 during actions (durA1()) execute and complete. State A.A1 is evaluated for valid transitions. There are no valid transitions as a result of E_two within state A1.

    4. State A1a during actions (durA1a()) execute.

    5. State A.A2 is evaluated. State A.A2 during actions (durA2()) execute and complete. State A.A2 checks for valid transitions. State A.A2 has a valid transition as a result of E_two from state A.A2.A2a to state A.A2.A2b.

    6. State A.A2.A2a exit actions (exitA2a()) execute and complete.

    7. State A.A2.A2a is marked inactive.

    8. State A.A2.A2b is marked active.

    9. State A.A2.A2b entry actions (entA2b()) execute and complete.

  5. State A.A1.A1a executes and completes exit actions (exitA1a).

  6. State A.A1.A1a is marked inactive.

  7. State A.A1.A1b is marked active.

  8. State A.A1.A1b entry actions (entA1b()) execute and complete.

  9. Parallel state A.A2 is evaluated next. State A.A2 during actions (durA2()) execute and complete. There are no valid transitions as a result of E_one.

  10. State A.A2.A2b during actions (durA2b()) execute and complete.

    State A.A2.A2b is now active as a result of the processing of the condition action event broadcast of E_two.

  11. The chart goes back to sleep.

This sequence completes the execution of this Stateflow chart associated with event E_one and the event broadcast on a condition action to a parallel state of event E_two. The final chart activity is that parallel substates A.A1.A1b and A.A2.A2b are active.

Tip

Avoid using undirected local event broadcasts. Undirected local event broadcasts can cause unwanted recursive behavior in your chart. Instead, send local events by using directed broadcasts. 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 none, warning, or error. The default setting is warning. For more information, see Undirected event broadcasts (Simulink).