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