1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Software watchdog fallback: for boards with no real watchdog hardware,
//! arm a deadline and check it on every tick. **Not independent of the
//! CPU**: unlike a real hardware watchdog, this cannot catch a hang that
//! stops the tick itself (e.g. a spin loop with interrupts disabled) —
//! document that limitation prominently in any BSP that uses this.
use ;
static PERIOD_US: AtomicU32 = new;
// Not a native atomic on RV32 (no AtomicU64); `feed()` can race
// `expired()` (one from a fed task, one from tick/ISR context), but a
// torn read here only ever produces an early or late expiry check by one
// tick's worth of time — never a wildly wrong one (`now_us`/period are
// both bounded, ordinary values, not a "wrap the future in" kind of
// hazard) — an acceptable trade for a fallback that's already documented
// as best-effort, not hardware-grade. Guarded with a critical section
// instead of the mtime driver's hi/lo/hi-recheck protocol for simplicity.
static mut DEADLINE_US: u64 = 0;
/// Arm the deadline at `now_us() + period_us`. `period_us == 0` disables
/// the watchdog.
/// Re-arm the deadline. Call periodically from the fed task's main loop.
/// Check whether the deadline has passed. Call every tick; the board
/// decides what to do on expiry (typically: print a diagnostic, reset).