void main(void) { printk("Quark SE: Power Management sample application\n"); #if (CONFIG_RTC) setup_rtc(); #elif (CONFIG_COUNTER) setup_counter(); #elif (CONFIG_GPIO_QMSI_1) setup_aon_gpio(); #endif build_suspend_device_list(); #ifdef CONFIG_SOC_WATCH /* Start the event monitoring thread */ soc_watch_logger_thread_start(); #endif /* All our application does is putting the task to sleep so the kernel * triggers the suspend operation. */ while (1) { k_sleep(TIMEOUT * 1000); printk("Back to the application\n"); } }
void main(void) { printk("Power Management Demo on %s\n", CONFIG_ARCH); setup_rtc(); create_device_list(); while (1) { printk("\nApplication main thread\n"); k_sleep(SECONDS_TO_SLEEP * 1000); } }
static void reset_clocks(void) { /* 4MHz MSI raw range 2*/ struct rcc_clock_scale myclock_config = { .hpre = RCC_CFGR_HPRE_SYSCLK_NODIV, .ppre1 = RCC_CFGR_PPRE1_HCLK_NODIV, .ppre2 = RCC_CFGR_PPRE2_HCLK_NODIV, .voltage_scale = PWR_SCALE2, .flash_waitstates = FLASH_ACR_LATENCY_0WS, .apb1_frequency = 4194000, .apb2_frequency = 4194000, .msi_range = RCC_ICSCR_MSIRANGE_4MHZ, }; rcc_clock_setup_msi(&myclock_config); /* buttons and uarts */ rcc_periph_clock_enable(RCC_GPIOA); /* user feedback leds */ rcc_periph_clock_enable(RCC_GPIOB); /* Enable clocks for USART2. */ rcc_periph_clock_enable(RCC_USART2); /* And a timers for button presses */ rcc_periph_clock_enable(RCC_TIM7); } int main(void) { reset_clocks(); gpio_setup(); usart_setup(); setup_buttons(); setup_button_press_timer(); printf("we're awake!\n"); setup_rtc(); setup_rtc_wakeup(1); while (1) { PWR_CR |= PWR_CR_LPSDSR; pwr_set_stop_mode(); __WFI(); reset_clocks(); process_state(&state); } return 0; }
/** * sleepRtc * * Put panStamp into Power-down state during "time". * This function uses Timer 2 connected to an external 32.768KHz crystal * in order to exit (interrupt) from the power-down state * * 'time' Sleeping time: * RTC_250MS = 250 ms * RTC_500MS = 500 ms * RTC_1S = 1 s * RTC_2S = 2 s * RTC_8S = 8 s */ void AVRRTC::sleepRtc(unsigned char time) { // Power-down panStamp set_sleep_mode(SLEEP_MODE_PWR_SAVE); sleep_enable(); setup_rtc(time); delayMicroseconds(10); // Disable ADC ADCSRA &= ~(1 << ADEN); // Unpower functions PRR = 0xFF; // Enter sleep mode sleep_mode(); // ZZZZZZZZ... // Wake-up!! wakeUp(); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { // Chip errata CHIP_Init(); setup_rtc(); setup_gpio_and_buttons(); setup_lcd(); // Set 1ms SysTick if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) { DEBUG_BREAK; } typedef enum { INIT, PROGRAM, ON, OFF } program_modes; program_modes mode = INIT; program_modes last_mode = INIT; while (1) { if (!set_button.short_press) { EMU_EnterEM2(false); } switch (mode) { case INIT: if (set_button.short_press || program_button.long_press) { mode = PROGRAM; } break; case PROGRAM: program_timer(); last_mode = PROGRAM; mode = ON; break; case ON: if (mode != last_mode) { SegmentLCD_Write("ON"); timer_on = true; last_mode = ON; RTC_CompareSet(0, time_keeper.timer_start_seconds); //SysTick->CTRL = 0; } if (program_button.long_press) { mode = PROGRAM; } else if (set_button.short_press) { mode = OFF; // Delay so that we don't get double presses delay(BUTTON_DELAY); } break; case OFF: if (mode != last_mode) { SegmentLCD_Write("OFF"); timer_on = false; last_mode = OFF; //SysTick->CTRL = 0; } if (program_button.long_press) { mode = PROGRAM; } else if (set_button.short_press) { mode = ON; // Delay so that we don't get double presses delay(BUTTON_DELAY); } break; } } }