Skip to content

Commit 66a195c

Browse files
committed
VirtualWatchdog: provide hw timeout via ctor
1 parent b2da4a5 commit 66a195c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

drivers/VirtualWatchdog.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifdef DEVICE_WATCHDOG
1818

1919
#include "drivers/VirtualWatchdog.h"
20-
#include "drivers/Watchdog.h"
2120

2221
#define MS_TO_US(x) ((x) * 1000)
2322
#define US_TO_MS(x) ((x) / 1000)
@@ -34,7 +33,7 @@ VirtualWatchdog *VirtualWatchdog::_first = NULL;
3433
bool VirtualWatchdog::_is_hw_watchdog_running = false;
3534
us_timestamp_t VirtualWatchdog::_ticker_timeout = 0;
3635

37-
VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str): _name(str)
36+
VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str, uint32_t watchdog_hw_timeout) : _name(str)
3837
{
3938
_current_count = 0;
4039
_is_initialized = false;
@@ -47,8 +46,8 @@ VirtualWatchdog::VirtualWatchdog(uint32_t timeout, const char *const str): _name
4746
MBED_MAKE_ERROR(MBED_MODULE_DRIVER_WATCHDOG, MBED_ERROR_INITIALIZATION_FAILED);
4847
}
4948
// we use default hw timeout provided by config
50-
watchdog.start(Watchdog::watchdog_timeout);
51-
_ticker_timeout = MS_TO_US(Watchdog::watchdog_timeout / 2);
49+
watchdog.start(watchdog_hw_timeout);
50+
_ticker_timeout = MS_TO_US(watchdog_hw_timeout / 2);
5251
if (_ticker_timeout == 0) {
5352
_ticker_timeout = 1;
5453
}

drivers/VirtualWatchdog.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "platform/mbed_power_mgmt.h"
2727
#include "platform/mbed_assert.h"
2828
#include "platform/SingletonPtr.h"
29+
#include "drivers/Watchdog.h"
2930

3031
#if DEVICE_LPTICKER
3132
#include "drivers/LowPowerTicker.h"
@@ -65,11 +66,13 @@ class VirtualWatchdog {
6566

6667
/** Constructor configured with timeout and name for this software watchdog instance.
6768
*
68-
* We start hardware watchdog on the first run. This set-up uses default watchdog timeout set via config value
69-
* MBED_CONF_TARGET_WATCHDOG_TIMEOUT.
69+
* @param timeout Timer timeout
70+
* @param str The name for this watchdog timer
71+
* @param watchdog_hw_timeout The watchdog driver timeout - can be set only once (as soon as watchdog runs, cannot be reconfigured)
7072
*
7173
*/
72-
VirtualWatchdog(uint32_t timeout = 1000, const char *const str = NULL);
74+
VirtualWatchdog(uint32_t timeout = 1000, const char *const str = NULL, uint32_t watchdog_hw_timeout = Watchdog::watchdog_timeout);
75+
7376
~VirtualWatchdog();
7477
public:
7578

0 commit comments

Comments
 (0)