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; }