//**************************************************************************** // //! Implements Sleep followed by wakeup using WDT timeout //! //! \param none //! //! This function //! 1. Implements Sleep followed by wakeup using WDT //! //! \return None. // //**************************************************************************** void PerformPRCMSleepWDTWakeup() { // // Initialize the WDT // WDT_IF_Init(AppWDTCallBackHandler, (4 * SYS_CLK)); // // Enable the Sleep Clock // MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_SLP_MODE_CLK); // // Enter SLEEP...WaitForInterrupt ARM intrinsic // DBG_PRINT("WDT_SLEEP: Entering Sleep\n\r"); MAP_UtilsDelay(80000); MAP_PRCMSleepEnter(); DBG_PRINT("WDT_SLEEP: Exiting Sleep\n\r"); // // Disable the Sleep Clock // MAP_PRCMPeripheralClkDisable(PRCM_WDT, PRCM_SLP_MODE_CLK); // // Deinitialize the WDT // WDT_IF_DeInit(); // // PowerOff WDT // MAP_PRCMPeripheralClkDisable(PRCM_WDT, PRCM_RUN_MODE_CLK); }
//**************************************************************************** // //! Implements Sleep followed by wakeup using GPT timeout //! //! \param none //! //! This function //! 1. Implements Sleep followed by wakeup using GPT //! //! \return None. // //**************************************************************************** void PerformPRCMSleepGPTWakeup() { // // Power On the GPT along with sleep clock // MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK); // // Initialize the GPT as One Shot timer // Timer_IF_Init(PRCM_TIMERA0, TIMERA0_BASE, TIMER_CFG_ONE_SHOT, TIMER_BOTH, 0); Timer_IF_IntSetup(TIMERA0_BASE, TIMER_BOTH, AppGPTCallBackHandler); // // Start timer with value in mSec // Timer_IF_Start(TIMERA0_BASE, TIMER_BOTH, 4000); // // Enable the Sleep Clock // MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_SLP_MODE_CLK); // // Enter SLEEP...WaitForInterrupt ARM intrinsic // DBG_PRINT("GPT_SLEEP: Entering Sleep\n\r"); MAP_UtilsDelay(80000); MAP_PRCMSleepEnter(); DBG_PRINT("GPT_SLEEP: Exiting Sleep\n\r"); // // Disable the Sleep Clock // MAP_PRCMPeripheralClkDisable(PRCM_TIMERA0, PRCM_SLP_MODE_CLK); // // Deinitialize the GPT // Timer_IF_Stop(TIMERA0_BASE, TIMER_BOTH); Timer_IF_DeInit(TIMERA0_BASE, TIMER_BOTH); // // PowerOff GPT // MAP_PRCMPeripheralClkDisable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK); }
/* * ======== PowerCC3200_sleepPolicy ======== */ void PowerCC3200_sleepPolicy() { bool returnFromSleep = FALSE; uint32_t constraintMask; uint32_t ticks; uint64_t time; uint64_t match; uint64_t curr; uint64_t remain; uint32_t taskKey; uint32_t swiKey; /* disable interrupts */ CPUcpsid(); /* disable Swi and Task scheduling */ swiKey = Swi_disable(); taskKey = Task_disable(); /* query the declared constraints */ constraintMask = Power_getConstraintMask(); /* * Do not go into LPDS if not allowed into DEEPSLEEP. * Check to see if we can go into LPDS (lowest level sleep). * If not allowed, then attempt to go into DEEPSLEEP. * If not allowed in DEEPSLEEP then just SLEEP. */ /* check if we are allowed to go to LPDS */ if ((constraintMask & ((1 << PowerCC3200_DISALLOW_LPDS) | (1 << PowerCC3200_DISALLOW_DEEPSLEEP))) == 0) { /* * Check how many ticks until the next scheduled wakeup. A value of * zero indicates a wakeup will occur as the current Clock tick period * expires; a very large value indicates a very large number of Clock * tick periods will occur before the next scheduled wakeup. */ /* Get the time remaining for the RTC timer to expire */ ticks = Clock_getTicksUntilInterrupt(); /* convert ticks to microseconds */ time = ticks * Clock_tickPeriod; /* check if can go to LPDS */ if (time > Power_getTransitionLatency(PowerCC3200_LPDS, Power_TOTAL)) { /* get the current and match values for RTC */ match = MAP_PRCMSlowClkCtrMatchGet(); curr = MAP_PRCMSlowClkCtrGet(); remain = match - curr - (((uint64_t)PowerCC3200_TOTALTIMELPDS * 32768) / 1000000); /* set the LPDS wakeup time interval */ MAP_PRCMLPDSIntervalSet(remain); /* enable the wake source to be timer */ MAP_PRCMLPDSWakeupSourceEnable(PRCM_LPDS_TIMER); /* go to LPDS mode */ Power_sleep(PowerCC3200_LPDS); /* set 'returnFromSleep' to TRUE*/ returnFromSleep = TRUE; } } /* check if we are allowed to go to DEEPSLEEP */ if ((constraintMask & (1 << PowerCC3200_DISALLOW_DEEPSLEEP) == 0) && (!returnFromSleep)) { /* * Check how many ticks until the next scheduled wakeup. A value of * zero indicates a wakeup will occur as the current Clock tick period * expires; a very large value indicates a very large number of Clock * tick periods will occur before the next scheduled wakeup. */ ticks = Clock_getTicksUntilInterrupt(); /* convert ticks to microseconds */ time = ticks * Clock_tickPeriod; /* check if can go to DEEPSLEEP */ if (time > Power_getTransitionLatency(PowerCC3200_DEEPSLEEP, Power_TOTAL)) { /* schedule the wakeup event */ ticks -= PowerCC3200_RESUMETIMEDEEPSLEEP / Clock_tickPeriod; Clock_setTimeout(Clock_handle(&clockObj), ticks); Clock_start(Clock_handle(&clockObj)); /* go to DEEPSLEEP mode */ Power_sleep(PowerCC3200_DEEPSLEEP); Clock_stop(Clock_handle(&clockObj)); /* set 'returnFromSleep' to TRUE so we don't go to sleep (below) */ returnFromSleep = TRUE; } } /* re-enable interrupts */ CPUcpsie(); /* restore Swi scheduling */ Swi_restore(swiKey); /* restore Task scheduling */ Task_restore(taskKey); /* sleep only if we are not returning from one of the sleep modes above */ if (!(returnFromSleep)) { MAP_PRCMSleepEnter(); } }