Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Watchdog by
Watchdog.h@0:7a316f14da9c, 2011-03-20 (annotated)
- Committer:
- WiredHome
- Date:
- Sun Mar 20 23:22:50 2011 +0000
- Revision:
- 0:7a316f14da9c
- Child:
- 1:5a1ff72b5915
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:7a316f14da9c | 6 | /// system restart. |
WiredHome | 0:7a316f14da9c | 7 | /// |
WiredHome | 0:7a316f14da9c | 8 | /// Adapted from Simon's Watchdog code from http://mbed.org/forum/mbed/topic/508/ |
WiredHome | 0:7a316f14da9c | 9 | /// |
WiredHome | 0:7a316f14da9c | 10 | /// @note Copyright © 2011 by Smartware Computing, all rights reserved. |
WiredHome | 0:7a316f14da9c | 11 | /// This software may be used to derive new software, as long as |
WiredHome | 0:7a316f14da9c | 12 | /// this copyright statement remains in the source file. |
WiredHome | 0:7a316f14da9c | 13 | /// @author David Smart |
WiredHome | 0:7a316f14da9c | 14 | /// |
WiredHome | 0:7a316f14da9c | 15 | #ifndef WATCHDOG_H |
WiredHome | 0:7a316f14da9c | 16 | #define WATCHDOG_H |
WiredHome | 0:7a316f14da9c | 17 | #include "mbed.h" |
WiredHome | 0:7a316f14da9c | 18 | |
WiredHome | 0:7a316f14da9c | 19 | /// Watchdog provides the interface to the Watchdog feature |
WiredHome | 0:7a316f14da9c | 20 | /// |
WiredHome | 0:7a316f14da9c | 21 | /// example: |
WiredHome | 0:7a316f14da9c | 22 | /// @code |
WiredHome | 0:7a316f14da9c | 23 | /// Watchdog wd; |
WiredHome | 0:7a316f14da9c | 24 | /// |
WiredHome | 0:7a316f14da9c | 25 | /// ... |
WiredHome | 0:7a316f14da9c | 26 | /// main() { |
WiredHome | 0:7a316f14da9c | 27 | /// if (wd.WatchdogCausedReset()) |
WiredHome | 0:7a316f14da9c | 28 | /// pc.printf("Watchdog caused reset. WD being armed for 30s cycle.\r\n"); |
WiredHome | 0:7a316f14da9c | 29 | /// |
WiredHome | 0:7a316f14da9c | 30 | /// wd.Configure(30.0); // sets the timeout interval |
WiredHome | 0:7a316f14da9c | 31 | /// for (;;) { |
WiredHome | 0:7a316f14da9c | 32 | /// wd.Service; // kick the dog before the timeout |
WiredHome | 0:7a316f14da9c | 33 | /// @endcode |
WiredHome | 0:7a316f14da9c | 34 | /// |
WiredHome | 0:7a316f14da9c | 35 | class Watchdog { |
WiredHome | 0:7a316f14da9c | 36 | public: |
WiredHome | 0:7a316f14da9c | 37 | /// Create a Watchdog object |
WiredHome | 0:7a316f14da9c | 38 | /// |
WiredHome | 0:7a316f14da9c | 39 | /// example: |
WiredHome | 0:7a316f14da9c | 40 | /// @code |
WiredHome | 0:7a316f14da9c | 41 | /// Watchdog wd; // placed before main |
WiredHome | 0:7a316f14da9c | 42 | /// @endcode |
WiredHome | 0:7a316f14da9c | 43 | Watchdog(); |
WiredHome | 0:7a316f14da9c | 44 | |
WiredHome | 0:7a316f14da9c | 45 | /// Configure the timeout for the Watchdog |
WiredHome | 0:7a316f14da9c | 46 | /// |
WiredHome | 0:7a316f14da9c | 47 | /// This configures the Watchdog service and starts it. It must |
WiredHome | 0:7a316f14da9c | 48 | /// be serviced before the timeout, or the system will be restarted. |
WiredHome | 0:7a316f14da9c | 49 | /// |
WiredHome | 0:7a316f14da9c | 50 | /// example: |
WiredHome | 0:7a316f14da9c | 51 | /// @code |
WiredHome | 0:7a316f14da9c | 52 | /// ... |
WiredHome | 0:7a316f14da9c | 53 | /// wd.Configure(1.4); // configure for a 1.4 second timeout |
WiredHome | 0:7a316f14da9c | 54 | /// ... |
WiredHome | 0:7a316f14da9c | 55 | /// @endcode |
WiredHome | 0:7a316f14da9c | 56 | /// |
WiredHome | 0:7a316f14da9c | 57 | /// @param timeout in seconds, as a floating point number |
WiredHome | 0:7a316f14da9c | 58 | /// @returns none |
WiredHome | 0:7a316f14da9c | 59 | /// |
WiredHome | 0:7a316f14da9c | 60 | void Configure(float timeout); |
WiredHome | 0:7a316f14da9c | 61 | |
WiredHome | 0:7a316f14da9c | 62 | /// Service the Watchdog so it does not cause a system reset |
WiredHome | 0:7a316f14da9c | 63 | /// |
WiredHome | 0:7a316f14da9c | 64 | /// @returns none |
WiredHome | 0:7a316f14da9c | 65 | void Service(); |
WiredHome | 0:7a316f14da9c | 66 | |
WiredHome | 0:7a316f14da9c | 67 | /// WatchdogCausedReset identifies if the cause of the system |
WiredHome | 0:7a316f14da9c | 68 | /// reset was the Watchdog |
WiredHome | 0:7a316f14da9c | 69 | /// |
WiredHome | 0:7a316f14da9c | 70 | /// example: |
WiredHome | 0:7a316f14da9c | 71 | /// @code |
WiredHome | 0:7a316f14da9c | 72 | /// if (wd.WatchdogCausedReset())) { |
WiredHome | 0:7a316f14da9c | 73 | /// @endcode |
WiredHome | 0:7a316f14da9c | 74 | /// |
WiredHome | 0:7a316f14da9c | 75 | /// @returns true if the Watchdog was the cause of the reset |
WiredHome | 0:7a316f14da9c | 76 | bool WatchdogCausedReset(); |
WiredHome | 0:7a316f14da9c | 77 | private: |
WiredHome | 0:7a316f14da9c | 78 | bool wdreset; |
WiredHome | 0:7a316f14da9c | 79 | }; |
WiredHome | 0:7a316f14da9c | 80 | |
WiredHome | 0:7a316f14da9c | 81 | #endif // WATCHDOG_H |