From e92ef1e4d04f3ebed7fe9eeaee6f3c12f19aac15 Mon Sep 17 00:00:00 2001 From: Dmytro Kosmii Date: Mon, 11 Jul 2022 11:22:04 +0300 Subject: [PATCH] Added PM sample in led_demo project. Signed-off-by: Dmytro Kosmii --- led_demo/led_demo/BUILD.gn | 12 +++++++++++- led_demo/led_demo/app.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/led_demo/led_demo/BUILD.gn b/led_demo/led_demo/BUILD.gn index 09751df..e4b6334 100755 --- a/led_demo/led_demo/BUILD.gn +++ b/led_demo/led_demo/BUILD.gn @@ -15,6 +15,7 @@ declare_args() { telink_gpio_irq_sample_enable = false + telink_powermanager_sample_enable = false } config("myapp_config") { @@ -26,7 +27,10 @@ config("myapp_config") { source_set("myapp_inner") { sources = [ "app.c" ] - deps = [ "//base/hiviewdfx/hiview_lite" ] + deps = [ + "//base/hiviewdfx/hiview_lite", + "//base/powermgr/powermgr_lite/frameworks:powermgr" + ] if (!defined(defines)) { defines = [] @@ -38,6 +42,12 @@ source_set("myapp_inner") { defines += [ "TELINK_GPIO_IRQ_SAMPLE_ENABLE=0" ] } + if (telink_powermanager_sample_enable) { + defines += [ "TELINK_POWERMANAGER_SAMPLE_ENABLE=1" ] + } else { + defines += [ "TELINK_POWERMANAGER_SAMPLE_ENABLE=0" ] + } + configs += [ ":myapp_config" ] } diff --git a/led_demo/led_demo/app.c b/led_demo/led_demo/app.c index 5a1d8a6..28dda3d 100755 --- a/led_demo/led_demo/app.c +++ b/led_demo/led_demo/app.c @@ -29,20 +29,38 @@ #include #include +#include +#include +#include #include #define LED_TASK_PRIORITY LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO #define PROTO_TASK_PRIORITY (OS_TASK_PRIORITY_LOWEST-1) -#define DELAY 1000 +#define DELAY_MS 1000 STATIC VOID HelloWorldTask(VOID) { +#if TELINK_POWERMANAGER_SAMPLE_ENABLE + RunningLock *lock = CreateRunningLock(__func__, RUNNINGLOCK_BACKGROUND, RUNNINGLOCK_FLAG_WAKEUP_WHEN_ACQUIRED); +#endif /* TELINK_POWERMANAGER_SAMPLE_ENABLE */ + while (1) { time_t t = time(NULL); printf("Hello World, time: %lld\r\n", (long long)t); - LOS_TaskDelay(DELAY); + LOS_Msleep(10000); + +#if TELINK_POWERMANAGER_SAMPLE_ENABLE + printf(" *** Acquiring Running Lock\r\n"); + AcquireRunningLock(lock); + printf(" *** Acquired Running Lock\r\n"); + + LOS_Msleep(5000); + printf(" *** Releasing Running Lock\r\n"); + ReleaseRunningLock(lock); + printf(" *** Released Running Lock\r\n"); +#endif /* TELINK_POWERMANAGER_SAMPLE_ENABLE */ } } @@ -52,10 +70,10 @@ STATIC VOID LedTask(VOID) while (1) { GpioWrite(LED_BLUE_HDF, GPIO_VAL_HIGH); - LOS_Msleep(DELAY); + LOS_Msleep(DELAY_MS); GpioWrite(LED_BLUE_HDF, GPIO_VAL_LOW); - LOS_Msleep(DELAY); + LOS_Msleep(DELAY_MS); } } @@ -101,6 +119,10 @@ void AppMain(void) GpioSetIrq(SW1_3_GPIO_HDF, GPIO_IRQ_TRIGGER_RISING, gpio_handler, NULL); GpioEnableIrq(SW1_3_GPIO_HDF); #endif /* TELINK_GPIO_IRQ_SAMPLE_ENABLE */ + +#if TELINK_POWERMANAGER_SAMPLE_ENABLE + SuspendDevice(SUSPEND_DEVICE_REASON_APPLICATION, FALSE); +#endif /* TELINK_POWERMANAGER_SAMPLE_ENABLE */ } SYS_RUN(AppMain); -- Gitee