Skip to content

Commit

Permalink
sid: add thread for sid_process
Browse files Browse the repository at this point in the history
just for testing

Signed-off-by: Robert Gałat <[email protected]>
  • Loading branch information
RobertGalatNordic committed Feb 11, 2025
1 parent d3cb88a commit 823693a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions samples/sid_end_device/src/sidewalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand All @@ -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.");
Expand All @@ -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);
}

Expand Down

0 comments on commit 823693a

Please sign in to comment.