Merge pull request #8279 from fkjagodzinski/fix-lp_ticker_wrapper-suspend

Fix LowPowerTickerWrapper operation when suspended
pull/8562/head
Cruz Monrreal 2018-10-26 11:39:12 -05:00 committed by GitHub
commit 3f5eeac29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 12 deletions

View File

@ -32,15 +32,7 @@ void LowPowerTickerWrapper::irq_handler(ticker_irq_handler_type handler)
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
if (_suspended) { if (_pending_fire_now || _match_check(_intf->read()) || _suspended) {
if (handler) {
handler(&data);
}
core_util_critical_section_exit();
return;
}
if (_pending_fire_now || _match_check(_intf->read())) {
_timeout.detach(); _timeout.detach();
_pending_timeout = false; _pending_timeout = false;
_pending_match = false; _pending_match = false;
@ -78,6 +70,14 @@ void LowPowerTickerWrapper::resume()
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
// Wait until rescheduling is allowed
while (!_set_interrupt_allowed) {
timestamp_t current = _intf->read();
if (((current - _last_actual_set_interrupt) & _mask) >= _min_count_between_writes) {
_set_interrupt_allowed = true;
}
}
_suspended = false; _suspended = false;
core_util_critical_section_exit(); core_util_critical_section_exit();
@ -118,7 +118,7 @@ uint32_t LowPowerTickerWrapper::read()
core_util_critical_section_enter(); core_util_critical_section_enter();
timestamp_t current = _intf->read(); timestamp_t current = _intf->read();
if (_match_check(current)) { if (!_suspended && _match_check(current)) {
_intf->fire_interrupt(); _intf->fire_interrupt();
} }
@ -133,7 +133,13 @@ void LowPowerTickerWrapper::set_interrupt(timestamp_t timestamp)
_last_set_interrupt = _intf->read(); _last_set_interrupt = _intf->read();
_cur_match_time = timestamp; _cur_match_time = timestamp;
_pending_match = true; _pending_match = true;
_schedule_match(_last_set_interrupt); if (!_suspended) {
_schedule_match(_last_set_interrupt);
} else {
_intf->set_interrupt(timestamp);
_last_actual_set_interrupt = _last_set_interrupt;
_set_interrupt_allowed = false;
}
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
@ -277,7 +283,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
_intf->set_interrupt(_cur_match_time); _intf->set_interrupt(_cur_match_time);
current = _intf->read(); current = _intf->read();
_last_actual_set_interrupt = current; _last_actual_set_interrupt = current;
_set_interrupt_allowed = false; _set_interrupt_allowed = false;
// Check for overflow // Check for overflow
uint32_t new_cycles_until_match = (_cur_match_time - current) & _mask; uint32_t new_cycles_until_match = (_cur_match_time - current) & _mask;

View File

@ -74,6 +74,9 @@ public:
* *
* This stops to wrapper layer from using the microsecond ticker. * This stops to wrapper layer from using the microsecond ticker.
* This should be called before using the low power ticker APIs directly. * This should be called before using the low power ticker APIs directly.
*
* @warning: Make sure to suspend the LP ticker first (call ticker_suspend()),
* otherwise the behavior is undefined.
*/ */
void suspend(); void suspend();

View File

@ -53,6 +53,9 @@ const ticker_data_t *get_lp_ticker_wrapper_data(const ticker_data_t *data);
* *
* Pass through all interrupts to the low power ticker and stop using * Pass through all interrupts to the low power ticker and stop using
* the microsecond ticker. * the microsecond ticker.
*
* @warning: Make sure to suspend the LP ticker first (call ticker_suspend()),
* otherwise the behavior is undefined.
*/ */
void lp_ticker_wrapper_suspend(void); void lp_ticker_wrapper_suspend(void);