Timers not stopping | Telit Cinterion IoT Developer Community
April 18, 2022 - 3:59pm, 1115 views
The APIs for creating, starting, and stopping timers are not working.
The APIs I am using follows this basic structure found in this documentation: https://github.com/Thalhammer/simcom_dam/blob/master/api/include/qapi/qa...
Which is basically this code (from the link above):
qapi_TIMER_handle_t timer_handle;
qapi_TIMER_def_attr_t timer_def_attr;
timer_def_attr.cb_type = TIMER_FUNC1_CB_TYPE; //notification type
timer_def_attr.sigs_func_ptr = &timer_test_cb; //callback to call when timer expires
timer_def_attr.sigs_mask_data = 0x1; //this data will be returned in the callback
timer_def_attr.deferrable = false; //set to true for non-deferrable timer
qapi_Timer_def( &timer_handle, &timer_def_attr);
qapi_TIMER_set_attr_t timer_set_attr;
timer_set_attr.reload = FALSE; //Do not restart timer after it expires
timer_set_attr.time = time_duration;
timer_set_attr.unit = T_MSEC;
//set or start the timer
qapi_Timer_set( timer_handle, &timer_set_attr);
//stop a running timer
qapi_Timer_stop( timer_handle);
//Undef the timer. Releases memory allocated in qapi_Timer_Def()
qapi_Timer_undef( timer_handle);
I did some tests and what is happening is that the timer is not being stopped, that is, it keeps expiring, and printing the message on the callback I have registered.
The SDK I am using is for the EXS82-W module.
SDK Version (according to the SDK_Release_Note.pdf) is 0.2.002
DocID: iot_sdk_rn_v0.2.002
This is a more detailed code that I have used to test.
Basically, it runs on an infinite loop, then starts the timer.
Then, the code falls into an infinite loop doing nothing, so the timer will expire and tries to Stop() and Undef() itself.
I see these two behaviors:
1 - If I leave the Stop() and Undef() in the callback, then a segmantation fault will happen, because Undef() will cause some access violation.
2 - If I comment the Undef() call, and leave only the Stop() un-commented, then the timer will expire, and run again, and expire, run again, which will print the message TIMER EXPIRED, etc.. and repeat.
Have you tried to call stop and undef functions not from the callback function?
Followed your instructions @Bartlomiej, by removing the undef from the callback.
I figured out the problem, here is the solution:
Turns out that the undef should be called only once, when the timer is no longer used (never restarted again).
So, my problem was that I was calling undef when I wanted the timer to stop. And later on, I called the set() for thet same timer, which caused some Segfault or something (I forgot now, but I could see through UART the error message).
Thus, to have the timer working properly, I just had to remove the undef() call from my code, and now the timer works as required:
1 - start timer
2 - if specific event occurs, then I reload the timer
3 - if specific event does not occurs during the timer period, then timer will expire and do some work