From 7bcf7dcbcf2b8ce3f5d885c8d332d0f6f4d51320 Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Wed, 3 Jun 2026 13:31:36 +0700 Subject: [PATCH] feat(lp_core): optimize ulp_lp_core_delay_X functions --- components/ulp/lp_core/lp_core/lp_core_utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/ulp/lp_core/lp_core/lp_core_utils.c b/components/ulp/lp_core/lp_core/lp_core_utils.c index f1739d8e96a..2ba6464aeec 100644 --- a/components/ulp/lp_core/lp_core/lp_core_utils.c +++ b/components/ulp/lp_core/lp_core/lp_core_utils.c @@ -112,10 +112,12 @@ void ulp_lp_core_delay_us(uint32_t us) if (us == 0) { return; } + uint32_t start = RV_READ_CSR(mcycle) - ULP_LP_CORE_DELAY_CALL_OVERHEAD_IN_CYCLES; uint32_t req_delay = us * LP_CORE_CYCLES_PER_US_NUM / LP_CORE_CYCLES_PER_US_DENOM; + uint32_t end = start + req_delay; - while ((uint32_t)(RV_READ_CSR(mcycle) - start) < req_delay) { + while (RV_READ_CSR(mcycle) < end) { /* busy wait */ } } @@ -132,7 +134,9 @@ void ulp_lp_core_delay_cycles(uint32_t cycles) } uint32_t start = RV_READ_CSR(mcycle) - ULP_LP_CORE_DELAY_CALL_OVERHEAD_IN_CYCLES; - while ((uint32_t)(RV_READ_CSR(mcycle) - start) < cycles) { + uint32_t end = start + cycles; + + while (RV_READ_CSR(mcycle) < end) { /* busy wait */ } }