mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-26 02:37:41 +00:00
btstack_run_loop_wiced: use run loop base
This commit is contained in:
parent
86dbc093a7
commit
6cdca94f97
@ -48,6 +48,7 @@
|
||||
|
||||
#include "btstack_run_loop_wiced.h"
|
||||
|
||||
#include "btstack_run_loop_base.h"
|
||||
#include "btstack_linked_list.h"
|
||||
#include "btstack_debug.h"
|
||||
#include "btstack_util.h"
|
||||
@ -78,44 +79,6 @@ static void btstack_run_loop_wiced_set_timer(btstack_timer_source_t *ts, uint32_
|
||||
ts->timeout = btstack_run_loop_wiced_get_time_ms() + timeout_in_ms + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add timer to run_loop (keep list sorted)
|
||||
*/
|
||||
static void btstack_run_loop_wiced_add_timer(btstack_timer_source_t *ts){
|
||||
btstack_linked_item_t *it;
|
||||
for (it = (btstack_linked_item_t *) &timers; it->next ; it = it->next){
|
||||
// don't add timer that's already in there
|
||||
btstack_timer_source_t * next = (btstack_timer_source_t *) it->next;
|
||||
if (next == ts){
|
||||
log_error( "btstack_run_loop_timer_add error: timer to add already in list!");
|
||||
return;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove timer from run loop
|
||||
*/
|
||||
static bool btstack_run_loop_wiced_remove_timer(btstack_timer_source_t *ts){
|
||||
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
|
||||
}
|
||||
|
||||
static void btstack_run_loop_wiced_dump_timer(void){
|
||||
#ifdef ENABLE_LOG_INFO
|
||||
btstack_linked_item_t *it;
|
||||
int i = 0;
|
||||
for (it = (btstack_linked_item_t *) timers; it ; it = it->next){
|
||||
btstack_timer_source_t *ts = (btstack_timer_source_t*) it;
|
||||
log_info("timer %u, timeout %u\n", i, (unsigned int) ts->timeout);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// schedules execution similar to wiced_rtos_send_asynchronous_event for worker threads
|
||||
void btstack_run_loop_wiced_execute_code_on_main_thread(wiced_result_t (*fn)(void *arg), void * arg){
|
||||
function_call_t message;
|
||||
@ -129,21 +92,18 @@ void btstack_run_loop_wiced_execute_code_on_main_thread(wiced_result_t (*fn)(voi
|
||||
*/
|
||||
static void btstack_run_loop_wiced_execute(void) {
|
||||
while (true) {
|
||||
// get next timeout
|
||||
|
||||
// process timers
|
||||
uint32_t now = btstack_run_loop_wiced_get_time_ms();
|
||||
btstack_run_loop_base_process_timers(now);
|
||||
|
||||
// get time until next timeout
|
||||
int32_t timeout_next_timer_ms = btstack_run_loop_base_get_time_until_timeout(now);
|
||||
uint32_t timeout_ms = WICED_NEVER_TIMEOUT;
|
||||
if (timers) {
|
||||
btstack_timer_source_t * ts = (btstack_timer_source_t *) timers;
|
||||
uint32_t now = btstack_run_loop_wiced_get_time_ms();
|
||||
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);
|
||||
ts->process(ts);
|
||||
continue;
|
||||
}
|
||||
timeout_ms = delta_ms;
|
||||
if (timeout_next_timer_ms >= 0){
|
||||
timeout_ms = (uint32_t) timeout_next_timer_ms;
|
||||
}
|
||||
|
||||
|
||||
// pop function call
|
||||
function_call_t message = { NULL, NULL };
|
||||
wiced_rtos_pop_from_queue( &btstack_run_loop_queue, &message, timeout_ms);
|
||||
@ -155,7 +115,7 @@ static void btstack_run_loop_wiced_execute(void) {
|
||||
}
|
||||
|
||||
static void btstack_run_loop_wiced_btstack_run_loop_init(void){
|
||||
timers = NULL;
|
||||
btstack_run_loop_base_init();
|
||||
|
||||
// queue to receive events: up to 2 calls from transport, up to 3 for app
|
||||
wiced_rtos_init_queue(&btstack_run_loop_queue, "BTstack Run Loop", sizeof(function_call_t), 5);
|
||||
@ -175,9 +135,9 @@ static const btstack_run_loop_t btstack_run_loop_wiced = {
|
||||
NULL,
|
||||
NULL,
|
||||
&btstack_run_loop_wiced_set_timer,
|
||||
&btstack_run_loop_wiced_add_timer,
|
||||
&btstack_run_loop_wiced_remove_timer,
|
||||
&btstack_run_loop_base_add_timer,
|
||||
&btstack_run_loop_base_remove_timer,
|
||||
&btstack_run_loop_wiced_execute,
|
||||
&btstack_run_loop_wiced_dump_timer,
|
||||
&btstack_run_loop_base_dump_timer,
|
||||
&btstack_run_loop_wiced_get_time_ms,
|
||||
};
|
||||
|
@ -49,6 +49,7 @@ $(NAME)_SOURCES += \
|
||||
../../src/btstack_memory_pool.c \
|
||||
../../src/btstack_resample.c \
|
||||
../../src/btstack_run_loop.c \
|
||||
../../src/btstack_run_loop_base.c \
|
||||
../../src/btstack_tlv.c \
|
||||
../../src/btstack_util.c \
|
||||
../../src/hci.c \
|
||||
|
Loading…
x
Reference in New Issue
Block a user