Main Content

Execution of aStateflowChart

When a Stateflow®chart wakes up, the chart follows a workflow and executes actions. A Stateflow chart wakes up:

  • At each time step

  • When the Stateflow chart receives an event

When a chart wakes up for the first time, the chart is initialized and becomes active, as described inWorkflow for Entering a Chart or State. When there are no more actions to take, the chart goes to sleep until a new time step or event wakes up the chart.

Workflow forStateflowChart Execution

This flow chart shows the progression of events that Stateflow takes when executing a chart or state. In this flow chart, the current state refers to the state in which a decision or a process takes place.

Flow chart that shows the steps for executing a chart or state.

Default Transitions

Adefault transition是一个过渡,没有来源。In a Stateflow chart that does not contain any states, a default transition marks the start of a flow chart. For more information, seeCreate Flow Charts in Stateflow.

If a Stateflow chart does not contain any states, the chart evaluates the default transition paths each time the chart wakes up. After marking a default transition for evaluation, the chart follows the steps shown inWorkflow for Evaluating Transitions.

Note

Charts evaluate default transition paths inside a state only during state entry, and not each time the chart wakes up.

Outer Transition

Anouter transitionis a transition that exits the source state. A Stateflow chart marks outer transitions for evaluation as the first step in executing a state. After marking an outer transition for evaluation, the chart follows the steps shown inWorkflow for Evaluating Transitions.

During Actions

Aduringaction is an action defined in a state label actions by using the prefixduringordu. For more information, seeDefine Actions in a State.

A state performsduringactions when the chart wakes up, the state is active, and there are no valid outer transitions.

Inner Transitions

Aninner transitionis a transition that does not exit the source state. For more information, seeControl Chart Execution by Using Inner Transitions.

A Stateflow chart marks inner transitions for evaluation after a state performsduringactions. After marking an inner transition for evaluation, the chart follows the steps shown inWorkflow for Evaluating Transitions.

Chart Execution with a Valid Transition

In this example, the Stateflow chart has been initialized and theentry行动已经执行了StateAandStateA1. A new time step occurs and the chart wakes up.

At this time step,x = 5,y = 2, andz = 0.

Stateflow chart with top-level states called StateA and StateB. StateA has substates StateA1 and StateA2. StateB has substates StateB1 and StateB2.

The chart executes these steps:

  1. The chart has an active substate,StateA.

  2. StateAhas an outer transition toStateB. The chart determines that the transition is valid.

  3. The chart marksStateB条目和StateAis marked for exit.

  4. To exitStateA, the chart follows the steps shown inWorkflow for Exiting a State.

  5. To enterStateB, the chart follows the steps shown inWorkflow for Entering a Chart or State

Chart Execution Without a Valid Transition

In this example, the Stateflow chart has been initialized and theentry行动已经执行了StateAandStateA1. A new time step occurs and the chart wakes up.

At this time step,x = 3,y = 0, andz = 0.

Stateflow chart with top-level states called StateA and StateB. StateA has substates StateA1 and StateA2. StateB has substates StateB1 and StateB2.

The chart executes these steps:

  1. The chart has an active substate,StateA.

  2. StateAhas an outer transition toStateB. The chart determines that the transition is invalid.

  3. The chart performs theduringactions forStateA. Nowy = 1.

  4. StateAdoes not have any inner transitions.

  5. The active substate ofStateAisStateA1.

  6. StateA1has an outer transition toStateA2. The chart determines that the transition is invalid.

  7. The chart performs theduringactions forStateA1. Nowx = 4.

  8. StateA1does not have any active substates.

  9. The chart goes to sleep.

Related Topics