Skip to content

Conversation

@peterharperuk
Copy link
Contributor

@peterharperuk peterharperuk commented Jan 17, 2025

Handle target in the past and running for > 2^32 us.

Fixes #2186

@kilograham
Copy link
Contributor

Hmm; i think the bug lies elsewhere...

does this help?

static inline bool ta_wakes_up_on_or_before(alarm_pool_timer_t *timer, uint alarm_num, int64_t target) {
    int64_t current = (int64_t)timer_time_us_64(timer_hw_from_timer(timer));
    int64_t time_til_target = target - current;
    uint32_t time_til_alarm = timer_hw_from_timer(timer)->alarm[alarm_num] - (uint32_t)current;
    return time_til_alarm <= time_til_target;
}

(it also should fix another fairly glaring error if you'd been running for > 2^32 us

@peterharperuk
Copy link
Contributor Author

@kilograham Your fix seems to work. I think my analysis was wrong? It was actually seems stuck on WFE? I'll use your fix instead.

Handle target in the past and running for > 2^32 us.

Fixes raspberrypi#2186
@peterharperuk peterharperuk changed the title async_context_poll can wait too long Fix ta_wakes_up_on_or_before Jan 20, 2025
@kilograham kilograham merged commit b8dc8c4 into raspberrypi:develop Jan 20, 2025
4 checks passed
@kilograham kilograham added this to the 2.1.1 milestone Jan 20, 2025
will-v-pi pushed a commit to will-v-pi/pico-sdk that referenced this pull request Mar 20, 2025
* Fix ta_wakes_up_on_or_before

Handle target in the past and running for > 2^32 us.

Fixes raspberrypi#2186

* Add test for ta_wakes_up_on_or_before fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants