Software Counter(s) are used as the basis for the implementation of timeouts. When a timeout or delay is set, the current value of the relevant Software Counter will be added to the requested delay time, and stored in a variable, using a defined macro:
INSTALL_TIMEOUT
. By default, MicroC relates to the primary Software Counter defined in the compilation profile.Note: Use Compilation Profile >Setting >OS >System Counter Timer to define the primary Software Counter.Other Software Counter(s) might be referenced using an optional third argument in the timeout operator. The name of the counter is as written in the model using the syntax:
In this example, the name of the counter is:
myCounter
. Each counter receives an index value defined as <counter_name>_INDEX. That index value identifies that specific counter in the application.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:
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:
That 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 done in the function:
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:
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. If there is more than one counter that the Timeout Variable can be installed for, then the code will include the following provisions:
In theglob_dat.c
file an uint8 variable is generated: tm_999999993_counter¡that holds the index of the current relevant counter.
Inmacro_def.h
file along with the previous code that was generated for theINSTALL_TIMEOUT
macro, there is one more statement that keep the INDEX of the counter that the timeout was installed for.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 that the timeout is pending on.
When the option Generate Timer Overflow Task is selected, in the compilation profile setting, then the following code elements are generated: