/***************************************************************/
/* VLLS0 mode entry routine. Puts the processor into
* VLLS0 mode from normal run mode or VLPR.
*
* Mode transitions:
* RUN to VLLS0* VLPR to VLLS0
*
* NOTE: VLLSx modes will always exit to RUN mode even if you were
* in VLPR mode before entering VLLSx.
*
* Wake-up from VLLSx mode is controlled by the LLWU module. Most
* modules cannot issue a wake-up interrupt in VLLSx mode, so make
* sure to setup the desired wake-up sources in the LLWU before
* calling this function.
*
* Parameters:
* PORPO_value - 0 POR detect circuit is enabled in VLLS0
* 1 POR detect circuit is disabled in VLLS0
*/
/***************************************************************/
void enter_vlls0(unsigned char PORPO_value )
{
volatile unsigned int dummyread;
/* Write to PMPROT to allow all possible power modes */
SMC_PMPROT = SMC_PMPROT_AVLLS_MASK;
/* Set the STOPM field to 0b100 for VLLS0 mode */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4);
/* set VLLSM = 0b00 */
SMC_VLLSCTRL = (PORPO_value <<SMC_VLLSCTRL_PORPO_SHIFT)
| SMC_VLLSCTRL_VLLSM(3);
/*wait for write to complete to SMC before stopping core */
dummyread = SMC_VLLSCTRL;
/* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
#ifdef CMSIS
__wfi();
#else
/* WFI instruction will start entry into STOP mode */
asm("WFI");
#endif