mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-10 15:44:32 +00:00
esp32: use dedicated thread for btstack, fix run loop crash
This commit is contained in:
parent
3534659c26
commit
17b3e0b8c9
@ -132,48 +132,59 @@ void btstack_run_loop_freertos_single_threaded_execute_code_on_main_thread_from_
|
|||||||
/**
|
/**
|
||||||
* Execute run_loop
|
* Execute run_loop
|
||||||
*/
|
*/
|
||||||
static void btstack_run_loop_freertos_single_threaded_execute(void) {
|
static void btstack_run_loop_freertos_single_threaded_task(void *pvParameter){
|
||||||
|
UNUSED(pvParameter);
|
||||||
|
|
||||||
log_info("run loop execute");
|
log_debug("RL: execute");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
// get next timeout
|
// get next timeout
|
||||||
uint32_t timeout_ms = portMAX_DELAY;
|
uint32_t timeout_ms = portMAX_DELAY;
|
||||||
|
log_debug("RL: portMAX_DELAY %u", portMAX_DELAY);
|
||||||
if (timers) {
|
if (timers) {
|
||||||
btstack_timer_source_t * ts = (btstack_timer_source_t *) timers;
|
btstack_timer_source_t * ts = (btstack_timer_source_t *) timers;
|
||||||
|
log_debug("RL: have timer %p", ts);
|
||||||
uint32_t now = btstack_run_loop_freertos_single_threaded_get_time_ms();
|
uint32_t now = btstack_run_loop_freertos_single_threaded_get_time_ms();
|
||||||
|
log_debug("RL: now %u, expires %u", now, ts->timeout);
|
||||||
if (ts->timeout < now){
|
if (ts->timeout < now){
|
||||||
// remove timer before processing it to allow handler to re-register with run loop
|
// remove timer before processing it to allow handler to re-register with run loop
|
||||||
btstack_run_loop_remove_timer(ts);
|
btstack_run_loop_remove_timer(ts);
|
||||||
printf("RL: timer %p\n", ts->process);
|
log_debug("RL: first timer %p", ts->process);
|
||||||
ts->process(ts);
|
ts->process(ts);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
timeout_ms = ts->timeout - now;
|
timeout_ms = ts->timeout - now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop function call
|
// pop function call
|
||||||
function_call_t message = { NULL, NULL };
|
function_call_t message = { NULL, NULL };
|
||||||
printf("RL: wait with timeout %u\n", (int) timeout_ms);
|
log_debug("RL: wait with timeout %u", (int) timeout_ms);
|
||||||
BaseType_t res = xQueueReceive( &btstack_run_loop_queue, &message, pdMS_TO_TICKS(timeout_ms));
|
BaseType_t res = xQueueReceive( btstack_run_loop_queue, &message, pdMS_TO_TICKS(timeout_ms));
|
||||||
printf("RL: queue receive res %u\n", res);
|
log_debug("RL: queue receive res %u", res);
|
||||||
if (res == pdPASS && message.fn){
|
if (res == pdPASS && message.fn){
|
||||||
// execute code on run loop
|
// execute code on run loop
|
||||||
printf("RL: execute %p\n", message.fn);
|
log_debug("RL: execute %p", message.fn);
|
||||||
message.fn(message.arg);
|
message.fn(message.arg);
|
||||||
} else {
|
} else {
|
||||||
printf("RL: just timeout\n");
|
log_debug("RL: just timeout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void btstack_run_loop_freertos_single_threaded_execute(void) {
|
||||||
|
// use dedicated task, might not be needed in all cases
|
||||||
|
xTaskCreate(&btstack_run_loop_freertos_single_threaded_task, "btstack_task", 2048, NULL, 5, NULL);
|
||||||
|
// btstack_run_loop_freertos_single_threaded_task(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void btstack_run_loop_freertos_single_threaded_init(void){
|
static void btstack_run_loop_freertos_single_threaded_init(void){
|
||||||
timers = NULL;
|
timers = NULL;
|
||||||
|
|
||||||
// queue to receive events: up to 2 calls from transport, up to 3 for app
|
// queue to receive events: up to 2 calls from transport, up to 3 for app
|
||||||
btstack_run_loop_queue = xQueueCreate(5, sizeof(function_call_t));
|
btstack_run_loop_queue = xQueueCreate(5, sizeof(function_call_t));
|
||||||
|
|
||||||
printf("run loop init, queue item size %u\n", (int) sizeof(function_call_t));
|
log_info("run loop init, queue item size %u", (int) sizeof(function_call_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user