nrf5-zephyr: use run loop base

This commit is contained in:
Matthias Ringwald 2021-03-04 15:16:59 +01:00
parent b23e1511be
commit 1a6cbb821e
2 changed files with 15 additions and 56 deletions

View File

@ -6,6 +6,7 @@ obj-y += \
btstack_memory_pool.o \
btstack_ring_buffer.o \
btstack_run_loop.o \
btstack_run_loop_base.o \
btstack_tlv.o \
btstack_util.o \
hci.o \

View File

@ -194,64 +194,22 @@ static void btstack_run_loop_zephyr_set_timer(btstack_timer_source_t *ts, uint32
ts->timeout = k_uptime_get_32() + 1 + timeout_in_ms;
}
/**
* Add timer to run_loop (keep list sorted)
*/
static void btstack_run_loop_zephyr_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
if ((btstack_timer_source_t *) it->next == 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;
}
}
ts->item.next = it->next;
it->next = (btstack_linked_item_t *) ts;
}
/**
* Remove timer from run loop
*/
static int btstack_run_loop_zephyr_remove_timer(btstack_timer_source_t *ts){
return btstack_linked_list_remove(&timers, (btstack_linked_item_t *) ts);
}
static void btstack_run_loop_zephyr_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
}
/**
* Execute run_loop
*/
static void btstack_run_loop_zephyr_execute(void) {
while (1) {
// get next timeout
int32_t timeout_ticks = K_FOREVER;
if (timers) {
btstack_timer_source_t * ts = (btstack_timer_source_t *) timers;
uint32_t now = k_uptime_get_32();
if (ts->timeout < now){
// remove timer before processing it to allow handler to re-register with run loop
btstack_run_loop_remove_timer(ts);
// printf("RL: timer %p\n", ts->process);
ts->process(ts);
continue;
}
timeout_ticks = ts->timeout - now;
// process timers
uint32_t now = k_uptime_get_32();
btstack_run_loop_base_process_timers(now);
// get time until next timer expires
int32_t timeout_ticks = btstack_run_loop_base_get_time_until_timeout(now);
if (timeout_ticks < 0){
timeout_ticks = K_FOREVER;
}
// process RX fifo only
// process RX fifo only
struct net_buf *buf = net_buf_get(&rx_queue, timeout_ticks);
if (buf){
transport_deliver_controller_packet(buf);
@ -260,7 +218,7 @@ static void btstack_run_loop_zephyr_execute(void) {
}
static void btstack_run_loop_zephyr_btstack_run_loop_init(void){
timers = NULL;
btstack_run_loop_base_init();
}
static const btstack_run_loop_t btstack_run_loop_wiced = {
@ -270,10 +228,10 @@ static const btstack_run_loop_t btstack_run_loop_wiced = {
NULL,
NULL,
&btstack_run_loop_zephyr_set_timer,
&btstack_run_loop_zephyr_add_timer,
&btstack_run_loop_zephyr_remove_timer,
&btstack_run_loop_base_add_timer,
&btstack_run_loop_base_remove_timer,
&btstack_run_loop_zephyr_execute,
&btstack_run_loop_zephyr_dump_timer,
&btstack_run_loop_base_dump_timer,
&btstack_run_loop_zephyr_get_time_ms,
};
/**