Skip to content

Commit 962273c

Browse files
authored
Merge pull request #8029 from OpenNuvoton/nuvoton_fix_lpticker_wrapper
Fix issues with LowPowerTickerWrapper
2 parents 3d94fb8 + 5b90b4c commit 962273c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

hal/LowPowerTickerWrapper.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,14 @@ void LowPowerTickerWrapper::_timeout_handler()
207207
_pending_timeout = false;
208208

209209
timestamp_t current = _intf->read();
210-
if (_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time)) {
210+
/* Add extra check for '_last_set_interrupt == _cur_match_time'
211+
*
212+
* When '_last_set_interrupt == _cur_match_time', _ticker_match_interval_passed sees it as
213+
* one-round interval rather than just-pass, so add extra check for it. In rare cases, we
214+
* may trap in _timeout_handler/_schedule_match loop. This check can break it.
215+
*/
216+
if ((_last_set_interrupt == _cur_match_time) ||
217+
_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time)) {
211218
_intf->fire_interrupt();
212219
} else {
213220
_schedule_match(current);
@@ -223,7 +230,9 @@ bool LowPowerTickerWrapper::_match_check(timestamp_t current)
223230
if (!_pending_match) {
224231
return false;
225232
}
226-
return _ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time);
233+
/* Add extra check for '_last_set_interrupt == _cur_match_time' as above */
234+
return (_last_set_interrupt == _cur_match_time) ||
235+
_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time);
227236
}
228237

229238
uint32_t LowPowerTickerWrapper::_lp_ticks_to_us(uint32_t ticks)
@@ -245,7 +254,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
245254
}
246255
}
247256

248-
uint32_t cycles_until_match = (_cur_match_time - _last_set_interrupt) & _mask;
257+
uint32_t cycles_until_match = (_cur_match_time - current) & _mask;
249258
bool too_close = cycles_until_match < _min_count_until_match;
250259

251260
if (!_set_interrupt_allowed) {

0 commit comments

Comments
 (0)