Tomonori Kuroki / MuWatchdog

Fork of Watchdog by David Smart

Committer:
mutech
Date:
Sun Feb 25 13:36:35 2018 +0000
Revision:
16:de80257a1ed0
Parent:
15:e0e4c2268558
Child:
18:edfbf294c9e2
MuWatchdog

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:7a316f14da9c 1 /// @file Watchdog.h provides the interface to the Watchdog module
WiredHome 0:7a316f14da9c 2 ///
WiredHome 0:7a316f14da9c 3 /// This provides basic Watchdog service for the mbed. You can configure
WiredHome 0:7a316f14da9c 4 /// various timeout intervals that meet your system needs. Additionally,
WiredHome 0:7a316f14da9c 5 /// it is possible to identify if the Watchdog was the cause of any
WiredHome 2:2873f068f325 6 /// system restart, permitting the application code to take appropriate
WiredHome 2:2873f068f325 7 /// behavior.
WiredHome 0:7a316f14da9c 8 ///
WiredHome 0:7a316f14da9c 9 /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/
WiredHome 0:7a316f14da9c 10 ///
WiredHome 6:e0f547e22dd5 11 /// @note Copyright © 2011,2015 by Smartware Computing, all rights reserved.
WiredHome 0:7a316f14da9c 12 /// This software may be used to derive new software, as long as
WiredHome 0:7a316f14da9c 13 /// this copyright statement remains in the source file.
WiredHome 0:7a316f14da9c 14 /// @author David Smart
WiredHome 0:7a316f14da9c 15 ///
WiredHome 2:2873f068f325 16 /// History
mutech 7:3814d72b8166 17 /// \li v2.10 - 20160914: Changed TARGET_STM by mutech, t.kuroki
WiredHome 5:2dad2a78ffbd 18 /// \li v2.00 - 20150315: Enhanced beyond TARGET_LPC1768 to TARGET_LPC4088, TARGET_STM
WiredHome 2:2873f068f325 19 /// \li v1.00 - 20110616: initial release with some documentation improvements
WiredHome 2:2873f068f325 20 ///
WiredHome 0:7a316f14da9c 21 #ifndef WATCHDOG_H
WiredHome 0:7a316f14da9c 22 #define WATCHDOG_H
WiredHome 0:7a316f14da9c 23 #include "mbed.h"
WiredHome 0:7a316f14da9c 24
WiredHome 2:2873f068f325 25 /// The Watchdog class provides the interface to the Watchdog feature
WiredHome 2:2873f068f325 26 ///
WiredHome 2:2873f068f325 27 /// Embedded programs, by their nature, are usually unattended. If things
WiredHome 2:2873f068f325 28 /// go wrong, it is usually important that the system attempts to recover.
WiredHome 2:2873f068f325 29 /// Aside from robust software, a hardware watchdog can monitor the
WiredHome 2:2873f068f325 30 /// system and initiate a system reset when appropriate.
WiredHome 2:2873f068f325 31 ///
WiredHome 2:2873f068f325 32 /// This Watchdog is patterned after one found elsewhere on the mbed site,
WiredHome 2:2873f068f325 33 /// however this one also provides a method for the application software
WiredHome 2:2873f068f325 34 /// to determine the cause of the reset - watchdog or otherwise.
WiredHome 0:7a316f14da9c 35 ///
WiredHome 5:2dad2a78ffbd 36 /// Supports:
WiredHome 5:2dad2a78ffbd 37 /// \li TARGET_LPC1768
WiredHome 5:2dad2a78ffbd 38 /// \li TARGET_LPC4088
WiredHome 5:2dad2a78ffbd 39 /// \li TARGET_STM
WiredHome 5:2dad2a78ffbd 40 ///
WiredHome 0:7a316f14da9c 41 /// example:
WiredHome 0:7a316f14da9c 42 /// @code
WiredHome 0:7a316f14da9c 43 /// Watchdog wd;
WiredHome 0:7a316f14da9c 44 ///
WiredHome 0:7a316f14da9c 45 /// ...
WiredHome 0:7a316f14da9c 46 /// main() {
WiredHome 0:7a316f14da9c 47 /// if (wd.WatchdogCausedReset())
WiredHome 2:2873f068f325 48 /// pc.printf("Watchdog caused reset.\r\n");
WiredHome 0:7a316f14da9c 49 ///
WiredHome 2:2873f068f325 50 /// wd.Configure(3.0); // sets the timeout interval
WiredHome 0:7a316f14da9c 51 /// for (;;) {
WiredHome 1:5a1ff72b5915 52 /// wd.Service(); // kick the dog before the timeout
WiredHome 2:2873f068f325 53 /// // do other work
WiredHome 2:2873f068f325 54 /// }
WiredHome 2:2873f068f325 55 /// }
WiredHome 0:7a316f14da9c 56 /// @endcode
WiredHome 0:7a316f14da9c 57 ///
mutech 16:de80257a1ed0 58 class Watchdog : private NonCopyable<Watchdog> {
WiredHome 0:7a316f14da9c 59 public:
WiredHome 0:7a316f14da9c 60 /// Create a Watchdog object
WiredHome 0:7a316f14da9c 61 ///
WiredHome 0:7a316f14da9c 62 /// example:
WiredHome 0:7a316f14da9c 63 /// @code
WiredHome 0:7a316f14da9c 64 /// Watchdog wd; // placed before main
WiredHome 0:7a316f14da9c 65 /// @endcode
WiredHome 0:7a316f14da9c 66 Watchdog();
WiredHome 0:7a316f14da9c 67
WiredHome 0:7a316f14da9c 68 /// Configure the timeout for the Watchdog
WiredHome 0:7a316f14da9c 69 ///
WiredHome 0:7a316f14da9c 70 /// This configures the Watchdog service and starts it. It must
WiredHome 0:7a316f14da9c 71 /// be serviced before the timeout, or the system will be restarted.
WiredHome 0:7a316f14da9c 72 ///
WiredHome 0:7a316f14da9c 73 /// example:
WiredHome 0:7a316f14da9c 74 /// @code
WiredHome 0:7a316f14da9c 75 /// ...
WiredHome 0:7a316f14da9c 76 /// wd.Configure(1.4); // configure for a 1.4 second timeout
WiredHome 0:7a316f14da9c 77 /// ...
WiredHome 0:7a316f14da9c 78 /// @endcode
WiredHome 0:7a316f14da9c 79 ///
WiredHome 4:22c5c4aa4661 80 /// @param[in] timeout in seconds, as a floating point number
WiredHome 0:7a316f14da9c 81 /// @returns none
WiredHome 0:7a316f14da9c 82 ///
WiredHome 0:7a316f14da9c 83 void Configure(float timeout);
mutech 7:3814d72b8166 84
mutech 7:3814d72b8166 85 void Configure(int timeout_ms);
WiredHome 0:7a316f14da9c 86
WiredHome 0:7a316f14da9c 87 /// Service the Watchdog so it does not cause a system reset
WiredHome 0:7a316f14da9c 88 ///
WiredHome 1:5a1ff72b5915 89 /// example:
WiredHome 1:5a1ff72b5915 90 /// @code
WiredHome 1:5a1ff72b5915 91 /// wd.Service();
WiredHome 1:5a1ff72b5915 92 /// @endcode
WiredHome 0:7a316f14da9c 93 /// @returns none
WiredHome 0:7a316f14da9c 94 void Service();
WiredHome 0:7a316f14da9c 95
WiredHome 0:7a316f14da9c 96 /// WatchdogCausedReset identifies if the cause of the system
WiredHome 0:7a316f14da9c 97 /// reset was the Watchdog
WiredHome 0:7a316f14da9c 98 ///
WiredHome 0:7a316f14da9c 99 /// example:
WiredHome 0:7a316f14da9c 100 /// @code
WiredHome 0:7a316f14da9c 101 /// if (wd.WatchdogCausedReset())) {
WiredHome 0:7a316f14da9c 102 /// @endcode
WiredHome 0:7a316f14da9c 103 ///
WiredHome 0:7a316f14da9c 104 /// @returns true if the Watchdog was the cause of the reset
WiredHome 0:7a316f14da9c 105 bool WatchdogCausedReset();
mutech 15:e0e4c2268558 106
mutech 15:e0e4c2268558 107 #if defined( TARGET_STM )
mutech 15:e0e4c2268558 108 uint32_t reset_status() { return _rcc_csr; }
mutech 15:e0e4c2268558 109 #endif
WiredHome 0:7a316f14da9c 110 private:
mutech 15:e0e4c2268558 111 bool _wdreset;
mutech 15:e0e4c2268558 112
mutech 15:e0e4c2268558 113 #if defined( TARGET_STM )
mutech 15:e0e4c2268558 114 uint32_t _rcc_csr; // RCC clock control & status register
mutech 15:e0e4c2268558 115
mutech 7:3814d72b8166 116 int calcExponent16bit(uint16_t v); // 整数Xを含む最小のべき乗指数
mutech 15:e0e4c2268558 117 #endif
WiredHome 0:7a316f14da9c 118 };
WiredHome 0:7a316f14da9c 119
mutech 7:3814d72b8166 120 #endif // WATCHDOG_H