Index: firmware/App/Controllers/UVReactors.c =================================================================== diff -u -rccf1219089b835ab2f9d401c0be0d2000be9010a -rd3819286869611f9c02add72a0f8e321598fdf42 --- firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision ccf1219089b835ab2f9d401c0be0d2000be9010a) +++ firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision d3819286869611f9c02add72a0f8e321598fdf42) @@ -19,7 +19,7 @@ #define INLET_UV_REACTOR_ENABLE_PIN 0 ///< Inlet UV reactor GPIO pin number (enable pin). #define OUTLET_UV_REACTOR_ENABLE_PIN 1 ///< Outlet UV reactor GPIO pin number (enable Pin). -#define INLET_UV_REACTOR_INDICATION_PIN 0x1A ///< Inlet UV reactor N2HET1 pin number (health check). +#define INLET_UV_REACTOR_INDICATION_PIN 0x18 ///< Inlet UV reactor N2HET1 pin number (health check). #define OUTLET_UV_REACTOR_INDICATION_PIN 0x0B ///< Outlet UV reactor N2HET1 pin number (health check). #define UV_REACTORS_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< UV reactors data publication time interval. /// Self test wait time after enabling the reactors and before checking for their health in ms. @@ -48,7 +48,7 @@ { UV_REACTOR_STATE_T execState; ///< UV reactor executive state PIN_SIGNAL_STATE_T pinSignalState; ///< UV reactor pin signal state - SWITCH_STATES_T switchState; ///< UV reactor turn on/turn off state + UV_REACTOR_STATES_T switchState; ///< UV reactor turn on/turn off state U32 reactorEnablePin; ///< UV reactor enable pin of GIO port A U32 reactorHealthStatusPin; ///< UV reactor status pin of N2HET1 OVERRIDE_U32_T healthStatus; ///< UV reactor current health status @@ -75,10 +75,9 @@ static UV_REACTOR_STATE_T handleUVReactorStateOn( UV_REACTORS_T reactor ); // Support functions -static BOOL isReactorHealthy( UV_REACTORS_T reactor ); +static U32 getReactorHealth( UV_REACTORS_T reactor ); static void setReactorEnableStatus( UV_REACTORS_T reactor, PIN_SIGNAL_STATE_T state ); static void publishUVReactorsData( void ); -static U32 getPublishUVReactorsDataInterval( void ); /*********************************************************************//** * @brief @@ -93,7 +92,7 @@ { UV_REACTORS_T reactor; - uvReactorsSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; + uvReactorsSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; uvReactorsSelfTestStates = UV_REACTORS_SELF_TEST_OFF; dataPublishCounter = 0; @@ -108,9 +107,9 @@ // 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 ].switchState = TURN_OFF; + reactorsStatus[ reactor ].pinSignalState = PIN_SIGNAL_LOW; + reactorsStatus[ reactor ].execState = UV_REACTOR_STATE_OFF; + reactorsStatus[ reactor ].switchState = TURN_OFF; } initPersistentAlarm( ALARM_ID_UV_REACTOR_NOT_HEALTHY, MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD, MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD ); @@ -186,28 +185,21 @@ /*********************************************************************//** * @brief - * The getUVReactorHealth function returns the health status of a UV reactor. + * The getUVReactorHealth function returns the health status of a UV + * reactor. * @details Inputs: reactorsStatus * @details Outputs: none * @param reactor to return its health - * @return returns the health of the requested UV reactor + * @return returns the health of the requested UV reactor as an enum *************************************************************************/ -BOOL getUVReactorHealth( UV_REACTORS_T reactor ) +UV_REACTORS_HEALTH_STATUS_T getUVReactorHealth( UV_REACTORS_T reactor ) { - BOOL health = FALSE; + UV_REACTORS_HEALTH_STATUS_T health = UV_REACTOR_OFF; // Check if the reactor selected is in range if ( reactor < NUM_OF_UV_REACTORS ) { - // Check if the health is in override or not - if ( reactorsStatus[ reactor ].healthStatus.override == OVERRIDE_KEY ) - { - health = reactorsStatus[ reactor ].healthStatus.ovData; - } - else - { - health = reactorsStatus[ reactor ].healthStatus.data; - } + health = (UV_REACTORS_HEALTH_STATUS_T)getU32OverrideValue( &reactorsStatus[ reactor ].healthStatus ); } else { @@ -306,11 +298,11 @@ if ( TRUE == didTimeout( selfTestElapsedTime, SELF_TEST_DELAY_TIME ) ) { // Get the health status of the reactors - BOOL isInletHealthy = isReactorHealthy( INLET_UV_REACTOR ); - BOOL isOutletHealthy = isReactorHealthy( OUTLET_UV_REACTOR ); + BOOL isInletHealthy = (BOOL)getReactorHealth( INLET_UV_REACTOR ); + BOOL isOutletHealthy = (BOOL)getReactorHealth( OUTLET_UV_REACTOR ); // Check if both of them are healthy and if not, raise an alarm - if ( TRUE == isInletHealthy && TRUE == isOutletHealthy ) + if ( ( TRUE == isInletHealthy ) &&( TRUE == isOutletHealthy ) ) { uvReactorsSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -351,9 +343,13 @@ { UV_REACTOR_STATE_T state = UV_REACTOR_STATE_OFF; + // Set the health status to be off. When the reactor is off, it does not report + // its health status + reactorsStatus[reactor].healthStatus.data = (U32)UV_REACTOR_OFF; + // If the a reactor is requested to be on and it is off, turn it on // and change the state - if( TURN_ON == reactorsStatus[ reactor ].switchState ) + if ( TURN_ON == reactorsStatus[ reactor ].switchState ) { setReactorEnableStatus( reactor, PIN_SIGNAL_HIGH ); @@ -375,20 +371,22 @@ { UV_REACTOR_STATE_T state = UV_REACTOR_STATE_ON; - reactorsStatus[ reactor ].healthStatus.data = (U32)isReactorHealthy( reactor ); + // Update the UV reactor's health. It should be either healthy (1) or not healthy (0) + reactorsStatus[ reactor ].healthStatus.data = getReactorHealth( reactor ); - BOOL isReactorHealthy = getUVReactorHealth( reactor ); + // Get the health of the reactor (override or non-override) and decide the status + BOOL isReactorUnhealthy = ( UV_REACTOR_HEALTHY == getUVReactorHealth( reactor ) ? FALSE : TRUE ); - checkPersistentAlarm( ALARM_ID_UV_REACTOR_NOT_HEALTHY, !isReactorHealthy, (U32)reactor, MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD ); + checkPersistentAlarm( ALARM_ID_UV_REACTOR_NOT_HEALTHY, isReactorUnhealthy, (U32)reactor, MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD ); // Check if the alarm has been active - if( isAlarmActive( ALARM_ID_UV_REACTOR_NOT_HEALTHY ) ) + if ( TRUE == isAlarmActive( ALARM_ID_UV_REACTOR_NOT_HEALTHY ) ) { reactorsStatus[ reactor ].switchState = TURN_OFF; } // Check if it has been requested to turn off a reactor - if( TURN_OFF == reactorsStatus[ reactor ].switchState ) + if ( TURN_OFF == reactorsStatus[ reactor ].switchState ) { setReactorEnableStatus( reactor, PIN_SIGNAL_LOW ); @@ -411,68 +409,50 @@ static void setReactorEnableStatus( UV_REACTORS_T reactor, PIN_SIGNAL_STATE_T state ) { // Set the GIO pin to enable or disable - gioSetBit( gioPORTA, reactorsStatus[ reactor ].reactorEnablePin, state ); + gioSetBit( gioPORTA, reactorsStatus[ reactor ].reactorEnablePin, (U32)state ); // Update the pin signal state reactorsStatus[ reactor ].pinSignalState = state; } /*********************************************************************//** * @brief - * The isReactorHealthy function checks the health status of a reactor. + * The getReactorHealth function checks the health status of a reactor. * @details Inputs: reactorsStatus * @details Outputs: none * @param reactor to check its health - * @return returns TRUE if the reactor is healthy otherwise a FALSE + * @return returns 1 if the reactor is healthy otherwise a 0 *************************************************************************/ -static BOOL isReactorHealthy( UV_REACTORS_T reactor ) +static U32 getReactorHealth( UV_REACTORS_T reactor ) { - return (BOOL)gioGetBit( hetPORT1, reactorsStatus[ reactor ].reactorHealthStatusPin ); + return gioGetBit( hetPORT1, reactorsStatus[ reactor ].reactorHealthStatusPin ); } /*********************************************************************//** * @brief - * The getPublishValvesDataInterval function gets the data publish interval - * @details Inputs: uvReactorsDataPublishInterval - * @details Outputs: none - * @return returns data publish interval - *************************************************************************/ -static U32 getPublishUVReactorsDataInterval( void ) -{ - U32 result = uvReactorsDataPublishInterval.data; - - if ( OVERRIDE_KEY == uvReactorsDataPublishInterval.override ) - { - result = uvReactorsDataPublishInterval.ovData; - } - - return result; -} - -/*********************************************************************//** - * @brief * The publishUVReactorsData function publishes the UV reactors data. * @details Inputs: dataPublishCounter, reactorsStatus * @details Outputs: dataPublishCounter * @return none *************************************************************************/ static void publishUVReactorsData( void ) { - if ( ++dataPublishCounter > getPublishUVReactorsDataInterval() ) + if ( ++dataPublishCounter > getU32OverrideValue( &uvReactorsDataPublishInterval ) ) { UV_REACTORS_DATA_T uvReactorsData; // 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; + uvReactorsData.inletUVReactorHealthStatus = (U32)getUVReactorHealth( INLET_UV_REACTOR ); + uvReactorsData.outletUVReactorHealthStatus = (U32)getUVReactorHealth( OUTLET_UV_REACTOR ); + uvReactorsData.inletUVReactorState = (U32)reactorsStatus[ INLET_UV_REACTOR ].execState; + uvReactorsData.outletUVReactorState = (U32)reactorsStatus[ OUTLET_UV_REACTOR ].execState; broadcastUVReactorsData( &uvReactorsData ); dataPublishCounter = 0; } } + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -535,15 +515,15 @@ * @param health which is high for healthy on and low for not healthy * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetUVReactorHealthOverride( U32 reactor, BOOL health ) +BOOL testSetUVReactorHealthOverride( U32 reactor, U32 health ) { BOOL result = FALSE; - if ( TRUE == isTestingActivated() && (UV_REACTORS_T)reactor < NUM_OF_UV_REACTORS ) + if ( ( TRUE == isTestingActivated() ) && ( (UV_REACTORS_T)reactor < NUM_OF_UV_REACTORS ) ) { reactorsStatus[ (UV_REACTORS_T)reactor ].healthStatus.ovInitData = reactorsStatus[ (UV_REACTORS_T)reactor ].healthStatus.data; reactorsStatus[ (UV_REACTORS_T)reactor ].healthStatus.override = OVERRIDE_KEY; - reactorsStatus[ (UV_REACTORS_T)reactor ].healthStatus.ovData = (U32)health; + reactorsStatus[ (UV_REACTORS_T)reactor ].healthStatus.ovData = health; result = TRUE; }