rtic/book/en/src/by-example/hardware_tasks.md
2022-03-05 11:14:36 +01:00

1.6 KiB

Hardware tasks

At its core RTIC is using the hardware interrupt controller (ARM NVIC on cortex-m) to perform scheduling and executing tasks, and all tasks except #[init] and #[idle] run as interrupt handlers. This also means that you can manually bind tasks to interrupt handlers.

To bind an interrupt use the #[task] attribute argument binds = InterruptName. This task becomes the interrupt handler for this hardware interrupt vector.

All tasks bound to an explicit interrupt are hardware tasks since they start execution in reaction to a hardware event.

Specifying a non-existing interrupt name will cause a compilation error. The interrupt names are commonly defined by PAC or HAL crates.

Any available interrupt vector should work, but different hardware might have added special properties to select interrupt priority levels, such as the nRF “softdevice”.

Beware of re-purposing interrupt vectors used internally by hardware features, RTIC is unaware of such hardware specific details.

The example below demonstrates the use of the #[task(binds = InterruptName)] attribute to declare a hardware task bound to an interrupt handler.

{{#include ../../../../examples-runner/src/bin/hardware.rs}}
$ cargo run --target thumbv7m-none-eabi --example hardware
{{#include ../../../../examples-runner/ci/expected/hardware.run}}