//***************************************************************************** // //! Enables the processor interrupt. //! //! This function allows the processor to respond to interrupts. This function //! does not affect the set of interrupts enabled in the interrupt controller; //! it just gates the single interrupt from the controller to the processor. //! //! \note Previously, this function had no return value. As such, it was //! possible to include <tt>interrupt.h</tt> and call this function without //! having included <tt>hw_types.h</tt>. Now that the return is a //! <tt>tBoolean</tt>, a compiler error occurs in this case. The solution //! is to include <tt>hw_types.h</tt> before including <tt>interrupt.h</tt>. //! //! \return Returns \b true if interrupts were disabled when the function was //! called or \b false if they were initially enabled. // //***************************************************************************** tBoolean IntMasterEnable(void) { // // Enable processor interrupts. // return(CPUcpsie()); }
//***************************************************************************** // // SafeHapiAuxAdiSelect() // Common wrapper function for the Hapi functions needing the "bus arbitration // issue" workaround. // //***************************************************************************** void SafeHapiAuxAdiSelect( FPTR_VOID_UINT8_T fPtr, uint8_t ut8Signal ) { bool bIrqEnabled = ( ! CPUcpsid() ); while ( ! HWREG( AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 )); fPtr( ut8Signal ); HWREG( AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 ) = 1; if ( bIrqEnabled ) { CPUcpsie(); } }
/* Enable system / global interrupt. */ void enable_system_irq(u32 primask) { if(intr_ref_cnt && (--intr_ref_cnt == 0)) { /* Enable the interrupts */ primask = CPUcpsie(); } UNUSED(primask); return; }
//***************************************************************************** // // SafeHapiVoid() and SafeHapiAuxAdiSelect() // Common wrapper functions for the Hapi functions needing the "bus arbitration // issue" workaround. // //***************************************************************************** void SafeHapiVoid( FPTR_VOID_VOID_T fPtr ) { bool bIrqEnabled = ( ! CPUcpsid() ); while ( ! HWREG( AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 )); fPtr(); HWREG( AUX_SMPH_BASE + AUX_SMPH_O_SMPH0 ) = 1; if ( bIrqEnabled ) { CPUcpsie(); } }
// Enable interrupt on CPU void initInterrupts(void) { // CPE1 - Int channels 31:16: Boot done is bit 30 HWREG(NVIC_EN0) = 1 << (INT_RF_CPE1 - 16); // CPE0 - Int channels 15:0: CMD_DONE is bit 1, LAST_CMD_DONE is bit 0 HWREG(NVIC_EN0) = 1 << (INT_RF_CPE0 - 16); // RTC combined event output HWREG(NVIC_EN0) = 1 << (INT_AON_RTC - 16); // Global interrupt enable CPUcpsie(); }
/* Enable system / global interrupt. */ void cc_enbl_sys_irq(void) { u32 primask; if(cc_pm_ctrl.intr_ref_cnt && (--cc_pm_ctrl.intr_ref_cnt == 0)) { /* Enable the interrupts */ primask = CPUcpsie(); } UNUSED(primask); return; }
/* * ======== Power_sleep ======== */ Power_Status Power_sleep(Power_SleepState sleepState, UArg arg0, UArg arg1) { Power_Status status = Power_SOK; UInt xosc_hf_active = FALSE; Power_Event postEventLate; UInt32 poweredDomains = 0; Bool exitNow = FALSE; Power_Event preEvent; Power_Event postEvent; UInt32 constraints; Bool retainCache = FALSE; UInt32 modeVIMS; UInt taskKey; UInt swiKey; UInt hwiKey; /* first validate the sleep code */ if ( sleepState != Power_STANDBY) { status = Power_EFAIL; } if (status == Power_SOK) { /* make sure Power is not still busy with a previous transition */ hwiKey = Hwi_disable(); if (Power_module->state == Power_ACTIVE) { /* set transition state to entering sleep */ Power_module->state = Power_ENTERING_SLEEP; } else { exitNow = TRUE; } Hwi_restore(hwiKey); if (exitNow == TRUE) { status = Power_EBUSY; } else { /* setup sleep vars */ if (sleepState == Power_STANDBY) { preEvent = Power_ENTERING_STANDBY; postEvent = Power_AWAKE_STANDBY; postEventLate = Power_AWAKE_STANDBY_LATE; } /* disable Task scheduling; allow Swis and Hwis for notifications */ taskKey = Task_disable(); /* signal all clients registered for pre-sleep notification */ status = Power_notify(preEvent); /* check for any error */ if (status != Power_SOK) { Power_module->state = Power_ACTIVE; Task_restore(taskKey); /* re-enable scheduler */ return (status); } /* now disable Swi scheduling */ swiKey = Swi_disable(); /* freeze the IOs on the boundary between MCU and AON */ AONIOCFreezeEnable(); /* if XOSC_HF is active, force it off */ if(OSCClockSourceGet(OSC_SRC_CLK_HF) == OSC_XOSC_HF) { xosc_hf_active = TRUE; ti_sysbios_family_arm_cc26xx_Power_XOSC_HF(DISABLE); } /* allow AUX to power down */ AONWUCAuxWakeupEvent(AONWUC_AUX_ALLOW_SLEEP); /* make sure writes take effect */ SysCtrlAonSync(); /* invoke specific sequences to activate sleep states... */ if (sleepState == Power_STANDBY) { /* query and save domain states before powering them off */ if (Power_getDependencyCount(DOMAIN_RFCORE)) { poweredDomains |= PRCM_DOMAIN_RFCORE; } if (Power_getDependencyCount(DOMAIN_SERIAL)){ poweredDomains |= PRCM_DOMAIN_SERIAL; } if (Power_getDependencyCount(DOMAIN_PERIPH)) { poweredDomains |= PRCM_DOMAIN_PERIPH; } /* gate running deep sleep clocks for Crypto and DMA */ if (Power_getDependencyCount(PERIPH_CRYPTO)) { PRCMPeripheralDeepSleepDisable( ti_sysbios_family_arm_cc26xx_Power_db[ PERIPH_CRYPTO].driverlibID); } if (Power_getDependencyCount(PERIPH_UDMA)) { PRCMPeripheralDeepSleepDisable( ti_sysbios_family_arm_cc26xx_Power_db[ PERIPH_UDMA].driverlibID); } /* make sure clock settings take effect */ PRCMLoadSet(); /* request power off of domains in the MCU voltage domain */ PRCMPowerDomainOff(poweredDomains | PRCM_DOMAIN_CPU); /* request uLDO during standby */ PRCMMcuUldoConfigure(true); /* query constraints to determine if cache should be retained */ constraints = Power_getConstraintInfo(); if ((constraints & Power_SB_VIMS_CACHE_RETAIN) != 0) { retainCache = TRUE; } /* if don't want retention in standby, disable it now ... */ if (retainCache == FALSE) { modeVIMS = VIMSModeGet(VIMS_BASE); /* wait if invalidate in progress... */ while (modeVIMS == VIMS_MODE_CHANGING) { modeVIMS = VIMSModeGet(VIMS_BASE); } PRCMCacheRetentionDisable(); VIMSModeSet(VIMS_BASE, VIMS_MODE_OFF); } /* setup recharge parameters */ SysCtrlSetRechargeBeforePowerDown(XoscInHighPowerMode); /* make sure all writes have taken effect */ SysCtrlAonSync(); /* invoke deep sleep to go to STANDBY */ PRCMDeepSleep(); /* if didn't retain cache in standby, re-enable retention now */ if (retainCache == FALSE) { VIMSModeSet(VIMS_BASE, modeVIMS); PRCMCacheRetentionEnable(); } /* force power on of AUX to keep it on when system is not * sleeping; this also counts as a write to the AON interface * ensuring that a following sync of the AON interface will * force an update of all registers */ AONWUCAuxWakeupEvent(AONWUC_AUX_WAKEUP); while(!(AONWUCPowerStatusGet() & AONWUC_AUX_POWER_ON)) {}; /* if XOSC_HF was forced off above, initiate switch back */ if (xosc_hf_active == TRUE) { ti_sysbios_family_arm_cc26xx_Power_XOSC_HF(ENABLE); } /* restore power domain states in effect before standby */ PRCMPowerDomainOn(poweredDomains); while (PRCMPowerDomainStatus(poweredDomains) != PRCM_DOMAIN_POWER_ON){}; /* restore deep sleep clocks of Crypto and DMA */ if (Power_getDependencyCount(PERIPH_CRYPTO)) { PRCMPeripheralDeepSleepEnable( ti_sysbios_family_arm_cc26xx_Power_db[ PERIPH_CRYPTO].driverlibID); } if (Power_getDependencyCount(PERIPH_UDMA)) { PRCMPeripheralDeepSleepEnable( ti_sysbios_family_arm_cc26xx_Power_db[ PERIPH_UDMA].driverlibID); } /* make sure clock settings take effect */ PRCMLoadSet(); } /* release request for uLDO */ PRCMMcuUldoConfigure(false); /* set transition state to EXITING_SLEEP */ Power_module->state = Power_EXITING_SLEEP; /* * signal clients registered for early post-sleep notification; * this should be used to initialize any timing critical or IO * dependent hardware */ status = Power_notify(postEvent); /* disable IO freeze and ensure RTC shadow value is updated */ AONIOCFreezeDisable(); SysCtrlAonSync(); /* re-enable interrupts */ CPUcpsie(); /* signal all clients registered for late post-sleep notification */ status = Power_notify(postEventLate); /* now clear the transition state before re-enabling scheduler */ Power_module->state = Power_ACTIVE; /* re-enable Swi scheduling */ Swi_restore(swiKey); /* adjust recharge parameters */ SysCtrlAdjustRechargeAfterPowerDown(); /* re-enable Task scheduling */ Task_restore(taskKey); /* check for any notification error */ if (status != Power_SOK) { return (status); } } } return (status); }
/* * ======== Power_shutdown ======== */ Power_Status Power_shutdown(UArg arg) { Power_Status status = Power_EFAIL; Bool exitNow = FALSE; UInt32 constraints; UInt hwiKey; /* make sure shutdown request doesn't violate a constraint */ constraints = Power_getConstraintInfo(); if ((constraints & (Power_SD_DISALLOW)) != 0) { status = Power_ECHANGE_NOT_ALLOWED; } if (status == Power_EFAIL) { /* make sure Power is not still busy with a previous transition */ hwiKey = Hwi_disable(); if (Power_module->state == Power_ACTIVE) { /* set new transition state to entering shutdown */ Power_module->state = Power_SHUTDOWN; } else { exitNow = TRUE; } Hwi_restore(hwiKey); if (exitNow == TRUE) { status = Power_EBUSY; } else { /* disable interrupts as start the shutdown sequence */ Hwi_disable(); /* signal all clients registered for pre-shutdown notification */ status = Power_notify(Power_ENTERING_SHUTDOWN); /* check for any error */ if (status != Power_SOK) { Power_module->state = Power_ACTIVE; CPUcpsie(); return (status); } /* proceed with shutdown sequence ... */ /* switch to RCOSC_HF and RCOSC_LF */ OSCInterfaceEnable(); if(OSCClockSourceGet(OSC_SRC_CLK_HF) != OSC_RCOSC_HF) { OSCClockSourceSet(OSC_SRC_CLK_HF | OSC_SRC_CLK_MF, OSC_RCOSC_HF); while(!OSCHfSourceReady()); OSCHfSourceSwitch(); } OSCClockSourceSet(OSC_SRC_CLK_LF,OSC_RCOSC_LF); while(OSCClockSourceGet(OSC_SRC_CLK_LF) != OSC_RCOSC_LF); OSCInterfaceDisable(); /* make sure DMA and CRYTO clocks are off in deep-sleep */ PRCMPeripheralDeepSleepDisable(PRCM_PERIPH_CRYPTO); PRCMPeripheralDeepSleepDisable(PRCM_PERIPH_UDMA); PRCMLoadSet(); while(!PRCMLoadGet()){}; /* power OFF AUX and disconnect from bus */ AUXWUCPowerCtrl(AUX_WUC_POWER_OFF); /* remove AUX force ON */ HWREG(AON_WUC_BASE + AON_WUC_O_AUXCTL) &= ~AON_WUC_AUXCTL_AUX_FORCE_ON; /* * reset AON event source IDs to avoid pending events powering * on MCU/AUX */ HWREG(AON_EVENT_BASE + AON_EVENT_O_MCUWUSEL) = 0x3F3F3F3F; HWREG(AON_EVENT_BASE + AON_EVENT_O_AUXWUSEL) = 0x003F3F3F; /* sync AON */ HWREG(AON_RTC_BASE + AON_RTC_O_SYNC); /* * enable shutdown - this latches the IOs, so configuration of * IOCFGx registers must be done prior to this */ AONWUCShutDownEnable(); /* sync AON */ HWREG(AON_RTC_BASE + AON_RTC_O_SYNC); /* wait until AUX powered off */ while (AONWUCPowerStatusGet() & AONWUC_AUX_POWER_ON); /* request to power off MCU when go to deep sleep */ PRCMMcuPowerOff(); /* turn off power domains inside MCU VD (BUS, FL_BUS, RFC, CPU) */ PRCMPowerDomainOff(PRCM_DOMAIN_RFCORE | PRCM_DOMAIN_SERIAL | PRCM_DOMAIN_PERIPH | PRCM_DOMAIN_CPU | PRCM_DOMAIN_VIMS); /* deep sleep to activate shutdown */ PRCMDeepSleep(); } } Power_module->state = Power_ACTIVE; /* if get here failed to shutdown, return failure code */ return (Power_EFAIL); }
// Main loop of the program int main(void) { // // Set the clocking to run directly from the crystal. 8Mhz // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); delay(500); LED_init(); delay(500); ADC_init(); //init the adc delay(500); timer0_init(); //init the first timer delay(500); timer1_init(); //second timer delay(500); key_init(); //keypad display_init(); CPUcpsie(); //turn on cpu inttrupts //init all prices and indexes int upDownIndex = 0; int currDollars = 0; int currCents = 0; int leftRightIndex = 0; display_on(1,1); print_welcome(); //print initial welcome menu /* handles key inputs User can toggle through display menus (welcome menu, food menu,...) using LEFT and RIGHT While on the food menu, user can toggle through food options using UP and DOWN and select food items using SELECT. */ while(1) { int currentKey = keymaster(); if (!readKey) { //if we have not read the key since it has been updated switch (currentKey) //main control flow loop { case UP: if (upDownIndex) { upDownIndex--; //de-inc the vertical index print_menu(upDownIndex, currDollars, currCents); } break; case DOWN: if (upDownIndex < maxUpDownIndex) { upDownIndex++; //inc the vertical index print_menu(upDownIndex, currDollars, currCents); } break; case RIGHT: if (leftRightIndex < maxLeftRightIndex) { leftRightIndex++; //inc the left right index select_menu(&leftRightIndex, upDownIndex, currDollars, currCents); } break; case LEFT: if (leftRightIndex) { leftRightIndex--; //de-inc the left right index select_menu(&leftRightIndex, upDownIndex, currDollars, currCents); } break; case SELECT: currDollars += dollars[upDownIndex]; //update the total costs currCents += cents[upDownIndex]; if (currCents >= 100) { currDollars += 1; currCents -= 100; } print_menu(upDownIndex, currDollars, currCents); break; } } readKey = 1; //tell timer 0 we have read the key //Reset the totals for the costs if (leftRightIndex == 0) { currDollars = 0; currCents = 0; } } }
/* * ======== 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(); } }
/** * global interrupt enable */ void hwEnableInterrupts(){ CPUcpsie(); }