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:
- 17:ccd155378a9b
- Parent:
- 15:e0e4c2268558
- Child:
- 18:edfbf294c9e2
--- a/Watchdog.cpp Sun Feb 25 13:36:35 2018 +0000
+++ b/Watchdog.cpp Thu Mar 15 10:31:54 2018 +0000
@@ -85,6 +85,67 @@
bool Watchdog::WatchdogCausedReset() {
return _wdreset;
}
+
+#elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X)
+// from Gesotec Gesotec
+/// Watchdog gets instantiated at the module level
+Watchdog::Watchdog()
+{
+ _wdreset = (LPC_WWDT->MOD >> 2) & 1; // capture the cause of the previous reset
+}
+
+/// Load timeout value in watchdog timer and enable
+void Watchdog::Configure(float s)
+{
+ Configure((int)(s * 1000));
+}
+
+void Watchdog::Configure(int ms)
+{
+ 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;
+ }
+ 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();
+}
+
+/// "Service", "kick" or "feed" the dog - reset the watchdog timer
+/// by writing this required bit pattern
+void Watchdog::Service()
+{
+ LPC_WWDT->FEED = 0xAA;
+ LPC_WWDT->FEED = 0x55;
+}
+
+/// get the flag to indicate if the watchdog causes the reset
+bool Watchdog::WatchdogCausedReset()
+{
+ return _wdreset;
+}
+
#elif defined(TARGET_STM)
Watchdog::Watchdog()
{
