mirror of https://github.com/ARMmbed/mbed-os.git
Watchdog & VirtualWatchdog process() update
Add uint32 argument - pass how much time already passed to the callback.pull/10857/head
parent
701d8f7cef
commit
455015daf5
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -31,9 +31,9 @@ Watchdog::~Watchdog()
|
|||
{
|
||||
}
|
||||
|
||||
bool Watchdog::start(Callback<void()> func, uint32_t timeout)
|
||||
bool Watchdog::start(Callback<void(uint32_t)> 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<void()> 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<void()> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<void()> func = NULL, uint32_t timeout = watchdog_timeout);
|
||||
bool start(Callback<void(uint32_t)> func = NULL, uint32_t timeout = watchdog_timeout);
|
||||
|
||||
/** Stops the watchdog timer
|
||||
*
|
||||
|
@ -113,7 +113,8 @@ private:
|
|||
~Watchdog();
|
||||
|
||||
bool _running;
|
||||
Callback<void()> _callback;
|
||||
Callback<void(uint32_t)> _callback;
|
||||
us_timestamp_t _ticker_timeout;
|
||||
|
||||
#if DEVICE_LPTICKER
|
||||
/** Create singleton instance of LowPowerTicker for watchdog periodic call back of kick.
|
||||
|
|
Loading…
Reference in New Issue