From 3e569bac587d90dcd21aff7d8ec53216dfbb8f1c Mon Sep 17 00:00:00 2001 From: zhushengle Date: Mon, 8 Nov 2021 14:38:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcortex-m=E7=B3=BB?= =?UTF-8?q?=E5=88=97=E7=B3=BB=E7=BB=9F=E6=8F=90=E4=BE=9B=E7=9A=84timer?= =?UTF-8?q?=E5=9C=A8=E4=BD=8E=E9=A2=91=E4=B8=8B=E6=97=B6=E9=97=B4=E4=B8=8D?= =?UTF-8?q?=E5=87=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 触发场景: cpu主频比较高,timer频率较低时,当SysTick->VAL == 0时, 触发tick中断,在中断中系统将当前周期累加到基准时间里,在中 断结束更新tick响应时间时,会更新系统基准时间(为了让时间更 加准确)此时由于SysTick->VAL任然等于0,接口HalGetTickCycle 返回的仍然是当前周期,导致该周期被累加了两次。 解决方案: 接口HalGetTickCycle在SysTick->VAL == 0时返回0. 因为SysTick->VAL == 0时,必然会触发tick中断,周期 的累加是由中断处理的,此时只需要返回0即可。 Close #I4HBGR Signed-off-by: zhushengle Change-Id: Iba6e8799b0ae851fc94aa23867b2360a4245994d --- kernel/arch/arm/cortex-m3/keil/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m33/gcc/NTZ/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m33/gcc/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m4/gcc/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m4/iar/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m7/gcc/los_timer.c | 7 +++++-- kernel/arch/arm/cortex-m7/iar/los_timer.c | 7 +++++-- 10 files changed, 50 insertions(+), 20 deletions(-) diff --git a/kernel/arch/arm/cortex-m3/keil/los_timer.c b/kernel/arch/arm/cortex-m3/keil/los_timer.c index f7898d75..ad59cff8 100644 --- a/kernel/arch/arm/cortex-m3/keil/los_timer.c +++ b/kernel/arch/arm/cortex-m3/keil/los_timer.c @@ -85,10 +85,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m33/gcc/NTZ/los_timer.c b/kernel/arch/arm/cortex-m33/gcc/NTZ/los_timer.c index 46057696..66e1f0de 100755 --- a/kernel/arch/arm/cortex-m33/gcc/NTZ/los_timer.c +++ b/kernel/arch/arm/cortex-m33/gcc/NTZ/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c b/kernel/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c index c202a5b9..a8deecd9 100755 --- a/kernel/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c +++ b/kernel/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m33/gcc/los_timer.c b/kernel/arch/arm/cortex-m33/gcc/los_timer.c index 46057696..66e1f0de 100644 --- a/kernel/arch/arm/cortex-m33/gcc/los_timer.c +++ b/kernel/arch/arm/cortex-m33/gcc/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c b/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c index 85654968..8ed46258 100644 --- a/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c +++ b/kernel/arch/arm/cortex-m33/iar/NTZ/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINTPTR intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c index 966e7a72..8bf355f2 100644 --- a/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c +++ b/kernel/arch/arm/cortex-m33/iar/TZ/non_secure/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINTPTR intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m4/gcc/los_timer.c b/kernel/arch/arm/cortex-m4/gcc/los_timer.c index 1044e59f..776c5102 100644 --- a/kernel/arch/arm/cortex-m4/gcc/los_timer.c +++ b/kernel/arch/arm/cortex-m4/gcc/los_timer.c @@ -85,10 +85,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m4/iar/los_timer.c b/kernel/arch/arm/cortex-m4/iar/los_timer.c index 4af50757..2029890b 100644 --- a/kernel/arch/arm/cortex-m4/iar/los_timer.c +++ b/kernel/arch/arm/cortex-m4/iar/los_timer.c @@ -85,10 +85,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m7/gcc/los_timer.c b/kernel/arch/arm/cortex-m7/gcc/los_timer.c index 46057696..66e1f0de 100644 --- a/kernel/arch/arm/cortex-m7/gcc/los_timer.c +++ b/kernel/arch/arm/cortex-m7/gcc/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; } diff --git a/kernel/arch/arm/cortex-m7/iar/los_timer.c b/kernel/arch/arm/cortex-m7/iar/los_timer.c index 46057696..66e1f0de 100644 --- a/kernel/arch/arm/cortex-m7/iar/los_timer.c +++ b/kernel/arch/arm/cortex-m7/iar/los_timer.c @@ -84,10 +84,13 @@ WEAK VOID HalSysTickReload(UINT64 nextResponseTime) WEAK UINT64 HalGetTickCycle(UINT32 *period) { - UINT32 hwCycle; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); + UINT32 val = SysTick->VAL; *period = SysTick->LOAD; - hwCycle = *period - SysTick->VAL; + if (val != 0) { + hwCycle = *period - val; + } LOS_IntRestore(intSave); return (UINT64)hwCycle; }