30
30
namespace mbed {
31
31
32
32
/* * \addtogroup drivers */
33
- /* * Hardware system timer that will reset the system in the case of system failures or
34
- * malfunctions. There is only one instance in the system.
33
+ /* * A hardware watchdog timer that resets the system in the case of system
34
+ * failures or malfunctions. If you fail to refresh the Watchdog timer periodically,
35
+ * it resets the system after a set period of time.
36
+ *
37
+ * There is only one instance of the Watchdog class in the system, which directly maps to the hardware.
38
+ * Use Watchdog::get_instance to obtain a reference.
39
+ *
40
+ * Watchdog::start initializes a system timer with a time period specified in
41
+ * @a timeout param. This timer counts down and triggers a system reset
42
+ * when it wraps. To prevent the system reset, you must periodically kick or refresh
43
+ * the timer by calling Watchdog::kick, which resets the countdown
44
+ * to the initial value.
35
45
*
36
46
* Example:
37
47
* @code
38
- *
39
48
* Watchdog &watchdog = Watchdog::get_instance();
40
- * watchdog.start();
49
+ * watchdog.start(500 );
41
50
*
42
51
* while (true) {
43
52
// kick watchdog regularly within provided timeout
@@ -52,9 +61,10 @@ namespace mbed {
52
61
class Watchdog : private NonCopyable <Watchdog> {
53
62
public:
54
63
55
- /* * As Watchdog might not stop ever, there is just one instance - we use single instance.
56
- * This ensures we keep Watchdog alive. To operate watchdog, use start/stop methods.
57
- */
64
+ /* * Get a reference to the single Watchdog instance in the system.
65
+ *
66
+ * @return A reference to the single Watchdog instance present in the system.
67
+ */
58
68
static Watchdog &get_instance ()
59
69
{
60
70
// Use this implementation of singleton (Meyer's) rather than the one that allocates
@@ -64,61 +74,71 @@ class Watchdog : private NonCopyable<Watchdog> {
64
74
return instance;
65
75
}
66
76
67
- /* * Start the watchdog timer with the maximum timeout available on a target
77
+ /* * Start the Watchdog timer with the maximum timeout value available for
78
+ * the target.
79
+ *
80
+ * @note The timeout is set to a value returned by Watchdog::get_max_timeout.
68
81
*
69
- * Timeout is defined as get_max_timeout()
82
+ * If the Watchdog timer is already running, this function does nothing.
70
83
*
71
- * @return status true if the watchdog timer was started
72
- * successfully. assert if one of the input parameters is out of range for the current platform.
73
- * false if watchdog timer was not started
84
+ * @return true if the Watchdog timer was started successfully;
85
+ * false if the Watchdog timer was not started or if the Watchdog
86
+ * timer is already running.
74
87
*/
75
88
bool start ();
76
89
77
- /* * Start the watchdog timer
90
+ /* * Start the Watchdog timer.
78
91
*
79
- * @param timeout Watchdog timeout
92
+ * @note Asset that the timeout param is supported by the target
93
+ * (0 < timeout <= Watchdog::get_max_timeout).
80
94
*
81
- * @return status true if the watchdog timer was started
82
- * successfully. assert if one of the input parameters is out of range for the current platform.
83
- * false if watchdog timer was not started
95
+ * @param timeout Watchdog timeout in milliseconds.
96
+ *
97
+ * @return true if the Watchdog timer was started successfully;
98
+ * false if Watchdog timer was not started or if the Watchdog
99
+ * timer is already running.
84
100
*/
85
101
bool start (uint32_t timeout);
86
102
87
- /* * Stops the watchdog timer
103
+ /* * Stop the Watchdog timer.
88
104
*
89
- * Calling this function will attempt to disable any currently running
90
- * watchdog timers if supported by the current platform.
105
+ * Calling this function disables a running Watchdog
106
+ * peripheral if the platform supports it .
91
107
*
92
- * @return Returns true if the watchdog timer was successfully
93
- * stopped, Returns false if the watchdog cannot be disabled
94
- * on the current platform or if the timer was never started.
108
+ * @return true if the Watchdog timer was successfully stopped;
109
+ * false if the Watchdog timer cannot be disabled on this platform
110
+ * or if the Watchdog timer has not been started.
95
111
*/
96
112
bool stop ();
97
113
98
- /* * Get the watchdog timer refresh value
114
+ /* * Get the Watchdog timer refresh value.
99
115
*
100
- * This function returns the refresh timeout of the watchdog timer .
116
+ * This function returns the refresh timeout of the watchdog peripheral .
101
117
*
102
- * @return Reload value for the watchdog timer in milliseconds.
118
+ * @return Reload value for the Watchdog timer in milliseconds.
103
119
*/
104
120
uint32_t get_timeout () const ;
105
121
106
- /* * Get the maximum refresh value for the current platform in milliseconds
122
+ /* * Get the maximum Watchdog refresh value for this platform.
107
123
*
108
- * @return Maximum refresh value supported by the watchdog for the current
109
- * platform in milliseconds
124
+ * @return Maximum reload value supported by the Watchdog timer for this
125
+ * platform in milliseconds.
110
126
*/
111
127
uint32_t get_max_timeout () const ;
112
128
113
- /* * Check if watchdog is already running
129
+ /* * Check if the Watchdog timer is already running.
114
130
*
115
- * @return true if watchdog is running, false otherwise
131
+ * @return true if the Watchdog timer is running and
132
+ * false otherwise.
116
133
*/
117
134
bool is_running () const ;
118
135
119
- /* * Kick watchdog
136
+ /* * Refresh the Watchdog timer.
137
+ *
138
+ * Call this function periodically before the Watchdog times out.
139
+ * Otherwise, the system resets.
120
140
*
121
- * This method is useful to control kicking by application in ticker callback periodically
141
+ * If the Watchdog timer is not running, this function does nothing.
122
142
*/
123
143
void kick ();
124
144
0 commit comments