summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/stm32/stm32_idle.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-08 21:33:57 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-08 21:33:57 +0000
commit0bc978aa032d7bd2a60c577cc261ccdcb8dfd628 (patch)
tree4a16b4b9277f9ddb00b016918c819e991aab8e70 /nuttx/arch/arm/src/stm32/stm32_idle.c
parentf0656284a031663c77d59bd4a7fa3b2857767676 (diff)
downloadpx4-nuttx-0bc978aa032d7bd2a60c577cc261ccdcb8dfd628.tar.gz
px4-nuttx-0bc978aa032d7bd2a60c577cc261ccdcb8dfd628.tar.bz2
px4-nuttx-0bc978aa032d7bd2a60c577cc261ccdcb8dfd628.zip
Replace logic STM32 IDLE loop with standard power management interfaces
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4284 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/stm32/stm32_idle.c')
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_idle.c74
1 files changed, 59 insertions, 15 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_idle.c b/nuttx/arch/arm/src/stm32/stm32_idle.c
index 0919265ff..ec78861c8 100644
--- a/nuttx/arch/arm/src/stm32/stm32_idle.c
+++ b/nuttx/arch/arm/src/stm32/stm32_idle.c
@@ -1,8 +1,8 @@
/****************************************************************************
* arch/arm/src/stm32/stm32_idle.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,8 +41,11 @@
#include <nuttx/config.h>
#include <nuttx/arch.h>
+#include <nuttx/pm.h>
+
+#include <arch/irq.h>
+
#include "up_internal.h"
-#include "stm32_rcc.h"
/****************************************************************************
* Pre-processor Definitions
@@ -69,6 +72,57 @@
****************************************************************************/
/****************************************************************************
+ * Name: up_idlepm
+ *
+ * Description:
+ * Perform IDLE state power management.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_PM
+static void up_idlepm(void)
+{
+ static enum pm_state_e oldstate = PM_NORMAL;
+ enum pm_state_e newstate;
+ irqstate_t flags;
+ int ret;
+
+ /* Decide, which power saving level can be obtained */
+
+ newstate = pm_checkstate();
+
+ /* Check for state changes */
+
+ if (newstate != oldstate)
+ {
+ flags = irqsave();
+
+ /* Perform board-specific, state-dependent logic here */
+ /* <-- ADD CODE HERE --> */
+
+ /* Then force the global state change */
+
+ ret = pm_changestate(newstate);
+ if (ret < 0)
+ {
+ /* The new state change failed, revert to the preceding state */
+
+ (void)pm_changestate(oldstate);
+ }
+ else
+ {
+ /* Save the new state */
+
+ oldstate = newstate;
+ }
+ irqrestore(flags);
+ }
+}
+#else
+# define up_idlepm()
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -95,19 +149,9 @@ void up_idle(void)
sched_process_timer();
#else
-#ifdef CONFIG_STM32_RCCLOCK
+ /* Perform IDLE mode power management */
- /* Decide, which power saving level can be obtained */
-
- if (stm32_getrccactivity())
- {
- /* Sleep mode */
- }
- else
- {
- /* Stop mode */
- }
-#endif
+ up_idlepm();
/* Sleep until an interrupt occurs to save power */