mirror of https://github.com/ARMmbed/mbed-os.git
Watchdog: refactor timeout handling
Enable kicking directly by kick() and handle timeout by using private handler.pull/10857/head
parent
0aa095b944
commit
581bf208ad
|
@ -54,7 +54,7 @@ bool Watchdog::start(Callback<void(uint32_t)> func, uint32_t timeout)
|
|||
if (_ticker_timeout == 0) {
|
||||
_ticker_timeout = 1;
|
||||
}
|
||||
_ticker->attach_us(callback(this, &Watchdog::kick), _ticker_timeout);
|
||||
_ticker->attach_us(callback(this, &Watchdog::timeout_handler), _ticker_timeout);
|
||||
}
|
||||
return _running;
|
||||
}
|
||||
|
@ -87,13 +87,16 @@ void Watchdog::kick()
|
|||
core_util_critical_section_enter();
|
||||
hal_watchdog_kick();
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
void Watchdog::timeout_handler()
|
||||
{
|
||||
kick();
|
||||
if (_callback) {
|
||||
_callback(_ticker_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Watchdog::is_running() const
|
||||
{
|
||||
return _running;
|
||||
|
|
|
@ -121,6 +121,10 @@ private:
|
|||
Watchdog();
|
||||
~Watchdog();
|
||||
|
||||
/** Ticker invokes this handler when it timeouts - kicking watchdog periodically
|
||||
*/
|
||||
void timeout_handler();
|
||||
|
||||
bool _running;
|
||||
Callback<void(uint32_t)> _callback;
|
||||
us_timestamp_t _ticker_timeout;
|
||||
|
|
Loading…
Reference in New Issue