Neptune_170620

Dependencies:   mbed

Committer:
Picmon
Date:
Wed Jun 17 10:11:19 2020 +0000
Revision:
0:20b4b057fa7f
Neptune;

Who changed what in which revision?

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