Merge pull request #5364 from osresearch/delay-overflow

mp_hal_delay_ms: avoid overflow when scaling ticks
This commit is contained in:
Limor "Ladyada" Fried 2021-09-17 17:16:19 -04:00 committed by GitHub
commit f9b40d417a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -127,12 +127,12 @@ void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() {
background_callback_run_all();
}
void mp_hal_delay_ms(mp_uint_t delay) {
void mp_hal_delay_ms(mp_uint_t delay_ms) {
uint64_t start_tick = port_get_raw_ticks(NULL);
// Adjust the delay to ticks vs ms.
delay = delay * 1024 / 1000;
uint64_t end_tick = start_tick + delay;
int64_t remaining = delay;
uint64_t delay_ticks = (delay_ms * (uint64_t)1024) / 1000;
uint64_t end_tick = start_tick + delay_ticks;
int64_t remaining = delay_ticks;
// Loop until we've waited long enough or we've been CTRL-Ced by autoreload
// or the user.