/** * @brief main routine for ATIMER example * @return Nothing (function should not exit) */ int main(void) { bool On = false; SystemCoreClockUpdate(); Board_Init(); /* Init Alarm Timer with Preset Count for about 1s */ Chip_ATIMER_Init(LPC_ATIMER, PresetCount); /* Init EVRT */ Chip_EVRT_Init(); /* Enable EVRT in order to be able to read the ATIMER interrupt */ Chip_EVRT_ConfigIntSrcActiveType(EVRT_SRC_ATIMER, EVRT_SRC_ACTIVE_HIGH_LEVEL); /* Enable Alarm Timer Source */ Chip_EVRT_SetUpIntSrc(EVRT_SRC_ATIMER, ENABLE); /* Enable NVIC */ NVIC_EnableIRQ(EVENTROUTER_IRQn); /* Clear the interrupt states */ ATIMER_ClearInts(); /* Enable Alarm Timer */ Chip_ATIMER_IntEnable(LPC_ATIMER); while (1) { /* Sleep until ATIMER fires */ __WFI(); On = (bool) !On; Board_LED_Set(1, On); } }
/** * Event Router configure function */ static void PMC_Evrt_Configure(CHIP_EVRT_SRC_T Evrt_Src) { /* Configure Interrupt signal from Evrt_Src pin to EVRT */ Chip_EVRT_ConfigIntSrcActiveType(Evrt_Src, EVRT_SRC_ACTIVE_RISING_EDGE); /* Enable interrupt signal from Evrt_Src pin to EVRT */ Chip_EVRT_SetUpIntSrc(Evrt_Src, ENABLE); /* Clear any pending interrupt */ Chip_EVRT_ClrPendIntSrc(Evrt_Src); /* Disable EVRT interrupt in NVIC */ NVIC_DisableIRQ(EVENTROUTER_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(EVENTROUTER_IRQn, ((0x01 << 3) | 0x01)); /* Enable Event Router interrupt in NVIC */ NVIC_EnableIRQ(EVENTROUTER_IRQn); }
/** * Power State handler function */ static void PMC_PwrState_Handler(uint8_t buffer, uint8_t Wake_RTC) { CHIP_EVRT_SRC_T Evrt_Src; CHIP_PMC_PWR_STATE_T Pwr_state; uint8_t confirm = 0xFF; if (Wake_RTC) { /* Configure EVRT_SRC_RTC as wake up signal */ Evrt_Src = EVRT_SRC_RTC; /* Disable interrupt signal from Evrt_Src pin to EVRT */ Chip_EVRT_SetUpIntSrc(Evrt_Src, DISABLE); /* Initialize and configure RTC */ Chip_RTC_Init(LPC_RTC); Chip_RTC_ResetClockTickCounter(LPC_RTC); Chip_RTC_SetTime(LPC_RTC, RTC_TIMETYPE_SECOND, 0); /* Set alarm time = RTC_ALARM_TIME seconds. * So after each RTC_ALARM_TIME seconds, RTC will generate and wake-up system */ Chip_RTC_SetAlarmTime(LPC_RTC, RTC_TIMETYPE_SECOND, RTC_ALARM_TIME); Chip_RTC_CntIncrIntConfig(LPC_RTC, RTC_AMR_CIIR_IMSEC, DISABLE); /* Set the AMR for RTC_ALARM_TIME match alarm interrupt */ Chip_RTC_AlarmIntConfig(LPC_RTC, RTC_AMR_CIIR_IMSEC, ENABLE); Chip_RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM); } else { Evrt_Src = EVRT_SRC_WAKEUP0; } /* Configure wake up signal */ PMC_Evrt_Configure(Evrt_Src); /* Get confirmation from user to continue * Print wake up signal information to user */ DEBUGOUT(menu3); while ( (confirm != 'C') && (confirm != 'c')) { confirm = DEBUGIN(); } switch (buffer) { case '1': DEBUGOUT("Entering 'Sleep' state ...\r\n"); if (Wake_RTC) { DEBUGOUT("Wait for %d seconds, RTC alarm will wake up from 'Sleep' mode \r\n", RTC_ALARM_TIME); Chip_RTC_Enable(LPC_RTC, ENABLE); } else { DEBUGOUT("Press WAKEUP0 button/Connect WAKEUP0 pin to 3.3V to exit 'Sleep' mode \r\n"); } Chip_PMC_Sleep(); Chip_RTC_DeInit(LPC_RTC); DEBUGOUT("Woken up \r\n"); break; case '2': DEBUGOUT("Entering 'Deep Sleep' state ...\r\n"); if (Wake_RTC) { DEBUGOUT("Wait for %d seconds, RTC alarm will wake up from 'Deep Sleep' mode \r\n", RTC_ALARM_TIME); Chip_RTC_Enable(LPC_RTC, ENABLE); } else { DEBUGOUT("Press WAKEUP0 button/Connect WAKEUP0 pin to 3.3V to exit 'Deep Sleep' mode \r\n"); } Pwr_state = PMC_DeepSleep; /* Call Pre SleepPowerDown function */ PMC_Pre_SleepPowerDown(); /* Goto Deep Sleep mode */ Chip_PMC_Set_PwrState(Pwr_state); /* Call Post Wake up Initialisation function */ PMC_Post_Wakeup(buffer); DEBUGOUT("\r\nWoken up \r\n"); break; case '3': DEBUGOUT("Entering 'Power Down' state ...\r\n"); if (Wake_RTC) { DEBUGOUT("Wait for %d seconds, RTC alarm will wake up from 'Power Down' mode \r\n", RTC_ALARM_TIME); Chip_RTC_Enable(LPC_RTC, ENABLE); } else { DEBUGOUT("Press WAKEUP0 button/Connect WAKEUP0 pin to 3.3V to exit 'Power Down' mode \r\n"); } Pwr_state = PMC_PowerDown; /* Call Pre SleepPowerDown function */ PMC_Pre_SleepPowerDown(); /* Goto Deep Sleep mode */ Chip_PMC_Set_PwrState(Pwr_state); /* Call Post Wake up Initialisation function */ PMC_Post_Wakeup(buffer); DEBUGOUT("\r\nWoken up \r\n"); break; case '4': DEBUGOUT("Entering 'Deep Power Down' state ...\r\n"); if (Wake_RTC) { DEBUGOUT("Wait for %d seconds, RTC alarm will wake up from 'Deep Power Down' mode \r\n", RTC_ALARM_TIME); Chip_RTC_Enable(LPC_RTC, ENABLE); } else { DEBUGOUT("Press WAKEUP0 button/Connect WAKEUP0 pin to 3.3V to exit 'Deep Power Down' mode \r\n"); } Pwr_state = PMC_DeepPowerDown; /* Call Pre SleepPowerDown function */ PMC_Pre_SleepPowerDown(); /* Goto Deep Sleep mode */ Chip_PMC_Set_PwrState(Pwr_state); /* Wake up from Deep power down state is as good as RESET */ while (1) {} break; default: break; } }