diff --git a/samples/sid_end_device/src/sidewalk.c b/samples/sid_end_device/src/sidewalk.c index bbc840dd6..1c9a17979 100644 --- a/samples/sid_end_device/src/sidewalk.c +++ b/samples/sid_end_device/src/sidewalk.c @@ -15,12 +15,28 @@ LOG_MODULE_REGISTER(sidewalk_app, CONFIG_SIDEWALK_LOG_LEVEL); static struct k_thread sid_thread; K_THREAD_STACK_DEFINE(sid_thread_stack, CONFIG_SIDEWALK_THREAD_STACK_SIZE); +static struct k_thread sid_process_thread; +K_THREAD_STACK_DEFINE(sid_process_thread_stack, CONFIG_SIDEWALK_THREAD_STACK_SIZE); + K_MSGQ_DEFINE(sidewalk_thread_msgq, sizeof(sidewalk_ctx_event_t), CONFIG_SIDEWALK_THREAD_QUEUE_SIZE, 4); K_SEM_DEFINE(sid_thread_started, 0, 1); K_SEM_DEFINE(sid_process_requested, 0, 1); + +static void sid_process_thread_entry(void *context, void *unused, void *unused2) +{ + sidewalk_ctx_t *sid = (sidewalk_ctx_t *)context; + ARG_UNUSED(unused); + ARG_UNUSED(unused2); + while (true) { + if (0 == k_sem_take(&sid_process_requested, K_NO_WAIT)) { + sidewalk_event_process(sid, NULL); + } + } +} + static void sid_thread_entry(void *context, void *unused, void *unused2) { ARG_UNUSED(unused); @@ -32,7 +48,7 @@ static void sid_thread_entry(void *context, void *unused, void *unused2) k_sem_give(&sid_thread_started); while (1) { - int err = k_msgq_get(&sidewalk_thread_msgq, &event, K_MSEC(1)); + int err = k_msgq_get(&sidewalk_thread_msgq, &event, K_FOREVER); #if CONFIG_SIDEWALK_TRACE_SIDEWALK_QUEUE LOG_INF("event handler get = %p, sidewalk workq usage (%d/%d) ( after get )", (void *)(event.handler), k_msgq_num_used_get(&sidewalk_thread_msgq), @@ -57,10 +73,6 @@ static void sid_thread_entry(void *context, void *unused, void *unused2) LOG_ERR("Sidewalk msgq err %d", err); } } - - if (0 == k_sem_take(&sid_process_requested, K_NO_WAIT)) { - sidewalk_event_process(sid, NULL); - } } LOG_ERR("Sidewalk thread ends. You should never see this message."); @@ -72,6 +84,10 @@ void sidewalk_start(sidewalk_ctx_t *context) K_THREAD_STACK_SIZEOF(sid_thread_stack), sid_thread_entry, context, NULL, NULL, CONFIG_SIDEWALK_THREAD_PRIORITY, 0, K_NO_WAIT); (void)k_thread_name_set(&sid_thread, "sidewalk"); + (void)k_thread_create(&sid_process_thread, sid_process_thread_stack, + K_THREAD_STACK_SIZEOF(sid_thread_stack), sid_process_thread_entry, + context, NULL, NULL, CONFIG_SIDEWALK_THREAD_PRIORITY, 0, K_NO_WAIT); + (void)k_thread_name_set(&sid_thread, "sidewalk_process"); k_sem_take(&sid_thread_started, K_FOREVER); }