π‘οΈ task-watchdog πΊ
A robust, flexible watchdog management library for embedded systems that multiplexes multiple task watchdogs into a single hardware watchdog timer, preventing system lockups when tasks fail to respond.
β¨ Key Features
- π Hardware Agnostic API: Implements a consistent interface across different embedded microcontrollers with extensible trait system for hardware watchdog and clock types
- π Task Multiplexing: Consolidates multiple independent task watchdogs into a single hardware watchdog, triggering if any task fails to check in
- π Dynamic Task Management: Tasks can be registered and deregistered at runtime, allowing for flexible monitoring configurations
- β‘ Async and Sync Support: Works with both synchronous (via device HALs) and asynchronous (Embassy) execution environments
- π¦ No-Alloc Mode: Functions in both
alloc
andno_alloc
modes for environments with or without heap availability - β±οΈ Configurable Timeouts: Individual timeout durations for each registered task
- π§ͺ
no_std
Compatible: Designed for resource-constrained embedded environments without an operating system
π Quick Start
Examples are provided for async (using embassy-rs) and sync operation of task-watchdog
. The async/embassy example supports the Pico, Pico 2 and STM32F103C8 (blue pill). The sync example supports the Pico and Pico 2.
First, install Rust
Add the approriate target(s):
Next, install probe-rs
Now connect your Pico/Pico 2/STM321F103C8 device to a connected debug probe, and run one of:
To understand how to use task-watchdog
yourself, check out one of the examples:
intro.rs
- A very basic Pico/Pico 2/STM32/nRF/ESP32 async exampleembassy.rs
- Pico/Pico 2/STM32rp-sync.rs
- Pico/Pico 2
For ESP32 support see scripts/README.md
.
π Usage
The library supports both synchronous and asynchronous APIs with a consistent pattern across both styles.
π§ Core Concepts
- Task Registration: Each monitored task is registered with its own timeout period
- Feeding: Tasks must feed, or pet, the watchdog within their timeout period to prevent a reset
- Task Multiplexing: The library efficiently manages multiple task timeouts through a single hardware watchdog, triggering if any individual task fails to check in
β‘Asynchronous API (Embassy)
For platforms using Embassy, tasks feed the watchdog asynchronously:
// Setup
let watchdog = new;
// Register tasks with individual timeouts
watchdog.register_task.await;
watchdog.register_task.await;
// Spawn the watchdog task itself
spawner.spawn.unwrap;
// In your application tasks
async !
// Implement other tasks
See complete example at examples/src/embasy.rs
βοΈ Synchronous API (non-Embassy)
For platforms without an async runtime, manually manage the watchdog in your main loop:
// Setup
let mut watchdog = new;
// Register tasks with individual timeouts
watchdog.register_task;
watchdog.register_task;
// Start the watchdog
watchdog.start;
// In your main loop
loop
See complete example at examples/src/rp-sync.rs
ποΈ Platform Support
The crate is designed to be platform-agnostic via trait implementations, but includes first-class support for:
- RP2040 and RP2350 (Raspberry Pi Pico and Pico 2) via the
rp2040
/rp2350
features (embassy) andrp2040-hal
/rp2350-hal
(rp2040-hal/rp235x-hal respectively) - Embassy async runtime via the
embassy
feature
There are many other features - see scripts/build-lib.sh
for the valid combinations. The most common are:
embassy,rp2040,defmt
- Async, Pico with defmt supportembassy,rp2350,defmt
- Async, Pico 2 with defmt supportembassy,stm32,defmt
- Async, STM32 with defmt support - you will also needembassy-stm32/your_stm32_board_type
embassy,nrf,defmt
- Async, nRF with defmt support - you will also needembassy-nrf/your_nrf_board_type
π License
Licensed under either of the following, at your option:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)