watchdog_core/
platform.rs1#[async_trait::async_trait]
6pub trait WatchdogPlatform: Send {
7 async fn on_timeout(&mut self);
9
10 async fn read_and_clear_boot_status(&mut self) -> bool;
13}
14
15pub struct SimpleWatchdogPlatform {
17 watchdog_status: bool,
18 cb: Box<dyn Fn() + Send + Sync>,
19}
20
21impl SimpleWatchdogPlatform {
22 pub fn new(on_timeout: Box<dyn Fn() + Send + Sync>) -> Self {
23 SimpleWatchdogPlatform {
24 watchdog_status: false,
25 cb: on_timeout,
26 }
27 }
28}
29
30#[async_trait::async_trait]
31impl WatchdogPlatform for SimpleWatchdogPlatform {
32 async fn on_timeout(&mut self) {
33 self.watchdog_status = true;
34 (self.cb)()
35 }
36
37 async fn read_and_clear_boot_status(&mut self) -> bool {
38 if self.watchdog_status {
39 self.watchdog_status = false;
40 }
41 self.watchdog_status
42 }
43}