From 7657aadc204ea0c234bee14ccd63a21e74efd7a4 Mon Sep 17 00:00:00 2001 From: zhushengle Date: Mon, 5 Dec 2022 14:14:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E4=BD=8E=E5=8A=9F?= =?UTF-8?q?=E8=80=97=E4=B8=8B=E6=97=B6=E9=97=B4=E6=9B=B4=E6=96=B0=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.注释说明低功耗框架中tickLock和tickUnlock两个钩子函数的要求 2.解决极端情况下OsTickTimerBaseReset断言失败的问题 BREAKING CHANGE: 修复低功耗下时间更新缺陷对外变更描述: 低功耗启用另一个低功耗timer时: LosPmTickTimer 中tickLock函数的功能实现描述由原来的:暂停系统tick timer 修改为:关闭系统tick timer,并将timer的count值清零 LosPmTickTimer 中tickUnlock函数的功能实现描述由原来的:恢复系统tick timer 修改为:重新启动系统tick timer Close #I5O80Z Signed-off-by: zhushengle Change-Id: I2ee17518e4a388ff5a1f9e3d8d7c61c81aa3e569 --- components/power/los_pm.c | 35 ++++++++++++++++++--------- components/power/los_pm.h | 50 ++++++++++++++++++++++++--------------- kernel/src/los_tick.c | 2 +- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/components/power/los_pm.c b/components/power/los_pm.c index 8d4df79c..3e2922c2 100644 --- a/components/power/los_pm.c +++ b/components/power/los_pm.c @@ -101,21 +101,27 @@ STATIC VOID OsPmTickTimerStart(LosPmCB *pm) } #if (LOSCFG_BASE_CORE_TICK_WTIMER == 0) - if ((tickTimer->timerStop != NULL) && (pm->enterSleepTime != 0)) { - /* Restore the main CPU frequency */ - sleepTime = tickTimer->timerCycleGet(); - tickTimer->timerStop(); + if (tickTimer->timerStop != NULL) { + if (pm->enterSleepTime != 0) { + /* Restore the main CPU frequency */ + sleepTime = tickTimer->timerCycleGet(); + tickTimer->timerStop(); - realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq); - realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, g_sysClock); - currTime = pm->enterSleepTime + realSleepTime; - pm->enterSleepTime = 0; + realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq); + realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, g_sysClock); + currTime = pm->enterSleepTime + realSleepTime; + pm->enterSleepTime = 0; - OsTickTimerBaseReset(currTime); - OsSchedResetSchedResponseTime(0); + OsTickTimerBaseReset(currTime); + OsSchedResetSchedResponseTime(0); + /* Restart the system tick timer */ + tickTimer->tickUnlock(); + } + return; } #endif + /* Restore the system tick timer */ tickTimer->tickUnlock(); return; } @@ -142,14 +148,21 @@ STATIC BOOL OsPmTickTimerStop(LosPmCB *pm) sleepCycle = OS_SYS_CYCLE_TO_NS(realSleepTime, g_sysClock); sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq); + if (sleepCycle == 0) { + pm->sysMode = LOS_SYS_NORMAL_SLEEP; + return FALSE; + } + /* The main CPU reduces the frequency */ pm->enterSleepTime = LOS_SysCycleGet(); + /* Turn off the system tick timer and clear the count value to zero */ tickTimer->tickLock(); tickTimer->timerStart(sleepCycle); return TRUE; } #endif + /* Pause the system tick timer */ tickTimer->tickLock(); return TRUE; } @@ -167,7 +180,7 @@ STATIC VOID OsPmCpuResume(LosPmCB *pm) STATIC VOID OsPmCpuSuspend(LosPmCB *pm) { - /* cpu enter low power mode */ + /* cpu enter low-power mode */ if (pm->sysMode == LOS_SYS_NORMAL_SLEEP) { pm->sysctrl->normalSuspend(); diff --git a/components/power/los_pm.h b/components/power/los_pm.h index aea1dfb7..b87489f8 100644 --- a/components/power/los_pm.h +++ b/components/power/los_pm.h @@ -39,7 +39,7 @@ /** * @ingroup los_pm - * Pm error code: Invalid low power mode. + * Pm error code: Invalid low-power mode. * * Value: 0x02002001 * @@ -141,21 +141,33 @@ typedef enum { } LOS_PmNodeType; typedef struct { - UINT32 (*suspend)(UINT32 mode); /* The device enters low power consumption, Unlocked task scheduling. */ - VOID (*resume)(UINT32 mode); /* The device exits from low power consumption, Unlocked task scheduling. */ + UINT32 (*suspend)(UINT32 mode); /* The device enters low-power consumption, Unlocked task scheduling. */ + VOID (*resume)(UINT32 mode); /* The device exits from low-power consumption, Unlocked task scheduling. */ } LosPmDevice; typedef struct { - UINT32 freq; /* The frequency of the low power timer */ - VOID (*timerStart)(UINT64); /* Start the low power timer */ - VOID (*timerStop)(VOID); /* Stop the low power timer */ - UINT64 (*timerCycleGet)(VOID); /* Gets the running time of the low power timer in unit cycle */ - VOID (*tickLock)(VOID); /* Pause the system tick timer */ - VOID (*tickUnlock)(VOID); /* Restore the system tick timer */ + /* Low-power timer related implementation functions. + * The function is not NULL, the low-power timer is enabled. + */ + UINT32 freq; /* The frequency of the low-power timer */ + VOID (*timerStart)(UINT64); /* Start the low-power timer and set the response period */ + VOID (*timerStop)(VOID); /* Turn off the low-power timer */ + UINT64 (*timerCycleGet)(VOID); /* Gets the time the system sleeps */ + + /* When the low-power timer is enabled, the function of tickLock is to turn off the system tick timer and + * clear the timer's count value to zero. + * When the low-power timer is disabled, the function of tickLock is to pause the system timer. + */ + VOID (*tickLock)(VOID); + + /* When the low-power timer is enabled, the function of tickUnlock is to restart the system tick timer. + * When the low-power timer is disabled, the function of tickUnlock is to restore the system tick timer. + */ + VOID (*tickUnlock)(VOID); } LosPmTickTimer; typedef struct { - /* Preparations before the CPU enters low power consumption. + /* Preparations before the CPU enters low-power consumption. * All modes except normal mode are invoked. * Unlocked task scheduling. */ @@ -203,10 +215,10 @@ typedef struct { /** * @ingroup los_pm - * @brief Initialize system low power frame. + * @brief Initialize system low-power frame. * * @par Description: - * This API is used to initialize the system low power frame. + * This API is used to initialize the system low-power frame. * * @attention None. * @@ -221,10 +233,10 @@ UINT32 OsPmInit(VOID); /** * @ingroup los_pm - * @brief Whether the low power consumption condition is met. + * @brief Whether the low-power consumption condition is met. * * @par Description: - * This API is used to check whether low power consumption is met. + * This API is used to check whether low-power consumption is met. * * @attention None. * @@ -302,10 +314,10 @@ VOID LOS_PmWakeSet(VOID); /** * @ingroup los_pm - * @brief Get the low power mode of the current system. + * @brief Get the low-power mode of the current system. * * @par Description: - * This API is used to get the low power mode of the current system. + * This API is used to get the low-power mode of the current system. * * @attention None. * @@ -320,14 +332,14 @@ LOS_SysSleepEnum LOS_PmModeGet(VOID); /** * @ingroup los_pm - * @brief Set low power mode. + * @brief Set low-power mode. * * @par Description: - * This API is used to set low power mode. + * This API is used to set low-power mode. * * @attention None. * - * @param mode [IN] low power mode. + * @param mode [IN] low-power mode. * * @retval error code, LOS_OK means success. * @par Dependency: diff --git a/kernel/src/los_tick.c b/kernel/src/los_tick.c index afba77c1..4d14083d 100644 --- a/kernel/src/los_tick.c +++ b/kernel/src/los_tick.c @@ -64,7 +64,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsUpdateSysTimeBase(VOID) LITE_OS_SEC_TEXT VOID OsTickTimerBaseReset(UINT64 currTime) { - LOS_ASSERT(currTime > g_tickTimerBase); + LOS_ASSERT(currTime >= g_tickTimerBase); g_tickTimerBase = currTime; }