Watchdog
LibXR::Watchdog provides a general-purpose abstract interface for watchdog functionality. It supports configuring the overflow timeout, auto-feed interval, and provides control methods like start, stop, and manual feeding. It is suitable for multi-threaded environments or timer-based task scheduling systems.
In current mainline, hardware configuration and auto-feed scheduling are split into two layers:
SetConfig(...)only passestimeout_ms / feed_msinto the concrete platform implementation;- whether
ThreadFun()/TaskFun()actually perform automatic feeding still depends on the public runtime membersauto_feed_andauto_feed_interval_ms.
Interface Overview
Configuration Structure
struct Configuration {
uint32_t timeout_ms; // Watchdog overflow time (milliseconds)
uint32_t feed_ms; // Auto-feed interval (milliseconds)
};
Constructor and Configuration
Watchdog();
virtual ~Watchdog();
virtual ErrorCode SetConfig(const Configuration& config) = 0;
Control Interface
virtual ErrorCode Start() = 0;
virtual ErrorCode Stop() = 0;
virtual ErrorCode Feed() = 0;
Auto-Feed Helper Functions
static void ThreadFun(Watchdog* wdg);
static void TaskFun(Watchdog* wdg);
ThreadFun: Used in threaded environments for continuous auto-feeding;TaskFun: Used in polling/timer task systems for periodic auto-feeding.
Actual current helper semantics:
ThreadFun()loops, sleeps withLibXR::Thread::Sleep(auto_feed_interval_ms), and callsFeed()only whenauto_feed_ == true.TaskFun()does not loop; it only checksauto_feed_once for the current scheduling point and decides whether to callFeed().
So automatic feeding is not enabled by SetConfig() alone. The upper layer still needs to arrange a thread or periodic task and set auto_feed_ / auto_feed_interval_ms explicitly.
Feature Summary
- Supports configurable overflow timeout and auto-feed interval;
- Provides manual
Feedfunction and auto-feed helpers; - Suitable for various embedded execution models such as RTOS threads or timer tasks;
- Platform-independent, allowing unified usage across different hardware;
- Easily extendable, with implementation-specific logic in derived classes.