!952 fix: 修复低功耗下时间更新缺陷

Merge pull request !952 from zhushengle/pm_timer
This commit is contained in:
openharmony_ci 2022-12-05 13:02:02 +00:00 committed by Gitee
commit 588abc0645
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 56 additions and 31 deletions

View File

@ -101,7 +101,8 @@ STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
}
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
if ((tickTimer->timerStop != NULL) && (pm->enterSleepTime != 0)) {
if (tickTimer->timerStop != NULL) {
if (pm->enterSleepTime != 0) {
/* Restore the main CPU frequency */
sleepTime = tickTimer->timerCycleGet();
tickTimer->timerStop();
@ -113,9 +114,14 @@ STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
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();

View File

@ -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:

View File

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