Stateflow |
 |
Semantic Rules Summary
Entering a Chart
The set of default flow paths is executed (see Executing a Set of Flow Graphs on page 8-63). If this does not cause a state entry and the chart has parallel decomposition, then each parallel state is entered (see Entering a State).
If executing the default flow paths does not cause state entry, a state inconsistency error occurs.
Executing an Active Chart
If the chart has no states, each execution is equivalent to initializing a chart. Otherwise, the active children are executed. Parallel states are executed in the same order that they are entered.
Entering a State
- If the parent of the state is not active, perform steps 1-4 for the parent.
- If this is a parallel state, check that all siblings with a higher (i.e., earlier) entry order are active. If not, perform all entry steps for these states first.
- Mark the state active.
- Perform any entry actions.
- Enter children, if needed:
- If the state contains a history junction and there was an active child of
this state at some point after the most recent chart initialization, perform
the entry actions for that child. Otherwise, execute the default flow paths
for the state.
- If this state has parallel decomposition, i.e., has children that are parallel
states, perform entry steps 1-5 for each state according to its entry order.
- If this is a parallel state, perform all entry actions for the sibling state next in entry order if one exists.
- If the transition path parent is not the same as the parent of the current state, perform entry steps 6 and 7 for the immediate parent of this state.
Executing an Active State
- The set of outer flow graphs is executed (see Executing a Set of Flow Graphs). If this causes a state transition, execution stops. (Note that this step is never required for parallel states)
- During actions and valid on-event actions are preformed.
- The set of inner flow graphs is executed. If this does not cause a state transition, the active children are executed, starting at step 1. Parallel states are executed in the same order that they are entered.
Exiting an Active State
- If this is a parallel state, make sure that all sibling states that were entered after this state have already been exited. Otherwise, perform all exiting steps on those sibling states.
- If there are any active children perform the exit steps on these states in the reverse order they were entered.
- Perform any exit actions.
- Mark the state as inactive.
Executing a Set of Flow Graphs
Flow graphs are executed by starting at step 1 below with a set of starting transitions. The starting transitions for inner flow graphs are all transition segments that originate on the respective state and reside entirely within that state. The starting transitions for outer flow graphs are all transition segments that originate on the respective state but reside at least partially outside that state. The starting transitions for default flow graphs are all default transition segments that have starting points with the same parent:
- A set of transition segments is ordered.
- While there are remaining segments to test, a segment is tested for validity. If the segment is invalid, move to the next segment in order. If the segment is valid, execution depends on the destination:
States
No more transition segments are tested and a transition path is formed
by backing up and including the transition segment from each preceding
junction until the respective starting transition.
- The states that are the immediate children of the parent of the transition
path are exited (see Exiting an Active State).
The transition action from the final transition segment is executed.
- The destination state is entered (see Entering a State).
Junctions with no outgoing transition segments
Testing stops without any states being exited or entered.
Junctions with outgoing transition segments
Step 1 is repeated with the set of outgoing segments from the junction.
After testing all outgoing transition segments at a junction, back up the incoming transition segment that brought you to the junction and continue at step 2, starting with the next transition segment after the back up segment. The set of flow graphs is done executing when all starting transitions have been tested.
Executing an Event Broadcast
Output edge trigger event execution is equivalent to changing the value of an output data value. All other events have the following execution:
- If the receiver of the event is active, then it is executed (see Executing an Active Charton page 8-62 and Executing an Active State on page 8-63). (The event receiver is the parent of the event unless the event was explicitly directed to a receiver using the
send()
function.)
If the receiver of the event is not active, nothing happens.
- After broadcasting the event, the broadcaster performs early return logic based on the type of action statement that caused the event.
Action Type
|
Early Return Logic
|
State Entry
|
If the state is no longer active at the end of the event broadcast, any remaining steps in entering a state are not performed.
|
State Exit
|
If the state is no longer active at the end of the event broadcast, any remaining exit actions and steps in state transitioning are not performed.
|
State During
|
If the state is no longer active at the end of the event broadcast, any remaining steps in executing an active state are not performed.
|
Condition
|
If the origin state of the inner or outer flow graph or parent state of the default flow graph is no longer active at the end of the event broadcast, the remaining steps in the execution of the set of flow graphs are not performed.
|
Transition
|
If the parent of the transition path is not active or if that parent has an active child, the remaining transition actions and state entry are not performed.
|
| Parallel (AND) States | | Building Targets |  |