Make PM button logic configurable

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4934 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-07-12 12:38:11 +00:00
parent 6a33da2088
commit 931f784f3b
5 changed files with 37 additions and 22 deletions

View File

@ -473,6 +473,7 @@ CONFIG_IDLE_CUSTOM=y
# Board/Application-Specific Power Management Configuration. # Board/Application-Specific Power Management Configuration.
# These settings are probably not meaningful outside of this configuration # These settings are probably not meaningful outside of this configuration
# #
CONFIG_PM_BUTTONS=y
CONFIG_PM_IRQBUTTONS_MIN=0 CONFIG_PM_IRQBUTTONS_MIN=0
CONFIG_PM_IRQBUTTONS_MAX=7 CONFIG_PM_IRQBUTTONS_MAX=7
CONFIG_PM_BUTTONS_NAME0="WAKEUP" CONFIG_PM_BUTTONS_NAME0="WAKEUP"

View File

@ -80,7 +80,7 @@ ifeq ($(CONFIG_PM_CUSTOMINIT),y)
CSRCS += up_pm.c CSRCS += up_pm.c
endif endif
ifeq ($(CONFIG_PM),y) ifeq ($(CONFIG_PM_BUTTONS),y)
CSRCS += up_pmbuttons.c CSRCS += up_pmbuttons.c
endif endif

View File

@ -313,7 +313,7 @@ void up_ledpminitialize(void);
* *
************************************************************************************/ ************************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) #if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) && defined(CONFIG_PM_BUTTONS)
void up_pmbuttons(void); void up_pmbuttons(void);
#endif #endif
@ -325,7 +325,7 @@ void up_pmbuttons(void);
* *
************************************************************************************/ ************************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) #if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) && defined(CONFIG_PM_BUTTONS)
void up_unregisterbuttons(void); void up_unregisterbuttons(void);
#endif #endif

View File

@ -86,7 +86,7 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_PM #if defined(CONFIG_PM) && defined(CONFIG_RTC_ALARM)
static void up_alarmcb(void); static void up_alarmcb(void);
#endif #endif
@ -105,7 +105,9 @@ static void up_alarmcb(void);
#ifdef CONFIG_PM #ifdef CONFIG_PM
static void up_idlepm(void) static void up_idlepm(void)
{ {
#ifdef CONFIG_RTC_ALARM
struct timespec alarmtime; struct timespec alarmtime;
#endif
static enum pm_state_e oldstate = PM_NORMAL; static enum pm_state_e oldstate = PM_NORMAL;
enum pm_state_e newstate; enum pm_state_e newstate;
irqstate_t flags; irqstate_t flags;
@ -143,21 +145,17 @@ static void up_idlepm(void)
{ {
case PM_NORMAL: case PM_NORMAL:
{ {
/* Cancel the alarm that was set in PM_STANDBY */
if (oldstate == PM_STANDBY)
{
ret = up_rtc_cancelalarm();
if (ret < 0)
{
lldbg("Warning: Cancel alarm failed\n");
}
}
} }
break; break;
case PM_IDLE: case PM_IDLE:
{ {
/* The wake-up event is really dependent upon the application
* an resources provided by the application. However,
* CONFIG_PM_BUTTONS may defined to support PM testing.
*/
#ifdef CONFIG_PM_BUTTONS
/* Check if the buttons have already been registered */ /* Check if the buttons have already been registered */
up_unregisterbuttons(); up_unregisterbuttons();
@ -167,11 +165,18 @@ static void up_idlepm(void)
*/ */
up_pmbuttons(); up_pmbuttons();
#endif
} }
break; break;
case PM_STANDBY: case PM_STANDBY:
{ {
/* The wake-up event is really dependent upon the application
* an resources provided by the application. However,
* CONFIG_PM_BUTTONS may defined to support PM testing.
*/
#ifdef CONFIG_PM_BUTTONS
/* Check if the buttons have already been registered */ /* Check if the buttons have already been registered */
up_unregisterbuttons(); up_unregisterbuttons();
@ -179,11 +184,12 @@ static void up_idlepm(void)
/* Configure all the buttons as wakeup EXTI */ /* Configure all the buttons as wakeup EXTI */
up_pmbuttons(); up_pmbuttons();
#endif
#ifdef CONFIG_RTC_ALARM
/* Configure the RTC alarm to Auto Wake the system */
(void)up_rtc_gettime(&alarmtime); (void)up_rtc_gettime(&alarmtime);
/* Configure the RTC alarm to Auto Wake the system */
alarmtime.tv_sec += CONFIG_PM_ALARM_SEC; alarmtime.tv_sec += CONFIG_PM_ALARM_SEC;
alarmtime.tv_nsec += CONFIG_PM_ALARM_NSEC; alarmtime.tv_nsec += CONFIG_PM_ALARM_NSEC;
@ -204,9 +210,9 @@ static void up_idlepm(void)
ret = up_rtc_setalarm(&alarmtime, &up_alarmcb); ret = up_rtc_setalarm(&alarmtime, &up_alarmcb);
if (ret < 0) if (ret < 0)
{ {
lldbg("Warning: The alarm is already set.\n"); lldbg("Warning: The alarm is already set\n");
} }
#endif
/* Call the STM32 stop mode */ /* Call the STM32 stop mode */
stm32_pmstop(true); stm32_pmstop(true);
@ -216,7 +222,15 @@ static void up_idlepm(void)
* operation. * operation.
*/ */
up_rtc_cancelalarm(); #ifdef CONFIG_RTC_ALARM
ret = up_rtc_cancelalarm();
if (ret < 0)
{
lldbg("Warning: Cancel alarm failed\n");
}
#endif
/* Resume normal operation */
pm_changestate(PM_NORMAL); pm_changestate(PM_NORMAL);
newstate = PM_NORMAL; newstate = PM_NORMAL;
} }
@ -256,7 +270,7 @@ errout:
* *
************************************************************************************/ ************************************************************************************/
#ifdef CONFIG_PM #if defined(CONFIG_PM) && defined(CONFIG_RTC_ALARM)
static void up_alarmcb(void) static void up_alarmcb(void)
{ {
/* This alarm occurs because there wasn't any EXTI interrupt during the /* This alarm occurs because there wasn't any EXTI interrupt during the

View File

@ -53,7 +53,7 @@
#include "stm32_pm.h" #include "stm32_pm.h"
#include "stm3210e-internal.h" #include "stm3210e-internal.h"
#if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) #if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) && defined(CONFIG_PM_BUTTONS)
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@ -406,4 +406,4 @@ int i;
#endif #endif
} }
#endif /* defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) */ #endif /* defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) && defined(CONFIG_PM_BUTTONS) */