Statechart Implementation: Generated Functions
Consider the following example of code generated from a Statechart (Note: line numbers are included in this code sample for discussion purposes):
In general, the overall code frame of a Statechart looks like the cgDo_A11_CTRLcnt1 function shown above. However, you will discover in the following discussions that code frame is not fixed.
Line 4 resets the nextState variable. This variable will be set only if a transition has been made, and will hold the new state configuration of the Statechart.
Lines 13 and 14 check the nextState variable, to determine if a transition was taken and whether to enforce another step in the TASK holding the Statechart...
Line 16: currentState_A11_CTRLcnt1 = nextState_A11_CTRLcnt1advances the Statechart configuration a step, to hold the configuration of the next step.
Lines 5 to 12 will be replaced with specific code resulting from the specified Statechart logic. For example, two additional functions might be commonly generated here: entry actions and exit actions. If the Statechart logic requires entering/exiting reactions, the functions will resemble the following:
When either of these function are needed, the following changes to cgDo_… will also be made:
Of course, the function calls to cgExitActions_A11_CTRLcnt1() required. See Optimization Algorithms for information on the MicroC algorithms that create more efficient code.