summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamesh Thomas <ramesh.thomas@intel.com>2017-04-08 16:25:10 -0700
committerAnas Nashif <nashif@linux.intel.com>2017-04-27 13:46:35 +0000
commitc759ed1f948725c7618649e25260e011c7dccfb3 (patch)
treec8f7cbec242de0502033451cf2066db83136552a
parent700712f869d8c9d8d8576fd55727f6181caf1522 (diff)
samples: power: Time is passed as milliseconds in tickless kernel
In tickless kernel mode, time parameter of _sys_soc_suspend is in milliseconds. Based on the kernel mode use the correct mulitplier to convert to seconds. Jira:1821 Change-Id: Idf156f56ece79a82729ebb124d1552a5eeb69e25 Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
-rw-r--r--samples/power/power_mgr/prj_tickless.conf17
-rw-r--r--samples/power/power_mgr/src/main.c19
-rw-r--r--tests/power/power_states/prj_tickless.conf17
-rw-r--r--tests/power/power_states/src/main.c18
4 files changed, 65 insertions, 6 deletions
diff --git a/samples/power/power_mgr/prj_tickless.conf b/samples/power/power_mgr/prj_tickless.conf
new file mode 100644
index 000000000..9a651244a
--- /dev/null
+++ b/samples/power/power_mgr/prj_tickless.conf
@@ -0,0 +1,17 @@
+CONFIG_MDEF=n
+CONFIG_ASSERT=y
+CONFIG_ASSERT_LEVEL=2
+CONFIG_NUM_COOP_PRIORITIES=29
+CONFIG_NUM_PREEMPT_PRIORITIES=40
+
+CONFIG_SYS_POWER_MANAGEMENT=y
+CONFIG_TICKLESS_IDLE=y
+CONFIG_TICKLESS_KERNEL=y
+
+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_RTC=y
+CONFIG_GPIO=y
diff --git a/samples/power/power_mgr/src/main.c b/samples/power/power_mgr/src/main.c
index a5baf43dd..a8c4331b3 100644
--- a/samples/power/power_mgr/src/main.c
+++ b/samples/power/power_mgr/src/main.c
@@ -15,6 +15,19 @@
#define ALARM (RTC_ALARM_SECOND * (SECONDS_TO_SLEEP - 1))
#define GPIO_IN_PIN 16
+/* In Tickless Kernel mode, time is passed in milliseconds instead of ticks */
+#ifdef CONFIG_TICKLESS_KERNEL
+#define TICKS_TO_SECONDS_MULTIPLIER 1000
+#define TIME_UNIT_STRING "milliseconds"
+#else
+#define TICKS_TO_SECONDS_MULTIPLIER CONFIG_SYS_CLOCK_TICKS_PER_SEC
+#define TIME_UNIT_STRING "ticks"
+#endif
+
+#define MIN_TIME_TO_SUSPEND ((SECONDS_TO_SLEEP * \
+ TICKS_TO_SECONDS_MULTIPLIER) - \
+ (TICKS_TO_SECONDS_MULTIPLIER / 2))
+
static void create_device_list(void);
static void suspend_devices(void);
static void resume_devices(void);
@@ -160,9 +173,9 @@ int _sys_soc_suspend(s32_t ticks)
post_ops_done = 0;
- if (ticks < (SECONDS_TO_SLEEP * CONFIG_SYS_CLOCK_TICKS_PER_SEC)) {
- printk("Not enough time for PM operations (ticks: %d).\n",
- ticks);
+ if ((ticks != K_FOREVER) && (ticks < MIN_TIME_TO_SUSPEND)) {
+ printk("Not enough time for PM operations (" TIME_UNIT_STRING
+ ": %d).\n", ticks);
return SYS_PM_NOT_HANDLED;
}
diff --git a/tests/power/power_states/prj_tickless.conf b/tests/power/power_states/prj_tickless.conf
new file mode 100644
index 000000000..9a651244a
--- /dev/null
+++ b/tests/power/power_states/prj_tickless.conf
@@ -0,0 +1,17 @@
+CONFIG_MDEF=n
+CONFIG_ASSERT=y
+CONFIG_ASSERT_LEVEL=2
+CONFIG_NUM_COOP_PRIORITIES=29
+CONFIG_NUM_PREEMPT_PRIORITIES=40
+
+CONFIG_SYS_POWER_MANAGEMENT=y
+CONFIG_TICKLESS_IDLE=y
+CONFIG_TICKLESS_KERNEL=y
+
+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_RTC=y
+CONFIG_GPIO=y
diff --git a/tests/power/power_states/src/main.c b/tests/power/power_states/src/main.c
index 7d9536c1b..d5a97c030 100644
--- a/tests/power/power_states/src/main.c
+++ b/tests/power/power_states/src/main.c
@@ -32,6 +32,18 @@ static enum power_states states_list[] = {
#define MAX_SUSPEND_DEVICE_COUNT 15
#define NB_STATES ARRAY_SIZE(states_list)
+/* In Tickless Kernel mode, time is passed in milliseconds instead of ticks */
+#ifdef CONFIG_TICKLESS_KERNEL
+#define TICKS_TO_SECONDS_MULTIPLIER 1000
+#define TIME_UNIT_STRING "milliseconds"
+#else
+#define TICKS_TO_SECONDS_MULTIPLIER CONFIG_SYS_CLOCK_TICKS_PER_SEC
+#define TIME_UNIT_STRING "ticks"
+#endif
+
+#define MIN_TIME_TO_SUSPEND ((TIMEOUT * TICKS_TO_SECONDS_MULTIPLIER) - \
+ (TICKS_TO_SECONDS_MULTIPLIER / 2))
+
static struct device *suspend_devices[MAX_SUSPEND_DEVICE_COUNT];
static int suspend_device_count;
static unsigned int current_state = NB_STATES - 1;
@@ -234,9 +246,9 @@ int _sys_soc_suspend(s32_t ticks)
int pm_operation = SYS_PM_NOT_HANDLED;
post_ops_done = 0;
- if (ticks < (TIMEOUT * CONFIG_SYS_CLOCK_TICKS_PER_SEC)) {
- printk("Not enough time for PM operations (ticks: %d).\n",
- ticks);
+ if ((ticks != K_FOREVER) && (ticks < MIN_TIME_TO_SUSPEND)) {
+ printk("Not enough time for PM operations (" TIME_UNIT_STRING
+ ": %d).\n", ticks);
return SYS_PM_NOT_HANDLED;
}