Skip to content

Commit 3f5eeac

Browse files
author
Cruz Monrreal
authored
Merge pull request #8279 from fkjagodzinski/fix-lp_ticker_wrapper-suspend
Fix LowPowerTickerWrapper operation when suspended
2 parents c25f156 + effabc5 commit 3f5eeac

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

hal/LowPowerTickerWrapper.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@ void LowPowerTickerWrapper::irq_handler(ticker_irq_handler_type handler)
3232
{
3333
core_util_critical_section_enter();
3434

35-
if (_suspended) {
36-
if (handler) {
37-
handler(&data);
38-
}
39-
core_util_critical_section_exit();
40-
return;
41-
}
42-
43-
if (_pending_fire_now || _match_check(_intf->read())) {
35+
if (_pending_fire_now || _match_check(_intf->read()) || _suspended) {
4436
_timeout.detach();
4537
_pending_timeout = false;
4638
_pending_match = false;
@@ -78,6 +70,14 @@ void LowPowerTickerWrapper::resume()
7870
{
7971
core_util_critical_section_enter();
8072

73+
// Wait until rescheduling is allowed
74+
while (!_set_interrupt_allowed) {
75+
timestamp_t current = _intf->read();
76+
if (((current - _last_actual_set_interrupt) & _mask) >= _min_count_between_writes) {
77+
_set_interrupt_allowed = true;
78+
}
79+
}
80+
8181
_suspended = false;
8282

8383
core_util_critical_section_exit();
@@ -118,7 +118,7 @@ uint32_t LowPowerTickerWrapper::read()
118118
core_util_critical_section_enter();
119119

120120
timestamp_t current = _intf->read();
121-
if (_match_check(current)) {
121+
if (!_suspended && _match_check(current)) {
122122
_intf->fire_interrupt();
123123
}
124124

@@ -133,7 +133,13 @@ void LowPowerTickerWrapper::set_interrupt(timestamp_t timestamp)
133133
_last_set_interrupt = _intf->read();
134134
_cur_match_time = timestamp;
135135
_pending_match = true;
136-
_schedule_match(_last_set_interrupt);
136+
if (!_suspended) {
137+
_schedule_match(_last_set_interrupt);
138+
} else {
139+
_intf->set_interrupt(timestamp);
140+
_last_actual_set_interrupt = _last_set_interrupt;
141+
_set_interrupt_allowed = false;
142+
}
137143

138144
core_util_critical_section_exit();
139145
}
@@ -277,7 +283,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
277283
_intf->set_interrupt(_cur_match_time);
278284
current = _intf->read();
279285
_last_actual_set_interrupt = current;
280-
_set_interrupt_allowed = false;
286+
_set_interrupt_allowed = false;
281287

282288
// Check for overflow
283289
uint32_t new_cycles_until_match = (_cur_match_time - current) & _mask;

hal/LowPowerTickerWrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class LowPowerTickerWrapper {
7474
*
7575
* This stops to wrapper layer from using the microsecond ticker.
7676
* This should be called before using the low power ticker APIs directly.
77+
*
78+
* @warning: Make sure to suspend the LP ticker first (call ticker_suspend()),
79+
* otherwise the behavior is undefined.
7780
*/
7881
void suspend();
7982

hal/mbed_lp_ticker_wrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const ticker_data_t *get_lp_ticker_wrapper_data(const ticker_data_t *data);
5353
*
5454
* Pass through all interrupts to the low power ticker and stop using
5555
* the microsecond ticker.
56+
*
57+
* @warning: Make sure to suspend the LP ticker first (call ticker_suspend()),
58+
* otherwise the behavior is undefined.
5659
*/
5760
void lp_ticker_wrapper_suspend(void);
5861

0 commit comments

Comments
 (0)