Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with LowPowerTickerWrapper #8029

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions hal/LowPowerTickerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,14 @@ void LowPowerTickerWrapper::_timeout_handler()
_pending_timeout = false;

timestamp_t current = _intf->read();
if (_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time)) {
/* Add extra check for '_last_set_interrupt == _cur_match_time'
*
* When '_last_set_interrupt == _cur_match_time', _ticker_match_interval_passed sees it as
* one-round interval rather than just-pass, so add extra check for it. In rare cases, we
* may trap in _timeout_handler/_schedule_match loop. This check can break it.
*/
if ((_last_set_interrupt == _cur_match_time) ||
_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time)) {
_intf->fire_interrupt();
} else {
_schedule_match(current);
Expand All @@ -223,7 +230,9 @@ bool LowPowerTickerWrapper::_match_check(timestamp_t current)
if (!_pending_match) {
return false;
}
return _ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time);
/* Add extra check for '_last_set_interrupt == _cur_match_time' as above */
return (_last_set_interrupt == _cur_match_time) ||
_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time);
}

uint32_t LowPowerTickerWrapper::_lp_ticks_to_us(uint32_t ticks)
Expand All @@ -245,7 +254,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
}
}

uint32_t cycles_until_match = (_cur_match_time - _last_set_interrupt) & _mask;
uint32_t cycles_until_match = (_cur_match_time - current) & _mask;
bool too_close = cycles_until_match < _min_count_until_match;

if (!_set_interrupt_allowed) {
Expand Down