Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r9cb97698939c1da40f8648934e4a244c4aba3799 -r6ad57767b87b8e691c6cbb728b56efabe8a28e8e --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 9cb97698939c1da40f8648934e4a244c4aba3799) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 6ad57767b87b8e691c6cbb728b56efabe8a28e8e) @@ -166,7 +166,7 @@ if ( ( TRUE == force ) || ( FALSE == currentValveStates[ valve ].hasValveBeenHomed ) ) { if ( ( FALSE == isPinchValveBusy( valve ) ) && ( FALSE == currentValveStates[ valve ].hasHomingBeenRequested ) && - ( FALSE == currentValveStates[ valve ].homingOperationActive ) ) + ( FALSE == currentValveStates[ valve ].homingOperationActive ) ) { currentValveStates[ valve ].hasHomingBeenRequested = TRUE; currentValveStates[ valve ].hasTransitionBeenRequested = FALSE; @@ -207,17 +207,17 @@ ( FALSE == currentValveStates[ valve ].homingOperationActive ) && ( currentValveStates[ valve ].commandedPosition != position ) ) { - pendingValvePositionChange[ valve ] = position; + pendingValvePositionChange[ valve ] = position; currentValveStates[ valve ].hasTransitionBeenRequested = TRUE; - result = TRUE; + result = TRUE; } } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_PARAM, ( (U32)valve << SHIFT_16_BITS_FOR_WORD_SHIFT ) | (U32)position ) } - SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_VALVE_POS_CHANGE, (u32)result, (U32)position ); + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_VALVE_POS_CHANGE, (U32)result, (U32)position ); return result; } @@ -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 @@ -485,7 +485,7 @@ currentValveStates[ valve ].hasValveBeenHomed = FALSE; currentValveStates[ valve ].homingOperationActive = FALSE; currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; - nextState = VALVE_STATE_HOMING_NOT_HOMED; + nextState = VALVE_STATE_HOMING_NOT_HOMED; } else if ( TRUE == currentValveStates[ valve ].hasTransitionBeenRequested ) {