fix: 修复cortex-m系列系统提供的timer在低频下时间不准的问题

触发场景:
    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 <zhushengle@huawei.com>
Change-Id: Iba6e8799b0ae851fc94aa23867b2360a4245994d
This commit is contained in:
zhushengle 2021-11-08 14:38:01 +08:00
parent c488edd707
commit 3e569bac58
10 changed files with 50 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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