+++

Fork of Watchdog by David Smart

Watchdog.h

Committer:
WiredHome
Date:
2011-03-20
Revision:
0:7a316f14da9c
Child:
1:5a1ff72b5915

File content as of revision 0:7a316f14da9c:

/// @file Watchdog.h 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
///
#ifndef WATCHDOG_H
#define WATCHDOG_H
#include "mbed.h"

/// Watchdog provides the interface to the Watchdog feature
///
/// example:
/// @code
/// Watchdog wd;
///
/// ...
/// main() {
///    if (wd.WatchdogCausedReset())
///        pc.printf("Watchdog caused reset. WD being armed for 30s cycle.\r\n");
///      
///    wd.Configure(30.0);      // sets the timeout interval
///    for (;;) {
///         wd.Service;       // kick the dog before the timeout
/// @endcode
///
class Watchdog {
public:
    /// Create a Watchdog object
    ///
    /// example:
    /// @code
    /// Watchdog wd;    // placed before main
    /// @endcode
    Watchdog();
    
    /// Configure the timeout for the Watchdog
    ///
    /// This configures the Watchdog service and starts it. It must
    /// be serviced before the timeout, or the system will be restarted.
    ///
    /// example:
    /// @code
    ///     ...
    ///     wd.Configure(1.4);  // configure for a 1.4 second timeout
    ///     ...
    /// @endcode
    ///
    /// @param timeout in seconds, as a floating point number
    /// @returns none
    ///
    void Configure(float timeout);
    
    /// Service the Watchdog so it does not cause a system reset
    ///
    /// @returns none
    void Service();
    
    /// WatchdogCausedReset identifies if the cause of the system
    /// reset was the Watchdog
    ///
    /// example:
    /// @code
    ///    if (wd.WatchdogCausedReset())) {
    /// @endcode
    ///
    /// @returns true if the Watchdog was the cause of the reset
    bool WatchdogCausedReset();
private:
    bool wdreset;
};

#endif // WATCHDOG_H