Esempio n. 1
0
void vbat_init(void)
{
	vbat_reset();
	vbat_enable_xosc(0);
	RTC32_Initialize(0xffffffff, 0, 2 );
	RTC32_SetCompareIntLevel(RTC32_COMPINTLVL_LO_gc);
}
/*! \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);
}
Esempio n. 3
0
/**
 * \brief This function Initializes the Sleep functions 
*/
void sm_init(void)
{
		// Set the sleep mode to initially lock.
		enum sleepmgr_mode mode = SLEEPMGR_PSAVE;

		sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
		
		RTC32_Initialize(0xffffffff, 0, 0);		

		RTC32.INTCTRL |= RTC32_COMPINTLVL_LO_gc ;

		// Initialize the sleep manager, lock initial mode.
		sleepmgr_init();
		sleepmgr_lock_mode(mode);
}