Hiroh Satoh / keyboard Featured

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
42:2c3be8694896
Child:
45:f4be69c936f6
diff -r 2b034f22b98f -r 2c3be8694896 WatchDog.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WatchDog.h	Sat Aug 27 08:43:53 2016 +0000
@@ -0,0 +1,19 @@
+
+class WatchDog {
+    static const uint32_t RELOAD_VALUE = 0x6E524635;
+    static const uint8_t WDT_TIMEOUT = 3; // sec
+public:
+    static void init() {
+        // timeout [s] = (CRV + 1) / 32768;
+        // crv = 32768 * timeout - 1
+        NRF_WDT->CRV = 32768 * WDT_TIMEOUT - 1;
+        NRF_WDT->RREN = WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos;
+        NRF_WDT->CONFIG = WDT_CONFIG_SLEEP_Pause << WDT_CONFIG_SLEEP_Pos;
+        NRF_WDT->TASKS_START = 1;
+    }
+    
+    static void reload() {
+        NRF_WDT->RR[0] = RELOAD_VALUE;
+    }
+    
+};
\ No newline at end of file