mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2024-09-29 03:28:49 +08:00
Avoid setting an alarm in the past (#1954)
* Avoid setting an alarm in the past Fixes #1953 * Call ta_time_us_64 when needed Remove local "now" variable.
This commit is contained in:
parent
d08f36cd1c
commit
9f56a47dca
|
@ -142,7 +142,6 @@ static void alarm_pool_irq_handler(void) {
|
|||
uint timer_num = ta_timer_num(timer);
|
||||
alarm_pool_t *pool = pools[timer_num][timer_alarm_num];
|
||||
assert(pool->timer_alarm_num == timer_alarm_num);
|
||||
int64_t now = (int64_t) ta_time_us_64(timer);
|
||||
int64_t earliest_target;
|
||||
// 1. clear force bits if we were forced (do this outside the loop, as forcing is hopefully rare)
|
||||
ta_clear_force_irq(timer, timer_alarm_num);
|
||||
|
@ -159,7 +158,7 @@ static void alarm_pool_irq_handler(void) {
|
|||
if (earliest_index >= 0) {
|
||||
alarm_pool_entry_t *earliest_entry = &pool->entries[earliest_index];
|
||||
earliest_target = earliest_entry->target;
|
||||
if ((now - earliest_target) >= 0) {
|
||||
if (((int64_t)ta_time_us_64(timer) - earliest_target) >= 0) {
|
||||
// time to call the callback now (or in the past)
|
||||
// note that an entry->target of < 0 means the entry has been canceled (not this is set
|
||||
// by this function, in response to the entry having been queued by the cancel_alarm API
|
||||
|
@ -259,7 +258,6 @@ static void alarm_pool_irq_handler(void) {
|
|||
index = next;
|
||||
}
|
||||
}
|
||||
now = (int64_t) ta_time_us_64(timer);
|
||||
earliest_index = pool->ordered_head;
|
||||
if (earliest_index < 0) break;
|
||||
// need to wait
|
||||
|
@ -267,7 +265,7 @@ static void alarm_pool_irq_handler(void) {
|
|||
earliest_target = earliest_entry->target;
|
||||
ta_set_timeout(timer, timer_alarm_num, earliest_target);
|
||||
// check we haven't now past the target time; if not we don't want to loop again
|
||||
} while ((earliest_target - now) <= 0);
|
||||
} while ((earliest_target - (int64_t)ta_time_us_64(timer)) <= 0);
|
||||
}
|
||||
|
||||
void alarm_pool_post_alloc_init(alarm_pool_t *pool, alarm_pool_timer_t *timer, uint hardware_alarm_num, uint max_timers) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user