Modified version of the Watchdog library with improved support for STM32

Dependents:   LightSaber iot_water_monitor_v2

Fork of Watchdog by David Smart

Committer:
salarian
Date:
Wed Nov 11 16:05:42 2015 +0000
Revision:
9:84f7c088c261
Parent:
6:e0f547e22dd5
Refactored the STM32 bit variant of the functions and set the default clock to 32.768 kHz (crystal oscillator)

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
WiredHome 5:2dad2a78ffbd 17 /// \li v2.00 - 20150315: Enhanced beyond TARGET_LPC1768 to TARGET_LPC4088, TARGET_STM
WiredHome 2:2873f068f325 18 /// \li v1.00 - 20110616: initial release with some documentation improvements
WiredHome 2:2873f068f325 19 ///
WiredHome 0:7a316f14da9c 20 #ifndef WATCHDOG_H
WiredHome 0:7a316f14da9c 21 #define WATCHDOG_H
WiredHome 0:7a316f14da9c 22 #include "mbed.h"
WiredHome 0:7a316f14da9c 23
WiredHome 2:2873f068f325 24 /// The Watchdog class provides the interface to the Watchdog feature
WiredHome 2:2873f068f325 25 ///
WiredHome 2:2873f068f325 26 /// Embedded programs, by their nature, are usually unattended. If things
WiredHome 2:2873f068f325 27 /// go wrong, it is usually important that the system attempts to recover.
WiredHome 2:2873f068f325 28 /// Aside from robust software, a hardware watchdog can monitor the
WiredHome 2:2873f068f325 29 /// system and initiate a system reset when appropriate.
WiredHome 2:2873f068f325 30 ///
WiredHome 2:2873f068f325 31 /// This Watchdog is patterned after one found elsewhere on the mbed site,
WiredHome 2:2873f068f325 32 /// however this one also provides a method for the application software
WiredHome 2:2873f068f325 33 /// to determine the cause of the reset - watchdog or otherwise.
WiredHome 0:7a316f14da9c 34 ///
WiredHome 5:2dad2a78ffbd 35 /// Supports:
WiredHome 5:2dad2a78ffbd 36 /// \li TARGET_LPC1768
WiredHome 5:2dad2a78ffbd 37 /// \li TARGET_LPC4088
WiredHome 5:2dad2a78ffbd 38 /// \li TARGET_STM
WiredHome 5:2dad2a78ffbd 39 ///
WiredHome 0:7a316f14da9c 40 /// example:
WiredHome 0:7a316f14da9c 41 /// @code
WiredHome 0:7a316f14da9c 42 /// Watchdog wd;
WiredHome 0:7a316f14da9c 43 ///
WiredHome 0:7a316f14da9c 44 /// ...
WiredHome 0:7a316f14da9c 45 /// main() {
WiredHome 0:7a316f14da9c 46 /// if (wd.WatchdogCausedReset())
WiredHome 2:2873f068f325 47 /// pc.printf("Watchdog caused reset.\r\n");
WiredHome 0:7a316f14da9c 48 ///
WiredHome 2:2873f068f325 49 /// wd.Configure(3.0); // sets the timeout interval
WiredHome 0:7a316f14da9c 50 /// for (;;) {
WiredHome 1:5a1ff72b5915 51 /// wd.Service(); // kick the dog before the timeout
WiredHome 2:2873f068f325 52 /// // do other work
WiredHome 2:2873f068f325 53 /// }
WiredHome 2:2873f068f325 54 /// }
WiredHome 0:7a316f14da9c 55 /// @endcode
WiredHome 0:7a316f14da9c 56 ///
WiredHome 0:7a316f14da9c 57 class Watchdog {
WiredHome 0:7a316f14da9c 58 public:
WiredHome 0:7a316f14da9c 59 /// Create a Watchdog object
WiredHome 0:7a316f14da9c 60 ///
WiredHome 0:7a316f14da9c 61 /// example:
WiredHome 0:7a316f14da9c 62 /// @code
WiredHome 0:7a316f14da9c 63 /// Watchdog wd; // placed before main
WiredHome 0:7a316f14da9c 64 /// @endcode
WiredHome 0:7a316f14da9c 65 Watchdog();
WiredHome 0:7a316f14da9c 66
WiredHome 0:7a316f14da9c 67 /// Configure the timeout for the Watchdog
WiredHome 0:7a316f14da9c 68 ///
WiredHome 0:7a316f14da9c 69 /// This configures the Watchdog service and starts it. It must
WiredHome 0:7a316f14da9c 70 /// be serviced before the timeout, or the system will be restarted.
WiredHome 0:7a316f14da9c 71 ///
WiredHome 0:7a316f14da9c 72 /// example:
WiredHome 0:7a316f14da9c 73 /// @code
WiredHome 0:7a316f14da9c 74 /// ...
WiredHome 0:7a316f14da9c 75 /// wd.Configure(1.4); // configure for a 1.4 second timeout
WiredHome 0:7a316f14da9c 76 /// ...
WiredHome 0:7a316f14da9c 77 /// @endcode
WiredHome 0:7a316f14da9c 78 ///
WiredHome 4:22c5c4aa4661 79 /// @param[in] timeout in seconds, as a floating point number
WiredHome 0:7a316f14da9c 80 /// @returns none
WiredHome 0:7a316f14da9c 81 ///
WiredHome 0:7a316f14da9c 82 void Configure(float timeout);
WiredHome 0:7a316f14da9c 83
WiredHome 0:7a316f14da9c 84 /// Service the Watchdog so it does not cause a system reset
WiredHome 0:7a316f14da9c 85 ///
WiredHome 1:5a1ff72b5915 86 /// example:
WiredHome 1:5a1ff72b5915 87 /// @code
WiredHome 1:5a1ff72b5915 88 /// wd.Service();
WiredHome 1:5a1ff72b5915 89 /// @endcode
WiredHome 0:7a316f14da9c 90 /// @returns none
WiredHome 0:7a316f14da9c 91 void Service();
WiredHome 0:7a316f14da9c 92
WiredHome 0:7a316f14da9c 93 /// WatchdogCausedReset identifies if the cause of the system
WiredHome 0:7a316f14da9c 94 /// reset was the Watchdog
WiredHome 0:7a316f14da9c 95 ///
WiredHome 0:7a316f14da9c 96 /// example:
WiredHome 0:7a316f14da9c 97 /// @code
WiredHome 0:7a316f14da9c 98 /// if (wd.WatchdogCausedReset())) {
WiredHome 0:7a316f14da9c 99 /// @endcode
WiredHome 0:7a316f14da9c 100 ///
WiredHome 0:7a316f14da9c 101 /// @returns true if the Watchdog was the cause of the reset
WiredHome 0:7a316f14da9c 102 bool WatchdogCausedReset();
WiredHome 0:7a316f14da9c 103 private:
WiredHome 0:7a316f14da9c 104 bool wdreset;
salarian 9:84f7c088c261 105
salarian 9:84f7c088c261 106 #if defined( TARGET_STM )
salarian 9:84f7c088c261 107 /// Logarithm in base 2
salarian 9:84f7c088c261 108 ///
salarian 9:84f7c088c261 109 /// This function is needed for the STM32 platforms to compute the prescaler
salarian 9:84f7c088c261 110 /// value for the watchdog timer
salarian 9:84f7c088c261 111 ///
salarian 9:84f7c088c261 112 /// @param[in] the input value as an unsigned integer (i.e. always positive)
salarian 9:84f7c088c261 113 /// @returns the computed log2
salarian 9:84f7c088c261 114 int log2(unsigned v);
salarian 9:84f7c088c261 115 #endif
WiredHome 0:7a316f14da9c 116 };
WiredHome 0:7a316f14da9c 117
WiredHome 0:7a316f14da9c 118 #endif // WATCHDOG_H