This is an automated email from the ASF dual-hosted git repository. kasjer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 14fc5de8580f0a58d22f0b00e2cf176552ab46e3 Author: Jerzy Kasenberg <[email protected]> AuthorDate: Thu Oct 22 12:26:32 2026 +0200 net/lora/node: Use STATIC_TASK_DEFINE for MAC task Define the MAC task with STATIC_TASK_DEFINE() and os_eventq_task_handler() instead of a hand-written handler and os_task_init() in lora_node_init(). The task stack is now OS_STACK_ALIGN'ed. The MAC event queue stays in g_lora_mac_data and is now initialized statically with OS_EVENTQ_INITIALIZER(), so code putting events on it is unchanged. Task, stack and queue initializer are only present when LORA_NODE_CLI is disabled, as before the task was only created then; in CLI builds the static task table is empty. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jerzy Kasenberg <[email protected]> --- net/lora/node/pkg.yml | 1 + net/lora/node/src/lora_node.c | 39 ++++++++++++--------------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/net/lora/node/pkg.yml b/net/lora/node/pkg.yml index 0c2b48f5b..195c2bbd1 100644 --- a/net/lora/node/pkg.yml +++ b/net/lora/node/pkg.yml @@ -29,6 +29,7 @@ pkg.cflags: - "-std=c99" pkg.deps: + - "@apache-mynewt-core/util/static_task" pkg.deps.LORA_NODE_CLI: - "@apache-mynewt-core/sys/shell" diff --git a/net/lora/node/src/lora_node.c b/net/lora/node/src/lora_node.c index 0d47731df..6305c513b 100644 --- a/net/lora/node/src/lora_node.c +++ b/net/lora/node/src/lora_node.c @@ -19,6 +19,7 @@ #include <string.h> #include "os/mynewt.h" +#include "static_task/static_task.h" #include "node/lora.h" #include "node/lora_priv.h" #include "node/lora_band.h" @@ -64,15 +65,21 @@ uint8_t g_lora_node_last_tx_mac_cmd; LoRaMacCallback_t lora_cb; #endif -/* MAC task */ -#define LORA_MAC_STACK_SIZE (256) -struct os_task g_lora_mac_task; -os_stack_t g_lora_mac_stack[LORA_MAC_STACK_SIZE]; - /* * Lora MAC data object */ +#if !MYNEWT_VAL(LORA_NODE_CLI) +struct lora_mac_obj g_lora_mac_data = { + .lm_evq = OS_EVENTQ_INITIALIZER(g_lora_mac_data.lm_evq), +}; + +/* MAC task, processes events from g_lora_mac_data.lm_evq */ +#define LORA_MAC_STACK_SIZE (256) +STATIC_TASK_DEFINE(loramac, MYNEWT_VAL(LORA_MAC_PRIO), LORA_MAC_STACK_SIZE, + os_eventq_task_handler, &g_lora_mac_data.lm_evq); +#else struct lora_mac_obj g_lora_mac_data; +#endif /* The join event argument */ struct lm_join_ev_arg_obj @@ -391,20 +398,6 @@ lora_mac_txq_timer_cb(struct os_event *ev) { lora_mac_proc_tx_q_event(NULL); } - -/** - * The LoRa mac task - * - * @param arg Pointer to arg passed to task (currently NULL). - */ -void -lora_mac_task(void *arg) -{ - /* Process events */ - while (1) { - os_eventq_run(&g_lora_mac_data.lm_evq); - } -} #endif #if !MYNEWT_VAL(LORA_APP_AUTO_JOIN) @@ -647,17 +640,9 @@ lora_node_init(void) lora_app_init(); /*--- MAC INIT ---*/ - /* Initialize eventq */ - os_eventq_init(&g_lora_mac_data.lm_evq); - /* Set up transmit done queue and event */ os_mqueue_init(&g_lora_mac_data.lm_txq, lora_mac_proc_tx_q_event, NULL); - /* Create the mac task */ - os_task_init(&g_lora_mac_task, "loramac", lora_mac_task, NULL, - MYNEWT_VAL(LORA_MAC_PRIO), OS_WAIT_FOREVER, g_lora_mac_stack, - LORA_MAC_STACK_SIZE); - /* Initialize join event */ g_lora_mac_data.lm_join_ev.ev_cb = lora_mac_join_event; g_lora_mac_data.lm_join_ev.ev_arg = &g_lm_join_ev_arg;
