You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2026/10/23 07:16:56 UTC
(mynewt-core) branch master updated (b26015465 -> 3b82efc0e)
This is an automated email from the ASF dual-hosted git repository.
kasjer pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
from b26015465 hw/bsp: Add WeAct STM32H503CB board
new 704a2e6c2 kernel/os: Add os_eventq_loop()
new c49b8541b util/static_task: Add statically defined tasks
new 14fc5de85 net/lora/node: Use STATIC_TASK_DEFINE for MAC task
new 3b82efc0e apps/eventq_task: Add STATIC_EVENTQ_TASK_DEFINE example
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
apps/{rust_blinky => eventq_task}/pkg.yml | 15 ++-
apps/eventq_task/src/main.c | 86 +++++++++++++
{mgmt/smp => apps/eventq_task}/syscfg.yml | 18 +--
docs/os/core_os/event_queue/event_queue.rst | 18 +++
docs/os/core_os/task/task.rst | 52 ++++++++
kernel/os/include/os/os_eventq.h | 28 +++++
kernel/os/src/os.c | 4 +-
kernel/os/src/os_eventq.c | 14 +++
net/lora/node/pkg.yml | 1 +
net/lora/node/src/lora_node.c | 39 ++----
test/testutil/src/testutil.c | 4 +-
util/static_task/include/static_task/static_task.h | 137 +++++++++++++++++++++
{fs/disk => util/static_task}/pkg.yml | 10 +-
.../static_task/src/static_task.c | 26 ++--
.../static_task}/syscfg.yml | 9 +-
15 files changed, 391 insertions(+), 70 deletions(-)
copy apps/{rust_blinky => eventq_task}/pkg.yml (76%)
create mode 100644 apps/eventq_task/src/main.c
copy {mgmt/smp => apps/eventq_task}/syscfg.yml (64%)
create mode 100644 util/static_task/include/static_task/static_task.h
copy {fs/disk => util/static_task}/pkg.yml (83%)
copy hw/mcu/nxp/mkw41z/src/hal_system.c => util/static_task/src/static_task.c (70%)
copy {compiler/arm-none-eabi-m3 => util/static_task}/syscfg.yml (75%)
(mynewt-core) 01/04: kernel/os: Add os_eventq_loop()
Posted by je...@apache.org.
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 704a2e6c268a882a38ea73d5d77ba06b2388e15f
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Oct 22 11:30:49 2026 +0200
kernel/os: Add os_eventq_loop()
Almost every user of os_eventq_run() wraps it in the same endless
loop. Add os_eventq_loop() that does exactly that and never returns,
and os_eventq_task_handler() that runs it on the event queue passed
as task argument, so it can be given directly to os_task_init().
Use os_eventq_loop() in os_main() for selftest builds and in testutil
default task handler.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
kernel/os/include/os/os_eventq.h | 16 ++++++++++++++++
kernel/os/src/os.c | 4 +---
kernel/os/src/os_eventq.c | 14 ++++++++++++++
test/testutil/src/testutil.c | 4 +---
4 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/kernel/os/include/os/os_eventq.h b/kernel/os/include/os/os_eventq.h
index ad9d74619..046410700 100644
--- a/kernel/os/include/os/os_eventq.h
+++ b/kernel/os/include/os/os_eventq.h
@@ -158,6 +158,22 @@ struct os_event *os_eventq_get(struct os_eventq *evq);
*/
void os_eventq_run(struct os_eventq *evq);
+/**
+ * Process events from the event queue forever. Equivalent to calling
+ * os_eventq_run() in an endless loop. Never returns.
+ *
+ * @param evq The event queue to process.
+ */
+void os_eventq_loop(struct os_eventq *evq) __attribute__((noreturn));
+
+/**
+ * Task handler that processes events from the event queue passed as task
+ * argument forever. Can be passed directly to os_task_init().
+ *
+ * @param arg The event queue to process
+ * (struct os_eventq *).
+ */
+void os_eventq_task_handler(void *arg) __attribute__((noreturn));
/**
* Poll the list of event queues specified by the evq parameter
diff --git a/kernel/os/src/os.c b/kernel/os/src/os.c
index e926337b5..d71814b04 100644
--- a/kernel/os/src/os.c
+++ b/kernel/os/src/os.c
@@ -182,9 +182,7 @@ os_main(void *arg)
fn(0, NULL);
#else
(void)fn;
- while (1) {
- os_eventq_run(os_eventq_dflt_get());
- }
+ os_eventq_loop(os_eventq_dflt_get());
#endif
assert(0);
}
diff --git a/kernel/os/src/os_eventq.c b/kernel/os/src/os_eventq.c
index c070ab08c..11219eb42 100644
--- a/kernel/os/src/os_eventq.c
+++ b/kernel/os/src/os_eventq.c
@@ -215,6 +215,20 @@ os_eventq_run(struct os_eventq *evq)
#endif
}
+void
+os_eventq_loop(struct os_eventq *evq)
+{
+ while (1) {
+ os_eventq_run(evq);
+ }
+}
+
+void
+os_eventq_task_handler(void *arg)
+{
+ os_eventq_loop(arg);
+}
+
static struct os_event *
os_eventq_poll_0timo(struct os_eventq **evq, int nevqs)
{
diff --git a/test/testutil/src/testutil.c b/test/testutil/src/testutil.c
index d59e9d07c..3f150185c 100644
--- a/test/testutil/src/testutil.c
+++ b/test/testutil/src/testutil.c
@@ -104,9 +104,7 @@ tu_restart(void)
static void
tu_dflt_task_handler(void *arg)
{
- while (1) {
- os_eventq_run(os_eventq_dflt_get());
- }
+ os_eventq_loop(os_eventq_dflt_get());
}
static void
(mynewt-core) 04/04: apps/eventq_task: Add STATIC_EVENTQ_TASK_DEFINE example
Posted by je...@apache.org.
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 3b82efc0ed8b2b8a57c57340baefc8b1b7be8cab
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Oct 22 12:26:37 2026 +0200
apps/eventq_task: Add STATIC_EVENTQ_TASK_DEFINE example
Small application showing a task defined with
STATIC_EVENTQ_TASK_DEFINE() from util/static_task. A callout on the
task's event queue blinks the LED, one event is put on the queue
during sysinit before the task is started and another one by main;
both print the name of the task that handled them.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
apps/eventq_task/pkg.yml | 38 ++++++++++++++++++++
apps/eventq_task/src/main.c | 86 +++++++++++++++++++++++++++++++++++++++++++++
apps/eventq_task/syscfg.yml | 33 +++++++++++++++++
3 files changed, 157 insertions(+)
diff --git a/apps/eventq_task/pkg.yml b/apps/eventq_task/pkg.yml
new file mode 100644
index 000000000..958179658
--- /dev/null
+++ b/apps/eventq_task/pkg.yml
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: apps/eventq_task
+pkg.type: app
+pkg.description: >
+ Example of task with its own event queue defined with
+ STATIC_EVENTQ_TASK_DEFINE() from util/static_task.
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/hw/hal"
+ - "@apache-mynewt-core/sys/console"
+ - "@apache-mynewt-core/sys/log"
+ - "@apache-mynewt-core/sys/sysinit"
+ - "@apache-mynewt-core/util/static_task"
+
+pkg.init:
+ eventq_task_app_init: 'MYNEWT_VAL(EVENTQ_TASK_APP_SYSINIT_STAGE)'
diff --git a/apps/eventq_task/src/main.c b/apps/eventq_task/src/main.c
new file mode 100644
index 000000000..8ecbd5a96
--- /dev/null
+++ b/apps/eventq_task/src/main.c
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+
+#include "os/mynewt.h"
+#include "bsp/bsp.h"
+#include "hal/hal_gpio.h"
+#include "console/console.h"
+#include "static_task/static_task.h"
+
+/*
+ * Defines task blink_task, its stack and event queue blink_evq.
+ * The task is created by sysinit at STATIC_TASK_SYSINIT_STAGE and
+ * processes events from blink_evq forever; no task handler or
+ * os_task_init() call is needed.
+ */
+STATIC_EVENTQ_TASK_DEFINE(blink, MYNEWT_VAL(EVENTQ_TASK_PRIO),
+ MYNEWT_VAL(EVENTQ_TASK_STACK_SIZE));
+
+static struct os_callout blink_callout;
+
+static void
+hello_ev_cb(struct os_event *ev)
+{
+ console_printf("%s from task %s\n", (const char *)ev->ev_arg,
+ os_sched_get_current_task()->t_name);
+}
+
+/* Put on blink_evq during sysinit, before blink task exists */
+static struct os_event early_ev = {
+ .ev_cb = hello_ev_cb,
+ .ev_arg = "Event queued during sysinit",
+};
+
+/* Put on blink_evq from main task */
+static struct os_event main_ev = {
+ .ev_cb = hello_ev_cb,
+ .ev_arg = "Event queued by main",
+};
+
+static void
+blink_timer_cb(struct os_event *ev)
+{
+ /* Callout events are delivered to blink_evq, this runs in blink task */
+ hal_gpio_toggle(LED_BLINK_PIN);
+ os_callout_reset(&blink_callout, OS_TICKS_PER_SEC);
+}
+
+void
+eventq_task_app_init(void)
+{
+ hal_gpio_init_out(LED_BLINK_PIN, 1);
+
+ /* blink_evq is statically initialized, it can be used right away */
+ os_callout_init(&blink_callout, &blink_evq, blink_timer_cb, NULL);
+ os_callout_reset(&blink_callout, OS_TICKS_PER_SEC);
+
+ os_eventq_put(&blink_evq, &early_ev);
+}
+
+int
+mynewt_main(int argc, char **argv)
+{
+ sysinit();
+
+ os_eventq_put(&blink_evq, &main_ev);
+
+ os_eventq_loop(os_eventq_dflt_get());
+}
diff --git a/apps/eventq_task/syscfg.yml b/apps/eventq_task/syscfg.yml
new file mode 100644
index 000000000..29ef002b2
--- /dev/null
+++ b/apps/eventq_task/syscfg.yml
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+ EVENTQ_TASK_PRIO:
+ description: 'Priority of the blink task.'
+ type: task_priority
+ value: 10
+ EVENTQ_TASK_STACK_SIZE:
+ description: 'Stack size of the blink task (os_stack_t units).'
+ value: 256
+ EVENTQ_TASK_APP_SYSINIT_STAGE:
+ description: >
+ Sysinit stage of application init function. Runs before
+ STATIC_TASK_SYSINIT_STAGE to show that events can be put on
+ the queue before its task is started.
+ value: 500
(mynewt-core) 02/04: util/static_task: Add statically defined tasks
Posted by je...@apache.org.
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 c49b8541b785b08fc6c06c85e4bd2e5fcbd45f59
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Oct 22 12:26:26 2026 +0200
util/static_task: Add statically defined tasks
Packages that own a task repeat the same code: task structure, stack,
event queue, os_eventq_init() and os_task_init() from sysinit, and a
handler that only loops on os_eventq_run().
Add util/static_task package with STATIC_TASK_DEFINE() and
STATIC_EVENTQ_TASK_DEFINE() that define the task with its stack (and
statically initialized event queue) and put a descriptor in the
static_task_defs link table. static_task_init(), called by sysinit at
STATIC_TASK_SYSINIT_STAGE (9000, after all other packages), creates
all of them. The link table holds pointers to descriptors so element
size does not depend on section alignment.
Add static initializer for event queue OS_EVENTQ_INITIALIZER(),
equivalent of os_eventq_init(). A statically initialized queue is
valid from the start, so events can be put on it before the task
that processes them is created, e.g. from earlier sysinit stages.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
docs/os/core_os/event_queue/event_queue.rst | 18 +++
docs/os/core_os/task/task.rst | 52 ++++++++
kernel/os/include/os/os_eventq.h | 12 ++
util/static_task/include/static_task/static_task.h | 137 +++++++++++++++++++++
util/static_task/pkg.yml | 34 +++++
util/static_task/src/static_task.c | 35 ++++++
util/static_task/syscfg.yml | 26 ++++
7 files changed, 314 insertions(+)
diff --git a/docs/os/core_os/event_queue/event_queue.rst b/docs/os/core_os/event_queue/event_queue.rst
index 8c2aabcf7..fa0fc025b 100644
--- a/docs/os/core_os/event_queue/event_queue.rst
+++ b/docs/os/core_os/event_queue/event_queue.rst
@@ -49,6 +49,24 @@ waiting for an event on the queue and puts the task into the
A task can use the :c:func:`os_eventq_run()` wrapper function that calls the
:c:func:`os_eventq_get()` function to dequeue an event from the queue and then
calls the event callback function to process the event.
+A task that does nothing else can call :c:func:`os_eventq_loop()`, which
+calls :c:func:`os_eventq_run()` forever and never returns.
+:c:func:`os_eventq_task_handler()` does the same with the event queue
+passed as the task argument, so it can be given directly to
+:c:func:`os_task_init()`.
+
+An event queue can be initialized statically with
+``OS_EVENTQ_INITIALIZER``, so events can be put on it before the task
+that processes them is created:
+
+.. code:: c
+
+ struct os_eventq my_evq = OS_EVENTQ_INITIALIZER(my_evq);
+
+``STATIC_EVENTQ_TASK_DEFINE`` from ``util/static_task`` defines a task
+together with its stack and statically initialized event queue; see
+:doc:`../task/task`.
+
Note:
- Only one task should consume or block waiting for events from an
diff --git a/docs/os/core_os/task/task.rst b/docs/os/core_os/task/task.rst
index 01cf85a06..8d88a222e 100644
--- a/docs/os/core_os/task/task.rst
+++ b/docs/os/core_os/task/task.rst
@@ -108,6 +108,58 @@ task. This task simply toggles an LED at a one second interval.
/* main never returns */
}
+Statically defined tasks
+------------------------
+
+Many packages need a task that only processes events from its own event
+queue. Package ``util/static_task`` provides
+``STATIC_EVENTQ_TASK_DEFINE(name, prio, stack_size)`` that defines such
+a task ``name_task``, its stack ``name_stack`` and a statically
+initialized event queue ``name_evq``. No task handler or initialization
+code is needed: all tasks defined this way are created by
+:c:func:`static_task_init()`, which sysinit calls at stage
+``STATIC_TASK_SYSINIT_STAGE`` (by default after all other packages are
+initialized). Events can be put on ``name_evq`` at any time, also from
+earlier sysinit stages; they are processed once the task starts.
+Tasks are started in alphabetical order of their names. A package using
+the macros adds ``@apache-mynewt-core/util/static_task`` to its
+``pkg.deps`` and includes ``static_task/static_task.h``.
+
+``STATIC_TASK_DEFINE(name, prio, stack_size, func, arg)`` does the same for
+a task with its own handler and no event queue.
+``STATIC_EVENTQ_TASK_DECLARE(name)`` declares the symbols for use in other
+files.
+
+.. code-block:: c
+
+ /* foo.h */
+ STATIC_EVENTQ_TASK_DECLARE(foo);
+
+ /* foo.c */
+ STATIC_EVENTQ_TASK_DEFINE(foo, MYNEWT_VAL(FOO_TASK_PRIO),
+ MYNEWT_VAL(FOO_TASK_STACK_SIZE));
+
+ static void
+ foo_event_cb(struct os_event *ev)
+ {
+ /* Executed in foo_task context */
+ }
+
+ static struct os_event foo_event = {
+ .ev_cb = foo_event_cb,
+ };
+
+ void
+ foo_irq_handler(void)
+ {
+ os_eventq_put(&foo_evq, &foo_event);
+ }
+
+The definition is placed in a link table, so it is only linked in when
+its object file is pulled from the package library; this is the case
+when other code in the same file is referenced. Otherwise set
+``pkg.whole_archive: true`` in the package's ``pkg.yml``.
+
API
----
diff --git a/kernel/os/include/os/os_eventq.h b/kernel/os/include/os/os_eventq.h
index 046410700..4f798b3db 100644
--- a/kernel/os/include/os/os_eventq.h
+++ b/kernel/os/include/os/os_eventq.h
@@ -104,6 +104,18 @@ struct os_eventq {
#endif
};
+/**
+ * Static initializer for event queue, equivalent of os_eventq_init().
+ *
+ * struct os_eventq my_evq = OS_EVENTQ_INITIALIZER(my_evq);
+ *
+ * @param evq The event queue variable being initialized
+ */
+#define OS_EVENTQ_INITIALIZER(evq) \
+ { \
+ .evq_list = STAILQ_HEAD_INITIALIZER((evq).evq_list), \
+ }
+
/**
* Initialize the event queue
*
diff --git a/util/static_task/include/static_task/static_task.h b/util/static_task/include/static_task/static_task.h
new file mode 100644
index 000000000..89d036c5a
--- /dev/null
+++ b/util/static_task/include/static_task/static_task.h
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_STATIC_TASK_
+#define H_STATIC_TASK_
+
+#include "os/os.h"
+#include "os/link_tables.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Tasks defined with STATIC_TASK_DEFINE() or STATIC_EVENTQ_TASK_DEFINE()
+ * are collected in the static_task_defs link table and started by
+ * static_task_init() at sysinit stage STATIC_TASK_SYSINIT_STAGE, after
+ * all packages are initialized.
+ *
+ * - Task name is the stringified name argument; symbols defined are
+ * global so duplicate names fail to link.
+ * - Tasks are started in alphabetical order of their names.
+ * - Stack size is in os_stack_t units, as for OS_TASK_STACK_DEFINE().
+ * - Definition is only linked if its object file is pulled in from the
+ * package archive. This is normally the case since the file also has
+ * code referenced from elsewhere (e.g. users of <name>_evq or the
+ * package init function); otherwise set pkg.whole_archive: true.
+ *
+ * Example:
+ *
+ * STATIC_EVENTQ_TASK_DEFINE(foo, MYNEWT_VAL(FOO_TASK_PRIO),
+ * MYNEWT_VAL(FOO_TASK_STACK_SIZE));
+ *
+ * os_eventq_put(&foo_evq, &foo_event);
+ */
+
+/** Static definition of task, created by static_task_init(). */
+struct static_task_def {
+ /** Task to initialize */
+ struct os_task *task;
+ /** Task name */
+ const char *name;
+ /** Task handler */
+ os_task_func_t func;
+ /** Argument passed to task handler */
+ void *arg;
+ /** Bottom of task stack */
+ os_stack_t *stack;
+ /** Task stack size in os_stack_t units */
+ uint16_t stack_size;
+ /** Task priority */
+ uint8_t prio;
+};
+
+/*
+ * Table holds pointers rather than structures so element size does not
+ * depend on how the compiler aligns structures placed in sections.
+ */
+LINK_TABLE(const struct static_task_def *, static_task_defs)
+
+/**
+ * Defines task <name>_task with stack <name>_stack and adds it to the
+ * list of tasks started by static_task_init().
+ *
+ * @param _name Task name, also prefix of defined symbols
+ * @param _prio Task priority
+ * @param _stack_size Stack size in os_stack_t units
+ * @param _func Task handler
+ * @param _arg Argument passed to task handler
+ */
+#define STATIC_TASK_DEFINE(_name, _prio, _stack_size, _func, _arg) \
+ struct os_task _name##_task; \
+ OS_TASK_STACK_DEFINE(_name##_stack, _stack_size) \
+ static const struct static_task_def _name##_task_def = { \
+ .task = &_name##_task, \
+ .name = #_name, \
+ .func = (_func), \
+ .arg = (_arg), \
+ .stack = _name##_stack, \
+ .stack_size = OS_STACK_ALIGN(_stack_size), \
+ .prio = (_prio), \
+ }; \
+ LINK_TABLE_ELEMENT(static_task_defs, _name##_task_def_ptr) = \
+ &_name##_task_def
+
+/**
+ * Defines task <name>_task with stack <name>_stack and event queue
+ * <name>_evq. The task processes events from <name>_evq forever.
+ * The event queue is statically initialized, events can be put on it
+ * before the task is started.
+ *
+ * @param _name Task name, also prefix of defined symbols
+ * @param _prio Task priority
+ * @param _stack_size Stack size in os_stack_t units
+ */
+#define STATIC_EVENTQ_TASK_DEFINE(_name, _prio, _stack_size) \
+ struct os_eventq _name##_evq = OS_EVENTQ_INITIALIZER(_name##_evq); \
+ STATIC_TASK_DEFINE(_name, _prio, _stack_size, os_eventq_task_handler, \
+ &_name##_evq)
+
+/**
+ * Declares symbols defined by STATIC_EVENTQ_TASK_DEFINE() for use in
+ * other files.
+ *
+ * @param _name Name used in STATIC_EVENTQ_TASK_DEFINE()
+ */
+#define STATIC_EVENTQ_TASK_DECLARE(_name) \
+ extern struct os_task _name##_task; \
+ extern struct os_eventq _name##_evq
+
+/**
+ * Starts all tasks defined with STATIC_TASK_DEFINE() and
+ * STATIC_EVENTQ_TASK_DEFINE(). Called by sysinit.
+ */
+void static_task_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_STATIC_TASK_ */
diff --git a/util/static_task/pkg.yml b/util/static_task/pkg.yml
new file mode 100644
index 000000000..9a165f03e
--- /dev/null
+++ b/util/static_task/pkg.yml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: util/static_task
+pkg.description: >
+ Statically defined tasks, created by sysinit.
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+
+pkg.link_tables:
+ - static_task_defs
+
+pkg.init:
+ static_task_init: 'MYNEWT_VAL(STATIC_TASK_SYSINIT_STAGE)'
diff --git a/util/static_task/src/static_task.c b/util/static_task/src/static_task.c
new file mode 100644
index 000000000..49051196f
--- /dev/null
+++ b/util/static_task/src/static_task.c
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/mynewt.h"
+#include "static_task/static_task.h"
+
+void
+static_task_init(void)
+{
+ const struct static_task_def *td;
+ int rc;
+
+ LINK_TABLE_FOREACH(e, static_task_defs) {
+ td = *e;
+ rc = os_task_init(td->task, td->name, td->func, td->arg, td->prio,
+ OS_WAIT_FOREVER, td->stack, td->stack_size);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+ }
+}
diff --git a/util/static_task/syscfg.yml b/util/static_task/syscfg.yml
new file mode 100644
index 000000000..f56e69d50
--- /dev/null
+++ b/util/static_task/syscfg.yml
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+ STATIC_TASK_SYSINIT_STAGE:
+ description: >
+ Sysinit stage at which tasks defined with STATIC_TASK_DEFINE()
+ and STATIC_EVENTQ_TASK_DEFINE() are started. Should be later
+ than initialization of packages that define such tasks.
+ value: 9000
(mynewt-core) 03/04: net/lora/node: Use STATIC_TASK_DEFINE for MAC task
Posted by je...@apache.org.
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 <je...@codecoup.pl>
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 <je...@codecoup.pl>
---
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;