app_easy_timer_cancel checking if expired

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
4 posts / 0 new
Last post
Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
app_easy_timer_cancel checking if expired

Hi there,

I start a timer on app_on_connection. This timer terminates the connection after a given amount of time. If the user disconnects before the timer elapses, the timer should be cancelled. This works in the case that the user disconnects before the timer elapses but it gives me an error when the timer handler terminated the connection.
To my understanding this happens due to the fact that the timer_id that is passed to app_easy_timer_cancel is invalid when the timer has expired. However I thought adding a check like if(conn_timeout != EASY_TIMER_INVALID_TIMER){..} would take care of this issue.

1.) Can somebody please tell me why app_easy_timer_cancel is still executed even though I check for the validity just before ? This is a snippet from the code that is executed at app_on_disconnect.

printf_string("user disconnected!\n\r");
if(conn_timeout != EASY_TIMER_INVALID_TIMER){
//cancel timer
printf_string("conn_timeout was cancelled due to disconnection by user\n\r");
app_easy_timer_cancel (conn_timeout);
}

2.) I used the watch tool from Keil to keep an eye on the value of conn_timeout. It is 0x00 initially and stays this value if I connect and disconnect before the timer elapses. However when the timer does elapse and the callback of conn_timeout is executed, conn_timeout keeps the value 0x03. It stays at this value even if I proceed the software (after it gets stuck on ASSERT_WARNING(0) in void app_easy_timer_cancel(const timer_hnd timer_id)). Also connecting and disconnecting is still possible. Doing this ( quicker than the timer period) also does not make a change to the value 0x03.
What does this value mean? Isn't this value supposed to be reset to 0x00 when the timer elapses or when the timer is cancelled?

Kind regards,
Niek

Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

1) When you setup the timer for counting, and when the timer elapses the handle variable that stores the timer handle doesn't get an invalid value, the timer handle that you check still has a valid timer id if you dont explictly change it in the callback of the timer. For example when the timer elapses and the callback gets executed, in the callback store in timer handle an invalid value and before use the app_easy_timer_cancel() check if the value stored in that handle is valid.

2) As i ve mentioned above the variable that stores the timer's handle is in application level and doesn't get updated when the timer elapses unless you do that explicitly.

Thanks MT_dialog

Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Hi MT_dialog,

Hi MT_dialog,

setting the timer handler to EASY_TIMER_INVALID_TIMER in the callback fixed the issue.
Thank you for your help!

Can you maybe tell me where I can find the definitions like EASY_TIMER_INVALID_TIMER?
In UM-B-050 nor UM-B-051 is the definition EASY_TIMER_INVALID_TIMER mentioned. Am I missing some documents?
I know about this value through the forums but I figure there will be more defined return values like EASY_TIMER_INVALID_TIMER.
(Like I asked before, when the timer handler is valid it returns 0x03; can I find somewhere what these values mean?)

Kind regards,
Niek

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

I dont think that there is any document that mentions that definition, not all definitions and APIs of the SDK are documented. The values that are returned when you set up a timer are just id values are long as they are different from the EASY_TIMER_INVALID_TIMER its a valid timer id.

Thanks MT_dialog