Skip to content

Commit

Permalink
Call ta_time_us_64 when needed
Browse files Browse the repository at this point in the history
Remove local "now" variable.
  • Loading branch information
peterharperuk committed Sep 26, 2024
1 parent 76755e1 commit 67f4ad9
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/common/pico_time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -265,9 +264,8 @@ static void alarm_pool_irq_handler(void) {
alarm_pool_entry_t *earliest_entry = &pool->entries[earliest_index];
earliest_target = earliest_entry->target;
ta_set_timeout(timer, timer_alarm_num, earliest_target);
now = (int64_t) ta_time_us_64(timer);
// 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) {
Expand Down

0 comments on commit 67f4ad9

Please sign in to comment.