/** * @brief Main program body * @return int */ int main(void) { CHIP_PMU_MCUPOWER_T crntPowerSetting; /* Setup SystemCoreClock and any needed board code */ SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, true); /* Clear any previously set deep power down and sleep flags */ Chip_PMU_ClearSleepFlags(LPC_PMU, PMU_PCON_SLEEPFLAG | PMU_PCON_DPDFLAG); /* Enable the RTC oscillator, oscillator rate can be determined by calling Chip_Clock_GetRTCOscRate() */ Chip_Clock_EnableRTCOsc(); /* Initialize RTC driver (enables RTC clocking) */ Chip_RTC_Init(LPC_RTC); /* RTC reset */ Chip_RTC_Reset(LPC_RTC); /* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you need to disable it before setting the initial RTC count. */ Chip_RTC_Disable(LPC_RTC); Chip_RTC_SetCount(LPC_RTC, 0); /* Set a long alarm time so the interrupt won't trigger */ Chip_RTC_SetAlarm(LPC_RTC, 1000); /* Enable RTC */ Chip_RTC_Enable(LPC_RTC); /* Clear latched RTC interrupt statuses */ Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ)); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_ALARM_IRQn); /* Enable RTC alarm interrupt */ Chip_RTC_EnableWakeup(LPC_RTC, RTC_CTRL_ALARMDPD_EN); /* Output example's activity banner */ DEBUGSTR("\r\n"); DEBUGSTR("-----------------------------------------------------------------\r\n"); #ifdef RESET_POWER_CYCLE_COUNT ProcessCycleCounter(); DEBUGOUT("Power Control Example\r\n"); #else DEBUGOUT("Power Control Example Cycle Count: %d\r\n", ProcessCycleCounter()); #endif DEBUGSTR(" System will cycle through SLEEP, DEEP SLEEP, POWER\r\n"); DEBUGSTR(" DOWN, and DEEP POWER DOWN power states\r\n"); DEBUGSTR("-----------------------------------------------------------------\r\n\r\n"); /* Setup alarm, process next power state then wait for alarm to wake-up system */ crntPowerSetting = PMU_MCU_SLEEP; while (1) { /* Set alarm to wakeup in POWER_CYCLE_SEC_DELAY seconds */ Chip_RTC_SetAlarm(LPC_RTC, Chip_RTC_GetCount(LPC_RTC) + POWER_CYCLE_SEC_DELAY); /* Enter first (or next) power state */ ProcessPowerState(crntPowerSetting); /* Inc current power setting and test for overflow */ if (crntPowerSetting == PMU_MCU_DEEP_PWRDOWN) { /* Reset to lowest power setting */ crntPowerSetting = PMU_MCU_SLEEP; } else { crntPowerSetting++; } } return 0; }
/** * @brief Main program body * @return int */ int main(void) { int stateCounter = 0; /* Setup SystemCoreClock and any needed board code */ SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); /* Turn on the RTC 32K Oscillator by clearing the power down bit */ if ( !Is_Chip_SYSCTL_PowerUp(PDRUNCFG_PD_32K_OSC) ) { Chip_SYSCTL_PowerUp(PDRUNCFG_PD_32K_OSC); } /* Enable the RTC oscillator, oscillator rate can be determined by calling Chip_Clock_GetRTCOscRate() */ Chip_Clock_EnableRTCOsc(); /* Initialize RTC driver (enables RTC clocking) */ Chip_RTC_Init(LPC_RTC); /* Enable RTC as a peripheral wakeup event */ Chip_SYSCTL_EnableWakeup(STARTERP0_RTC); /* RTC reset */ Chip_RTC_Reset(LPC_RTC); /* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you need to disable it before setting the initial RTC count. */ Chip_RTC_Disable(LPC_RTC); Chip_RTC_SetCount(LPC_RTC, 0); /* Set a long alarm time so the interrupt won't trigger */ Chip_RTC_SetAlarm(LPC_RTC, 1000); /* Enable RTC and high resolution timer - this can be done in a single call with Chip_RTC_EnableOptions(LPC_RTC, (RTC_CTRL_RTC1KHZ_EN | RTC_CTRL_RTC_EN)); */ Chip_RTC_Enable1KHZ(LPC_RTC); Chip_RTC_Enable(LPC_RTC); /* Clear latched RTC interrupt statuses */ Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ)); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_IRQn); /* Enable RTC alarm interrupt */ Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN | RTC_CTRL_WAKEDPD_EN)); /* Sleep and do all the work in the RTC interrupt handler */ while (1) { DEBUGOUT("Tick number: %d, 1KHZ int:%d, alarm int:%d\r\n", stateCounter, rtcWake, rtcAlarm); rtcWake = rtcAlarm = false; /* 10 high resolution ticks that get slower each tick */ if (stateCounter < 10) { /* Wakeup in 300, 400, 500, etc. milliSeconds */ Chip_RTC_SetWake(LPC_RTC, (300 + (stateCounter * 100))); stateCounter++; } else { DEBUGOUT("Setting alarm to wake up in 4s\r\n"); /* Set alarm to wakeup in 4 seconds */ Chip_RTC_SetAlarm(LPC_RTC, Chip_RTC_GetCount(LPC_RTC) + 4); stateCounter = 0; } // FIXME - Use ROM API's to put chip to power down modes /* LPC_PWRD_API->power_mode_configure(PMU_DEEP_POWERDOWN, PDRUNCFG_PD_32K_OSC, 1); */ __WFI(); } return 0; }
/** * @brief Main program body * @return int */ int main(void) { uint32_t rtcCount; /* Starting time for this example used to set the RTC */ struct tm startTime = { 56, /* tm_sec, seconds after the minute, 0 to 59 */ 59, /* tm_min, minutes after the hour, 0 to 59 */ 23, /* tm_hour, hours since midnight, 0 to 23 */ 25, /* tm_mday, day of the month, 1 to 31 */ 9, /* tm_mon, months since January, 0 to 11 */ (2014 - TM_YEAR_BASE), /* tm_year, years since base year (1900) */ /* The following 3 fields are not used by the ConvertTimeRtc() function, while the ConvertRtcTime() fucntion will generate data in them from an RTC tick (except tm_isdst) */ 0, /* tm_wday, days since Sunday, 0 to 6 */ 0, /* tm_yday, days since January 1, 0 to 365 */ 0 /* tm_isdst, Daylight Savings Time flag */ }; /* Setup SystemCoreClock and any needed board code */ SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); /* Turn on the RTC 32K Oscillator */ Chip_SYSCON_PowerUp(SYSCON_PDRUNCFG_PD_32K_OSC); /* Enable the RTC oscillator, oscillator rate can be determined by calling Chip_Clock_GetRTCOscRate() */ Chip_Clock_EnableRTCOsc(); /* Initialize RTC driver (enables RTC clocking) */ Chip_RTC_Init(LPC_RTC); /* RTC reset */ Chip_RTC_Reset(LPC_RTC); /* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you need to disable it before setting the initial RTC count. */ Chip_RTC_Disable(LPC_RTC); /* COnvert tm structure to RTC tick count */ ConvertTimeRtc(&startTime, &rtcCount); Chip_RTC_SetCount(LPC_RTC, rtcCount); /* Set alarm to wakeup in 5s */ DEBUGOUT("Setting alarm to trigger in 5s\r\n"); rtcCount += 5; Chip_RTC_SetAlarm(LPC_RTC, rtcCount); /* Enable RTC */ Chip_RTC_Enable(LPC_RTC); /* Clear latched RTC interrupt statuses */ Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ)); /* Enable RTC interrupt */ NVIC_EnableIRQ(RTC_IRQn); /* Enable RTC alarm interrupt */ Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN | RTC_CTRL_WAKEDPD_EN)); /* Sleep and do all the work in the RTC interrupt handler */ while (1) { /* 10 high resolution ticks that get slower each tick */ if (rtcAlarm) { /* Will not reset alarm */ DEBUGOUT("Alarm triggered, alarm reset to trigger in 5s\r\n"); rtcCount = Chip_RTC_GetCount(LPC_RTC) + 5; Chip_RTC_SetAlarm(LPC_RTC, rtcCount); rtcAlarm = false; } /* Show RTC time in UT format */ showTime(Chip_RTC_GetCount(LPC_RTC)); /* Sleep while waiting for alarm */ __WFI(); } return 0; }
/** * @brief Main program body * @return int */ int main(void) { int stateCounter = 0; uint32_t ticks = 0; /* Setup SystemCoreClock and any needed board code */ SystemCoreClockUpdate(); Board_Init(); /* Enable the RTC oscillator, oscillator rate can be determined by calling Chip_Clock_GetRTCOscRate() */ Chip_Clock_EnableRTCOsc(); /* Initialize RTC driver (enables RTC clocking) */ Chip_RTC_Init(LPC_RTC); /* Enable RTC as a peripheral wakeup event */ Chip_SYSCTL_EnableERP1PeriphWakeup(SYSCTL_ERP1_WAKEUP_RTCALARMINT | SYSCTL_ERP1_WAKEUP_RTCWAKEINT); /* RTC reset */ Chip_RTC_Reset(LPC_RTC); /* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you need to disable it before setting the initial RTC count. */ Chip_RTC_Disable(LPC_RTC); Chip_RTC_SetCount(LPC_RTC, 0); /* Set a long alarm time so the interrupt won't trigger */ Chip_RTC_SetAlarm(LPC_RTC, 1000); /* Enable RTC and high resolution timer - this can be done in a single call with Chip_RTC_EnableOptions(LPC_RTC, (RTC_CTRL_RTC1KHZ_EN | RTC_CTRL_RTC_EN)); */ Chip_RTC_Enable1KHZ(LPC_RTC); Chip_RTC_Enable(LPC_RTC); /* Clear latched RTC interrupt statuses */ Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ)); /* Enable RTC wake and alarm interrupts */ NVIC_EnableIRQ(RTC_ALARM_IRQn); NVIC_EnableIRQ(RTC_WAKE_IRQn); /* Enable RTC alarm interrupt */ Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN | RTC_CTRL_WAKEDPD_EN)); /* Sleep and do all the work in the RTC interrupt handler */ while (1) { ticks = 0; DEBUGOUT("Tick number: %d, 1KHZ int:%d, alarm int:%d\r\n", stateCounter, rtcWake, rtcAlarm); rtcWake = rtcAlarm = false; /* 10 high resolution ticks that get slower each tick */ if (stateCounter < 10) { /* Wakeup in 300, 400, 500, etc. milliSeconds */ Chip_RTC_SetWake(LPC_RTC, (300 + (stateCounter * 100))); stateCounter++; } else { DEBUGOUT("Setting alarm to wake up in 4s\r\n"); /* Set alarm to wakeup in 4 seconds */ Chip_RTC_SetAlarm(LPC_RTC, Chip_RTC_GetCount(LPC_RTC) + 4); stateCounter = 0; } Chip_SYSCTL_SetWakeup(~(SYSCTL_SLPWAKE_IRCOUT_PD | SYSCTL_SLPWAKE_IRC_PD | SYSCTL_SLPWAKE_FLASH_PD | SYSCTL_SLPWAKE_SYSOSC_PD | SYSCTL_SLPWAKE_SYSPLL_PD)); Chip_SYSCTL_EnableERP1PeriphWakeup(SYSCTL_ERP1_WAKEUP_RTCALARMINT | SYSCTL_ERP1_WAKEUP_RTCWAKEINT); /* Delay to allow serial transmission to complete*/ while(ticks++ < 10000) {} /* Enter MCU Deep Sleep mode */ Chip_PMU_DeepSleepState(LPC_PMU); } return 0; }