From cb18b136b569490bae0dc8643b9b74f99a6a6e88 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Wed, 11 Dec 2024 15:59:26 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=9B=9E=E9=80=80?= =?utf8?q?=E6=B5=B7=E6=80=9D=E6=97=B6=E9=97=B4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../porting/liteos/riscv70/tick_timer.c | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/code/sdk/drivers/chips/brandy/porting/liteos/riscv70/tick_timer.c b/code/sdk/drivers/chips/brandy/porting/liteos/riscv70/tick_timer.c index 73d4fbd70..9e9712c1e 100755 --- a/code/sdk/drivers/chips/brandy/porting/liteos/riscv70/tick_timer.c +++ b/code/sdk/drivers/chips/brandy/porting/liteos/riscv70/tick_timer.c @@ -120,17 +120,48 @@ void HalDelayUs(unsigned usecs) } } +#ifdef SUPPORT_RC_CALIBRATION +volatile uint64_t g_pre_count = 0; +volatile double g_pre_msec = 0; +#endif + uint64_t HalClockGetCycles(void) { +#ifdef SUPPORT_RC_CALIBRATION + volatile double tick_count; +#else uint64_t tick_count; +#endif uint64_t cycle; uint32_t lock_int_save; uint32_t load_tick; +#ifdef SUPPORT_RC_CALIBRATION + volatile double msec; + volatile uint64_t now_count; +#endif lock_int_save = LOS_IntLock(); + +#ifdef SUPPORT_RC_CALIBRATION + if (g_pre_count == 0) { + tick_count = (uapi_systick_get_count() * OS_SYS_MS_PER_SECOND) / CLOCK_32K_CALI_FREQ; + g_pre_count = uapi_systick_get_count(); + g_pre_msec = tick_count; + } else { + now_count = uapi_systick_get_count(); + msec = (double)((now_count - g_pre_count) * OS_SYS_MS_PER_SECOND) / CLOCK_32K_CALI_FREQ; + tick_count = g_pre_msec + msec; + + g_pre_count = now_count; + g_pre_msec = tick_count; + } +#else tick_count = uapi_systick_get_ms(); +#endif + load_tick = machine_timer_get_load_count(); cycle = (uint64_t)(tick_count * load_tick); + LOS_IntRestore(lock_int_save); return cycle; } -- 2.17.1