Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r84eab2f306d2a7c33619042ec69a032f5edbb6db -r9cb97698939c1da40f8648934e4a244c4aba3799 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 84eab2f306d2a7c33619042ec69a032f5edbb6db) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 9cb97698939c1da40f8648934e4a244c4aba3799) @@ -378,94 +378,94 @@ * @param valve ID of valve for which to handle the Not Homed state * @return next state of the state machine for the given valve *************************************************************************/ -static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) -{ - VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; - - if ( ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) && - ( FALSE == currentValveStates[ valve ].homingOperationActive ) ) - { - if ( TRUE == homePinchValve( valve ) ) - { - currentValveStates[ valve ].hasHomingBeenRequested = FALSE; - currentValveStates[ valve ].hasValveBeenHomed = FALSE; - currentValveStates[ valve ].homingOperationActive = TRUE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - } - } - else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( TRUE == isPinchValveHomed( valve ) ) ) - { - currentValveStates[ valve ].homingOperationActive = FALSE; - currentValveStates[ valve ].hasValveBeenHomed = TRUE; - currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; - currentValveStates[ valve ].currentPosition = getCurrentValveABCPosition( valve ); - nextState = VALVE_STATE_IDLE; - } - else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && - ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && - ( TRUE != getCPLDACPowerLossDetected() ) ) - { - currentValveStates[ valve ].homingOperationActive = FALSE; - currentValveStates[ valve ].hasValveBeenHomed = FALSE; - currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) - } - - return nextState; -} - - //static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) //{ // VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; // -// if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) +// if ( ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) && +// ( FALSE == currentValveStates[ valve ].homingOperationActive ) ) // { // if ( TRUE == homePinchValve( valve ) ) // { // currentValveStates[ valve ].hasHomingBeenRequested = FALSE; // currentValveStates[ valve ].hasValveBeenHomed = FALSE; // currentValveStates[ valve ].homingOperationActive = TRUE; // currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; -// currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); +// currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); // } // } -// else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && -// ( TRUE == isPinchValveHomed( valve ) ) && ( FALSE == isPinchValveBusy( valve ) ) ) +// else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && ( TRUE == isPinchValveHomed( valve ) ) ) // { // currentValveStates[ valve ].homingOperationActive = FALSE; -// currentValveStates[ valve ].hasValveBeenHomed = TRUE; -// if ( TRUE == movePinchValveToStoredPosition( valve, VALVE_POSITION_C_CLOSE ) ) -// { -// currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; -// currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; -// currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); -// nextState = VALVE_STATE_IN_TRANSITION; -// } -// else -// { -// currentValveStates[ valve ].hasValveBeenHomed = FALSE; -// currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; -// nextState = VALVE_STATE_HOMING_NOT_HOMED; -// } +// currentValveStates[ valve ].hasValveBeenHomed = TRUE; +// currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; +// currentValveStates[ valve ].currentPosition = getCurrentValveABCPosition( valve ); +// nextState = VALVE_STATE_IDLE; // } // else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && -// ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && -// ( TRUE != getCPLDACPowerLossDetected() ) ) +// ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && +// ( TRUE != getCPLDACPowerLossDetected() ) ) // { -// // currentValveStates[ valve ].homingOperationActive = FALSE; // currentValveStates[ valve ].hasValveBeenHomed = FALSE; // currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; +// // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) -// nextState = VALVE_STATE_HOMING_NOT_HOMED; // } // // return nextState; //} + +static VALVE_STATE_T handleValvesNotHomedState( VALVE_T valve ) +{ + VALVE_STATE_T nextState = VALVE_STATE_HOMING_NOT_HOMED; + + if ( TRUE == currentValveStates[ valve ].hasHomingBeenRequested ) + { + if ( TRUE == homePinchValve( valve ) ) + { + currentValveStates[ valve ].hasHomingBeenRequested = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].homingOperationActive = TRUE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + } + } + else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && + ( TRUE == isPinchValveHomed( valve ) ) && ( FALSE == isPinchValveBusy( valve ) ) ) + { + currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = TRUE; + if ( TRUE == movePinchValveToStoredPosition( valve, VALVE_POSITION_C_CLOSE ) ) + { + currentValveStates[ valve ].commandedPosition = VALVE_POSITION_C_CLOSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); + nextState = VALVE_STATE_IN_TRANSITION; + } + else + { + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + nextState = VALVE_STATE_HOMING_NOT_HOMED; + } + } + else if ( ( TRUE == currentValveStates[ valve ].homingOperationActive ) && + ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, VALVE_HOMING_TIMEOUT_MS ) ) && + ( TRUE != getCPLDACPowerLossDetected() ) ) + { + + currentValveStates[ valve ].homingOperationActive = FALSE; + currentValveStates[ valve ].hasValveBeenHomed = FALSE; + currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_VALVE_TRANSITION_TIMEOUT, (U32)valve, (U32)getPinchValvePosition( valve ) ) + nextState = VALVE_STATE_HOMING_NOT_HOMED; + } + + return nextState; +} + /*********************************************************************//** * @brief * The handleValvesIdleState function handles the Idle state of the state