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.
Dependencies: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
Watchdog.h@22:14b4060dd027, 2015-10-16 (annotated)
- Committer:
- Bobty
- Date:
- Fri Oct 16 08:42:13 2015 +0000
- Revision:
- 22:14b4060dd027
- Parent:
- 19:0367cb46d003
Re-enabled web folder view on server
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Bobty | 12:a52996515063 | 1 | #ifndef __WATCHDOG__H |
| Bobty | 12:a52996515063 | 2 | #define __WATCHDOG__H |
| Bobty | 12:a52996515063 | 3 | #include "mbed.h" |
| Bobty | 12:a52996515063 | 4 | |
| Bobty | 12:a52996515063 | 5 | // Simon's Watchdog code from |
| Bobty | 12:a52996515063 | 6 | // http://mbed.org/forum/mbed/topic/508/ |
| Bobty | 12:a52996515063 | 7 | class Watchdog |
| Bobty | 12:a52996515063 | 8 | { |
| Bobty | 12:a52996515063 | 9 | public: |
| Bobty | 12:a52996515063 | 10 | // Load timeout value in watchdog timer and enable |
| Bobty | 12:a52996515063 | 11 | void SetTimeoutSecs(float s) |
| Bobty | 12:a52996515063 | 12 | { |
| Bobty | 12:a52996515063 | 13 | LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK |
| Bobty | 12:a52996515063 | 14 | uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 |
| Bobty | 12:a52996515063 | 15 | LPC_WDT->WDTC = s * (float)clk; |
| Bobty | 12:a52996515063 | 16 | LPC_WDT->WDMOD = 0x3; // Enabled and Reset |
| Bobty | 12:a52996515063 | 17 | Feed(); |
| Bobty | 12:a52996515063 | 18 | } |
| Bobty | 12:a52996515063 | 19 | // "kick" or "feed" the dog - reset the watchdog timer |
| Bobty | 12:a52996515063 | 20 | // by writing this required bit pattern |
| Bobty | 12:a52996515063 | 21 | void Feed() |
| Bobty | 12:a52996515063 | 22 | { |
| Bobty | 19:0367cb46d003 | 23 | __disable_irq(); |
| Bobty | 12:a52996515063 | 24 | LPC_WDT->WDFEED = 0xAA; |
| Bobty | 12:a52996515063 | 25 | LPC_WDT->WDFEED = 0x55; |
| Bobty | 19:0367cb46d003 | 26 | __enable_irq(); |
| Bobty | 12:a52996515063 | 27 | } |
| Bobty | 12:a52996515063 | 28 | |
| Bobty | 12:a52996515063 | 29 | bool WatchdogCausedRestart() |
| Bobty | 12:a52996515063 | 30 | { |
| Bobty | 12:a52996515063 | 31 | if ((LPC_WDT->WDMOD >> 2) & 1) |
| Bobty | 12:a52996515063 | 32 | return true; |
| Bobty | 12:a52996515063 | 33 | return false; |
| Bobty | 12:a52996515063 | 34 | } |
| Bobty | 12:a52996515063 | 35 | }; |
| Bobty | 12:a52996515063 | 36 | |
| Bobty | 12:a52996515063 | 37 | #endif |