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 LowPowerTickerWrapper operation when suspended #8279

Merged
merged 2 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
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
30 changes: 18 additions & 12 deletions hal/LowPowerTickerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ void LowPowerTickerWrapper::irq_handler(ticker_irq_handler_type handler)
{
core_util_critical_section_enter();

if (_suspended) {
if (handler) {
handler(&data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when suspended interrupts need to be passed through so higher layers can run tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note the interrupts are passed as before. I moved _suspended to the next if statement to have the flags cleared (i.e. _pending_match).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I didn't realize the interrupt was still getting through.

}
core_util_critical_section_exit();
return;
}

if (_pending_fire_now || _match_check(_intf->read())) {
if (_pending_fire_now || _match_check(_intf->read()) || _suspended) {
_timeout.detach();
_pending_timeout = false;
_pending_match = false;
Expand Down Expand Up @@ -78,6 +70,14 @@ void LowPowerTickerWrapper::resume()
{
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;

core_util_critical_section_exit();
Expand Down Expand Up @@ -118,7 +118,7 @@ uint32_t LowPowerTickerWrapper::read()
core_util_critical_section_enter();

timestamp_t current = _intf->read();
if (_match_check(current)) {
if (!_suspended && _match_check(current)) {
_intf->fire_interrupt();
}

Expand All @@ -133,7 +133,13 @@ void LowPowerTickerWrapper::set_interrupt(timestamp_t timestamp)
_last_set_interrupt = _intf->read();
_cur_match_time = timestamp;
_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();
}
Expand Down Expand Up @@ -277,7 +283,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
_intf->set_interrupt(_cur_match_time);
current = _intf->read();
_last_actual_set_interrupt = current;
_set_interrupt_allowed = false;
_set_interrupt_allowed = false;

// Check for overflow
uint32_t new_cycles_until_match = (_cur_match_time - current) & _mask;
Expand Down
3 changes: 3 additions & 0 deletions hal/LowPowerTickerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class LowPowerTickerWrapper {
*
* This stops to wrapper layer from using the microsecond ticker.
* 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();

Expand Down
3 changes: 3 additions & 0 deletions hal/mbed_lp_ticker_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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);

Expand Down