Skip to content

Commit

Permalink
samples: subsys: Add sample app to demo OS managed PM
Browse files Browse the repository at this point in the history
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 authored and nashif committed Aug 22, 2018
1 parent 2ad6478 commit b69d286
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 0 deletions.
10 changes: 10 additions & 0 deletions samples/subsys/power/power.rst
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _power_management-samples:

Power Management Samples
########################

.. toctree::
:maxdepth: 1
:glob:

**/*
6 changes: 6 additions & 0 deletions samples/subsys/power/power_mgr/CMakeLists.txt
Original file line number Original file line 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})
79 changes: 79 additions & 0 deletions samples/subsys/power/power_mgr/README.rst
Original file line number Original file line 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
13 changes: 13 additions & 0 deletions samples/subsys/power/power_mgr/prj.conf
Original file line number Original file line 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
16 changes: 16 additions & 0 deletions samples/subsys/power/power_mgr/prj_tickless.conf
Original file line number Original file line 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
6 changes: 6 additions & 0 deletions samples/subsys/power/power_mgr/sample.yaml
Original file line number Original file line 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
61 changes: 61 additions & 0 deletions samples/subsys/power/power_mgr/src/main.c
Original file line number Original file line 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");
}

0 comments on commit b69d286

Please sign in to comment.