Added definition for LCP11u24 and LCP11u24
Fork of Watchdog by
Embed:
(wiki syntax)
Show/hide line numbers
Watchdog.cpp
Go to the documentation of this file.
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 #if defined( TARGET_LPC1768 ) 00019 /// Watchdog gets instantiated at the module level 00020 Watchdog::Watchdog() { 00021 wdreset = (LPC_WDT->WDMOD >> 2) & 1; // capture the cause of the previous reset 00022 } 00023 00024 /// Load timeout value in watchdog timer and enable 00025 void Watchdog::Configure(float s) { 00026 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK 00027 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 00028 LPC_WDT->WDTC = (uint32_t)(s * (float)clk); 00029 LPC_WDT->WDMOD = 0x3; // Enabled and Reset 00030 Service(); 00031 } 00032 00033 /// "Service", "kick" or "feed" the dog - reset the watchdog timer 00034 /// by writing this required bit pattern 00035 void Watchdog::Service() { 00036 LPC_WDT->WDFEED = 0xAA; 00037 LPC_WDT->WDFEED = 0x55; 00038 } 00039 00040 /// get the flag to indicate if the watchdog causes the reset 00041 bool Watchdog::WatchdogCausedReset() { 00042 return wdreset; 00043 } 00044 #elif defined(TARGET_ARCH_GPRS) || defined(TARGET_LPC11U24) 00045 /// Watchdog gets instantiated at the module level 00046 Watchdog::Watchdog() { 00047 wdreset = (LPC_WWDT->MOD >> 2) & 1; // capture the cause of the previous reset 00048 } 00049 00050 void Watchdog::Configure(float s) { 00051 LPC_SYSCON->SYSAHBCLKCTRL |= 0x8000; 00052 LPC_SYSCON->PDRUNCFG &= 0xFFBF; 00053 LPC_SYSCON->WDTOSCCTRL = 0x40; 00054 00055 uint32_t clk = 100000; 00056 LPC_WWDT->TC = s * (float)clk; 00057 00058 LPC_WWDT->CLKSEL = 0x1; // Set CLK src to PCLK 00059 LPC_WWDT->MOD = 0x3; // Enabled and Reset 00060 Service(); 00061 } 00062 00063 /// "Service", "kick" or "feed" the dog - reset the watchdog timer 00064 /// by writing this required bit pattern 00065 void Watchdog::Service() { 00066 LPC_WWDT->FEED = 0xAA; 00067 LPC_WWDT->FEED = 0x55; 00068 } 00069 00070 /// get the flag to indicate if the watchdog causes the reset 00071 bool Watchdog::WatchdogCausedReset() { 00072 return wdreset; 00073 } 00074 #elif defined( TARGET_LPC4088 ) 00075 // from Gesotec Gesotec 00076 /// Watchdog gets instantiated at the module level 00077 Watchdog::Watchdog() { 00078 wdreset = (LPC_WDT->MOD >> 2) & 1; // capture the cause of the previous reset 00079 } 00080 00081 /// Load timeout value in watchdog timer and enable 00082 void Watchdog::Configure(float s) { 00083 //LPC_WDT->CLKSEL = 0x1; // Set CLK src to PCLK 00084 uint32_t clk = 500000 / 4; // WD has a fixed /4 prescaler, and a 500khz oscillator 00085 LPC_WDT->TC = (uint32_t)(s * (float)clk); 00086 LPC_WDT->MOD = 0x3; // Enabled and Reset 00087 Service(); 00088 } 00089 00090 /// "Service", "kick" or "feed" the dog - reset the watchdog timer 00091 /// by writing this required bit pattern 00092 void Watchdog::Service() { 00093 LPC_WDT->FEED = 0xAA; 00094 LPC_WDT->FEED = 0x55; 00095 } 00096 00097 /// get the flag to indicate if the watchdog causes the reset 00098 bool Watchdog::WatchdogCausedReset() { 00099 return wdreset; 00100 } 00101 #elif defined( TARGET_STM ) 00102 // Derived from Chau Vo 00103 /// Watchdog gets instantiated at the module level 00104 Watchdog::Watchdog() { 00105 wdreset = (RCC->CSR & (1<<29)) ? true : false; // read the IWDGRSTF (Independent WD, not the windows WD) 00106 } 00107 00108 /// Load timeout value in watchdog timer and enable 00109 void Watchdog::Configure(int pr) { 00110 // http://www.st.com/web/en/resource/technical/document/reference_manual/CD00171190.pdf 00111 IWDG->KR = 0x5555; // enable write to PR, RLR 00112 IWDG->PR = pr; // Init prescaler, page 486 Reference Manual 00113 IWDG->RLR = 0xFFF; // Init RLR 00114 IWDG->KR = 0xAAAA; // Reload the watchdog 00115 IWDG->KR = 0xCCCC; // Starts the WD 00116 } 00117 00118 /// "Service", "kick" or "feed" the dog - reset the watchdog timer 00119 void Watchdog::Service() { 00120 IWDG->KR = 0xAAAA; 00121 } 00122 00123 /// get the flag to indicate if the watchdog causes the reset 00124 bool Watchdog::WatchdogCausedReset() { 00125 if (wdreset) { 00126 RCC->CSR |= (1<<24); // clear reset flag 00127 } 00128 return wdreset; 00129 } 00130 #endif
Generated on Sat Jul 30 2022 16:59:22 by 1.7.2