From 6313e530b3e72cbd602a5a1988e412eed57cfa20 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Mon, 1 Jul 2019 14:29:49 +0100 Subject: [PATCH] VirtualWatchdog: provide hw timeout via ctor --- drivers/VirtualWatchdog.cpp | 7 +++---- drivers/VirtualWatchdog.h | 9 ++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/VirtualWatchdog.cpp b/drivers/VirtualWatchdog.cpp index 02a5e88d82..66e03ac486 100644 --- a/drivers/VirtualWatchdog.cpp +++ b/drivers/VirtualWatchdog.cpp @@ -17,7 +17,6 @@ #ifdef DEVICE_WATCHDOG #include "drivers/VirtualWatchdog.h" -#include "drivers/Watchdog.h" #define MS_TO_US(x) ((x) * 1000) #define US_TO_MS(x) ((x) / 1000) @@ -34,7 +33,7 @@ VirtualWatchdog *VirtualWatchdog::_first = NULL; bool VirtualWatchdog::_is_hw_watchdog_running = false; us_timestamp_t VirtualWatchdog::_ticker_timeout = 0; -VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str): _name(str) +VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str, uint32_t watchdog_hw_timeout) : _name(str) { _current_count = 0; _is_initialized = false; @@ -47,8 +46,8 @@ VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str): _name MBED_MAKE_ERROR(MBED_MODULE_DRIVER_WATCHDOG, MBED_ERROR_INITIALIZATION_FAILED); } // we use default hw timeout provided by config - watchdog.start(Watchdog::watchdog_timeout); - _ticker_timeout = MS_TO_US(Watchdog::watchdog_timeout / 2); + watchdog.start(watchdog_hw_timeout); + _ticker_timeout = MS_TO_US(watchdog_hw_timeout / 2); if (_ticker_timeout == 0) { _ticker_timeout = 1; } diff --git a/drivers/VirtualWatchdog.h b/drivers/VirtualWatchdog.h index ab9c354fe7..3e00918ad6 100644 --- a/drivers/VirtualWatchdog.h +++ b/drivers/VirtualWatchdog.h @@ -26,6 +26,7 @@ #include "platform/mbed_power_mgmt.h" #include "platform/mbed_assert.h" #include "platform/SingletonPtr.h" +#include "drivers/Watchdog.h" #if DEVICE_LPTICKER #include "drivers/LowPowerTicker.h" @@ -65,11 +66,13 @@ public: /** Constructor configured with timeout and name for this software watchdog instance. * - * We start hardware watchdog on the first run. This set-up uses default watchdog timeout set via config value - * MBED_CONF_TARGET_WATCHDOG_TIMEOUT. + * @param timeout Timer timeout + * @param str The name for this watchdog timer + * @param watchdog_hw_timeout The watchdog driver timeout - can be set only once (as soon as watchdog runs, cannot be reconfigured) * */ - VirtualWatchdog(uint32_t timeout = 1000, const char *const str = NULL); + VirtualWatchdog(uint32_t timeout = 1000, const char *const str = NULL, uint32_t watchdog_hw_timeout = Watchdog::watchdog_timeout); + ~VirtualWatchdog(); public: