From 252a57ef6adbf9695157824e27c20f637dcad560 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Thu, 12 Sep 2019 23:12:17 +0300 Subject: [PATCH] util: Utilize BPMP sleep when usleep is out of bounds --- bootloader/utils/util.c | 10 +++++++--- nyx/nyx_gui/utils/util.c | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bootloader/utils/util.c b/bootloader/utils/util.c index 8833feb..a1dd7cc 100644 --- a/bootloader/utils/util.c +++ b/bootloader/utils/util.c @@ -61,9 +61,13 @@ void usleep(u32 us) { #ifdef USE_RTC_TIMER u32 start = TMR(TIMERUS_CNTR_1US); - // Casting to u32 is important! - while ((u32)(TMR(TIMERUS_CNTR_1US) - start) <= us) - ; + + // Check if timer is at upper limits and use BPMP sleep so it doesn't wake up immediately. + if ((start + us) < start) + bpmp_usleep(us); + else + while ((u32)(TMR(TIMERUS_CNTR_1US) - start) <= us) // Casting to u32 is important! + ; #else bpmp_usleep(us); #endif diff --git a/nyx/nyx_gui/utils/util.c b/nyx/nyx_gui/utils/util.c index b1c5161..102ebeb 100644 --- a/nyx/nyx_gui/utils/util.c +++ b/nyx/nyx_gui/utils/util.c @@ -60,9 +60,13 @@ void usleep(u32 us) { #ifdef USE_RTC_TIMER u32 start = TMR(TIMERUS_CNTR_1US); - // Casting to u32 is important! - while ((u32)(TMR(TIMERUS_CNTR_1US) - start) <= us) - ; + + // Check if timer is at upper limits and use BPMP sleep so it doesn't wake up immediately. + if ((start + us) < start) + bpmp_usleep(us); + else + while ((u32)(TMR(TIMERUS_CNTR_1US) - start) <= us) // Casting to u32 is important! + ; #else bpmp_usleep(us); #endif