From f0c050dace949d0cd72b947d491000bea7803e2e Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Thu, 27 Jun 2019 15:46:06 +0100 Subject: [PATCH] Watchdog: cleanup after singleton usage --- drivers/Watchdog.cpp | 18 ++++++------------ drivers/Watchdog.h | 10 +++++----- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/Watchdog.cpp b/drivers/Watchdog.cpp index 275e41cd2f..805d2ab291 100644 --- a/drivers/Watchdog.cpp +++ b/drivers/Watchdog.cpp @@ -23,19 +23,12 @@ namespace mbed { -#if DEVICE_LPTICKER - /** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick. - */ - SingletonPtr Watchdog::_ticker; -#else - /** Create singleton instance of Ticker for watchdog periodic call back of kick. - */ - SingletonPtr Watchdog::_ticker; -#endif - -bool Watchdog::_running = false; static const uint32_t elapsed_ms = MBED_CONF_TARGET_WATCHDOG_TIMEOUT / 2; +Watchdog::Watchdog() : _running(false) +{ +} + bool Watchdog::start() { watchdog_status_t sts; @@ -54,7 +47,7 @@ bool Watchdog::start() core_util_critical_section_exit(); if (_running) { us_timestamp_t timeout = (MS_TO_US(((elapsed_ms <= 0) ? 1 : elapsed_ms))); - _ticker->attach_us(callback(&Watchdog::kick), timeout); + _ticker->attach_us(callback(&Watchdog::get_instance(), &Watchdog::kick), timeout); } return _running; } @@ -110,4 +103,5 @@ uint32_t Watchdog::get_max_timeout() const } // namespace mbed + #endif // DEVICE_WATCHDOG diff --git a/drivers/Watchdog.h b/drivers/Watchdog.h index d82c912c30..9845a272b2 100644 --- a/drivers/Watchdog.h +++ b/drivers/Watchdog.h @@ -108,17 +108,17 @@ private: Watchdog(); ~Watchdog(); - static void kick(); - static uint32_t _elapsed_ms; - static bool _running; + void kick(); + + bool _running; #if DEVICE_LPTICKER /** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick. */ - static SingletonPtr _ticker; + SingletonPtr _ticker; #else /** Create singleton instance of Ticker for watchdog periodic call back of kick. */ - static SingletonPtr _ticker; + SingletonPtr _ticker; #endif };