Index: firmware/App/Controllers/UVReactors.c =================================================================== diff -u -r45263215b372cd579e8e16bb8073c287c726c55d -rd00ad426d849083922332f832e88e7137a1cad60 --- firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision 45263215b372cd579e8e16bb8073c287c726c55d) +++ firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision d00ad426d849083922332f832e88e7137a1cad60) @@ -54,17 +54,17 @@ // ********** private data ********** -static UV_REACTOR_STATUS_T reactorsStatus[ NUM_OF_UV_REACTORS ]; ///< UV reactors status array -static UV_REACTORS_SELF_TEST_STATE_T uvReactorsSelfTestStates = UV_REACTORS_SELF_TEST_OFF; ///< UV reactors self test state -static SELF_TEST_STATUS_T uvReactosSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Valves self test result +static UV_REACTOR_STATUS_T reactorsStatus[ NUM_OF_UV_REACTORS ]; ///< UV reactors status array +static UV_REACTORS_SELF_TEST_STATE_T uvReactorsSelfTestStates = UV_REACTORS_SELF_TEST_OFF; ///< UV reactors self test state +static SELF_TEST_STATUS_T uvReactosSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Valves self test result static OVERRIDE_U32_T uvReactorsDataPublishInterval = { UV_REACTORS_DATA_PUB_INTERVAL, - UV_REACTORS_DATA_PUB_INTERVAL, 0, 0 }; ///< UV reactors data publish interval + UV_REACTORS_DATA_PUB_INTERVAL, 0, 0 }; ///< UV reactors data publish interval -static OVERRIDE_U32_T uvReactorsStateOverride[ NUM_OF_UV_REACTORS ] = { PIN_SIGNAL_LOW, PIN_SIGNAL_LOW, 0, 0 }; ///< UV reactors state override +static OVERRIDE_U32_T uvReactorsStateOverride[ NUM_OF_UV_REACTORS ]; ///< UV reactors state override TODO Remove -static U32 dataPublishCounter = 0; ///< UV reactors data publish counter -static U32 selfTestElapsedTime = 0; ///< UV reactors self test elapsed time +static U32 dataPublishCounter = 0; ///< UV reactors data publish counter +static U32 selfTestElapsedTime = 0; ///< UV reactors self test elapsed time // Self test functions static UV_REACTORS_SELF_TEST_STATE_T handleUVReactorsSelfTestOff( void ); @@ -91,18 +91,26 @@ *************************************************************************/ void initUVReactors( void ) { + UV_REACTORS_T reactor; uvReactosSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; uvReactorsSelfTestStates = UV_REACTORS_SELF_TEST_OFF; dataPublishCounter = 0; - // Initialize the UV reactors + // Initialize the UV reactors. These values are specific to the inlet and outlet reactor + // so they cannot be in a for loop reactorsStatus[ INLET_UV_REACTOR ].reactorEnablePin = INLET_UV_REACTOR_ENABLE_PIN; reactorsStatus[ INLET_UV_REACTOR ].reactorHealthStatusPin = INLET_UV_REACTOR_INDICATION_PIN; - reactorsStatus[ INLET_UV_REACTOR ].pinSignalState = PIN_SIGNAL_LOW; reactorsStatus[ OUTLET_UV_REACTOR ].reactorEnablePin = OUTLET_UV_REACTOR_ENABLE_PIN; reactorsStatus[ OUTLET_UV_REACTOR ].reactorHealthStatusPin = OUTLET_UV_REACTOR_INDICATION_PIN; - reactorsStatus[ OUTLET_UV_REACTOR ].pinSignalState = PIN_SIGNAL_LOW; + + // Initialize the common values in the UV reactors + for( reactor = INLET_UV_REACTOR; reactor < NUM_OF_UV_REACTORS; reactor++ ) + { + reactorsStatus[ reactor ].pinSignalState = PIN_SIGNAL_LOW; + reactorsStatus[ reactor ].execState = UV_REACTOR_STATE_OFF; + reactorsStatus[ reactor ].hasTurnOnBeenRequested = FALSE; + } } /*********************************************************************//** @@ -197,11 +205,19 @@ { BOOL result = FALSE; - if ( FALSE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) + // Check if the called reactor is in range. Otherwise, raise an alarm + if ( reactor < NUM_OF_UV_REACTORS ) { - reactorsStatus[ reactor ].hasTurnOnBeenRequested = TRUE; - result = TRUE; + if ( FALSE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) + { + reactorsStatus[ reactor ].hasTurnOnBeenRequested = TRUE; + result = TRUE; + } } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UV_REACOTRS_INVALID_REACTOR_SELECTD, reactor ) + } return result; } @@ -217,12 +233,19 @@ BOOL turnOffUVReactor( UV_REACTORS_T reactor ) { BOOL result = FALSE; - - if ( TRUE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) + // Check if the called reactor is in range + if ( reactor < NUM_OF_UV_REACTORS ) { - reactorsStatus[ reactor ].hasTurnOnBeenRequested = FALSE; - result = TRUE; + if ( TRUE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) + { + reactorsStatus[ reactor ].hasTurnOnBeenRequested = FALSE; + result = TRUE; + } } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UV_REACOTRS_INVALID_REACTOR_SELECTD, reactor ) + } return result; } @@ -258,15 +281,14 @@ { UV_REACTORS_SELF_TEST_STATE_T state = UV_REACTORS_SELF_TEST_CHECK_HEALTH; - if ( didTimeout( selfTestElapsedTime, SELF_TEST_DELAY_TIME ) ) { // Get the health status of the reactors BOOL isInletHealthy = isReactorHealthy( INLET_UV_REACTOR ); BOOL isOutletHealty = isReactorHealthy( OUTLET_UV_REACTOR ); // Check if both of them are healthy and if not, raise an alarm - if ( isInletHealthy || isOutletHealty ) + if ( isInletHealthy && isOutletHealty ) { uvReactosSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -312,8 +334,6 @@ { setReactorEnableStatus( reactor, PIN_SIGNAL_HIGH ); - // Set the turn on request flag to FALSE - reactorsStatus[ reactor ].hasTurnOnBeenRequested = FALSE; // Update the pin signal state reactorsStatus[ reactor ].pinSignalState = PIN_SIGNAL_HIGH; state = UV_REACTOR_STATE_ON; @@ -348,7 +368,7 @@ reactorsStatus[ reactor ].reactorUnhealthyCounter = 0; } - // Check if a reactor has been requested to be open + // Check if it has been requested to turn off a reactor if( FALSE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) { setReactorEnableStatus( reactor, PIN_SIGNAL_LOW ); @@ -414,8 +434,8 @@ /*********************************************************************//** * @brief * The publishUVReactorsData function publishes the UV reactors data. - * @details Inputs: dataPublishCounter, uvReactorsData, reactorsStatus - * @details Outputs: dataPublishCounter, uvReactorsData + * @details Inputs: dataPublishCounter, reactorsStatus + * @details Outputs: dataPublishCounter * @return none *************************************************************************/ static void publishUVReactorsData( void ) @@ -426,6 +446,8 @@ // Publish the reactors health status uvReactorsData.inletUVReactorHealthStatus = reactorsStatus[ INLET_UV_REACTOR ].reactorHealthStatusPin; uvReactorsData.outletUVReactorHealthStatus = reactorsStatus[ OUTLET_UV_REACTOR ].reactorHealthStatusPin; + uvReactorsData.inletUVReactorState = reactorsStatus[ INLET_UV_REACTOR ].execState; + uvReactorsData.outletUVReactorHealthStatus = reactorsStatus[ OUTLET_UV_REACTOR ].execState; broadcastUVReactorsData( &uvReactorsData ); @@ -495,7 +517,7 @@ * @param signal which is high for turn on and low for turn off * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetUVReactorsStateOverride( U32 reactor, PIN_SIGNAL_STATE_T signal ) +BOOL testSetUVReactorHealthOverride( U32 reactor, PIN_SIGNAL_STATE_T signal ) { BOOL result = FALSE; @@ -529,7 +551,7 @@ * @param reactor that its state will be reset * @return TRUE if override reset successful, FALSE if not *************************************************************************/ -BOOL testResetUVReactorsStateOverride( U32 reactor ) +BOOL testResetUVReactorHealthOverride( U32 reactor ) { BOOL result = FALSE;