-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: subsys: Add sample app to demo OS managed PM
Add a sample application to demonstrate OS managed Power Management framework. Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
- Loading branch information
Ramakrishna Pallala
committed
Aug 21, 2018
1 parent
48eebc9
commit 7f6d3e5
Showing
7 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. _power_management-samples: | ||
|
||
Power Management Samples | ||
######################## | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
|
||
**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.8.2) | ||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) | ||
project(NONE) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.. _os-power-mgr-sample: | ||
|
||
OS Power management demo | ||
########################### | ||
|
||
Overview | ||
******** | ||
|
||
This sample demonstrates OS managed power saving mechanism through the sample | ||
application which will periodically go sleep there by invoking the idle thread | ||
which will call the _sys_soc_suspend() to enter into low power states. The Low | ||
Power state will be selected based on the next timeout event. | ||
|
||
Requirements | ||
************ | ||
|
||
This application uses nrf52 DK board for the demo. | ||
|
||
Building, Flashing and Running | ||
****************************** | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/subsys/power/power_mgr | ||
:board: nrf52_pca10040 | ||
:goals: build flash | ||
:compact: | ||
|
||
Running: | ||
|
||
1. Open UART terminal. | ||
2. Power Cycle Device. | ||
3. Device will enter into Low Power Modes periodically. | ||
|
||
|
||
Sample Output | ||
================= | ||
nrf52 core output | ||
----------------- | ||
|
||
.. code-block:: console | ||
***OS Power Management Demo on arm**** | ||
Demo Description | ||
Application creates Idleness, Due to which System Idle Thread is | ||
scheduled and it enters into various Low Power States. | ||
<-- App doing busy wait for 10 Sec --> | ||
<-- App going to sleep for 6000 msec --> | ||
Entering Low Power state (0) | ||
Entering Low Power state (0) | ||
Entering Low Power state (0) | ||
Entering Low Power state (0) | ||
<-- App doing busy wait for 10 Sec --> | ||
<-- App going to sleep for 11000 msec --> | ||
Entering Low Power state (1) | ||
Entering Low Power state (1) | ||
Entering Low Power state (1) | ||
Entering Low Power state (1) | ||
<-- App doing busy wait for 10 Sec --> | ||
<-- App going to sleep for 6000 msec --> | ||
Entering Low Power state (0) | ||
Entering Low Power state (0) | ||
Entering Low Power state (0) | ||
Entering Low Power state (0) | ||
<-- App doing busy wait for 10 Sec --> | ||
<-- App going to sleep for 11000 msec --> | ||
Entering Low Power state (1) | ||
Entering Low Power state (1) | ||
Entering Low Power state (1) | ||
Entering Low Power state (1) | ||
OS managed Power Management Test completed | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CONFIG_SYS_POWER_MANAGEMENT=y | ||
CONFIG_SYS_POWER_LOW_POWER_STATE=y | ||
CONFIG_SYS_POWER_DEEP_SLEEP=y | ||
CONFIG_DEVICE_POWER_MANAGEMENT=y | ||
CONFIG_TICKLESS_IDLE=y | ||
|
||
CONFIG_PM_CONTROL_OS=y | ||
CONFIG_PM_CONTROL_OS_LPS=y | ||
CONFIG_PM_LPS_MIN_RES=5 | ||
CONFIG_PM_CONTROL_OS_LPS_1=y | ||
CONFIG_PM_LPS_1_MIN_RES=10 | ||
CONFIG_PM_CONTROL_OS_DEEP_SLEEP=y | ||
CONFIG_PM_DEEP_SLEEP_MIN_RES=60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CONFIG_NUM_COOP_PRIORITIES=29 | ||
CONFIG_NUM_PREEMPT_PRIORITIES=40 | ||
CONFIG_SYS_POWER_MANAGEMENT=y | ||
CONFIG_SYS_POWER_LOW_POWER_STATE=y | ||
CONFIG_SYS_POWER_DEEP_SLEEP=y | ||
CONFIG_DEVICE_POWER_MANAGEMENT=y | ||
CONFIG_TICKLESS_KERNEL=y | ||
CONFIG_TICKLESS_IDLE=y | ||
|
||
CONFIG_PM_CONTROL_OS=y | ||
CONFIG_PM_CONTROL_OS_LPS=y | ||
CONFIG_PM_LPS_MIN_RES=5 | ||
CONFIG_PM_CONTROL_OS_LPS_1=y | ||
CONFIG_PM_LPS_1_MIN_RES=10 | ||
CONFIG_PM_CONTROL_OS_DEEP_SLEEP=y | ||
CONFIG_PM_DEEP_SLEEP_MIN_RES=60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sample: | ||
name: OS managed Power Management Sample | ||
tests: | ||
ospm.low_power_state: | ||
platform_whitelist: nrf52840_pca10056 nrf52_pca10040 | ||
tags: power |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2016 Intel Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr.h> | ||
#include <power.h> | ||
#include <soc_power.h> | ||
#include <misc/printk.h> | ||
#include <string.h> | ||
#include <board.h> | ||
#include <device.h> | ||
#include <gpio.h> | ||
|
||
#define SECONDS_TO_SLEEP 1 | ||
|
||
#define BUSY_WAIT_DELAY_US (10 * 1000000) | ||
|
||
#define LPS_STATE_ENTER_TO ((CONFIG_PM_LPS_MIN_RES + 1) * 1000) | ||
#define LPS1_STATE_ENTER_TO ((CONFIG_PM_LPS_1_MIN_RES + 1) * 1000) | ||
|
||
#define DEMO_DESCRIPTION \ | ||
"Demo Description\n" \ | ||
"Application creates Idleness, Due to which System Idle Thread is\n"\ | ||
"scheduled and it enters into various Low Power States.\n"\ | ||
|
||
void sys_pm_notify_lps_entry(enum power_states state) | ||
{ | ||
printk("Entering Low Power state (%d)\n", state); | ||
} | ||
|
||
void sys_pm_notify_lps_exit(enum power_states state) | ||
{ | ||
printk("Entering Low Power state (%d)\n", state); | ||
} | ||
|
||
/* Application main Thread */ | ||
void main(void) | ||
{ | ||
printk("\n\n***OS Power Management Demo on %s****\n", CONFIG_ARCH); | ||
printk(DEMO_DESCRIPTION); | ||
|
||
for (int i = 1; i <= 4; i++) { | ||
printk("\n<-- App doing busy wait for 10 Sec -->\n"); | ||
k_busy_wait(BUSY_WAIT_DELAY_US); | ||
|
||
/* Create Idleness to make Idle thread run */ | ||
if ((i % 2) == 0) { | ||
printk("\n<-- App going to sleep for %d msec -->\n", | ||
LPS1_STATE_ENTER_TO); | ||
k_sleep(LPS1_STATE_ENTER_TO); | ||
} else { | ||
printk("\n<-- App going to sleep for %d msec -->\n", | ||
LPS_STATE_ENTER_TO); | ||
k_sleep(LPS_STATE_ENTER_TO); | ||
} | ||
} | ||
|
||
printk("OS managed Power Management Test completed\n"); | ||
} |