Basic implementation of watchdog

Dependencies:   STM_ResetSupervisor USBDevice

Committer:
JesiMiranda
Date:
Tue Jun 25 23:31:34 2019 +0000
Revision:
0:975e02a70882
Basic watchdog implementation for ST Nucleo boards;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JesiMiranda 0:975e02a70882 1 /// @file Watchdog.h provides the interface to the Watchdog module
JesiMiranda 0:975e02a70882 2 ///
JesiMiranda 0:975e02a70882 3 /// This provides basic Watchdog service for the mbed. You can configure
JesiMiranda 0:975e02a70882 4 /// various timeout intervals that meet your system needs. Additionally,
JesiMiranda 0:975e02a70882 5 /// it is possible to identify if the Watchdog was the cause of any
JesiMiranda 0:975e02a70882 6 /// system restart, permitting the application code to take appropriate
JesiMiranda 0:975e02a70882 7 /// behavior.
JesiMiranda 0:975e02a70882 8 ///
JesiMiranda 0:975e02a70882 9 /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/
JesiMiranda 0:975e02a70882 10 ///
JesiMiranda 0:975e02a70882 11 /// @note Copyright © 2011 by Smartware Computing, all rights reserved.
JesiMiranda 0:975e02a70882 12 /// This software may be used to derive new software, as long as
JesiMiranda 0:975e02a70882 13 /// this copyright statement remains in the source file.
JesiMiranda 0:975e02a70882 14 /// @author David Smart
JesiMiranda 0:975e02a70882 15 ///
JesiMiranda 0:975e02a70882 16 /// History
JesiMiranda 0:975e02a70882 17 /// \li v1.00 - 20110616: initial release with some documentation improvements
JesiMiranda 0:975e02a70882 18 ///
JesiMiranda 0:975e02a70882 19 #ifndef WATCHDOG_H
JesiMiranda 0:975e02a70882 20 #define WATCHDOG_H
JesiMiranda 0:975e02a70882 21 #include "mbed.h"
JesiMiranda 0:975e02a70882 22
JesiMiranda 0:975e02a70882 23 /// The Watchdog class provides the interface to the Watchdog feature
JesiMiranda 0:975e02a70882 24 ///
JesiMiranda 0:975e02a70882 25 /// Embedded programs, by their nature, are usually unattended. If things
JesiMiranda 0:975e02a70882 26 /// go wrong, it is usually important that the system attempts to recover.
JesiMiranda 0:975e02a70882 27 /// Aside from robust software, a hardware watchdog can monitor the
JesiMiranda 0:975e02a70882 28 /// system and initiate a system reset when appropriate.
JesiMiranda 0:975e02a70882 29 ///
JesiMiranda 0:975e02a70882 30 /// This Watchdog is patterned after one found elsewhere on the mbed site,
JesiMiranda 0:975e02a70882 31 /// however this one also provides a method for the application software
JesiMiranda 0:975e02a70882 32 /// to determine the cause of the reset - watchdog or otherwise.
JesiMiranda 0:975e02a70882 33 ///
JesiMiranda 0:975e02a70882 34 /// example:
JesiMiranda 0:975e02a70882 35 /// @code
JesiMiranda 0:975e02a70882 36 /// Watchdog wd;
JesiMiranda 0:975e02a70882 37 ///
JesiMiranda 0:975e02a70882 38 /// ...
JesiMiranda 0:975e02a70882 39 /// main() {
JesiMiranda 0:975e02a70882 40 /// if (wd.WatchdogCausedReset())
JesiMiranda 0:975e02a70882 41 /// pc.printf("Watchdog caused reset.\r\n");
JesiMiranda 0:975e02a70882 42 ///
JesiMiranda 0:975e02a70882 43 /// wd.Configure(3.0); // sets the timeout interval
JesiMiranda 0:975e02a70882 44 /// for (;;) {
JesiMiranda 0:975e02a70882 45 /// wd.Service(); // kick the dog before the timeout
JesiMiranda 0:975e02a70882 46 /// // do other work
JesiMiranda 0:975e02a70882 47 /// }
JesiMiranda 0:975e02a70882 48 /// }
JesiMiranda 0:975e02a70882 49 /// @endcode
JesiMiranda 0:975e02a70882 50 ///
JesiMiranda 0:975e02a70882 51 class Watchdog {
JesiMiranda 0:975e02a70882 52 public:
JesiMiranda 0:975e02a70882 53 /// Create a Watchdog object
JesiMiranda 0:975e02a70882 54 ///
JesiMiranda 0:975e02a70882 55 /// example:
JesiMiranda 0:975e02a70882 56 /// @code
JesiMiranda 0:975e02a70882 57 /// Watchdog wd; // placed before main
JesiMiranda 0:975e02a70882 58 /// @endcode
JesiMiranda 0:975e02a70882 59 Watchdog();
JesiMiranda 0:975e02a70882 60
JesiMiranda 0:975e02a70882 61 /// Configure the timeout for the Watchdog
JesiMiranda 0:975e02a70882 62 ///
JesiMiranda 0:975e02a70882 63 /// This configures the Watchdog service and starts it. It must
JesiMiranda 0:975e02a70882 64 /// be serviced before the timeout, or the system will be restarted.
JesiMiranda 0:975e02a70882 65 ///
JesiMiranda 0:975e02a70882 66 /// example:
JesiMiranda 0:975e02a70882 67 /// @code
JesiMiranda 0:975e02a70882 68 /// ...
JesiMiranda 0:975e02a70882 69 /// wd.Configure(1.4); // configure for a 1.4 second timeout
JesiMiranda 0:975e02a70882 70 /// ...
JesiMiranda 0:975e02a70882 71 /// @endcode
JesiMiranda 0:975e02a70882 72 ///
JesiMiranda 0:975e02a70882 73 /// @param[in] timeout in seconds, as a floating point number
JesiMiranda 0:975e02a70882 74 /// @returns none
JesiMiranda 0:975e02a70882 75 ///
JesiMiranda 0:975e02a70882 76 void Configure(float timeout);
JesiMiranda 0:975e02a70882 77
JesiMiranda 0:975e02a70882 78 /// Service the Watchdog so it does not cause a system reset
JesiMiranda 0:975e02a70882 79 ///
JesiMiranda 0:975e02a70882 80 /// example:
JesiMiranda 0:975e02a70882 81 /// @code
JesiMiranda 0:975e02a70882 82 /// wd.Service();
JesiMiranda 0:975e02a70882 83 /// @endcode
JesiMiranda 0:975e02a70882 84 /// @returns none
JesiMiranda 0:975e02a70882 85 void Service();
JesiMiranda 0:975e02a70882 86
JesiMiranda 0:975e02a70882 87 /// WatchdogCausedReset identifies if the cause of the system
JesiMiranda 0:975e02a70882 88 /// reset was the Watchdog
JesiMiranda 0:975e02a70882 89 ///
JesiMiranda 0:975e02a70882 90 /// example:
JesiMiranda 0:975e02a70882 91 /// @code
JesiMiranda 0:975e02a70882 92 /// if (wd.WatchdogCausedReset())) {
JesiMiranda 0:975e02a70882 93 /// @endcode
JesiMiranda 0:975e02a70882 94 ///
JesiMiranda 0:975e02a70882 95 /// @returns true if the Watchdog was the cause of the reset
JesiMiranda 0:975e02a70882 96 bool WatchdogCausedReset();
JesiMiranda 0:975e02a70882 97 private:
JesiMiranda 0:975e02a70882 98 bool wdreset;
JesiMiranda 0:975e02a70882 99 };
JesiMiranda 0:975e02a70882 100
JesiMiranda 0:975e02a70882 101 #endif // WATCHDOG_H