unsigned char st_suspend(void){ //State Transition is occuring if (timerCountDownActivated == POWER_BUTTON_OFF) { if (timerExpired()) { powerButtonPressed(RELEASED); timerCountDownActivated = NOT_ACTIVATED; if (getActivityInactiveTimeInS() > POWEROFF_THRESOLD_SEC) { return BEFOREPOWEROFF; } else { setHeartBeat(OFF); return BOOTING; } } else{ return SUSPEND; } } //Activty detected OR NON-Activity for too long if (activityDetected() || getActivityInactiveTimeInS() > POWEROFF_THRESOLD_SEC) { powerButtonPressed(PRESSED); timerCountDownActivated = POWER_BUTTON_OFF; setTimerIn100ms(POWER_BUTTON_PRESSED); } return SUSPEND; }
unsigned char st_powerOff(void){ //State Transition is occuring if (timerCountDownActivated == POWER_BUTTON_ON) { if (timerExpired()) { powerButtonPressed(RELEASED); if (isPowerLED_ON()) { timerCountDownActivated = NOT_ACTIVATED; setTimerIn100ms(ZERO); setHeartBeat(OFF); return BOOTING; } } //May hangs here return POWEROFF; } //Press the button for POWER_BUTTON_PRESSED time and switch state if (activityDetected()) { powerSupplyON(ON); powerButtonPressed(PRESSED); timerCountDownActivated = POWER_BUTTON_ON; setTimerIn100ms(POWER_BUTTON_PRESSED); } return POWEROFF; }
void initStateMachine() { activityDetected(); /* configure PIT module in chain mode */ /* PIT clock source is bus clock,24MHz */ /* PIT channel 0 load value = (600000-1) */ uint32_t u32LoadValue0 = (BUS_CLOCK / 1000) * STEP_TIME_MS - 1; /* 25ms */ sPITConfig.u32LoadValue = u32LoadValue0; sPITConfig.bFreeze = FALSE; sPITConfig.bModuleDis = FALSE; /*!< enable PIT module */ sPITConfig.bInterruptEn = TRUE; sPITConfig.bChainMode = FALSE; sPITConfig.bTimerEn = TRUE; PIT_Init(PIT_CHANNEL1, &sPITConfig); PIT_SetCallback(PIT_CHANNEL1, controlStateMachine); }