VirtualWatchdog: provide hw timeout via ctor

pull/10857/head
Martin Kojtal 2019-07-01 14:29:49 +01:00
parent 7b341847c4
commit 6313e530b3
2 changed files with 9 additions and 7 deletions

View File

@ -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;
}

View File

@ -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: