#include "reg_het.h" #include "gio.h" #include "TaskGeneral.h" #include "UVReactors.h" #include "Common.h" #include "SystemCommMessages.h" /** * @addtogroup UV Reactors * @{ */ // ********** private definitions ********** #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 24 ///< Inlet UV reactor N2HET1 pin number (health check) #define OUTLET_UV_REACTOR_INDICATION_PIN 11 ///< 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 /// UV reactors exec states typedef enum exec_states { UV_REACTOR_STATE_OFF = 0, ///< UV reactor state off UV_REACTOR_STATE_ON, ///< UV reactor state on NUM_OF_UV_REACTOR_STATES, ///< Number of UV reactor states } UV_REACTOR_STATE_T; /// UV reactor status typedef struct { PIN_SIGNAL_STATE_T enableStatus; ///< UV reactor enable status UV_REACTOR_STATE_T execState; ///< UV reactor executive state BOOL hasTurnOnBeenRequested; ///< UV reactor turn on request U32 reactorEnablePin; ///< UV reactor enable pin of GIO port A U32 reactorHealthStatusPin; ///< UV reactor status pin of N2HET1 } UV_REACTOR_STATUS_T; // ********** private data ********** static UV_REACTOR_STATUS_T reactorsStatus[ NUM_OF_UV_REACTORS ]; ///< UV reactors status array 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 static U32 dataPublishCounter = 0; // Monitor function of the UV reactors static UV_REACTOR_STATE_T handleUVReactorStateOff( UV_REACTORS_T reactor ); static UV_REACTOR_STATE_T handleUVReactorStateOn( UV_REACTORS_T reactor ); static void execMonitorUVReactors( void ); static void publishUVReactorsData( void ); static U32 getPublishValvesDataInterval( void ); void initUVReactors( void ) { uvReactosSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; dataPublishCounter = 0; reactorsStatus[ INLET_UV_REACTOR ].reactorEnablePin = INLET_UV_REACTOR_ENABLE_PIN; reactorsStatus[ INLET_UV_REACTOR ].reactorHealthStatusPin = INLET_UV_REACTOR_INDICATION_PIN; reactorsStatus[ OUTLET_UV_REACTOR ].reactorEnablePin = OUTLET_UV_REACTOR_ENABLE_PIN; reactorsStatus[ OUTLET_UV_REACTOR ].reactorHealthStatusPin = OUTLET_UV_REACTOR_INDICATION_PIN; } SELF_TEST_STATUS_T execUVReactorsSelfTest( void ) { //TODO what to do in POST? } void execUVReactos( void ) { UV_REACTORS_T reactor; execMonitorUVReactors(); for ( reactor = INLET_UV_REACTOR; reactor < NUM_OF_UV_REACTORS; reactor++ ) { switch ( reactorsStatus[ reactor ].execState ) { case UV_REACTOR_STATE_OFF: reactorsStatus[ reactor ].execState = handleUVReactorStateOff( reactor ); break; case UV_REACTOR_STATE_ON: reactorsStatus[ reactor ].execState = handleUVReactorStateOn( reactor ); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UV_REACTORS_INVALID_EXEC_STATE, reactorsStatus[ reactor ].execState ); reactorsStatus[ reactor].execState = UV_REACTOR_STATE_OFF; break; } publishUVReactorsData(); } } BOOL turnOnUVReactor( UV_REACTORS_T reactor ) { BOOL result = FALSE; //TODO check the status of reactor if ( FALSE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) { reactorsStatus[ reactor ].hasTurnOnBeenRequested = TRUE; result = TRUE; } return result; } BOOL turnOffUVReactor( UV_REACTORS_T reactor ) { BOOL result = FALSE; //TODO check the status of reactor if ( TRUE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) { reactorsStatus[ reactor ].hasTurnOnBeenRequested = FALSE; result = TRUE; } return result; } static UV_REACTOR_STATE_T handleUVReactorStateOff( UV_REACTORS_T reactor ) { UV_REACTOR_STATE_T state = UV_REACTOR_STATE_OFF; //TODO check the health if( TRUE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) { gioSetBit( gioPORTA, reactorsStatus[ reactor ].reactorEnablePin, PIN_SIGNAL_HIGH ); state = UV_REACTOR_STATE_ON; } return state; } static UV_REACTOR_STATE_T handleUVReactorStateOn( UV_REACTORS_T reactor ) { UV_REACTOR_STATE_T state = UV_REACTOR_STATE_ON; gioGetBit( hetPORT1, reactorsStatus[ reactor ].reactorHealthStatusPin ); if( FALSE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) { gioSetBit( gioPORTA, reactorsStatus[ reactor ].reactorEnablePin, PIN_SIGNAL_LOW ); state = UV_REACTOR_STATE_OFF; } return state; } static void execMonitorUVReactors( void ) { } static U32 getPublishValvesDataInterval( void ) { U32 result = uvReactorsDataPublishInterval.data; if ( OVERRIDE_KEY == uvReactorsDataPublishInterval.override ) { result = uvReactorsDataPublishInterval.ovData; } return result; } static void publishUVReactorsData( void ) { if ( ++dataPublishCounter > getPublishValvesDataInterval() ) { UV_REACTORS_DATA_T uvReactorsData; uvReactorsData.inletUVReactorEnable = reactorsStatus[ INLET_UV_REACTOR ].enableStatus; uvReactorsData.inletUVReactorHealthStatus = reactorsStatus[ INLET_UV_REACTOR ].reactorHealthStatusPin; uvReactorsData.outletUVReactorEnable = reactorsStatus[ OUTLET_UV_REACTOR ].enableStatus; uvReactorsData.outletUVReactorHealthStatus = reactorsStatus[ OUTLET_UV_REACTOR ].reactorHealthStatusPin; broadcastUVReactorsData( &uvReactorsData ); dataPublishCounter = 0; } } /**@}*/