2021-09-22 13:22:45 +02:00
|
|
|
# Software tasks & spawn
|
|
|
|
|
2022-02-05 13:38:01 +01:00
|
|
|
The RTIC concept of a software task shares a lot with that of [hardware tasks][hardware_tasks.md]
|
|
|
|
with the core difference that a software task is not explicitly bound to a specific
|
|
|
|
interrupt vector, but rather a “dispatcher” interrupt vector running
|
|
|
|
at the same priority as the software task.
|
2021-12-16 09:46:56 +01:00
|
|
|
|
2022-02-05 13:38:01 +01:00
|
|
|
Thus, software tasks are tasks which are not directly assigned to a specific interrupt vector.
|
2021-12-16 09:46:56 +01:00
|
|
|
|
|
|
|
The `#[task]` attribute used on a function declare it as a software tasks.
|
2022-02-05 13:38:01 +01:00
|
|
|
Observe the absence of a `binds = InterruptName` argument to the attribute.
|
2022-01-07 23:33:23 +01:00
|
|
|
The static method `task_name::spawn()` spawns (starts) a software task and
|
2021-12-16 09:46:56 +01:00
|
|
|
given that there are no higher priority tasks running the task will start executing directly.
|
|
|
|
|
2022-02-05 13:38:01 +01:00
|
|
|
All software tasks at the same priority level shares an interrupt handler acting as a dispatcher.
|
|
|
|
What differentiates software and hardware tasks are the dispatcher versus bound interrupt vector.
|
|
|
|
|
|
|
|
The interrupt vectors used as dispatchers can not be used by hardware tasks.
|
|
|
|
|
|
|
|
A list of “free” (not in use by hardware tasks) and usable interrupts allows the framework
|
|
|
|
to dispatch software tasks.
|
|
|
|
|
2021-12-16 09:46:56 +01:00
|
|
|
This list of dispatchers, `dispatchers = [FreeInterrupt1, FreeInterrupt2, ...]` is an
|
|
|
|
argument to the `#[app]` attribute.
|
|
|
|
|
|
|
|
Each interrupt vector acting as dispatcher gets assigned to one priority level meaning that
|
|
|
|
the list of dispatchers need to cover all priority levels used by software tasks.
|
|
|
|
|
|
|
|
Example: The `dispatchers =` argument needs to have at least 3 entries for an application using
|
|
|
|
three different priorities for software tasks.
|
|
|
|
|
|
|
|
The framework will give a compilation error if there are not enough dispatchers provided.
|
|
|
|
|
|
|
|
See the following example:
|
2021-09-22 13:22:45 +02:00
|
|
|
|
|
|
|
``` rust
|
|
|
|
{{#include ../../../../examples/spawn.rs}}
|
|
|
|
```
|
|
|
|
|
|
|
|
``` console
|
|
|
|
$ cargo run --target thumbv7m-none-eabi --example spawn
|
|
|
|
{{#include ../../../../ci/expected/spawn.run}}
|
|
|
|
```
|