use kernel::utilities::registers::interfaces::Writeable;
use kernel::utilities::registers::{register_bitfields, ReadWrite, WriteOnly};
use kernel::utilities::StaticRef;
#[repr(C)]
pub struct WatchdogRegisters {
wdogcfg: ReadWrite<u32, cfg::Register>,
_reserved0: [u8; 4],
wdogcount: ReadWrite<u32>,
_reserved1: [u8; 4],
wdogs: ReadWrite<u32>,
_reserved2: [u8; 4],
wdogfeed: ReadWrite<u32, feed::Register>,
wdogkey: WriteOnly<u32, key::Register>,
wdogcmp: ReadWrite<u32>,
}
register_bitfields![u32,
cfg [
cmpip OFFSET(28) NUMBITS(1) [],
encoreawake OFFSET(13) NUMBITS(1) [],
enalways OFFSET(12) NUMBITS(1) [],
zerocmp OFFSET(9) NUMBITS(1) [],
rsten OFFSET(8) NUMBITS(1) [],
scale OFFSET(0) NUMBITS(4) []
],
key [
key OFFSET(0) NUMBITS(32) []
],
feed [
feed OFFSET(0) NUMBITS(32) []
]
];
pub struct Watchdog {
registers: StaticRef<WatchdogRegisters>,
}
impl Watchdog {
pub const fn new(base: StaticRef<WatchdogRegisters>) -> Watchdog {
Watchdog { registers: base }
}
fn unlock(&self) {
self.registers.wdogkey.write(key::key.val(0x51F15E));
}
fn feed(&self) {
self.unlock();
self.registers.wdogfeed.write(feed::feed.val(0xD09F00D));
}
pub fn disable(&self) {
self.unlock();
self.registers.wdogcfg.write(
cfg::scale.val(0)
+ cfg::rsten::CLEAR
+ cfg::zerocmp::CLEAR
+ cfg::enalways::CLEAR
+ cfg::encoreawake::CLEAR,
);
self.feed();
}
}