Index: firmware/App/Controllers/UVReactors.c =================================================================== diff -u -r9dd9502d10f57408dd50fd43275b29b89a8a66c9 -raa36ab1ed13d099286cedcbd066f7dce11146d13 --- firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision 9dd9502d10f57408dd50fd43275b29b89a8a66c9) +++ firmware/App/Controllers/UVReactors.c (.../UVReactors.c) (revision aa36ab1ed13d099286cedcbd066f7dce11146d13) @@ -1,49 +1,200 @@ -/* - * UVReactors.c - * - * Created on: Jun 20, 2020 - * Author: fw - */ +#include "reg_het.h" #include "gio.h" +#include "TaskGeneral.h" #include "UVReactors.h" #include "Common.h" +#include "SystemCommMessages.h" -#define ENABLE_UV_REACTOR 1 -#define DISABLE_UV_REACTOR 0 +/** + * @addtogroup UV Reactors + * @{ + */ -#define UV_1_GIO_PORT_PIN 0 -#define UV_2_GIO_PORT_PIN 1 +// ********** private definitions ********** -SELF_TEST_STATUS_T execUVReactorsSelfTest( void ) +#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 startInletUVReactor() +BOOL turnOnUVReactor( UV_REACTORS_T reactor ) { - BOOL status = TRUE; - //gioSetBit( gioPORTA, UV_1_GIO_PORT_PIN, ENABLE_UV_REACTOR ); - return status; + BOOL result = FALSE; + + //TODO check the status of reactor + if ( FALSE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) + { + reactorsStatus[ reactor ].hasTurnOnBeenRequested = TRUE; + + result = TRUE; + } + + return result; } -BOOL startOutletUVReactor() +BOOL turnOffUVReactor( UV_REACTORS_T reactor ) { - BOOL status = TRUE; - //gioSetBit( gioPORTA, UV_2_GIO_PORT_PIN, ENABLE_UV_REACTOR ); - return status; + BOOL result = FALSE; + + //TODO check the status of reactor + if ( TRUE == reactorsStatus[ reactor ].hasTurnOnBeenRequested ) + { + reactorsStatus[ reactor ].hasTurnOnBeenRequested = FALSE; + + result = TRUE; + } + + return result; } -void stopInletUVReactor() +static UV_REACTOR_STATE_T handleUVReactorStateOff( UV_REACTORS_T reactor ) { - //gioSetBit( gioPORTA, UV_1_GIO_PORT_PIN, DISABLE_UV_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; } -void stopOutletUVReactor() + + +static UV_REACTOR_STATE_T handleUVReactorStateOn( UV_REACTORS_T reactor ) { - //gioSetBit( gioPORTA, UV_2_GIO_PORT_PIN, DISABLE_UV_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; + } +} + +/**@}*/