WathchDog

Dependencies:   mbed WDT

Revision:
6:1948d19f854f
Parent:
5:efffadf6d0e0
Child:
7:f201e2d0ed4f
--- a/main.cpp	Thu Aug 15 14:09:24 2019 +0000
+++ b/main.cpp	Thu Aug 15 14:16:46 2019 +0000
@@ -1,5 +1,22 @@
 #include "mbed.h"
 
+
+class WatchDog {
+private:
+    IWDG_HandleTypeDef hiwdg;
+public:
+    WatchDog(uint32_t prescaler = IWDG_PRESCALER_256, uint32_t reload = 0xFF) {
+        hiwdg.Instance = (IWDG_TypeDef*)0x40003000;
+        hiwdg.Init.Prescaler = prescaler;
+        hiwdg.Init.Reload = reload;
+        HAL_IWDG_Init(&hiwdg);
+    }
+    void kick() {
+        HAL_IWDG_Refresh(&hiwdg);
+    }
+};
+
+
 //const int _ID = 4;
 
 void irqrecv();
@@ -76,6 +93,8 @@
     int i,cnt;
     int pulse;
 
+    WatchDog wdg(IWDG_PRESCALER_8, 0x0FFF);
+    
     modem.baud(38400);
     modem.format(8,Serial::None,1);    
     RxPtr = 0;
@@ -170,6 +189,8 @@
         data[9] = ad2 * 0xffff;
         data[10] = ad3 * 0xffff;
         data[12] = ad4 * 0xffff;
+
+        wdg.kick(); // IWDGをリセット
     }
 }