/*! \brief The main RTC example. * * This function initializes the XMEGA to the least power consuming state, * before initializing the sleep manager and RTC32 as configured above.\n * The main loop doesn't do anything but put the device back to the configured * sleep mode after a delay of 0.5 second. */ int main(void) { // Initialize to the least power consuming state. LOWPOWER_Init(); // Enable EEPROM and Flash power reduction mode. CCPWrite(&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm); // Initialize the sleep manager, lock a sleep mode if configured. SLEEPMGR_Init(); #ifdef SLEEP_MODE SLEEPMGR_Lock( SLEEP_MODE ); #endif // SLEEP_MODE // If use of the RTC as interval timer is configured, set it up. #ifdef USE_RTC // Clear bit for RTC in PRR (it is set by LOWPOWER_Init()). PR.PRGEN &= ~PR_RTC_bm; // Reset the battery backup module. RTC32_Reset(); // Configure and enable TOSC, then set up and enable the RTC32 module. RTC32_ToscEnable( false ); RTC32_Initialize( RTC_PERIOD, 0, 0 ); // Enable RTC compare interrupts. RTC32_SetCompareIntLevel( RTC32_COMPINTLVL_LO_gc ); PMIC.CTRL |= PMIC_LOLVLEN_bm; sei(); #endif // USE_RTC // Main loop. do { /* On wake-up, stay in ACTIVE mode for 0.5 s and then go back to sleep. * * In an actual application, you would process events/data here. */ delay_us(500000); // Due to errata, disable Flash power reduction before sleep. CCPWrite(&NVM.CTRLB, NVM_EPRM_bm); SLEEPMGR_Sleep(); // Re-enable Flash power reduction mode after sleep. CCPWrite(&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm); } while (1); }
static stat_t _bootloader_handler(void) { if (tg.bootloader_requested == false) { return (STAT_NOOP);} cli(); CCPWrite(&RST.CTRL, RST_SWRST_bm); // fire a software reset return (STAT_EAGAIN); // never gets here but keeps the compiler happy }