Index: firmware/App/Controllers/UVReactors.c =================================================================== diff -u -r4638fd77792d0c7ecbeca3c84369cbed6c2ecee1 -r5e99007b56b14a0656fabb7145fe86ac17900f93 --- firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision 4638fd77792d0c7ecbeca3c84369cbed6c2ecee1) +++ firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision 5e99007b56b14a0656fabb7145fe86ac17900f93) @@ -3,6 +3,7 @@ #include "reg_het.h" #include "Common.h" +#include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Timers.h" @@ -22,7 +23,7 @@ #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. #define SELF_TEST_DELAY_TIME 1000 -#define MAX_ALLOWED_UNHEALTHY_REACTOR_COUNTER ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< UV reactors max counter to be unhealthy. +#define MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD MS_PER_SECOND ///< UV reactors unhealthy state period. /// UV reactors self test states typedef enum self_tests @@ -55,16 +56,19 @@ // ********** 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 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. +static const U32 MAX_UNHEALTHY_REACTOR_COUNT_LIMIT = MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD / + TASK_GENERAL_INTERVAL; ///< UV reactors max unhealthy count. + // Self test functions static UV_REACTORS_SELF_TEST_STATE_T handleUVReactorsSelfTestOff( void ); static UV_REACTORS_SELF_TEST_STATE_T handleUVReactorsSelfTestCheckHealth( void ); @@ -112,6 +116,9 @@ reactorsStatus[ reactor ].switchState = TURN_OFF; reactorsStatus[ reactor ].reactorUnhealthyCounter = 0; } + + initPersistentAlarm( PERSISTENT_ALARM_UV_REACTOR_UNHEALTHY, ALARM_ID_UV_REACTOR_NOT_HEALTHY, TRUE, + MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD, MAX_ALLOWED_UNHEALTHY_REACTOR_PERIOD ); } /*********************************************************************//** @@ -375,26 +382,26 @@ reactorsStatus[ reactor ].healthStatus.data = (U32)isReactorHealthy( reactor ); - // Check if the reactor is healthy - if ( FALSE == getUVReactorHealth( reactor ) ) + BOOL isReactorHealthy = getUVReactorHealth( reactor ); + + // Check if the reactor is not healthy and it has not been healthy for a certain period of time + if ( FALSE == isReactorHealthy ) { - // Check if the reactor has been unhealthy for the defined duration - if ( ++reactorsStatus[ reactor ].reactorUnhealthyCounter > MAX_ALLOWED_UNHEALTHY_REACTOR_COUNTER ) + if ( ++reactorsStatus[ reactor ].reactorUnhealthyCounter > MAX_UNHEALTHY_REACTOR_COUNT_LIMIT ) { - // The reactor has been unhealthy for a certain amount of time - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_UV_REACTOR_NOT_HEALTHY, reactor ); - // Done with health. turn off the reactor and go to off state reactorsStatus[ reactor ].reactorUnhealthyCounter = 0; reactorsStatus[ reactor ].switchState = TURN_OFF; } } + // If the reactor became healthy again but the counter was > 0, set it to 0 else { - // If the reactor is healthy, zero out the counter reactorsStatus[ reactor ].reactorUnhealthyCounter = 0; } + checkPersistentAlarm( PERSISTENT_ALARM_UV_REACTOR_UNHEALTHY, !isReactorHealthy, (U32)reactor, MAX_UNHEALTHY_REACTOR_COUNT_LIMIT ); + // Check if it has been requested to turn off a reactor if( TURN_OFF == reactorsStatus[ reactor ].switchState ) {