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 David Smart

Committer:
gesotec
Date:
Tue Jun 03 12:07:38 2014 +0000
Revision:
3:a6655a236a10
Parent:
2:2873f068f325
Added Watchdog Target LPC4088

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 2:2873f068f325 1 /// @file Watchdog.cpp provides the interface to the Watchdog module
WiredHome 2:2873f068f325 2 ///
WiredHome 2:2873f068f325 3 /// This provides basic Watchdog service for the mbed. You can configure
WiredHome 2:2873f068f325 4 /// various timeout intervals that meet your system needs. Additionally,
WiredHome 2:2873f068f325 5 /// it is possible to identify if the Watchdog was the cause of any
WiredHome 2:2873f068f325 6 /// system restart.
WiredHome 2:2873f068f325 7 ///
WiredHome 2:2873f068f325 8 /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/
WiredHome 2:2873f068f325 9 ///
WiredHome 2:2873f068f325 10 /// @note Copyright © 2011 by Smartware Computing, all rights reserved.
WiredHome 2:2873f068f325 11 /// This software may be used to derive new software, as long as
WiredHome 2:2873f068f325 12 /// this copyright statement remains in the source file.
WiredHome 2:2873f068f325 13 /// @author David Smart
WiredHome 2:2873f068f325 14 ///
WiredHome 0:7a316f14da9c 15 #include "mbed.h"
WiredHome 0:7a316f14da9c 16 #include "Watchdog.h"
WiredHome 0:7a316f14da9c 17
WiredHome 0:7a316f14da9c 18
gesotec 3:a6655a236a10 19 #if defined( TARGET_LPC1768 )
WiredHome 0:7a316f14da9c 20 /// Watchdog gets instantiated at the module level
WiredHome 0:7a316f14da9c 21 Watchdog::Watchdog() {
WiredHome 2:2873f068f325 22 wdreset = (LPC_WDT->WDMOD >> 2) & 1; // capture the cause of the previous reset
WiredHome 0:7a316f14da9c 23 }
WiredHome 0:7a316f14da9c 24
WiredHome 0:7a316f14da9c 25 /// Load timeout value in watchdog timer and enable
WiredHome 0:7a316f14da9c 26 void Watchdog::Configure(float s) {
WiredHome 0:7a316f14da9c 27 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
WiredHome 0:7a316f14da9c 28 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
WiredHome 2:2873f068f325 29 LPC_WDT->WDTC = (uint32_t)(s * (float)clk);
WiredHome 0:7a316f14da9c 30 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
WiredHome 0:7a316f14da9c 31 Service();
WiredHome 0:7a316f14da9c 32 }
WiredHome 0:7a316f14da9c 33
WiredHome 0:7a316f14da9c 34 /// "Service", "kick" or "feed" the dog - reset the watchdog timer
WiredHome 0:7a316f14da9c 35 /// by writing this required bit pattern
WiredHome 0:7a316f14da9c 36 void Watchdog::Service() {
WiredHome 0:7a316f14da9c 37 LPC_WDT->WDFEED = 0xAA;
WiredHome 0:7a316f14da9c 38 LPC_WDT->WDFEED = 0x55;
WiredHome 0:7a316f14da9c 39 }
WiredHome 0:7a316f14da9c 40
WiredHome 0:7a316f14da9c 41 /// get the flag to indicate if the watchdog causes the reset
WiredHome 0:7a316f14da9c 42 bool Watchdog::WatchdogCausedReset() {
WiredHome 0:7a316f14da9c 43 return wdreset;
WiredHome 0:7a316f14da9c 44 }
gesotec 3:a6655a236a10 45 #elif defined( TARGET_LPC4088 )
gesotec 3:a6655a236a10 46 /// Watchdog gets instantiated at the module level
gesotec 3:a6655a236a10 47 Watchdog::Watchdog() {
gesotec 3:a6655a236a10 48 wdreset = (LPC_WDT->MOD >> 2) & 1; // capture the cause of the previous reset
gesotec 3:a6655a236a10 49 }
WiredHome 0:7a316f14da9c 50
gesotec 3:a6655a236a10 51 /// Load timeout value in watchdog timer and enable
gesotec 3:a6655a236a10 52 void Watchdog::Configure(float s) {
gesotec 3:a6655a236a10 53 //LPC_WDT->CLKSEL = 0x1; // Set CLK src to PCLK
gesotec 3:a6655a236a10 54 uint32_t clk = 500000 / 4; // WD has a fixed /4 prescaler, and a 500khz oscillator
gesotec 3:a6655a236a10 55 LPC_WDT->TC = (uint32_t)(s * (float)clk);
gesotec 3:a6655a236a10 56 LPC_WDT->MOD = 0x3; // Enabled and Reset
gesotec 3:a6655a236a10 57 Service();
gesotec 3:a6655a236a10 58 }
WiredHome 0:7a316f14da9c 59
gesotec 3:a6655a236a10 60 /// "Service", "kick" or "feed" the dog - reset the watchdog timer
gesotec 3:a6655a236a10 61 /// by writing this required bit pattern
gesotec 3:a6655a236a10 62 void Watchdog::Service() {
gesotec 3:a6655a236a10 63 LPC_WDT->FEED = 0xAA;
gesotec 3:a6655a236a10 64 LPC_WDT->FEED = 0x55;
gesotec 3:a6655a236a10 65 }
gesotec 3:a6655a236a10 66
gesotec 3:a6655a236a10 67 /// get the flag to indicate if the watchdog causes the reset
gesotec 3:a6655a236a10 68 bool Watchdog::WatchdogCausedReset() {
gesotec 3:a6655a236a10 69 return wdreset;
gesotec 3:a6655a236a10 70 }
gesotec 3:a6655a236a10 71 #endif
gesotec 3:a6655a236a10 72