Skip to content

Commit

Permalink
test: check if sid_process is blocking the queue
Browse files Browse the repository at this point in the history
check if calling sid_process in a loop will solve the issue

Signed-off-by: Robert Gałat <[email protected]>
  • Loading branch information
RobertGalatNordic committed Feb 10, 2025
1 parent 1b0630d commit d3cb88a
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions samples/sid_end_device/src/sidewalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <sid_api.h>
#include <sid_error.h>
#include <sidewalk.h>

#include <zephyr/kernel.h>
Expand All @@ -17,6 +19,8 @@ K_MSGQ_DEFINE(sidewalk_thread_msgq, sizeof(sidewalk_ctx_event_t), CONFIG_SIDEWAL
4);

K_SEM_DEFINE(sid_thread_started, 0, 1);

K_SEM_DEFINE(sid_process_requested, 0, 1);
static void sid_thread_entry(void *context, void *unused, void *unused2)
{
ARG_UNUSED(unused);
Expand All @@ -28,21 +32,35 @@ 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_FOREVER);
int err = k_msgq_get(&sidewalk_thread_msgq, &event, K_MSEC(1));
#if CONFIG_SIDEWALK_TRACE_SIDEWALK_QUEUE
LOG_INF("sidewalk workq usage (%d/%d)", k_msgq_num_used_get(&sidewalk_thread_msgq),
LOG_INF("event handler get = %p, sidewalk workq usage (%d/%d) ( after get )",
(void *)(event.handler), k_msgq_num_used_get(&sidewalk_thread_msgq),
CONFIG_SIDEWALK_THREAD_QUEUE_SIZE);
#endif
if (!err) {
switch (err) {
case 0: {
if (event.handler) {
event.handler(sid, event.ctx);
}
if (event.ctx_free) {
event.ctx_free(event.ctx);
}
} else {
break;
}
case -EAGAIN:
case -ENOMSG: {
// Do nothing, just timeout
break;
}
default: {
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 @@ -59,6 +77,10 @@ void sidewalk_start(sidewalk_ctx_t *context)

int sidewalk_event_send(event_handler_t event, void *ctx, ctx_free free)
{
if (event == sidewalk_event_process) {
k_sem_give(&sid_process_requested);
return 0;
}
sidewalk_ctx_event_t ctx_event = {
.handler = event,
.ctx = ctx,
Expand All @@ -76,7 +98,8 @@ int sidewalk_event_send(event_handler_t event, void *ctx, ctx_free free)
#endif /* CONFIG_SIDEWALK_THREAD_QUEUE_TIMEOUT_VALUE > 0 */
result = k_msgq_put(&sidewalk_thread_msgq, (void *)&ctx_event, timeout);
#if CONFIG_SIDEWALK_TRACE_SIDEWALK_QUEUE
LOG_INF("sidewalk workq usage (%d/%d)", k_msgq_num_used_get(&sidewalk_thread_msgq),
LOG_INF("event handler send = %p, sidewalk workq usage (%d/%d) (after put)",
(event_handler_t *)event, k_msgq_num_used_get(&sidewalk_thread_msgq),
CONFIG_SIDEWALK_THREAD_QUEUE_SIZE);
#endif
LOG_DBG("sidewalk_event_send event = %p, context = %p, k_msgq_put result %d", (void *)event,
Expand Down

0 comments on commit d3cb88a

Please sign in to comment.