Skip to content

Commit 581bf20

Browse files
committed
Watchdog: refactor timeout handling
Enable kicking directly by kick() and handle timeout by using private handler.
1 parent 0aa095b commit 581bf20

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

drivers/Watchdog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool Watchdog::start(Callback<void(uint32_t)> func, uint32_t timeout)
5454
if (_ticker_timeout == 0) {
5555
_ticker_timeout = 1;
5656
}
57-
_ticker->attach_us(callback(this, &Watchdog::kick), _ticker_timeout);
57+
_ticker->attach_us(callback(this, &Watchdog::timeout_handler), _ticker_timeout);
5858
}
5959
return _running;
6060
}
@@ -87,13 +87,16 @@ void Watchdog::kick()
8787
core_util_critical_section_enter();
8888
hal_watchdog_kick();
8989
core_util_critical_section_exit();
90+
}
9091

92+
void Watchdog::timeout_handler()
93+
{
94+
kick();
9195
if (_callback) {
9296
_callback(_ticker_timeout);
9397
}
9498
}
9599

96-
97100
bool Watchdog::is_running() const
98101
{
99102
return _running;

drivers/Watchdog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class Watchdog : private NonCopyable<Watchdog> {
121121
Watchdog();
122122
~Watchdog();
123123

124+
/** Ticker invokes this handler when it timeouts - kicking watchdog periodically
125+
*/
126+
void timeout_handler();
127+
124128
bool _running;
125129
Callback<void(uint32_t)> _callback;
126130
us_timestamp_t _ticker_timeout;

0 commit comments

Comments
 (0)