k64f watchdog example

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
manitou
Date:
Sun Apr 09 23:38:25 2017 +0000
Child:
1:c0b9e466e9e5
Commit message:
k64f watchdog example

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 09 23:38:25 2017 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+
+#define PRREG(z) printf(#z" 0x%x\n",z)
+Timer tmr;
+
+void wdog_init() {
+    __disable_irq();
+    WDOG->UNLOCK = WDOG_UNLOCK_WDOGUNLOCK(0xC520); /* Key 1 */
+    WDOG->UNLOCK = WDOG_UNLOCK_WDOGUNLOCK(0xD928); /* Key 2 */
+    __NOP();
+    __NOP();
+
+    WDOG_TOVALL = (4000); // The next 2 lines sets the time-out value. This is the value that the watchdog timer compare itself to.
+    WDOG_TOVALH = 0;
+    WDOG_STCTRLH = (WDOG_STCTRLH_ALLOWUPDATE_MASK | WDOG_STCTRLH_WDOGEN_MASK | WDOG_STCTRLH_WAITEN_MASK | WDOG_STCTRLH_STOPEN_MASK); // Enable WDG
+    WDOG_PRESC = 0; // prescaler 
+    __enable_irq();
+}
+
+void kick() {
+     __disable_irq();
+    WDOG_REFRESH = 0xA602;
+    WDOG_REFRESH = 0xB480;
+    __enable_irq();
+}
+
+int main() {
+    int i,fbus,flashbus;
+    fbus = SystemCoreClock / (((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV2_MASK) >> SIM_CLKDIV1_OUTDIV2_SHIFT) + 1);
+    flashbus = SystemCoreClock / (((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV4_MASK) >> SIM_CLKDIV1_OUTDIV4_SHIFT) + 1);
+    printf("\nSystemCoreClock %d fbus %d flash %d %s %s\n",SystemCoreClock,fbus,flashbus,__TIME__,__DATE__);
+    PRREG(WDOG->STCTRLH);
+    PRREG(WDOG->PRESC);
+    PRREG(WDOG->TOVALL);
+    PRREG(WDOG->TOVALH);
+    PRREG(WDOG->RSTCNT);
+    wdog_init();
+    PRREG(WDOG->STCTRLH);
+    PRREG(WDOG->PRESC);
+    PRREG(WDOG->TOVALL);
+    PRREG(WDOG->TOVALH);
+    PRREG(WDOG->RSTCNT);
+    wait_ms(100);
+    kick();
+    for (i=1;i<=3; i++) {
+        printf("running %d\n",i);
+        wait(1.0);
+        kick();
+    }
+    printf("long wait reset\n");
+    wait(5.0);
+    printf("never happen\n");
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Apr 09 23:38:25 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file