static void setup_wake_event(void) { #if (CONFIG_RTC) set_rtc_alarm(); #elif (CONFIG_COUNTER) set_counter_alarm(); #elif (CONFIG_GPIO_QMSI_1) printk("USER_ACTION: Press AON_GPIO 4.\n"); #elif (CONFIG_AIO_COMPARATOR) setup_aon_comparator(); #endif }
void __enter_hibernate(uint32_t seconds, uint32_t microseconds) { if (seconds || microseconds) set_rtc_alarm(seconds, microseconds); /* interrupts off now */ asm volatile("cpsid i"); /* enable the wake up pin */ STM32_PWR_CSR |= STM32_PWR_CSR_EWUP; STM32_PWR_CR |= 0xe; CPU_SCB_SYSCTRL |= 0x4; /* go to Standby mode */ asm("wfi"); /* we should never reach that point */ while (1) ; }
/* Idle task. Executed when no tasks are ready to be scheduled. */ void __idle(void) { timestamp_t t0, t1; int next_delay; uint32_t rtc_t0, rtc_t1; while (1) { asm volatile("cpsid i"); t0 = get_time(); next_delay = __hw_clock_event_get() - t0.le.lo; if (DEEP_SLEEP_ALLOWED && (next_delay > STOP_MODE_LATENCY)) { /* deep-sleep in STOP mode */ enable_serial_wakeup(1); /* set deep sleep bit */ CPU_SCB_SYSCTRL |= 0x4; rtc_t0 = set_rtc_alarm(0, next_delay - STOP_MODE_LATENCY); asm("wfi"); CPU_SCB_SYSCTRL &= ~0x4; enable_serial_wakeup(0); /* re-lock the PLL */ config_hispeed_clock(); /* fast forward timer according to RTC counter */ rtc_t1 = reset_rtc_alarm(); t1.val = t0.val + (rtc_t1 - rtc_t0) * US_PER_RTC_TICK; force_time(t1); } else { /* normal idle : only CPU clock stopped */ asm("wfi"); } asm volatile("cpsie i"); } }
int suspend(struct device_info * dev, unsigned int seconds) { struct timespec t, now; if(AT_DBG) printf("%s\n",__func__); clock_gettime(CLOCK_REALTIME, &t); set_rtc_alarm(seconds); press_pwrkey(dev); while(1){ clock_gettime(CLOCK_REALTIME, &now); if(now.tv_sec >= (t.tv_sec + seconds)){ system("echo autotest > /sys/power/wake_lock"); break; } sleep(1); } return 0; }
void main_task ( uint_32 initial_data ) { LPM_OPERATION_MODE power_mode; /* Initialize switches */ button_led_init(); /* Install interrupt for RTC alarm */ install_rtc_interrupt(); /* Create global event */ if (_lwevent_create(&app_event, 0) != MQX_OK) { printf("\nCreating app_event failed.\n"); _task_block(); } printf("\nMQX Low Power Modes Demo\n"); while (1) { /* Find out current mode setting */ power_mode = _lpm_get_operation_mode(); printf("\n******************************************************************************\n"); printf("**************** Current Mode : %s ***********************\n", predefined_power_modes_names[power_mode]); printf("******************************************************************************\n"); display_operation_mode_setting(power_mode); /* Wait for button press */ printf ("Press button to move to next operation mode.\n"); _lwevent_wait_ticks (&app_event, SW_EVENT_MASK, FALSE, 0); _lwevent_clear (&app_event, ALL_EVENTS_MASK); printf("\nButton pressed. Moving to next operation mode.\n"); power_mode = LPM_OPERATION_MODE_WAIT; printf("\n******************************************************************************\n"); printf("**************** Current Mode : %s **********************\n", predefined_power_modes_names[power_mode]); printf("******************************************************************************\n"); display_operation_mode_setting(power_mode); printf( "Info: WAIT mode is mapped on Kinets VLPR mode by default.\n" " It requires 2 MHz clock and bypassed pll.\n" " Core continues the execution after entering the mode.\n"); /* The LPM_OPERATION_MODE_WAIT is mapped on LPM_CPU_POWER_MODE_KINETIS_VLPR by default, this mode requires 2 MHz, bypassed PLL clock setting. Change clocks to appropriate mode */ printf("\nChanging frequency to 2 MHz.\n"); if (CM_ERR_OK != _lpm_set_clock_configuration(BSP_CLOCK_CONFIGURATION_2MHZ)) { printf("Cannot change clock configuration"); _task_block(); } /* Change the operation mode */ printf ("\nSetting operation mode to %s ... ", predefined_power_modes_names[power_mode]); printf ("%s\n", _lpm_set_operation_mode (LPM_OPERATION_MODE_WAIT) == 0 ? "OK" : "ERROR"); /* Wait for button press */ printf ("\nPress button to move to next operation mode.\n"); _lwevent_wait_ticks (&app_event, SW_EVENT_MASK, FALSE, 0); _lwevent_clear (&app_event, ALL_EVENTS_MASK); printf("\nButton pressed.\n"); /* Return to RUN mode */ printf ("\nSetting operation mode back to %s ... ", predefined_power_modes_names[LPM_OPERATION_MODE_RUN]); printf ("%s\n", _lpm_set_operation_mode (LPM_OPERATION_MODE_RUN) == 0 ? "OK" : "ERROR"); /* Return default clock configuration */ printf("\nChanging frequency back to the default one.\n"); if (CM_ERR_OK != _lpm_set_clock_configuration(BSP_CLOCK_CONFIGURATION_DEFAULT)) { printf("Cannot change clock configuration"); _task_block(); } printf("\nMoving to next operation mode.\n"); power_mode = LPM_OPERATION_MODE_SLEEP; printf("\n******************************************************************************\n"); printf("**************** Current Mode : %s *********************\n", predefined_power_modes_names[power_mode]); printf("******************************************************************************\n"); display_operation_mode_setting(power_mode); printf( "Info: SLEEP mode is mapped on Kinetis WAIT mode by default. Core is inactive\n" " in this mode, reacting only to interrupts.\n" " The LPM_CPU_POWER_MODE_FLAG_SLEEP_ON_EXIT is set, therefore core goes\n" " to sleep again after any isr finishes. The core will stay awake after\n" " call to _lpm_wakeup_core() from RTC or serial line interrupt.\n"); /* Wake up in 10 seconds */ set_rtc_alarm(10); /* Change the operation mode */ printf ("\nSetting operation mode to %s ... ", predefined_power_modes_names[power_mode]); printf ("%s\n", _lpm_set_operation_mode (power_mode) == 0 ? "OK" : "ERROR"); if (LWEVENT_WAIT_TIMEOUT == _lwevent_wait_ticks (&app_event, RTC_EVENT_MASK, FALSE, 1)) { printf("\nCore woke up by serial interrupt. Waiting for RTC alarm ... "); _lwevent_wait_ticks (&app_event, RTC_EVENT_MASK, FALSE, 0); printf("OK\n"); } else { printf("\nCore woke up by RTC interrupt.\n"); } _lwevent_clear (&app_event, ALL_EVENTS_MASK); /* Wait for button press */ printf ("\nPress button to move to next operation mode.\n"); _lwevent_wait_ticks (&app_event, SW_EVENT_MASK, FALSE, 0); _lwevent_clear (&app_event, ALL_EVENTS_MASK); printf("\nButton pressed. Moving to next operation mode.\n"); power_mode = LPM_OPERATION_MODE_STOP; printf("\n******************************************************************************\n"); printf("**************** Current Mode : %s **********************\n", predefined_power_modes_names[power_mode]); printf("******************************************************************************\n"); display_operation_mode_setting(power_mode); printf( "Info: STOP mode is mapped to Kinets LLS mode by default.\n" " Core and most peripherals are inactive in this mode, reacting only to\n" " specified wake up events. The events can be changed in BSP (init_lpm.c).\n" " Serial line is turned off in this mode. The core will wake up from\n" " RTC interrupt.\n"); /* Wake up in 10 seconds */ set_rtc_alarm(10); /* Change the operation mode */ printf ("\nSetting operation mode to %s ... \n", predefined_power_modes_names[power_mode]); _lpm_set_operation_mode (power_mode); /**************************************************************************************************/ /* SCI HW MODULE IS DISABLED AT THIS POINT - SERIAL DRIVER MUST NOT BE USED UNTIL MODE IS CHANGED */ /**************************************************************************************************/ /* Return to RUN mode */ _lpm_set_operation_mode (LPM_OPERATION_MODE_RUN); printf("\nCore is awake. Moved to next operation mode.\n"); } }