2021-09-22 13:22:45 +02:00
|
|
|
# Software tasks & spawn
|
|
|
|
|
2022-03-07 21:05:34 +01:00
|
|
|
The RTIC concept of a software task shares a lot with that of [hardware tasks](./hardware_tasks.md)
|
2022-02-05 13:38:01 +01:00
|
|
|
with the core difference that a software task is not explicitly bound to a specific
|
2022-02-20 19:21:25 +01:00
|
|
|
interrupt vector, but rather bound to a “dispatcher” interrupt vector running
|
|
|
|
at the intended priority of the software task (see below).
|
2021-12-16 09:46:56 +01:00
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
Thus, software tasks are tasks which are not *directly* bound to an interrupt vector.
|
2021-12-16 09:46:56 +01:00
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
The `#[task]` attributes used on a function determine if it is
|
|
|
|
software tasks, specifically the absence of a `binds = InterruptName`
|
|
|
|
argument to the attribute definition.
|
2021-12-16 09:46:56 +01:00
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
The static method `task_name::spawn()` spawns (schedules) a software
|
|
|
|
task by registering it with a specific dispatcher. If there are no
|
|
|
|
higher priority tasks available to the scheduler (which serves a set
|
|
|
|
of dispatchers), the task will start executing directly.
|
2022-02-05 13:38:01 +01:00
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
All software tasks at the same priority level share an interrupt handler bound to their dispatcher.
|
|
|
|
What differentiates software and hardware tasks is the usage of either a dispatcher or a bound interrupt vector.
|
2022-02-05 13:38:01 +01:00
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
The interrupt vectors used as dispatchers cannot be used by hardware tasks.
|
2022-02-05 13:38:01 +01:00
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
Availability of a set of “free” (not in use by hardware tasks) and usable interrupt vectors allows the framework
|
|
|
|
to dispatch software tasks via dedicated interrupt handlers.
|
|
|
|
|
|
|
|
This set of dispatchers, `dispatchers = [FreeInterrupt1, FreeInterrupt2, ...]` is an
|
2021-12-16 09:46:56 +01:00
|
|
|
argument to the `#[app]` attribute.
|
|
|
|
|
2022-02-20 19:21:25 +01:00
|
|
|
Each interrupt vector acting as dispatcher gets assigned to a unique priority level meaning that
|
|
|
|
the list of dispatchers needs to cover all priority levels used by software tasks.
|
2021-12-16 09:46:56 +01:00
|
|
|
|
|
|
|
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}}
|
|
|
|
```
|