Designing Your Model: Model-Code Correspondence : Statecharts : Timeout Implementation : INSTALL_TIMEOUT Macro

INSTALL_TIMEOUT Macro

The INSTALL_TIMEOUT macro has three arguments:

This allows the code to reuse the same timeout variable with different counters. The first argument is concatenated to the INSTALL macro, as shown here. In the code, a call like the following will be used:

INSTALL_TM(tm_999999962, 10, SYS_TIMER)

This call will set a timeout to expire 10 ticks from the current time of SYS_TIMER. The macro itself will be defined as follows:

#define INSTALL_TM_tm_999999962(D, C) \
cgTimeoutsMask |= tm_999999962_TM_MASK;\
tm_999999962_TIME = currentTick + (D);

This call will assign to tm_999999962_TIME which is a variable of type Timeout Variable Type the current counter value, help in currentTick plus the requested delay time help in D. In addition, the bit tm_999999962_TM_MASK is set to flag that this timeout is pending.

A test for timeout expiration is carried out in the function:

genTmEvent_<CTRL_CHART_NAME>(<Timeout Variable Type>
currentTickVar, <Buffer> * buff, uint8 counterIndex)

The third parameter, uint8 counterIndex, holds the index of the counter that is referred to in the current call to this function. Before each call to this function, the correct counter would be read into the currentTick global variable.

For each Timeout Variable, there are three options for code generation inside the genTmEvent_… function:

1.
2.

if(counterIndex == <ITS_COUNTER_NAME>_INDEX &&
cgTimeoutsMask & tm_999999993_TM_MASK &&
currentTickVar >= tm_999999993_TIME) {
GEN_IN_BUFF(tm_999999993, buff);
cgTimeoutsMask &= ~tm_999999993_TM_MASK;
}

3.
a.
In the file, glob_dat.c a uint8 variable tm_999999993_counter¡ is generated, holding the index of the current relevant counter.
b.
In the file macro_def.h, along with the previous code that was generated for the INSTALL_TIMEOUT macro, there is one more statement that keeps the INDEX of the counter for which the timeout was installed.

The index that is passed to the function is compared with the index of the counter that was used when the timeout was installed. This enables the application to identify the counter on which the timeout is pending.