Skip to content

Commit f98c2fd

Browse files
committed
watchdog: remove manager
Watchdog can handle callbacks - VirtualManager can attach to the tick. This should simplify the logic. Watchdog can tick on its own using tickers. VirtualWatchdog uses attach to get a callback when Watchdog ticks - to process own linked list of virtual watchdogs.
1 parent 698b0ed commit f98c2fd

File tree

6 files changed

+20
-105
lines changed

6 files changed

+20
-105
lines changed

drivers/VirtualWatchdog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str): _name
3131
_max_timeout = timeout;
3232
// start watchdog
3333
Watchdog& watchdog = Watchdog::get_instance();
34-
watchdog.start(&VirtualWatchdog::process, WatchdogManager::elapsed_ms);
34+
watchdog.start(&VirtualWatchdog::process, Watchdog::elapsed_ms);
3535
}
3636

3737
VirtualWatchdog::~VirtualWatchdog()
@@ -104,7 +104,7 @@ void VirtualWatchdog::process()
104104
if (cur_ptr->_current_count > cur_ptr->_max_timeout) {
105105
system_reset();
106106
} else {
107-
cur_ptr->_current_count += WatchdogManager::elapsed_ms;
107+
cur_ptr->_current_count += Watchdog::elapsed_ms;
108108
}
109109
cur_ptr = cur_ptr->_next;
110110
}

drivers/VirtualWatchdog.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "platform/mbed_critical.h"
2626
#include "platform/mbed_power_mgmt.h"
2727
#include "mbed_assert.h"
28-
#include "WatchdogManager.h"
2928

3029
namespace mbed {
3130

drivers/Watchdog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool Watchdog::start(Callback<void()> func, uint32_t timeout)
5050
core_util_critical_section_exit();
5151
if (_running) {
5252
us_timestamp_t ticker_timeout = (MS_TO_US(((timeout <= 0) ? 1 : timeout)));
53-
WatchdogManager::attach(callback(this, &Watchdog::kick), ticker_timeout);
53+
_ticker->attach(callback(this, &Watchdog::kick), ticker_timeout);
5454
}
5555
return _running;
5656
}
@@ -66,7 +66,7 @@ bool Watchdog::stop()
6666
if (sts != WATCHDOG_STATUS_OK) {
6767
msts = false;
6868
} else {
69-
WatchdogManager::detach();
69+
_ticker->detach();
7070
_running = false;
7171
_callback = NULL;
7272
}
@@ -83,6 +83,7 @@ void Watchdog::kick()
8383
core_util_critical_section_enter();
8484
hal_watchdog_kick();
8585
core_util_critical_section_exit();
86+
8687
if (_callback) {
8788
_callback();
8889
}

drivers/Watchdog.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace mbed {
5050
*/
5151
class Watchdog : private NonCopyable<Watchdog> {
5252
public:
53+
const uint32_t watchdog_timeout = MBED_CONF_TARGET_WATCHDOG_TIMEOUT / 2;
5354

5455
/** As Watchdog might not stop ever, there is just one instance - we use single instance.
5556
* This ensures we keep Watchdog alive. To operate watchdog, use start/stop methods.
@@ -70,7 +71,7 @@ class Watchdog : private NonCopyable<Watchdog> {
7071
* successfully. assert if one of the input parameters is out of range for the current platform.
7172
* false if watchdog timer was not started
7273
*/
73-
bool start(Callback<void()> func = NULL, uint32_t timeout = WatchdogManager::elapsed_ms);
74+
bool start(Callback<void()> func = NULL, uint32_t timeout = watchdog_timeout);
7475

7576
/** Stops the watchdog timer
7677
*
@@ -106,12 +107,25 @@ class Watchdog : private NonCopyable<Watchdog> {
106107
bool is_running() const;
107108

108109
void kick();
110+
111+
109112
private:
110113
Watchdog();
111114
~Watchdog();
112115

113116
bool _running;
114117
Callback<void()> _callback;
118+
119+
#if DEVICE_LPTICKER
120+
/** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.
121+
*/
122+
SingletonPtr<LowPowerTicker> _ticker;
123+
#else
124+
/** Create singleton instance of Ticker for watchdog periodic call back of kick.
125+
*/
126+
SingletonPtr<Ticker> _ticker;
127+
#endif
128+
115129
};
116130

117131
} // namespace mbed

drivers/WatchdogManager.cpp

Lines changed: 0 additions & 46 deletions
This file was deleted.

drivers/WatchdogManager.h

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)