wiced: handle time_ms overrun after 49 days

This commit is contained in:
Matthias Ringwald 2019-08-04 20:07:47 +02:00
parent 9155bf8c4c
commit 85ce275a87

View File

@ -46,12 +46,14 @@
#include "wiced.h"
#include <stddef.h> // NULL
#include "btstack_run_loop_wiced.h"
#include "btstack_linked_list.h"
#include "btstack_debug.h"
#include "btstack_util.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_wiced.h"
#include <stddef.h> // NULL
typedef struct function_call {
wiced_result_t (*fn)(void * arg);
@ -87,9 +89,9 @@ static void btstack_run_loop_wiced_add_timer(btstack_timer_source_t *ts){
log_error( "btstack_run_loop_timer_add error: timer to add already in list!");
return;
}
if (ts->timeout < ((btstack_timer_source_t *) it->next)->timeout) {
break;
}
// exit if new timeout before list timeout
int32_t delta = btstack_time_delta(ts->timeout, next->timeout);
if (delta < 0) break;
}
ts->item.next = it->next;
it->next = (btstack_linked_item_t *) ts;
@ -131,14 +133,14 @@ static void btstack_run_loop_wiced_execute(void) {
if (timers) {
btstack_timer_source_t * ts = (btstack_timer_source_t *) timers;
uint32_t now = btstack_run_loop_wiced_get_time_ms();
if (ts->timeout < now){
int32_t delta_ms = btstack_time_delta(ts->timeout, now);
if (delta_ms <= 0){
// remove timer before processing it to allow handler to re-register with run loop
btstack_run_loop_wiced_remove_timer(ts);
// printf("RL: timer %p\n", ts->process);
ts->process(ts);
continue;
}
timeout_ms = ts->timeout - now;
timeout_ms = delta_ms;
}
// pop function call
@ -146,7 +148,6 @@ static void btstack_run_loop_wiced_execute(void) {
wiced_rtos_pop_from_queue( &btstack_run_loop_queue, &message, timeout_ms);
if (message.fn){
// execute code on run loop
// printf("RL: execute %p\n", message.fn);
message.fn(message.arg);
}
}