Stateflow    

Entering a State

A state is entered (becomes active) in one of the following ways:

A state performs its entry action (if specified) when it becomes active. The state is marked active before its entry action is executed and completed.

The execution steps for entering a state are as follows:

  1. If the parent of the state is not active, perform steps 1 through 4 for the parent first.
  2. If this is a parallel state, check to make sure that all sibling parallel states with a higher execution order are active. If not, perform all entry steps for these states first in the appropriate order of entry.
  1. Parallel (AND) states are ordered for entry based on their vertical top-to-bottom position in the diagram editor. Parallel states that occupy the same vertical level are ordered for entry from left to right. In the following example, parallel states A and B are aligned at the same vertical level while states A and C and states B and D are aligned at the same horizontal position. Based on their top-down positions in the diagram editor, the order of execution for these states is A or B, then D and C. Because A is left of B, A is evaluated first and the order of entry is A, B, D, C.

  1. Mark the state active.
  2. Perform any entry actions.
  3. Enter children, if needed:
    1. Execute the default flow paths for the state unless it contains a history junction.
    2. If the state contains a history junction and there is an active child of this state at some point after the most recent chart initialization, perform the entry actions for that child.
    3. If this state has children that are parallel states (parallel decomposition), perform entry steps 1 to 5 for each state according to its entry order.
  4. If this is a parallel state, perform all entry actions for the sibling state next in entry order if one exists.
  5. 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.
  6. The chart goes to sleep.

  Executing a State Executing an Active State