Statechart Implementation

Statechart Implementation

 

Statecharts are used to define the behavior of a Control Activity. For the purposes of code generation in MicroC and our discussion here, a single Statechart is considered to be the Statechart directly connected to a Control Activity, all of its sub-charts, and the generics instantiated within them. In short, all the states under the root are represented by the control Activity.

For example, for the control Activity A11_CTRL, the following two functions will be generated:

void cgActivity_A11_CTRLcnt1(void)
void cgDo_A11_CTRLcnt1(void)
 

 

The bodies of the generated code for these functions resembles the following:

void
cgDo_A11_CTRLcnt1(void)
{
StateInfo_A11_CTRLcnt1 nextState_A11_CTRLcnt1 = 0;
if (currentState_A11_CTRLcnt1 == 0) {
nextState_A11_CTRLcnt1 = FS_A11_CTRLst2;
}
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;
}
}
void
cgActivity_A11_CTRLcnt1(void)
{
cgDo_A11_CTRLcnt1();
}
 
 

Note that the function cgActivity_A11_CTRLcnt1() simply calls cgDo_A11_CTRLcnt1(). A more detailed discussion of the cgDo_… function is found below.

Note:  
Further Optimization: This might be changed, as the wrapping function, “cgActivity_A11_CTRLcnt1” in the above example, could be dropped.
Use the Compilation Profile >Setting >General >Use Macros flag to control function generation vs. pre-processor macro.