Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Watchdog by
Diff: Watchdog.cpp
- Revision:
- 18:edfbf294c9e2
- Parent:
- 17:ccd155378a9b
- Child:
- 19:3b172e42d8ee
diff -r ccd155378a9b -r edfbf294c9e2 Watchdog.cpp
--- a/Watchdog.cpp Thu Mar 15 10:31:54 2018 +0000
+++ b/Watchdog.cpp Mon Mar 19 04:35:39 2018 +0000
@@ -87,6 +87,7 @@
}
#elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X)
+
// from Gesotec Gesotec
/// Watchdog gets instantiated at the module level
Watchdog::Watchdog()
@@ -102,34 +103,46 @@
void Watchdog::Configure(int ms)
{
+#if 0
+ uint32_t clk = get_wdtclock() / 4; // WD has a fixed /4 prescaler, and a 500khz oscillator
+ LPC_WWDT->TC = (ms * clk) / 1000;
+#else
+ LPC_SYSCON->WDTOSCCTRL = (0xA << 5); // wdt_osc_clk = Fclkana/2, Fclkana = 3.5MHz
+ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 17); // Enable Clock WWDT
+ LPC_SYSCON->PDRUNCFG &= ~(1 << 6); // Enable Power WDTOSC_PD
+ uint32_t clk = ((3500000/2)/4); // COUNT = wdt_osc_clk/4
+ LPC_WWDT->TC = (ms * clk) / 1000;
+#endif
+ LPC_WWDT->MOD = 0x3; // Enabled and Reset
+ Service();
+}
+
+uint32_t Watchdog::get_wdtclock()
+{
uint32_t wdt_osc = 0;
-
+
/* Determine clock frequency according to clock register values */
switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F)
{
case 0: wdt_osc = 0; break;
- case 1: wdt_osc = 500000; break;
- case 2: wdt_osc = 800000; break;
- case 3: wdt_osc = 1100000; break;
- case 4: wdt_osc = 1400000; break;
- case 5: wdt_osc = 1600000; break;
- case 6: wdt_osc = 1800000; break;
- case 7: wdt_osc = 2000000; break;
- case 8: wdt_osc = 2200000; break;
- case 9: wdt_osc = 2400000; break;
- case 10: wdt_osc = 2600000; break;
- case 11: wdt_osc = 2700000; break;
- case 12: wdt_osc = 2900000; break;
- case 13: wdt_osc = 3100000; break;
- case 14: wdt_osc = 3200000; break;
- case 15: wdt_osc = 3400000; break;
+ case 1: wdt_osc = 600000; break;
+ case 2: wdt_osc = 1050000; break;
+ case 3: wdt_osc = 1400000; break;
+ case 4: wdt_osc = 1750000; break;
+ case 5: wdt_osc = 2100000; break;
+ case 6: wdt_osc = 2400000; break;
+ case 7: wdt_osc = 2700000; break;
+ case 8: wdt_osc = 3000000; break;
+ case 9: wdt_osc = 3250000; break;
+ case 10: wdt_osc = 3500000; break;
+ case 11: wdt_osc = 3750000; break;
+ case 12: wdt_osc = 4000000; break;
+ case 13: wdt_osc = 4200000; break;
+ case 14: wdt_osc = 4400000; break;
+ case 15: wdt_osc = 4600000; break;
}
- wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2;
-
- uint32_t clk = wdt_osc / 4; // WD has a fixed /4 prescaler, and a 500khz oscillator
- LPC_WWDT->TC = (ms * clk) / 1000;
- LPC_WWDT->MOD = 0x3; // Enabled and Reset
- Service();
+// wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2;
+ return wdt_osc;
}
/// "Service", "kick" or "feed" the dog - reset the watchdog timer
