kernel/platform/watchdog.rs
1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Interface for configuring a watchdog
6
7/// A trait for implementing a watchdog in the kernel.
8///
9/// This trait is called from the `kernel_loop()` code to setup
10/// and maintain the watchdog timer.
11/// It is up to the specific `Chip` how it will handle watchdog interrupts.
12pub trait WatchDog {
13 /// This function must enable the watchdog timer and configure it to
14 /// trigger regulary. The period of the timer is left to the implementation
15 /// to decide. The implementation must ensure that it doesn't trigger too
16 /// early (when we haven't hung for example) or too late as to not catch
17 /// faults.
18 /// After calling this function the watchdog must be running.
19 fn setup(&self) {}
20
21 /// This function must tickle the watchdog to reset the timer.
22 /// If the watchdog was previously suspended then this should also
23 /// resume the timer.
24 fn tickle(&self) {}
25
26 /// Suspends the watchdog timer. After calling this the timer should not
27 /// fire until after `tickle()` has been called. This function is called
28 /// before sleeping.
29 fn suspend(&self) {}
30
31 /// Resumes the watchdog timer. After calling this the timer should be
32 /// running again. This is called after returning from sleep, after
33 /// `suspend()` was called.
34 fn resume(&self) {
35 self.tickle();
36 }
37}
38
39/// Implement default WatchDog trait for unit.
40impl WatchDog for () {}