/*
* 2. goes here second to try and configure for lowest possible sleep
*/
void state_sleep_enter(void)
{
// turn off the XOUT
// Note: free to use XOUT after call to Radio_Init()
RadioWrite(XTAL_CTRL_ADR, XOUT_FNC_GPIO); // XOUT=GPIO
RadioWrite(IO_CFG_ADR, IRQ_GPIO); // IRQ=GPIO
RadioWrite(GPIO_CTRL_ADR, RadioRead(GPIO_CTRL_ADR) & ~XOUT_OP); // XOUT and MISO drive low
RadioWrite(GPIO_CTRL_ADR, RadioRead(GPIO_CTRL_ADR) & ~MISO_OP);
RadioWrite(GPIO_CTRL_ADR, RadioRead(GPIO_CTRL_ADR) & ~IRQ_OP);
RadioForceState(0); // Set END_STATE_SLEEP & Force transition now; go to sleep once after tx/rx operations.
RadioWrite(PWR_CTRL_ADR, PMU_MODE_FORCE); // Disable PMU
// put MCU in lowest power setting
// set to lowest cpu clk setting and sleep for 1 sec.
OSC_CR0 = OSC_CR0_CPU_187d5kHz | OSC_CR0_SLEEP_1Hz;
// put the 32kHz oscillator in low power mode
LPOSCTR |= 0x80;
// make sure ITMRCLK and TCPCLK are not source by either oscillator
TMRCLKCR |= 0x30;
}
/*
* 3.
* stay here for a while to measure sleep current.
*/
void state_sleep(void)
{
while(1) {
M8C_ClearIntFlag(INT_MSK0, INT_MSK0_SLEEP);
M8C_EnableIntMask(INT_MSK0, INT_MSK0_SLEEP); // Enable Sleep Timer
M8C_ClearWDTAndSleep; // Clear watchdog and sleep
M8C_Sleep; // ~800ms @ this clock speed
}
}
/*
* 1.
* Goes here first to initialize
*/
void state_main_enter(void)
{
M8C_EnableGInt;
P21_LO;
P17_LO;
P12_LO;
P11_LO;
P10_LO;
//TO_MISO_LO;
//TO_XOUT_LO;
//LP_IRQ_LO;
RadioForceState(0); // Set END_STATE_SLEEP & Force transition now; go to sleep once after tx/rx operations.
RadioWrite(PWR_CTRL_ADR, PMU_MODE_FORCE); // Disable PMU
}