diff --git a/drivers/VirtualWatchdog.cpp b/drivers/VirtualWatchdog.cpp index 1e7c207385..628e980541 100644 --- a/drivers/VirtualWatchdog.cpp +++ b/drivers/VirtualWatchdog.cpp @@ -103,14 +103,14 @@ void VirtualWatchdog::remove_from_list() } } -void VirtualWatchdog::process() +void VirtualWatchdog::process(uint32_t elapsed_ms) { VirtualWatchdog *cur_ptr = _first; while (cur_ptr != NULL) { if (cur_ptr->_current_count > cur_ptr->_max_timeout) { system_reset(); } else { - cur_ptr->_current_count += Watchdog::elapsed_ms; + cur_ptr->_current_count += elapsed_ms; } cur_ptr = cur_ptr->_next; } diff --git a/drivers/VirtualWatchdog.h b/drivers/VirtualWatchdog.h index 86dd6a84dd..197cc46211 100644 --- a/drivers/VirtualWatchdog.h +++ b/drivers/VirtualWatchdog.h @@ -94,7 +94,7 @@ public: * * Otherwise, the system resets. */ - static void process(); + static void process(uint32_t elapsed_ms); protected : /** Use add_to_list to store the registered user in the list. diff --git a/drivers/Watchdog.cpp b/drivers/Watchdog.cpp index 9f337dd7f5..1a526deecb 100644 --- a/drivers/Watchdog.cpp +++ b/drivers/Watchdog.cpp @@ -31,9 +31,9 @@ Watchdog::~Watchdog() { } -bool Watchdog::start(Callback func, uint32_t timeout) +bool Watchdog::start(Callback func, uint32_t timeout) { - MBED_ASSERT(MBED_CONF_TARGET_WATCHDOG_TIMEOUT < get_max_timeout()); + MBED_ASSERT(timeout < get_max_timeout()); core_util_critical_section_enter(); // we update callback always, to be able to register new hook if needed @@ -43,7 +43,7 @@ bool Watchdog::start(Callback func, uint32_t timeout) return false; } watchdog_config_t config; - config.timeout_ms = MBED_CONF_TARGET_WATCHDOG_TIMEOUT; + config.timeout_ms = timeout; watchdog_status_t sts = hal_watchdog_init(&config); if (sts == WATCHDOG_STATUS_OK) { _running = true; @@ -51,8 +51,11 @@ bool Watchdog::start(Callback func, uint32_t timeout) core_util_critical_section_exit(); if (_running) { - us_timestamp_t ticker_timeout = (MS_TO_US(((timeout <= 0) ? 1 : timeout))); - _ticker->attach(callback(this, &Watchdog::kick), ticker_timeout); + _ticker_timeout = MS_TO_US(timeout / 2); + if (_ticker_timeout == 0) { + _ticker_timeout = 1; + } + _ticker->attach_us(callback(this, &Watchdog::kick), _ticker_timeout); } return _running; } @@ -87,7 +90,7 @@ void Watchdog::kick() core_util_critical_section_exit(); if (_callback) { - _callback(); + _callback(_ticker_timeout); } } diff --git a/drivers/Watchdog.h b/drivers/Watchdog.h index 8681d963ef..5124c6f074 100644 --- a/drivers/Watchdog.h +++ b/drivers/Watchdog.h @@ -71,7 +71,7 @@ public: * successfully. assert if one of the input parameters is out of range for the current platform. * false if watchdog timer was not started */ - bool start(Callback func = NULL, uint32_t timeout = watchdog_timeout); + bool start(Callback func = NULL, uint32_t timeout = watchdog_timeout); /** Stops the watchdog timer * @@ -113,7 +113,8 @@ private: ~Watchdog(); bool _running; - Callback _callback; + Callback _callback; + us_timestamp_t _ticker_timeout; #if DEVICE_LPTICKER /** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.