@@ -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;
0 commit comments