Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/

Committer:
tylerjw
Date:
Tue Jul 24 23:11:37 2012 +0000
Revision:
0:daae6c64fbdf
simple watchdog

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:daae6c64fbdf 1 /* Copyright (c) 2012 Tyler Weaver, MIT License
tylerjw 0:daae6c64fbdf 2 *
tylerjw 0:daae6c64fbdf 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tylerjw 0:daae6c64fbdf 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tylerjw 0:daae6c64fbdf 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tylerjw 0:daae6c64fbdf 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tylerjw 0:daae6c64fbdf 7 * furnished to do so, subject to the following conditions:
tylerjw 0:daae6c64fbdf 8 *
tylerjw 0:daae6c64fbdf 9 * The above copyright notice and this permission notice shall be included in all copies or
tylerjw 0:daae6c64fbdf 10 * substantial portions of the Software.
tylerjw 0:daae6c64fbdf 11 *
tylerjw 0:daae6c64fbdf 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tylerjw 0:daae6c64fbdf 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tylerjw 0:daae6c64fbdf 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tylerjw 0:daae6c64fbdf 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tylerjw 0:daae6c64fbdf 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tylerjw 0:daae6c64fbdf 17 */
tylerjw 0:daae6c64fbdf 18
tylerjw 0:daae6c64fbdf 19 #include "mbed.h"
tylerjw 0:daae6c64fbdf 20 #include "watchdog.h"
tylerjw 0:daae6c64fbdf 21
tylerjw 0:daae6c64fbdf 22 // Simon's Watchdog code from
tylerjw 0:daae6c64fbdf 23 // http://mbed.org/forum/mbed/topic/508/
tylerjw 0:daae6c64fbdf 24
tylerjw 0:daae6c64fbdf 25 // Load timeout value in watchdog timer and enable
tylerjw 0:daae6c64fbdf 26 void Watchdog::kick(float s) {
tylerjw 0:daae6c64fbdf 27 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
tylerjw 0:daae6c64fbdf 28 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4
tylerjw 0:daae6c64fbdf 29 LPC_WDT->WDTC = s * (float)clk;
tylerjw 0:daae6c64fbdf 30 LPC_WDT->WDMOD = 0x3; // Enabled and Reset
tylerjw 0:daae6c64fbdf 31 kick();
tylerjw 0:daae6c64fbdf 32 }
tylerjw 0:daae6c64fbdf 33 // "kick" or "feed" the dog - reset the watchdog timer
tylerjw 0:daae6c64fbdf 34 // by writing this required bit pattern
tylerjw 0:daae6c64fbdf 35 void Watchdog::kick() {
tylerjw 0:daae6c64fbdf 36 LPC_WDT->WDFEED = 0xAA;
tylerjw 0:daae6c64fbdf 37 LPC_WDT->WDFEED = 0x55;
tylerjw 0:daae6c64fbdf 38 }