Statechart Implementation : Optimization Algorithms : Inline Setting of the “Need Another Step” Bit

Inline Setting of the “Need Another Step” Bit

To improve code efficiency, you can specify No. of Transition <= 0. This criteria determines whether the optimization is performed. When you apply this optimization, MicroC makes the following changes to the generated code:

The declaration of StateInfo_<CTRL Activity

Name > nextState_<CTRL ActivityName = 0;

is removed— there is no need for this local variable after the optimization.
All the assignments to nextState_<CTRL Activity Name> are replaced with assignments to currentState_<CTRL Activity Name>.
After every transition, MicroC makes the following assignment:

cgGlobalFlags |= BITSUPERSTEP_<Task Name>;
The code at the end of the cgDo...() is removed. This is the code that was inlined:

if (nextState_<CTRL Activity Name> != 0) {

if (currentState_<CTRL Activity Name> !=

nextState_<CTRL Activity Name>)

cgGlobalFlags |= BITSUPERSTEP_<Task Name>;

currentState_<CTRL Activity Name> =

nextState_<CTRLActivity Name>;

}

 

If a transition is inside an AndState component, the assignment to currentState includes a reset of the bits that represent the component that is the LCA of the transition. For example:

nextState_OPT_NEXT_STATE_CTRL =

(nextState_OPT_NEXT_STATE_CTR &~

(FM2_<ComponentLCA of Transition>)) |FS_<Next State>;

 

 

Note: The optimization will not take place if there is an entering or exiting reaction that could not be optimized out.