|
20 | 20 |
|
21 | 21 | #ifdef DEVICE_WATCHDOG
|
22 | 22 |
|
23 |
| -#include <cstdio> |
24 | 23 | #include "mbed_error.h"
|
25 |
| -#include "platform/mbed_critical.h" |
26 |
| -#include "platform/mbed_power_mgmt.h" |
27 | 24 | #include "mbed_assert.h"
|
| 25 | +#include "platform/mbed_critical.h" |
| 26 | +#include "watchdog_api.h" |
| 27 | +#include <cstdio> |
28 | 28 |
|
29 | 29 | namespace mbed {
|
30 | 30 |
|
31 | 31 | /** \addtogroup drivers */
|
32 |
| -/** Services that need to monitor nonblocking periodic behavior or |
33 |
| - * malfunctions, such as Wi-Fi and TLS, use a software watchdog. |
34 |
| - * Normally, one instance of a software watchdog gets created during hardware watchdog startup, so you can access the software watchdog. |
35 |
| - * The hardware watchdog periodically calls the "process" method of the services to check nonblocking periodic behavior. |
| 32 | +/** Hardware system timer that will reset the system in the case of system failures or |
| 33 | + * malfunctions. |
36 | 34 | *
|
37 | 35 | * Example:
|
38 | 36 | * @code
|
39 | 37 | *
|
40 |
| - * Watchdog watchdog(300,"Software Watchdog"); |
| 38 | + * Watchdog watchdog(); |
41 | 39 | * watchdog.start();
|
42 | 40 | *
|
43 | 41 | * while (true) {
|
44 |
| - * watchdog.kick(); |
45 |
| - * |
46 | 42 | * // Application code
|
47 | 43 | * }
|
48 | 44 | * @endcode
|
49 | 45 | * @ingroup drivers
|
50 | 46 | */
|
51 |
| -class Watchdog { |
| 47 | +class Watchdog : private NonCopyable<Watchdog> { |
52 | 48 | public:
|
53 | 49 |
|
54 |
| - /** Constructor configured with timeout and name for this software watchdog instance. |
| 50 | + /** Constructor configured with timeout |
55 | 51 | *
|
56 | 52 | */
|
57 |
| - Watchdog(uint32_t timeout = 1, const char *const str = NULL); |
| 53 | + Watchdog(); |
58 | 54 | ~Watchdog();
|
59 | 55 | public:
|
60 | 56 |
|
61 |
| - /** Start an independent watchdog timer with specified parameters. |
| 57 | + /** Start the watchdog timer |
| 58 | + * |
62 | 59 | *
|
63 |
| - * Assert for multiple calls of start. |
| 60 | + * @return status true if the watchdog timer was started |
| 61 | + * successfully. assert if one of the input parameters is out of range for the current platform. |
| 62 | + * false if watchdog timer was not started |
64 | 63 | */
|
65 |
| - void start(); |
| 64 | + bool start(); |
66 | 65 |
|
67 |
| - /** This stops the watchdog timer. |
| 66 | + /** Stops the watchdog timer |
68 | 67 | *
|
69 |
| - * Calling this function disables any running |
70 |
| - * watchdog timers if the platform supports them. |
| 68 | + * Calling this function will attempt to disable any currently running |
| 69 | + * watchdog timers if supported by the current platform. |
71 | 70 | *
|
72 |
| - * Assert without calling start. |
| 71 | + * @return Returns true if the watchdog timer was successfully |
| 72 | + * stopped, Returns false if the watchdog cannot be disabled |
| 73 | + * on the current platform or if the timer was never started. |
73 | 74 | */
|
74 |
| - void stop(); |
| 75 | + bool stop(); |
75 | 76 |
|
76 |
| - /** This function refreshes the watchdog timer. |
| 77 | + /** Get the watchdog timer refresh value |
77 | 78 | *
|
78 |
| - * Call this function periodically before the watchdog times out. |
79 |
| - * Otherwise, the system resets. |
| 79 | + * This function returns the refresh timeout of the watchdog timer. |
80 | 80 | *
|
81 |
| - * If the watchdog timer is not running, this function does nothing. |
| 81 | + * @return Reload value for the watchdog timer in milliseconds. |
82 | 82 | */
|
83 |
| - void kick(); |
| 83 | + uint32_t get_timeout() const; |
84 | 84 |
|
85 |
| - /** mbed_watchdog_manager (runs by periodic call from ticker) used this API interface |
86 |
| - * to go through all the registered user/threads of watchdog. |
| 85 | + /** Get the maximum refresh value for the current platform in milliseconds |
87 | 86 | *
|
88 |
| - * @param elapsed_ms completed ticker callback elapsed milliseconds |
89 |
| - * |
90 |
| - * Call this function from mbed_watchdog_manager_kick to monitor all the |
91 |
| - * user/threads alive states. |
92 |
| - * |
93 |
| - * Otherwise, the system resets. |
| 87 | + * @return Maximum refresh value supported by the watchdog for the current |
| 88 | + * platform in milliseconds |
94 | 89 | */
|
95 |
| - static void process(uint32_t elapsed_ms); |
96 |
| -protected : |
| 90 | + uint32_t get_max_timeout() const; |
97 | 91 |
|
98 |
| - /** Use add_to_list to store the registered user in the list. |
99 |
| - * This API is only used to call from start. |
100 |
| - */ |
101 |
| - void add_to_list(); |
| 92 | + /** Check if watchdog is already running |
| 93 | + * |
| 94 | + * @return Maximum refresh value supported by the watchdog for the current |
| 95 | + * platform in milliseconds |
| 96 | + */ |
| 97 | + bool is_running() const; |
102 | 98 |
|
103 |
| - /** Use remove_from_list to remove the entry from the list. |
104 |
| - * This API is only used to call from stop. |
105 |
| - * |
106 |
| - */ |
107 |
| - void remove_from_list(); |
108 | 99 | private:
|
109 |
| - uint32_t _max_timeout; //_max_timeout initialized via constructor while creating instance of this class |
110 |
| - const char *_name; //To store the details of user |
111 |
| - uint32_t _current_count; //this parameter is used to reset everytime threads/user calls kick |
112 |
| - bool _is_initialized; //To control start and stop functionality |
113 |
| - static Watchdog *_first; //List to store the user/threads who called start |
114 |
| - Watchdog *_next; |
| 100 | + static void kick(); |
| 101 | + static uint32_t _elapsed_ms; |
| 102 | + static bool _running; |
| 103 | +#if DEVICE_LPTICKER |
| 104 | + /** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick. |
| 105 | + */ |
| 106 | + static SingletonPtr<LowPowerTicker> _ticker; |
| 107 | +#else |
| 108 | + /** Create singleton instance of Ticker for watchdog periodic call back of kick. |
| 109 | + */ |
| 110 | + static SingletonPtr<Ticker> _ticker; |
| 111 | +#endif |
115 | 112 | };
|
116 | 113 |
|
117 | 114 | } // namespace mbed
|
|
0 commit comments