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