// Turn Off PLL0 because of errata declared bug that leaves it on
if (state.bPLL0_Running){
pll_LPC_DisablePLL0();
pll_LPC_DisablePLL1();
}
// Set CPU to use oscillator and not crystal
pll_LPC_UseOscillator();
start_sleep:
// Sleep
CLKPWR_DeepPowerDown(); // no ram
// Do we really need to wake up or can we just go back to sleep?
LPC_SC->PCONP |= CLKPWR_PCONP_PCGPIO;
if (!EXT_POWER_ON){
goto start_sleep;
}
|
#ifdef USE_LOW_POWER
#ifdef USE_DEEP_POWER_DOWN
//---------------------------------------------------------------------------
// Woke up from DeepPowerDown and still no External Power?
//---------------------------------------------------------------------------
if ((LPC_SC->PCON & BIT(11)) && !EXT_POWER_ON){
//-------------------------------------------------------------------------
// Set RTC to wakeup in 30s and go to the deepest sleep
//-------------------------------------------------------------------------
main_DeepPowerDownSleep();
}else{
//---------------------------------------------------------------------
// PCON
// 11 DPDFLAG Deep Power-down entry flag. Set when the Deep Power-down mode
// is successfully entered. Cleared by software writing a one to this bit.
//---------------------------------------------------------------------
LPC_SC->PCON |= BIT(11);
}
#endif
#endif
|
inline void main_DeepPowerDownSleep(void)
{
//---------------------------------------------------------------------------
// Set CPU to run from RTC clock
//---------------------------------------------------------------------------
LPC_SC->CLKSRCSEL = 2;//RTC -> PLL0
SystemCoreClock = FREQ_RTC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
//---------------------------------------------------------------------------
// Just before sleeping Kick watchdog if used
//---------------------------------------------------------------------------
#ifdef USE_WATCHDOG
WDT_UpdateTimeOut(WDT_TIMEOUT_150S);
#endif
RTC_Init(LPC_RTC);
RTC_ResetClockTickCounter(LPC_RTC);
RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
//-------------------------------------------------------------------------
// Set alarm time = 30s.
// So, after each 30s, RTC will generate and wake-up system out of Deep PowerDown mode.
//-------------------------------------------------------------------------
RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND,30);
RTC_CntIncrIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, DISABLE);
//-------------------------------------------------------------------------
// Set the AMR for 5s match alarm interrupt
//-------------------------------------------------------------------------
RTC_AlarmIntConfig (LPC_RTC,RTC_TIMETYPE_SECOND, ENABLE);
RTC_ClearIntPending(LPC_RTC,RTC_INT_COUNTER_INCREASE);
RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);
RTC_Cmd(LPC_RTC, ENABLE);
NVIC_EnableIRQ(RTC_IRQn);
//-------------------------------------------------------------------------
// PCON
// 11 DPDFLAG Deep Power-down entry flag. Set when the Deep Power-down mode
// is successfully entered. Cleared by software writing a one to this bit.
//-------------------------------------------------------------------------
LPC_SC->PCON |= BIT(11);
//-------------------------------------------------------------------------
// Disable GPIO Power
//-------------------------------------------------------------------------
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCGPIO,DISABLE);
CLKPWR_DeepPowerDown(); // no ram
} // main_DeepPowerDownSleep
|
LPC_SC->PLL0CON &= ~(1<<1); /* Disconnect the main PLL (PLL0) */ LPC_SC->PLL0FEED = 0xAA; /* Feed */ LPC_SC->PLL0FEED = 0x55; /* Feed */ while ((LPC_SC->PLL0STAT & (1<<25)) != 0x00); /* Wait for main PLL (PLL0) to disconnect */ LPC_SC->PLL0CON &= ~(1<<0); /* Turn off the main PLL (PLL0) */ LPC_SC->PLL0FEED = 0xAA; /* Feed */ LPC_SC->PLL0FEED = 0x55; /* Feed */ while ((LPC_SC->PLL0STAT & (1<<24)) != 0x00); /* Wait for main PLL (PLL0) to shut down */ /************** Then enter into Deep sleep mode or Power-down mode*****************/ |