Statechart Implementation : Statechart Implementation: Generated Functions : AndState Implementation

AndState Implementation

The implementation of AndState compresses a few otherwise different StateInfo variables into a single one, thus using potentially less RAM. However, in order to relate to each of the different parallel state hierarchies, some ROM is required to implement bit-masking. As a general rule, it is preferable (from a code size perspective) to use AndState when having few independent very small statecharts. The difference in the generated code will be that instead of few control activities, each having related cgDo_functions as is the case with a few Statecharts, here only one such control activity is required with one related cgDo_function. This code for such a function will only appear once. The function’s code frame would resemble the following:

StateInfo_A11_CTRLcnt1 nextState_A11_CTRLcnt1 = 0;
if (currentState_A11_CTRLcnt1 == 0) {
nextState_A11_CTRLcnt1 = FS_A11_CTRLst2;
}. MicroC 65
Timeout Implementation
else
{
The rest of the Statechart logic
}
if (nextState_A11_CTRLcnt1 != 0) {
if (currentState_A11_CTRLcnt1 !=
nextState_A11_CTRLcnt1)
cgGlobalFlags |= BITSUPERSTEP_TASK1;
currentState_A11_CTRLcnt1 = nextState_A11_CTRLcnt1;
}

On the other hand, the test for being in leaf-state will be done using the inState test and not inLeafState test. The inState test requires one more integer comparison then the inLeafState test. Thus, it is recommend for each particular case that the developer test both options and compare the results to choose the optimum implementation.