提交 3c0d17fc 编写于 作者: O openharmony_ci 提交者: Gitee

!281 fix: 优化低功耗流程

Merge pull request !281 from zhushengle/pm_optimize
......@@ -69,63 +69,67 @@ STATIC LosPmCB g_pmCB;
STATIC LosPmSysctrl *g_sysctrl = NULL;
STATIC UINT64 g_pmSleepTime;
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
{
UINT32 intSave;
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 currTime, sleepTime, realSleepTime;
#endif
LosPmTickTimer *tickTimer = pm->tickTimer;
intSave = LOS_IntLock();
/* Restore the main CPU frequency */
sleepTime = tickTimer->timerCycleGet();
tickTimer->timerStop();
if ((tickTimer == NULL) || (tickTimer->tickUnlock == NULL)) {
return;
}
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
if (tickTimer->timerStop != NULL) {
/* 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, OS_SYS_CLOCK);
currTime = pm->enterSleepTime + realSleepTime;
pm->enterSleepTime = 0;
realSleepTime = OS_SYS_CYCLE_TO_NS(sleepTime, tickTimer->freq);
realSleepTime = OS_SYS_NS_TO_CYCLE(realSleepTime, OS_SYS_CLOCK);
currTime = pm->enterSleepTime + realSleepTime;
pm->enterSleepTime = 0;
OsSchedTimerBaseReset(currTime);
}
#endif
OsSchedTimerBaseReset(currTime);
OsSchedUpdateExpireTime(currTime, FALSE);
tickTimer->tickUnlock();
LOS_IntRestore(intSave);
return;
}
STATIC VOID OsPmTickTimerStop(LosPmCB *pm)
{
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
UINT64 sleepCycle;
UINT64 realSleepTime = g_pmSleepTime;
#endif
LosPmTickTimer *tickTimer = pm->tickTimer;
if (realSleepTime == 0) {
if ((tickTimer == NULL) || (tickTimer->tickLock == NULL)) {
return;
}
sleepCycle = OS_SYS_CYCLE_TO_NS(realSleepTime, OS_SYS_CLOCK);
sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq);
/* The main CPU reduces the frequency */
pm->enterSleepTime = OsGetCurrSysTimeCycle();
tickTimer->tickLock();
tickTimer->timerStart(sleepCycle);
return;
}
#endif
STATIC VOID OsPmTickTimerResume(LosPmCB *pm)
{
if ((pm->sysMode == LOS_SYS_DEEP_SLEEP) && (pm->tickTimer->tickUnlock != NULL)) {
pm->tickTimer->tickUnlock();
} else {
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
/* Sys tick timer is restored from low power mode */
if (pm->enterSleepTime != 0) {
OsPmTickTimerStart(pm);
if (tickTimer->timerStart != NULL) {
if (realSleepTime == 0) {
return;
}
#endif
sleepCycle = OS_SYS_CYCLE_TO_NS(realSleepTime, OS_SYS_CLOCK);
sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq);
/* The main CPU reduces the frequency */
pm->enterSleepTime = OsGetCurrSysTimeCycle();
tickTimer->tickLock();
tickTimer->timerStart(sleepCycle);
return;
}
#endif
tickTimer->tickLock();
return;
}
STATIC VOID OsPmCpuResume(LosPmCB *pm)
......@@ -161,104 +165,94 @@ STATIC Suspend OsPmCpuSuspend(LosPmCB *pm)
return sysSuspend;
}
STATIC VOID OsPmTickTimerSuspend(LosPmCB *pm)
{
if (((pm->sysMode == LOS_SYS_DEEP_SLEEP) || (pm->sysMode == LOS_SYS_SHUTDOWN)) &&
(pm->tickTimer->tickLock != NULL)) {
pm->tickTimer->tickLock();
} else {
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
/* Sys tick timer enter low power mode */
if (pm->tickTimer == NULL) {
return;
}
if ((pm->tickTimer->timerStart != NULL) &&
(pm->tickTimer->timerStop != NULL) &&
(pm->tickTimer->timerCycleGet == NULL) &&
(pm->tickTimer->freq != 0)) {
OsPmTickTimerStop(pm);
}
#endif
}
}
STATIC VOID OsPmEnter(BOOL isIdle)
STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
{
UINT32 ret;
UINT32 intSave;
LOS_SysSleepEnum mode;
Suspend sysSuspend = NULL;
LosPmCB *pm = &g_pmCB;
BOOL isTaskLock = FALSE;
intSave = LOS_IntLock();
pm->sysMode = pm->pmMode;
if (isIdle) {
if ((pm->sysMode != LOS_SYS_NORMAL_SLEEP) && (pm->sysMode != LOS_SYS_LIGHT_SLEEP)) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
}
} else {
if ((pm->sysMode != LOS_SYS_DEEP_SLEEP) && (pm->sysMode != LOS_SYS_SHUTDOWN)) {
LOS_IntRestore(intSave);
return;
}
if ((pm->pmMode != LOS_SYS_NORMAL_SLEEP) && (pm->lock > 0)) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
}
if ((pm->sysMode == LOS_SYS_NORMAL_SLEEP) || (pm->sysMode == LOS_SYS_LIGHT_SLEEP)) {
if (pm->lock > 0) {
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
}
} else if (pm->lock > 0) {
if (pm->sysMode == LOS_SYS_NORMAL_SLEEP) {
LOS_IntRestore(intSave);
return;
return LOS_NOK;
}
if (pm->sysMode != LOS_SYS_NORMAL_SLEEP) {
pm->isWake = FALSE;
LOS_TaskLock();
isTaskLock = TRUE;
pm->isWake = FALSE;
LOS_TaskLock();
ret = pm->device->suspend((UINT32)pm->sysMode);
mode = pm->sysMode;
if (pm->device->suspend != NULL) {
ret = pm->device->suspend(mode);
if (ret != LOS_OK) {
goto EXIT;
goto DEVICE_EXIT;
}
}
OsPmTickTimerSuspend(pm);
OsPmTickTimerStop(pm);
sysSuspend = OsPmCpuSuspend(pm);
LOS_IntRestore(intSave);
if (!isTaskLock || (isTaskLock && !pm->isWake)) {
(VOID)sysSuspend();
if (!pm->isWake) {
ret = sysSuspend();
}
intSave = LOS_IntLock();
OsPmCpuResume(pm);
OsPmTickTimerResume(pm);
OsPmTickTimerStart(pm);
if (pm->sysMode != LOS_SYS_NORMAL_SLEEP) {
pm->device->resume((UINT32)pm->sysMode);
if (pm->device->resume != NULL) {
pm->device->resume(mode);
}
if (pm->pmMode == LOS_SYS_DEEP_SLEEP) {
pm->pmMode = LOS_SYS_NORMAL_SLEEP;
}
DEVICE_EXIT:
pm->sysMode = LOS_SYS_NORMAL_SLEEP;
LOS_IntRestore(intSave);
EXIT:
LOS_TaskUnlock();
return ret;
}
STATIC VOID OsPmNormalSleep(LosPmCB *pm)
{
UINT32 intSave;
Suspend sysSuspend = NULL;
intSave = LOS_IntLock();
sysSuspend = OsPmCpuSuspend(pm);
LOS_IntRestore(intSave);
(VOID)sysSuspend();
intSave = LOS_IntLock();
OsPmCpuResume(pm);
LOS_IntRestore(intSave);
}
STATIC VOID OsPmEnter(VOID)
{
UINT32 ret;
LosPmCB *pm = &g_pmCB;
if (isTaskLock) {
LOS_TaskUnlock();
ret = OsPmSuspendSleep(pm);
if (ret != LOS_OK) {
OsPmNormalSleep(pm);
}
return;
}
STATIC VOID OsPmTask(VOID)
{
OsPmEnter(FALSE);
OsPmEnter();
}
STATIC UINT32 OsPmDeviceRegister(LosPmCB *pm, LosPmDevice *device)
......@@ -280,13 +274,24 @@ STATIC UINT32 OsPmTickTimerRegister(LosPmCB *pm, LosPmTickTimer *tickTimer)
{
UINT32 intSave;
intSave = LOS_IntLock();
if ((tickTimer->tickLock == NULL) || (tickTimer->tickUnlock == NULL)) {
return LOS_ERRNO_PM_INVALID_PARAM;
}
if (((tickTimer->timerStart == NULL) && (tickTimer->timerStop == NULL) &&
(tickTimer->timerCycleGet == NULL) && (tickTimer->freq == 0)) ||
((tickTimer->timerStart != NULL) && (tickTimer->timerStop != NULL) &&
(tickTimer->timerCycleGet != NULL) && (tickTimer->freq != 0))) {
intSave = LOS_IntLock();
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
pm->enterSleepTime = 0;
pm->enterSleepTime = 0;
#endif
pm->tickTimer = tickTimer;
LOS_IntRestore(intSave);
return LOS_OK;
pm->tickTimer = tickTimer;
LOS_IntRestore(intSave);
return LOS_OK;
}
return LOS_ERRNO_PM_INVALID_PARAM;
}
STATIC UINT32 OsPmSysctrlRegister(LosPmCB *pm, LosPmSysctrl *sysctrl)
......@@ -464,15 +469,6 @@ UINT32 LOS_PmModeSet(LOS_SysSleepEnum mode)
return LOS_ERRNO_PM_HANDLER_NULL;
}
if ((mode == LOS_SYS_DEEP_SLEEP) || (mode == LOS_SYS_SHUTDOWN)) {
if ((pm->tickTimer == NULL) ||
(pm->tickTimer->tickLock == NULL) ||
(pm->tickTimer->tickUnlock == NULL)) {
LOS_IntRestore(intSave);
return LOS_ERRNO_PM_TICK_TIMER_NULL;
}
}
pm->pmMode = mode;
LOS_IntRestore(intSave);
......
......@@ -1622,7 +1622,7 @@ extern UINT32 OsGetAllTskInfo(VOID);
extern VOID *OsTskUserStackInit(VOID* stackPtr, VOID* userSP, UINT32 userStackSize);
extern UINT32 OsPmEnterHandlerSet(VOID (*func)(BOOL));
extern UINT32 OsPmEnterHandlerSet(VOID (*func)(VOID));
#ifdef __cplusplus
#if __cplusplus
......
......@@ -101,7 +101,7 @@ LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_losFreeTask;
LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_taskRecyleList;
LITE_OS_SEC_BSS BOOL g_taskScheduled = FALSE;
STATIC VOID (*PmEnter)(BOOL isIdle) = NULL;
STATIC VOID (*PmEnter)(VOID) = NULL;
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
TaskSwitchInfo g_taskSwitchInfo;
......@@ -142,7 +142,7 @@ STATIC VOID OsRecyleFinishedTask(VOID)
LOS_IntRestore(intSave);
}
UINT32 OsPmEnterHandlerSet(VOID (*func)(BOOL))
UINT32 OsPmEnterHandlerSet(VOID (*func)(VOID))
{
if (func == NULL) {
return LOS_NOK;
......@@ -165,7 +165,7 @@ LITE_OS_SEC_TEXT VOID OsIdleTask(VOID)
OsRecyleFinishedTask();
if (PmEnter != NULL) {
PmEnter(TRUE);
PmEnter();
} else {
(VOID)HalEnterSleep();
}
......
......@@ -68,6 +68,7 @@ lite_component("test") {
"sample/kernel/sem:test_sem",
"sample/kernel/swtmr:test_swtmr",
"sample/kernel/task:test_task",
"sample/kernel/power:test_pm",
#"sample/kernel/tickless:test_tickless",
]
......
......@@ -84,6 +84,7 @@ extern "C" {
#define LOS_KERNEL_MEM_TEST 1
#define LOS_KERNEL_DYNLINK_TEST 0
#define LOS_KERNEL_TICKLESS_TEST 0
#define LOS_KERNEL_PM_TEST 1
#define LITEOS_CMSIS_TEST 0
#define LOS_CMSIS2_CORE_TASK_TEST 0
......
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
static_library("test_pm") {
sources = [
"It_los_pm.c",
"It_los_pm_001.c",
"It_los_pm_002.c",
]
include_dirs = [ "//kernel/liteos_m/components/power" ]
configs += [ "//kernel/liteos_m/testsuits:include" ]
}
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_pm.h"
VOID ItSuiteLosPm()
{
ItLosPm001();
ItLosPm002();
}
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "los_pm.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define SELF_DELETED 0
#define SYS_EXIST_SWTMR 1
#define TEST_HWI_RUNTIME 0x100000
#define TASK_LOOP_NUM 0x100000
#if (LOSCFG_BASE_CORE_SWTMR == 1)
#define TASK_EXISTED_NUM 3
#else
#define TASK_EXISTED_NUM 2
#endif
#define TASK_EXISTED_D_NUM TASK_EXISTED_NUM
#define TASK_NAME_NUM 10
#define IT_TASK_LOOP 20
extern VOID ItLosPm001(VOID);
extern VOID ItLosPm002(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_pm.h"
static UINT32 DeviceSuspend(UINT32 mode)
{
return LOS_OK;
}
static VOID DeviceResume(UINT32 mode)
{
return;
}
static LosPmDevice g_device1 = {
.suspend = NULL,
.resume = NULL,
};
static VOID SysResume(VOID)
{
}
static UINT32 SysSuspend(VOID)
{
return HalEnterSleep();
}
static LosPmSysctrl g_sysctrl = {
.normalSuspend = NULL,
.normalResume = SysResume,
};
static VOID TickLock(VOID)
{
return;
}
static VOID TickUnlock(VOID)
{
return;
}
static LosPmTickTimer g_tickTimer = {
.tickLock = NULL,
.tickUnlock = NULL,
.timerStart = NULL,
.timerStop = NULL,
.timerCycleGet = NULL,
.freq = 0,
};
static UINT32 TestCase(VOID)
{
UINT32 ret;
ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, NULL);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_device1.suspend = DeviceSuspend;
ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_device1.suspend = NULL;
g_device1.resume = DeviceResume;
ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_device1.suspend = DeviceSuspend;
g_device1.resume = DeviceResume;
ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device1);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, NULL);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_tickTimer.tickLock = TickLock;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_tickTimer.tickLock = NULL;
g_tickTimer.tickUnlock = TickUnlock;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_tickTimer.tickLock = TickLock;
g_tickTimer.tickUnlock = TickUnlock;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmUnregister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
g_tickTimer.tickLock = TickLock;
g_tickTimer.tickUnlock = TickUnlock;
g_tickTimer.timerStart = TickLock;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_tickTimer.timerStop = TickLock;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_tickTimer.timerCycleGet = TickLock;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
g_tickTimer.freq = 32000; /* 32000HZ */
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmUnregister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmRegister(LOS_PM_TYPE_SYSCTRL, &g_sysctrl);
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_PM_INVALID_PARAM, ret);
ret = LOS_PmUnregister(LOS_PM_TYPE_DEVICE, &g_device1);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
return LOS_OK;
}
VOID ItLosPm001(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosPm001", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION);
}
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "osTest.h"
#include "It_los_pm.h"
#include "los_timer.h"
static UINT32 g_deviceCount = 0;
static UINT32 g_sysCount = 0;
static UINT32 g_sysTickTimerCount = 0;
static UINT32 DeviceSuspend(UINT32 mode)
{
g_deviceCount++;
g_testCount++;
return LOS_OK;
}
static VOID DeviceResume(UINT32 mode)
{
g_deviceCount--;
return;
}
static LosPmDevice g_device = {
.suspend = DeviceSuspend,
.resume = DeviceResume,
};
static VOID TickLock(VOID)
{
g_testCount++;
g_sysTickTimerCount++;
}
static VOID TickUnlock(VOID)
{
g_sysTickTimerCount--;
}
static LosPmTickTimer g_tickTimer = {
.tickLock = TickLock,
.tickUnlock = TickUnlock,
.timerStart = NULL,
.timerStop = NULL,
.timerCycleGet = NULL,
.freq = 0,
};
static VOID SysResume(VOID)
{
if (g_sysCount != (UINT32)-1) {
g_sysCount--;
}
}
static UINT32 SysSuspend(VOID)
{
g_testCount++;
g_sysCount++;
if ((g_sysTickTimerCount != 1) || (g_deviceCount != 1) || (g_sysCount != 1)) {
g_sysCount = (UINT32)-1;
}
return HalEnterSleep();
}
static LosPmSysctrl g_sysctrl = {
.normalSuspend = HalEnterSleep,
.normalResume = NULL,
.lightSuspend = SysSuspend,
.lightResume = SysResume,
};
static UINT32 TestCase(VOID)
{
UINT32 ret;
g_sysCount = 0;
g_deviceCount = 0;
g_sysTickTimerCount = 0;
g_testCount = 0;
ret = LOS_PmRegister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmRegister(LOS_PM_TYPE_DEVICE, &g_device);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmRegister(LOS_PM_TYPE_SYSCTRL, &g_sysctrl);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmModeSet(LOS_SYS_LIGHT_SLEEP);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
LOS_PmLockRequest("testlock");
LOS_TaskDelay(100); /* delay 100 ticks */
LOS_PmLockRelease("testlock");
ICUNIT_GOTO_EQUAL(g_testCount, 0, g_testCount, EXIT);
LOS_TaskDelay(100); /* delay 100 ticks */
ICUNIT_GOTO_NOT_EQUAL(g_testCount, 0, g_sysCount, EXIT);
ICUNIT_GOTO_EQUAL(g_sysCount, 0, g_sysCount, EXIT);
ret = LOS_PmUnregister(LOS_PM_TYPE_DEVICE, &g_device);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
ret = LOS_PmUnregister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
return LOS_OK;
EXIT:
LOS_PmUnregister(LOS_PM_TYPE_DEVICE, &g_device);
LOS_PmUnregister(LOS_PM_TYPE_TICK_TIMER, &g_tickTimer);
return LOS_NOK;
}
VOID ItLosPm002(VOID) // IT_Layer_ModuleORFeature_No
{
TEST_ADD_CASE("ItLosPm002", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION);
}
......@@ -129,6 +129,10 @@ void TestKernel(void)
#if (LOS_KERNEL_DYNLINK_TEST == 1)
ItSuiteLosDynlink();
#endif
#if (LOS_KERNEL_PM_TEST == 1)
ItSuiteLosPm();
#endif
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册