+++

Fork of Watchdog by David Smart

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Thu Jun 16 20:55:38 2011 +0000
Parent:
1:5a1ff72b5915
Child:
3:5959d3d35221
Commit message:
v1.00 initial documented version

Changed in this revision

Watchdog.cpp Show annotated file Show diff for this revision Revisions of this file
Watchdog.h Show annotated file Show diff for this revision Revisions of this file
--- a/Watchdog.cpp	Sun Mar 20 23:24:36 2011 +0000
+++ b/Watchdog.cpp	Thu Jun 16 20:55:38 2011 +0000
@@ -1,4 +1,17 @@
-
+/// @file Watchdog.cpp provides the interface to the Watchdog module
+///
+/// This provides basic Watchdog service for the mbed. You can configure
+/// various timeout intervals that meet your system needs. Additionally,
+/// it is possible to identify if the Watchdog was the cause of any 
+/// system restart.
+/// 
+/// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/
+///
+/// @note Copyright © 2011 by Smartware Computing, all rights reserved.
+///     This software may be used to derive new software, as long as
+///     this copyright statement remains in the source file.
+/// @author David Smart
+///
 #include "mbed.h"
 #include "Watchdog.h"
 
@@ -6,14 +19,14 @@
 
 /// Watchdog gets instantiated at the module level
 Watchdog::Watchdog() {
-    wdreset = (LPC_WDT->WDMOD >> 2) & 1;
+    wdreset = (LPC_WDT->WDMOD >> 2) & 1;    // capture the cause of the previous reset
 }
 
 /// Load timeout value in watchdog timer and enable
 void Watchdog::Configure(float s) {
     LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
     uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
-    LPC_WDT->WDTC = s * (float)clk;
+    LPC_WDT->WDTC = (uint32_t)(s * (float)clk);
     LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
     Service();
 }
--- a/Watchdog.h	Sun Mar 20 23:24:36 2011 +0000
+++ b/Watchdog.h	Thu Jun 16 20:55:38 2011 +0000
@@ -3,7 +3,8 @@
 /// This provides basic Watchdog service for the mbed. You can configure
 /// various timeout intervals that meet your system needs. Additionally,
 /// it is possible to identify if the Watchdog was the cause of any 
-/// system restart.
+/// system restart, permitting the application code to take appropriate
+/// behavior.
 /// 
 /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/
 ///
@@ -12,11 +13,23 @@
 ///     this copyright statement remains in the source file.
 /// @author David Smart
 ///
+/// History
+/// \li v1.00 - 20110616: initial release with some documentation improvements
+///
 #ifndef WATCHDOG_H
 #define WATCHDOG_H
 #include "mbed.h"
 
-/// Watchdog provides the interface to the Watchdog feature
+/// The Watchdog class provides the interface to the Watchdog feature
+///
+/// Embedded programs, by their nature, are usually unattended. If things
+/// go wrong, it is usually important that the system attempts to recover.
+/// Aside from robust software, a hardware watchdog can monitor the
+/// system and initiate a system reset when appropriate.
+///
+/// This Watchdog is patterned after one found elsewhere on the mbed site,
+/// however this one also provides a method for the application software
+/// to determine the cause of the reset - watchdog or otherwise.
 ///
 /// example:
 /// @code
@@ -25,11 +38,14 @@
 /// ...
 /// main() {
 ///    if (wd.WatchdogCausedReset())
-///        pc.printf("Watchdog caused reset. WD being armed for 30s cycle.\r\n");
+///        pc.printf("Watchdog caused reset.\r\n");
 ///      
-///    wd.Configure(30.0);      // sets the timeout interval
+///    wd.Configure(3.0);       // sets the timeout interval
 ///    for (;;) {
 ///         wd.Service();       // kick the dog before the timeout
+///         // do other work
+///    }
+/// }
 /// @endcode
 ///
 class Watchdog {