static void _sleep_entry(void) { rt_tick_t timeout; rt_uint32_t ms; rt_uint32_t count; system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY); timeout = rt_timer_next_timeout_tick() - rt_tick_get(); ms = timeout * (1000 / RT_TICK_PER_SECOND); rt_kprintf("os tick:%u entry sleep:%u tick\r\n", rt_tick_get(), timeout); _rtc_timer_start(ms); system_sleep(); rt_enter_critical(); count = rtc_count_get_count(&rtc_instance); ms = (count + 32) / 32.768; rtc_count_disable(&rtc_instance); sleep_tick_adjust(ms); timeout = rt_tick_get(); rt_exit_critical(); rt_kprintf("sleep exited, os tick:%u\n", timeout); }
void setup() { ledGreenLight(LOW); //attachInterrupt(pin, blink, RISING); system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY); /* Goes in STANDBY sleep */ system_sleep(); }
/** * \brief This function puts the transceiver and device to sleep */ void sm_sleep(uint32_t interval) { interval = interval * 1000; rtc_count_set_period(&rtc_instance, interval); rtc_count_enable(&rtc_instance); /*put the MCU in standby mode with RTC as wakeup source*/ system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY); system_sleep(); }
static uint16_t adc_get_value(void) { uint16_t adc = 0xffff; /* Step 1: Enable ADC */ #if ADC_USE_STANDBY ADC->INTENSET.reg = ADC_INTENSET_RESRDY; /* clear pending IRQs */ ADC->INTFLAG.reg |= ADC_INTFLAG_RESRDY; ADC->CTRLA.reg = ADC_CTRLA_RUNSTDBY | ADC_CTRLA_ENABLE; WAIT_ADC_SYNC(); NVIC_EnableIRQ(ADC_IRQn); #else ADC->CTRLA.reg = ADC_CTRLA_ENABLE; WAIT_ADC_SYNC(); #endif /* Step 2: Trigger ADC measurement */ ADC->SWTRIG.reg = ADC_SWTRIG_START; WAIT_ADC_SYNC(); /* Step 3: Get ADC value */ #if ADC_USE_STANDBY /* sleep during conversion */ system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY); cpu_irq_enable(); system_sleep(); adc = ADC->RESULT.reg; NVIC_DisableIRQ(ADC_IRQn); #else /* wait until conversion is ready */ while (0 == (ADC->INTFLAG.reg & ADC_INTFLAG_RESRDY)); adc = ADC->RESULT.reg; #endif /* switch off ADC */ ADC->CTRLA.reg = 0; WAIT_ADC_SYNC(); return adc; }
/** Send the device to deep sleep * * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode * has the same sleep features as sleep plus it powers down peripherals and clocks. All state * is still maintained. * @param[void] void * @return void */ void deepsleep(void) { system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY); system_sleep(); }
/** Send the device to sleep * * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the * system clock to the core is stopped until a reset or an interrupt occurs. * @param[void] void * @return void */ void sleep(void) { system_set_sleepmode(SYSTEM_SLEEPMODE_IDLE_2); system_sleep(); }
int main(void) { /** * Initialize and configure system and generic clocks. * Use conf_clocks.h to configure system and generic clocks. */ system_init(); hal_if_usart_init(); /** * Enable global interrupts. */ system_interrupt_enable_global(); /** * Initialize delay service. */ delay_init(); /* initialize timer */ timer_init(); /* Setup and enable generic clock source for PTC module. */ surface_configure_ptc_clock(); touch_time.measurement_period_ms = DEF_TOUCH_MEASUREMENT_PERIOD_MS; /* Initialize touchpad input parameters */ qts_init_surface(); qts_sensors_config(); /*initialize event system*/ #if (DEF_SURF_LOW_POWER_SENSOR_ENABLE == 1) init_evsys_config(); #endif /* Configure System Sleep mode to STANDBY. */ system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY); #ifdef POWER_OPT_ENABLE turn_off_bod33(); configure_power_manager(); #endif /* Calibration */ qts_start(); LOG("Hello QT6~\r\n"); /* Appl maintains this flag, * marked as 1 initially to start measurement cycle. */ qts_process_done = 1u; /* Appl maintains this flag, * marked as 1 initially to start measurement cycle. */ touch_time.time_to_measure_touch = 1u; while (1) { /** * Start touch surface process */ #if DEF_SURF_LOW_POWER_SENSOR_ENABLE == 1 qts_process_lp(); #else if (qts_process_done == 1) { qts_normal_process(); } #endif if (p_mutlcap_measure_data->measurement_done_touch == 1u) { p_mutlcap_measure_data->measurement_done_touch = 0u; } system_sleep(); } }