Hello,
We are using the following:
We utilize a lot of calls to the _time_get and _time_diff functions, and have a lot of variables (maybe 20?) that are declared as type TIME_STRUCT.
We are seeing strange behavior in logic statements that determine if an elapsed time has been longer than a constant value. Below is some psuedo code of our current logic:
//This code is executed in a task that runs ~ every 200 ms
#define TIME_ELEMENTS 10
#define TIME_DELAY 2
TIME_STRUCT start_time[ TIME_ELEMENTS ] = {0};
TIME_STRUCT end_time[ TIME_ELEMENTS ] = {0};
TIME_STRUCT time_diff[ TIME_ELEMENTS ] = {0};
uint8_t i;
uint8_t response[ TIME_ELEMENTS ] = {0};
bool flag[ TIME_ELEMENTS ] = false;
for(i=0; i<TIME_ELEMENTS; i++)
{
response[k] = get_external_variable( k );
if(response[k] == 1)
{
if( flag[k] == false )
{
flag[k] = true;
_time_get(&start_time[k]);
}
else
{
_time_get(&end_time[k]);
_time_diff(&start_time[k], &end_time[k], &time_diff[k])
}
if(time_diff[k].SECONDS >= TIME_DELAY)
{
// Code should xecute here only after TIME_DELAY,
// but it jumps here immediately.
}
}
else
{
start_time[k].SECONDS = 0;
start_time[k].MILLISECONDS = 0;
time_diff[k].SECONDS = 0;
time_diff[k].MILLISECONDS = 0;
end_time[k].SECONDS = 0;
end_time[k].MILLISECONDS = 0;
flag[k] = false;
} // End else
} // End for
I searched the forums for some MQX time problems, and found the following post:
How to solve MQX RTCS_time_get() problem?
I think they use the RTCS for _get_time, but should be similar to non-RTCS _get_time function call.
Does anyone know if the issue they were describing has been resolved in MQX for KSDK v1.2.0?
For MQX for KSDK1.2, the RTCS is the same as MQX 4.2.0.
Hi Jschepler:
This issue is fixed in MQX 4.0.1 (May 2013).
Calculation of time interval was replaced by RTCS_timer_get_interval() to avoid the time-rollover issue. You can check the MQX 4.0.1 release note for more details.
Regarding your issue
if(time_diff[k].SECONDS >= TIME_DELAY)
{
// Code should xecute here only after TIME_DELAY,
// but it jumps here immediately.
}
Have you check the real value of time_diff[k].SECONDS ?
Regards
Daniel