This provides a basic Watchdog service, and includes a startup detection to determine if the reset was caused by the WD. Added Target LPC4088.
Fork of Watchdog by
Watchdog.cpp
00001 /// @file Watchdog.cpp provides the interface to the Watchdog module 00002 /// 00003 /// This provides basic Watchdog service for the mbed. You can configure 00004 /// various timeout intervals that meet your system needs. Additionally, 00005 /// it is possible to identify if the Watchdog was the cause of any 00006 /// system restart. 00007 /// 00008 /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/ 00009 /// 00010 /// @note Copyright © 2011 by Smartware Computing, all rights reserved. 00011 /// This software may be used to derive new software, as long as 00012 /// this copyright statement remains in the source file. 00013 /// @author David Smart 00014 /// 00015 #include "mbed.h" 00016 #include "Watchdog.h" 00017 00018 00019 #if defined( TARGET_LPC1768 ) 00020 /// Watchdog gets instantiated at the module level 00021 Watchdog::Watchdog() { 00022 wdreset = (LPC_WDT->WDMOD >> 2) & 1; // capture the cause of the previous reset 00023 } 00024 00025 /// Load timeout value in watchdog timer and enable 00026 void Watchdog::Configure(float s) { 00027 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK 00028 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 00029 LPC_WDT->WDTC = (uint32_t)(s * (float)clk); 00030 LPC_WDT->WDMOD = 0x3; // Enabled and Reset 00031 Service(); 00032 } 00033 00034 /// "Service", "kick" or "feed" the dog - reset the watchdog timer 00035 /// by writing this required bit pattern 00036 void Watchdog::Service() { 00037 LPC_WDT->WDFEED = 0xAA; 00038 LPC_WDT->WDFEED = 0x55; 00039 } 00040 00041 /// get the flag to indicate if the watchdog causes the reset 00042 bool Watchdog::WatchdogCausedReset() { 00043 return wdreset; 00044 } 00045 #elif defined( TARGET_LPC4088 ) 00046 /// Watchdog gets instantiated at the module level 00047 Watchdog::Watchdog() { 00048 wdreset = (LPC_WDT->MOD >> 2) & 1; // capture the cause of the previous reset 00049 } 00050 00051 /// Load timeout value in watchdog timer and enable 00052 void Watchdog::Configure(float s) { 00053 //LPC_WDT->CLKSEL = 0x1; // Set CLK src to PCLK 00054 uint32_t clk = 500000 / 4; // WD has a fixed /4 prescaler, and a 500khz oscillator 00055 LPC_WDT->TC = (uint32_t)(s * (float)clk); 00056 LPC_WDT->MOD = 0x3; // Enabled and Reset 00057 Service(); 00058 } 00059 00060 /// "Service", "kick" or "feed" the dog - reset the watchdog timer 00061 /// by writing this required bit pattern 00062 void Watchdog::Service() { 00063 LPC_WDT->FEED = 0xAA; 00064 LPC_WDT->FEED = 0x55; 00065 } 00066 00067 /// get the flag to indicate if the watchdog causes the reset 00068 bool Watchdog::WatchdogCausedReset() { 00069 return wdreset; 00070 } 00071 #endif 00072
Generated on Wed Jul 13 2022 01:02:28 by 1.7.2