1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-12-23 08:32:04 +00:00

util: Utilize BPMP sleep when usleep is out of bounds

This commit is contained in:
CTCaer 2019-09-12 23:12:17 +03:00
parent 23e246f224
commit 252a57ef6a
2 changed files with 14 additions and 6 deletions

View file

@ -61,9 +61,13 @@ void usleep(u32 us)
{ {
#ifdef USE_RTC_TIMER #ifdef USE_RTC_TIMER
u32 start = TMR(TIMERUS_CNTR_1US); 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 #else
bpmp_usleep(us); bpmp_usleep(us);
#endif #endif

View file

@ -60,9 +60,13 @@ void usleep(u32 us)
{ {
#ifdef USE_RTC_TIMER #ifdef USE_RTC_TIMER
u32 start = TMR(TIMERUS_CNTR_1US); 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 #else
bpmp_usleep(us); bpmp_usleep(us);
#endif #endif