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.
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
Aduring
action is an action defined in a state label actions by using the prefixduring
ordu
. For more information, seeDefine Actions in a State.
A state performsduring
actions 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 performsduring
actions. 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
行动已经执行了StateA
andStateA1
. A new time step occurs and the chart wakes up.
At this time step,x = 5
,y = 2
, andz = 0
.
The chart executes these steps:
The chart has an active substate,
StateA
.StateA
has an outer transition toStateB
. The chart determines that the transition is valid.The chart marks
StateB
条目和StateA
is marked for exit.To exit
StateA
, the chart follows the steps shown inWorkflow for Exiting a State.To enter
StateB
, 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
行动已经执行了StateA
andStateA1
. A new time step occurs and the chart wakes up.
At this time step,x = 3
,y = 0
, andz = 0
.
The chart executes these steps:
The chart has an active substate,
StateA
.StateA
has an outer transition toStateB
. The chart determines that the transition is invalid.The chart performs the
during
actions forStateA
. Nowy = 1
.StateA
does not have any inner transitions.The active substate of
StateA
isStateA1
.StateA1
has an outer transition toStateA2
. The chart determines that the transition is invalid.The chart performs the
during
actions forStateA1
. Nowx = 4
.StateA1
does not have any active substates.The chart goes to sleep.