Designing Your Model: Model-Code Correspondence : Statecharts : Statechart - Data Usage

Statechart - Data Usage

When a statechart is created, a StateInfo data type is defined and a few variables of that type are declared.

For the previous example, the StateInfo data type would be named StateInfo_All_CTRLcntl, and would be defined as an unsigned type of 8, 16, or 32 bits (e.g., typedef int8 StateInfo_A11_CTRLcnt1)

The StateInfo variables will be currentState, nextState, and staySame:

StateInfo_A11_CTRLcnt1 currentState_A11_CTRLcnt1;

(global variable)

StateInfo_A11_CTRLcnt1 nextState_A11_CTRLcnt1;

(automatic variable)

StateInfo_A11_CTRLcnt1 staySame_A11_CTRLcnt1;

(automatic variable)

The currentState and nextState variables will always be allocated. The staySame variable will be allocated only if the entering or exiting reaction function is required.

currentState is allocated as a global variable, while nextState and staySame are allocated as local, automatic variables to the statechart function cgDo_....