/* VLLS1 mode entry routine. Puts the processor into VLLS1 mode from * normal run mode or VLPR. * * Mode transitions: * RUN -> VLLS1 * VLPR -> VLLS1 * * NOTE: VLLSx modes will always exit to RUN mode even if you were * in VLPR mode before entering VLLSx. * * Wakeup from VLLSx mode is controlled by the LLWU module. Most * modules cannot issue a wakeup interrupt in VLLSx mode, so make * sure to setup the desired wakeup sources in the LLWU before * calling this function. * * Parameters: * none */ void enter_vlls1(void) { /* Write to PMPROT to allow all possible power modes */ MC_PMPROT = MC_PMPROT_AVLLS1_MASK; /* Set the LPLLSM field to 0b111 for VLLS1 mode */ MC_PMCTRL = MC_PMCTRL_LPLLSM(7); // set LPLLSM = 0b111 /* Now execute the stop instruction to go into VLLS1 */ stop(); }
void enter_stop_mode(char mode) { printf("\n-------------------------------------\n"); printf(" MC_Enter Low Power Modes Utility \n"); printf("--------------------------------------\n"); MC_PMPROT = 0x37; //This value enables all possible power modes. MC_PMCTRL = MC_PMCTRL_LPWUI_MASK | MC_PMCTRL_LPLLSM(mode) ; stop(); }
/* VLLS2 mode entry routine. Puts the processor into VLLS2 mode from * normal run mode or VLPR. * * Mode transitions: * RUN -> VLLS2 * VLPR -> VLLS2 * * NOTE: VLLSx modes will always exit to RUN mode even if you were * in VLPR mode before entering VLLSx. * * Wakeup from VLLSx mode is controlled by the LLWU module. Most * modules cannot issue a wakeup interrupt in VLLSx mode, so make * sure to setup the desired wakeup sources in the LLWU before * calling this function. * * Parameters: * none */ void enter_vlls2(void) { /* Write to PMPROT to allow VLLS2 power modes */ MC_PMPROT = MC_PMPROT_AVLLS2_MASK; /* Set the LPLLSM field to 0b110 for VLLS2 mode */ MC_PMCTRL = MC_PMCTRL_LPLLSM(6); // set LPLLSM = 0b110 /* Now execute the stop instruction to go into VLLS2 */ stop(); }
/* VLLS3 mode entry routine. Puts the processor into VLLS3 mode from * normal run mode or VLPR. * * Mode transitions: * RUN -> VLLS3 * VLPR -> VLLS3 * * NOTE: VLLSx modes will always exit to RUN mode even if you were * in VLPR mode before entering VLLSx. * * Wakeup from VLLSx mode is controlled by the LLWU module. Most * modules cannot issue a wakeup interrupt in VLLSx mode, so make * sure to setup the desired wakeup sources in the LLWU before * calling this function. * * Parameters: * none */ void enter_vlls3(void) { /* Write to PMPROT to allow VLLS3 power modes */ MC_PMPROT = MC_PMPROT_AVLLS3_MASK; /* Set the LPLLSM field to 0b101 for VLLS3 mode */ MC_PMCTRL = MC_PMCTRL_LPLLSM(5); // set LPLLSM = 0b101 /* Now execute the stop instruction to go into VLLS3 */ stop(); }
/* LLS mode entry routine. Puts the processor into LLS mode from * normal run mode or VLPR. * * Mode transitions: * RUN -> LLS * VLPR -> LLS * * NOTE: LLS mode will always exit to RUN mode even if you were * in VLPR mode before entering LLS. * * Wakeup from LLS mode is controlled by the LLWU module. Most * modules cannot issue a wakeup interrupt in LLS mode, so make * sure to setup the desired wakeup sources in the LLWU before * calling this function. * * Parameters: * none */ void enter_lls(void) { /* Write to PMPROT to allow LLS power modes */ MC_PMPROT = MC_PMPROT_ALLS_MASK; //this write-once bit allows the MCU to enter the //LLS low power mode /* Set the LPLLSM field to 0b011 for LLS mode */ MC_PMCTRL = MC_PMCTRL_LPLLSM(3); // set LPLLSM = 0b11 /* Now execute the stop instruction to go into LLS */ stop(); }
/* VLPS mode entry routine. Puts the processor into VLPS mode directly * from normal run mode. * * Mode transitions: * RUN -> VLPS * * If VLPS mode is entered directly from normal RUN mode, then the * LPWUI bit is forced to 1 by hardware. This means that when an * interrupt occurs you will exit to normal run mode instead of VLPR. * * If however VLPS mode is entered from VLPR the state of the LPWUI bit * determines the state the MCU will return to upon exit from VLPS.If LPWUI is set * and an interrupt occurs you will exit to normal run mode instead of VLPR. * If LPWUI is clear and an interrupt occurs you will exit to VLPR. * * Parameters: value of LPWUI * none */ void enter_vlps(char lpwui_value) { /* Write to PMPROT to allow VLPS power modes */ MC_PMPROT = MC_PMPROT_AVLP_MASK; // write oneif not all set make sure all enabled //this write-once bit allows the MCU to enter the //very low power modes: VLPR, VLPW, and VLPS. /* Reduce system clock to < 2MHz */ // mcg_pee_2_blpi(); // you don't need to chage to lower frequency for VLPS /* Set the LPLLSM field to 0b010 for VLPS mode - Need to set state of LPWUI bit 8 */ if(lpwui_value) { MC_PMCTRL = (MC_PMCTRL_LPWUI_MASK // set LPWUI | MC_PMCTRL_LPLLSM(2)); // set LPLLSM = 0b10 } else { MC_PMCTRL = (!MC_PMCTRL_LPWUI_MASK // set LPWUI | MC_PMCTRL_LPLLSM(2)); // set LPLLSM = 0b10 } /* Now execute the stop instruction to go into VLPS */ stop(); }
/* STOP mode entry routine. Puts the processor into normal stop mode. * In this mode core, bus and peripheral clocks are disabled. * * Mode transitions: * RUN -> STOP * VLPR -> VLPS * * This function can be used to enter normal stop mode or VLPS * mode. If you are executing in normal run mode when calling this * function, then you will enter normal stop mode. If you are in VLPR * mode when calling this function, then you will enter VLPS mode instead. * * STOP mode is exited using any enabled interrupt or RESET, so no * exit_stop routine is needed. * * Parameters: * none */ void enter_stop(void) { /* Set the LPLLSM field to 0b000 for normal STOP mode - Need to retain state of LPWUI bit 8 */ MC_PMCTRL = MC_PMCTRL_LPLLSM(0); // set LPLLSM = 0b000 stop(); }
MC_PMCTRL_LPWUI_MASK, // Mode PMCTRL register == voltage regulator ON after wakeup LPM_CPU_POWER_MODE_FLAG_DEEP_SLEEP | LPM_CPU_POWER_MODE_FLAG_USE_WFI, // Mode flags == deepsleep, execute WFI }, // Kinetis VLPR { MC_PMCTRL_RUNM(2), // Mode PMCTRL register == VLPR 0, // Mode flags == clear settings }, // Kinetis VLPW { MC_PMCTRL_RUNM(2), // Mode PMCTRL register == VLPW LPM_CPU_POWER_MODE_FLAG_USE_WFI, // Mode flags == execute WFI }, // Kinetis VLPS { MC_PMCTRL_LPLLSM(2), // Mode PMCTRL register == VLPS LPM_CPU_POWER_MODE_FLAG_DEEP_SLEEP | LPM_CPU_POWER_MODE_FLAG_USE_WFI, // Mode flags == deepsleep, execute WFI }, // Kinetis LLS { MC_PMCTRL_LPWUI_MASK | MC_PMCTRL_LPLLSM(3), // Mode PMCTRL register == voltage regulator ON after wakeup, LLS LPM_CPU_POWER_MODE_FLAG_DEEP_SLEEP | LPM_CPU_POWER_MODE_FLAG_USE_WFI, // Mode flags == deepsleep, execute WFI } }; #else static const LDD_TDriverOperationMode LPM_PE_OPERATION_MODE_MAP[LPM_OPERATION_MODES] = {