int sol_platform_impl_get_state(void) { switch (lpm_get()) { case LPM_POWERDOWN: case LPM_SLEEP: return SOL_PLATFORM_STATE_STOPPING; case LPM_UNKNOWN: return SOL_PLATFORM_STATE_UNKNOWN; default: return SOL_PLATFORM_STATE_RUNNING; } }
/* Change the current power-saving mode. */ enum lpm_mode lpm_set(enum lpm_mode target) { enum lpm_mode last_mode = lpm_get(); switch (target) { case LPM_ON: // fully running MCU __bic_status_register(CPUOFF | OSCOFF | SCG0 | SCG1); break; case LPM_IDLE: // lightest mode => LPM0 mode of MSP430 __bic_status_register(OSCOFF | SCG0 | SCG1); // only stops CPU block __bis_status_register(CPUOFF); break; case LPM_SLEEP: // mid-level mode => LPM1 mode of MSP430 __bic_status_register(OSCOFF | SCG1); // stops CPU and master clock blocks __bis_status_register(CPUOFF | SCG0); break; case LPM_POWERDOWN: // deep-level mode => LPM3 mode of MSP430 __bic_status_register(OSCOFF); // stops all blocks except auxiliary clock (timers) __bis_status_register(CPUOFF | SCG0 | SCG1); break; case LPM_OFF: // MCU totally down (LPM4), only RESET or NMI can resume execution __bis_status_register(CPUOFF | OSCOFF | SCG0 | SCG1); // all blocks off break; default: printf("ERROR: trying to set an invalid low-power mode!\n"); printf(" Operation aborted.\n\n"); } return last_mode; }