Watchdog Timer for the K64F. User can set timeout value from 1 to 356 seconds with a one second resolution.

Dependents:   Telliskivi2_2014 mbed-IBooth-ETH TwitterReader

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Watchdog.cpp Source File

Watchdog.cpp

00001 #include "mbed.h"
00002 #include "Watchdog.h"
00003 
00004 #if defined(TARGET_K64F)
00005 
00006 void Watchdog::kick(int toVal) {  
00007     const uint32_t K64FWDONESEC = 0x00B80000;   //approx 1 second delay
00008     if((toVal < 1) || (toVal > 356)) toVal = 356;
00009     WDOG_UNLOCK = 0xC520; 
00010     WDOG_UNLOCK = 0xD928;
00011     uint32_t wdogCntl = K64FWDONESEC * toVal;
00012     WDOG_TOVALH = wdogCntl >> 16;
00013     WDOG_TOVALL = wdogCntl & 0xFFFF;
00014     EnableWDOG();
00015 }
00016 
00017 void Watchdog::kick() {
00018     WDOG_REFRESH = 0xA602; 
00019     WDOG_REFRESH = 0xB480; 
00020 }
00021 
00022 void Watchdog::DisableWDOG() {   
00023     WDOG_UNLOCK = 0xC520; 
00024     WDOG_UNLOCK = 0xD928; 
00025     WDOG_STCTRLH &= 0xFFFE;
00026 }
00027     
00028 void Watchdog::EnableWDOG() {   
00029     WDOG_UNLOCK = 0xC520; 
00030     WDOG_UNLOCK = 0xD928; 
00031     WDOG_STCTRLH |= 0x0001;
00032     kick();
00033 }
00034 
00035 #endif  //(TARGET_K64F)