Watchdog: refactor timeout handling

Enable kicking directly by kick() and handle timeout by using private handler.
pull/10857/head
Martin Kojtal 2019-06-28 09:55:11 +01:00
parent 0aa095b944
commit 581bf208ad
2 changed files with 9 additions and 2 deletions

View File

@ -54,7 +54,7 @@ bool Watchdog::start(Callback<void(uint32_t)> func, uint32_t timeout)
if (_ticker_timeout == 0) { if (_ticker_timeout == 0) {
_ticker_timeout = 1; _ticker_timeout = 1;
} }
_ticker->attach_us(callback(this, &Watchdog::kick), _ticker_timeout); _ticker->attach_us(callback(this, &Watchdog::timeout_handler), _ticker_timeout);
} }
return _running; return _running;
} }
@ -87,13 +87,16 @@ void Watchdog::kick()
core_util_critical_section_enter(); core_util_critical_section_enter();
hal_watchdog_kick(); hal_watchdog_kick();
core_util_critical_section_exit(); core_util_critical_section_exit();
}
void Watchdog::timeout_handler()
{
kick();
if (_callback) { if (_callback) {
_callback(_ticker_timeout); _callback(_ticker_timeout);
} }
} }
bool Watchdog::is_running() const bool Watchdog::is_running() const
{ {
return _running; return _running;

View File

@ -121,6 +121,10 @@ private:
Watchdog(); Watchdog();
~Watchdog(); ~Watchdog();
/** Ticker invokes this handler when it timeouts - kicking watchdog periodically
*/
void timeout_handler();
bool _running; bool _running;
Callback<void(uint32_t)> _callback; Callback<void(uint32_t)> _callback;
us_timestamp_t _ticker_timeout; us_timestamp_t _ticker_timeout;