WathchDog

Dependencies:   mbed WDT

Revision:
8:0c5a091410cf
Parent:
7:f201e2d0ed4f
Child:
9:6c267eecb235
--- a/main.cpp	Fri Aug 16 08:43:23 2019 +0000
+++ b/main.cpp	Thu Sep 12 05:42:04 2019 +0000
@@ -1,21 +1,5 @@
 #include "mbed.h"
-
-
-class WatchDog {
-private:
-    IWDG_HandleTypeDef hiwdg;
-public:
-    WatchDog(uint32_t prescaler = IWDG_PRESCALER_256, uint32_t reload = 0x0FFF) {
-        hiwdg.Instance = (IWDG_TypeDef*)0x40003000;
-        hiwdg.Init.Prescaler = prescaler;
-        hiwdg.Init.Reload = reload;
-        HAL_IWDG_Init(&hiwdg);
-    }
-    void kick() {
-        HAL_IWDG_Refresh(&hiwdg);
-    }
-};
-
+#include "WDT.h"
 
 //const int _ID = 4;
 
@@ -55,7 +39,6 @@
 
 
 char rsgetc() {
-//    pc.printf("%c",RxBuff[RdPtr]);
 
     RdPtr++;
     if(RdPtr >= bufsize-1) RdPtr = 0;
@@ -94,8 +77,12 @@
     int i,cnt;
     int pulse;
 
-//    WatchDog wdg(IWDG_PRESCALER_16, 0x0FFF);
+    pc.printf("\n--Initial Start--\r\n");
+
+    WDT wdgTimer;
     
+    wdgTimer.Configure(10);
+
     modem.baud(38400);
     modem.format(8,Serial::None,1);    
     RxPtr = 0;
@@ -104,9 +91,8 @@
     cnt485 = 0;
     buf485[0] = '\0';
 
-    pc.printf("\nSTM32 ADC internal channels reading example\r\n");
+    wdgTimer.Service();
 
-//    wdg.kick(); // IWDGをリセット
 
     pos1 = 1;
     pos2 = 1;
@@ -118,11 +104,15 @@
     pulse_watcher.start();
     pulse = pulse1 || pulse2;
 
+
+
     for (i = 0;i<40;i++) {
         data[i] = 0;
-//        wdg.kick(); // IWDGをリセット
+        wdgTimer.Service();
     }
-    
+
+    pc.printf("\n--Initial End--\r\n");
+
     while(1) {
         if (pulse_watcher.read() > 100) pulse_watcher.reset();
         
@@ -169,7 +159,8 @@
                 pos2 = 1;
             }
             
-//            wdg.kick(); // IWDGをリセット
+//            if (jmp != 0) wdgTimer.Service();
+            wdgTimer.Service();
 
             // pulsewatch
         }
@@ -202,6 +193,8 @@
 //        if (jmp == 0) while(1) ; 
 
 //        wdg.kick(); // IWDGをリセット
+//        if (jmp != 0) wdgTimer.Service();
+        wdgTimer.Service();
     }
 }