From b877701d96de0fff7611c7c3be1b5aa78922e0db Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Thu, 9 Jan 2025 14:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0cpu=E6=97=B6=E9=92=9F?= =?UTF-8?q?=E5=91=A8=E6=9C=9F=E5=BB=B6=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- driver/src/hal/clock.c | 20 ++++++++++++++++++++ inc/driver/iot_clock.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/driver/src/hal/clock.c b/driver/src/hal/clock.c index 82bf943..c0c753f 100644 --- a/driver/src/hal/clock.c +++ b/driver/src/hal/clock.c @@ -65,6 +65,26 @@ void IRAM_ATTR iot_delay_us_cpu_cycle(uint32_t us) } } +void IRAM_ATTR iot_delay_cpu_cycle(uint32_t c) +{ + uint64_t start, now; + uint64_t cycle = c; + + start = cpu_get_mcycle(); + + while(1) { + now = cpu_get_mcycle(); + if (now >= start) { + if((now - start) > cycle) + break; + } else { + if(((uint64_t)(-1) - start + now) > cycle) + break; + } + } +} + + void system_cpu_sleep(bool_t tick) { clk_sys_sleep(tick); diff --git a/inc/driver/iot_clock.h b/inc/driver/iot_clock.h index aceb83d..a871517 100644 --- a/inc/driver/iot_clock.h +++ b/inc/driver/iot_clock.h @@ -36,6 +36,8 @@ void iot_delay_us(uint32_t us); */ void iot_delay_us_cpu_cycle(uint32_t us); +void iot_delay_cpu_cycle(uint32_t c); + void system_cpu_sleep(); void system_cpu_wakeup();