+++

Fork of Watchdog by David Smart

Committer:
WiredHome
Date:
Sun Mar 20 23:22:50 2011 +0000
Revision:
0:7a316f14da9c
Child:
2:2873f068f325

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:7a316f14da9c 1
WiredHome 0:7a316f14da9c 2 #include "mbed.h"
WiredHome 0:7a316f14da9c 3 #include "Watchdog.h"
WiredHome 0:7a316f14da9c 4
WiredHome 0:7a316f14da9c 5
WiredHome 0:7a316f14da9c 6
WiredHome 0:7a316f14da9c 7 /// Watchdog gets instantiated at the module level
WiredHome 0:7a316f14da9c 8 Watchdog::Watchdog() {
WiredHome 0:7a316f14da9c 9 wdreset = (LPC_WDT->WDMOD >> 2) & 1;
WiredHome 0:7a316f14da9c 10 }
WiredHome 0:7a316f14da9c 11
WiredHome 0:7a316f14da9c 12 /// Load timeout value in watchdog timer and enable
WiredHome 0:7a316f14da9c 13 void Watchdog::Configure(float s) {
WiredHome 0:7a316f14da9c 14 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
WiredHome 0:7a316f14da9c 15 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
WiredHome 0:7a316f14da9c 16 LPC_WDT->WDTC = s * (float)clk;
WiredHome 0:7a316f14da9c 17 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
WiredHome 0:7a316f14da9c 18 Service();
WiredHome 0:7a316f14da9c 19 }
WiredHome 0:7a316f14da9c 20
WiredHome 0:7a316f14da9c 21 /// "Service", "kick" or "feed" the dog - reset the watchdog timer
WiredHome 0:7a316f14da9c 22 /// by writing this required bit pattern
WiredHome 0:7a316f14da9c 23 void Watchdog::Service() {
WiredHome 0:7a316f14da9c 24 LPC_WDT->WDFEED = 0xAA;
WiredHome 0:7a316f14da9c 25 LPC_WDT->WDFEED = 0x55;
WiredHome 0:7a316f14da9c 26 }
WiredHome 0:7a316f14da9c 27
WiredHome 0:7a316f14da9c 28 /// get the flag to indicate if the watchdog causes the reset
WiredHome 0:7a316f14da9c 29 bool Watchdog::WatchdogCausedReset() {
WiredHome 0:7a316f14da9c 30 return wdreset;
WiredHome 0:7a316f14da9c 31 }
WiredHome 0:7a316f14da9c 32
WiredHome 0:7a316f14da9c 33