From dffdcd36dbee5e82dd5d2fdb7817590ebaf1dab0 Mon Sep 17 00:00:00 2001 From: adrien balleyguier Date: Thu, 21 May 2026 10:22:25 +0200 Subject: [PATCH] feat(nodes): using an explicit thread, as it may cause the huge battery usage --- nodes/src/main.c | 12 ++++++------ nodes/src/supervisor.c | 10 ++++++++++ nodes/src/supervisor.h | 5 +++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/nodes/src/main.c b/nodes/src/main.c index 899afdd..3ced2ea 100644 --- a/nodes/src/main.c +++ b/nodes/src/main.c @@ -10,9 +10,9 @@ #include "supervisor.h" -int main(void){ - supervisor_init(); - supervisor_run(); - // should never come here - return 0; -} +// size of a stack used by the supervisor thread +#define STACKSIZE 1024 +// scheduling priority used by the supervisor thread +#define PRIORITY 7 + +K_THREAD_DEFINE(supervisor_id, STACKSIZE, thread_supervisor, NULL, NULL, NULL, PRIORITY, 0, 0); diff --git a/nodes/src/supervisor.c b/nodes/src/supervisor.c index 11ccaa2..66d0583 100644 --- a/nodes/src/supervisor.c +++ b/nodes/src/supervisor.c @@ -4,6 +4,16 @@ const int SLEEP_GRANULARITY = 2; // [min] const int SLEEP_MIN_DURATION = SLEEP_GRANULARITY; // [min] const int SLEEP_MAX_DURATION = 30; // [min] +// Zephyr related stuff + +void thread_supervisor(){ + supervisor_init(); + supervisor_run(); + //should never return +} + +// supervisor stuff + enum error_code supervisor_init(){ enum error_code ret = init_failed; if( diff --git a/nodes/src/supervisor.h b/nodes/src/supervisor.h index ff71e2b..68c3576 100644 --- a/nodes/src/supervisor.h +++ b/nodes/src/supervisor.h @@ -16,6 +16,11 @@ extern const int SLEEP_GRANULARITY; // [min] extern const int SLEEP_MIN_DURATION; // [min] extern const int SLEEP_MAX_DURATION; // [min] +/** +* @brief thread function to run the supervisor in zephyr environment +*/ +void thread_supervisor(); + /** * @brief init the supervisor, and thus the complete plein_de_ee application * @return init_failed upon any error occurring during the initialisation of any module