Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r97e0100921ccad633b39b509a93a7237e4d80446 -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 97e0100921ccad633b39b509a93a7237e4d80446) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -49,7 +49,7 @@ #define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the Drain Pump data is published on the CAN bus. -#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Drain pump is controlled. TODO original one is 1 second +#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Drain pump is controlled. TODO original one is 1 second #define RPM_2_DAC_SLOPE 0.0547 ///< RPM to DAC conversion slope. #define RPM_2_DAC_INTERCEPT 2.9968 ///< RPM to DAC conversion intercept. @@ -105,7 +105,7 @@ static OVERRIDE_U32_T drainPumpDataPublishInterval = { DRAIN_PUMP_DATA_PUB_INTERVAL, DRAIN_PUMP_DATA_PUB_INTERVAL, - 0, 0 }; ///< Interval (in ms) at which to publish RO flow data to CAN bus. + 0, 0 }; ///< Interval (in ms) at which to publish drain pump data to CAN bus. static U32 targetDrainPumpRPM = 0; ///< Target drain pump RPM. static F32 targetDrainPumpOutletPressure = 0.0; ///< Target outlet pressure for the drain pump. Index: firmware/App/Controllers/Switches.c =================================================================== diff -u --- firmware/App/Controllers/Switches.c (revision 0) +++ firmware/App/Controllers/Switches.c (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -0,0 +1,248 @@ + + +#include "FPGA.h" +#include "Switches.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" + +/** + * @addtogroup Switches + * @{ + */ + +// ********** private definitions ********** + +#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. +#define FLUID_DOOR_SWITCH_BIT_MASK 0x01 ///< Fluid door switch bit mask. +#define DIALYSATE_CAP_SWITCH_BIT_MASK 0x02 ///< Dialysate cap switch bit mask. +#define CONCENTRATE_CAP_SWITCH_BIT_MASK 0x04 ///< Concentrate cap switch bit mask. +#define SWITCHES_FPGA_STATUS_CHECK_INTERVAL ( MS_PER_SECOND / ( 5 * TASK_GENERAL_INTERVAL ) ) ///< Switches FPGA status check interval. + +// ********** private data ********** + +static U32 switchesDataPublicationCounter; ///< Switches data publication counter. +static OVERRIDE_U32_T switchesDataPublishInterval = { SWITCHES_DATA_PUB_INTERVAL, + SWITCHES_DATA_PUB_INTERVAL, + 0, 0 }; ///< Interval (in ms) at which to publish switches data to CAN bus. +static OVERRIDE_U32_T switchStatus[ NUM_OF_DOORS_AND_CAPS ]; ///< Switches status array. +static U32 switchesFPGAStatusCheckCounter; ///< Switches FPGA status check counter. + +// ********** private function prototypes ********** + +static void publishSwitchesData( void ); +static U32 getPublishSwitchesDataInterval( void ); + +/*********************************************************************//** + * @brief + * The initSwitches function initializes the switches module. + * @details Inputs: none + * @details Outputs: switchesDataPublicationCounter, switchStatus + * @return none + *************************************************************************/ +void initSwitches( void ) +{ + U08 i; + + switchesDataPublicationCounter = 0; + switchesFPGAStatusCheckCounter = 0; + + for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) + { + switchStatus[ i ].data = (U32)CLOSED; + } +} + +/*********************************************************************//** + * @brief + * The execSwitches function executes the switches executive. + * @details Inputs: switchStatus + * @details Outputs: switchStatus + * @return none + *************************************************************************/ +void execSwitches( void ) +{ + if ( ++switchesFPGAStatusCheckCounter > SWITCHES_FPGA_STATUS_CHECK_INTERVAL ) + { + U08 fpgaRegister = getFPGAGPIOCount(); + + switchStatus[ CONCENTRATE_CAP ].data = fpgaRegister & CONCENTRATE_CAP_SWITCH_BIT_MASK; + switchStatus[ DIALYSATE_CAP ].data = fpgaRegister & DIALYSATE_CAP_SWITCH_BIT_MASK; + switchStatus[ FLUID_DOOR ].data = fpgaRegister & FLUID_DOOR_SWITCH_BIT_MASK; + + switchesFPGAStatusCheckCounter = 0; + } + + publishSwitchesData(); +} + +/*********************************************************************//** + * @brief + * The getSwitchStatus function returns the status of the called switch. + * @details Inputs: switchStatus + * @details Outputs: switchStatus + * @param switchId which is the switch that its status is requested + * @return switch status + *************************************************************************/ +SWITCH_STATUS_T getSwitchStatus( SWITCH_T switchId ) +{ + U32 status; + + if ( OVERRIDE_KEY == switchStatus[ switchId ].override ) + { + status = switchStatus[ switchId ].ovData; + } + else + { + status = switchStatus[ switchId ].data; + } + + return (SWITCH_STATUS_T)status; +} + +/*********************************************************************//** + * @brief + * The testSetSwitchesDataPublishIntervalOverride function overrides + * the switches publish data interval. + * @details Inputs: switchesDataPublishInterval + * @details Outputs: switchesDataPublishInterval + * @param value switches data broadcast interval (in ms) to override + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSwitchesDataPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( isTestingActivated() ) + { + U32 interval = value / TASK_GENERAL_INTERVAL; + + result = TRUE; + switchesDataPublishInterval.ovData = interval; + switchesDataPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSwitchesDataPublishIntervalOverrid function resets + * the override value of switches publish data interval. + * @details Inputs: switchesDataPublishInterval + * @details Outputs: switchesDataPublishInterval + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetSwitchesDataPublishIntervalOverrid( void ) +{ + BOOL result = FALSE; + + if ( isTestingActivated() ) + { + result = TRUE; + switchesDataPublishInterval.override = OVERRIDE_RESET; + switchesDataPublishInterval.ovData = switchesDataPublishInterval.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetSwitchesStatusOverride function sets the override status + * for a specific switch. + * @details Inputs: none + * @details Outputs: switchStatus + * @param switchId switch index + * @param status switch status to override if testing is activated + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSwitchesStatusOverride( U32 switchId, U32 status ) +{ + BOOL result = FALSE; + + if ( switchId < NUM_OF_DOORS_AND_CAPS ) + { + if ( isTestingActivated() ) + { + result = TRUE; + switchStatus[ switchId ].ovData = status; + switchStatus[ switchId ].override = OVERRIDE_KEY; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSwitchesStatusOverride function resets the override + * status of a specified switch. + * @details Inputs: none + * @details Outputs: switchStatus + * @param switchId switch index + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetSwitchesStatusOverride( U32 switchId ) +{ + BOOL result = FALSE; + + if ( switchId < NUM_OF_DOORS_AND_CAPS ) + { + if ( isTestingActivated() ) + { + result = TRUE; + switchStatus[ switchId ].override = OVERRIDE_RESET; + switchStatus[ switchId ].ovData = switchStatus[ switchId ].ovInitData; + } + } + + return result; +} + +// ********** private functions ********** + +/*********************************************************************//** + * @brief + * The publishSwitchesData function broadcasts the switches data at the + * publication interval. + * @details Inputs: switchesDataPublicationCounter + * @details Outputs: switchesDataPublicationCounter + * @return none + *************************************************************************/ +static void publishSwitchesData( void ) +{ + if ( ++switchesDataPublicationCounter > getPublishSwitchesDataInterval() ) + { + SWITCHES_DATA_T data; + + data.concentrateCap = (U32)getSwitchStatus( CONCENTRATE_CAP ); + data.dialysateCap = (U32)getSwitchStatus( DIALYSATE_CAP ); + data.fluidDoor = (U32)getSwitchStatus( FLUID_DOOR ); + + switchesDataPublicationCounter = 0; + + broadcastSwitchesData( &data ); + } +} + +/*********************************************************************//** + * @brief + * The getPublishSwitchesDataInterval function returns the data + * publication interval either from the data or from the override. + * @details Inputs: switchesDataPublishInterval + * @details Outputs: none + * @return data publish interval + *************************************************************************/ +static U32 getPublishSwitchesDataInterval( void ) +{ + U32 result = switchesDataPublishInterval.data; + + if ( OVERRIDE_KEY == switchesDataPublishInterval.override ) + { + result = switchesDataPublishInterval.ovData; + } + + return result; +} + +/**@}*/ Index: firmware/App/Controllers/Switches.h =================================================================== diff -u --- firmware/App/Controllers/Switches.h (revision 0) +++ firmware/App/Controllers/Switches.h (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -0,0 +1,55 @@ + +#ifndef APP_CONTROLLERS_SWITCHES_H_ +#define APP_CONTROLLERS_SWITCHES_H_ + +#include "Common.h" + + +/** + * @defgroup Switches Switches + * @brief Switches module. Controls the shunt, acid/bicarb cover and door switches. TODO fill up + * + * @addtogroup NVDataMgmt + * @{ + */ + +// ********** public definitions ********** + +/// DG doors and caps enumeration +typedef enum switches_names +{ + CONCENTRATE_CAP = 0, ///< Concentrate cap + DIALYSATE_CAP, ///< Dialysate cap + FLUID_DOOR, ///< Fluid door + NUM_OF_DOORS_AND_CAPS ///< Number of doors and caps +} SWITCH_T; + +typedef enum switches_status +{ + CLOSED = 0, ///< Closed + OPEN, ///< Open + NUM_OF_SWITCH_STATUS ///< Number of switch status +} SWITCH_STATUS_T; + +/// DG doors and caps data publish structure +typedef struct +{ + U32 concentrateCap; ///< Concentrate cap + U32 dialysateCap; ///< Dialysate cap + U32 fluidDoor; ///< Fluid door +} SWITCHES_DATA_T; + +// ********** public function prototypes ********** + +void initSwitches( void ); + +void execSwitches( void ); + +SWITCH_STATUS_T getSwitchStatus( SWITCH_T switchId ); + +BOOL testSetSwitchesDataPublishIntervalOverride( U32 value ); +BOOL testResetSwitchesDataPublishIntervalOverrid( void ); +BOOL testSetSwitchesStatusOverride( U32 switchId, U32 status ); +BOOL testResetSwitchesStatusOverride( U32 switchId ); + +#endif /* APP_CONTROLLERS_SWITCHES_H_ */ Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r97e0100921ccad633b39b509a93a7237e4d80446 -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 97e0100921ccad633b39b509a93a7237e4d80446) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -308,7 +308,8 @@ /*********************************************************************//** * @brief - * The execTemperatureSensors function executes the temperature sensors' state machine. + * The execTemperatureSensors function executes the temperature sensors' + * state machine. * @details Inputs: tempSensorsExecState * @details Outputs: tempSensorsExecState * @return none @@ -949,8 +950,8 @@ /*********************************************************************//** * @brief - * The testSetMeasuredTemperatureOverride function resets the override value - * of a specified temperature sensor. + * The testSetMeasuredTemperatureOverride function resets the override + * value of a specified temperature sensor. * @details Inputs: tempSensors * @details Outputs: tempSensors * @param sensorIndex temperature sensor index Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r97e0100921ccad633b39b509a93a7237e4d80446 -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 97e0100921ccad633b39b509a93a7237e4d80446) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -1831,4 +1831,16 @@ return ( 0 == noFluidLeakDetected ? FALSE : TRUE ); } +/*********************************************************************//** + * @brief + * The getFPGAGPIOCount function gets the FPGA GPIO register. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA GPIO register value + *************************************************************************/ +U08 getFPGAGPIOCount( void ) +{ + return fpgaSensorReadings.fpgaGPIO; +} + /**@}*/ Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r5f86e35ac3c021b68708457d17d4ef51b20aef9c -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 5f86e35ac3c021b68708457d17d4ef51b20aef9c) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -132,8 +132,10 @@ U08 getFPGAADC2ReadCount( void ); U08 getFPGAADC2ErrorCount( void ); -BOOL noFPGAFluidLeakDetected( void); +BOOL noFPGAFluidLeakDetected( void ); +U08 getFPGAGPIOCount( void ); + /**@}*/ #endif Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r1463d830cefd58198bfc6d4ae3775ad0f2eb1d0b -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 1463d830cefd58198bfc6d4ae3775ad0f2eb1d0b) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -1180,6 +1180,14 @@ handleSetDrainPumpDeltaPressureOverrideRequest( message ); break; + case MSG_ID_DG_SWITCHES_STATUS_OVERRIDE: + handleSetSwitchesStatusOverrideRequest( message ); + break; + + case MSG_ID_DG_SWITCHES_PUBLISH_INTERVAL_OVERRIDE: + handleTestSwitchesPublishIntervalOverrideRequest( message ); + break; + case MSG_ID_DG_SOFTWARE_RESET_REQUEST: handleDGSoftwareResetRequest( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r1463d830cefd58198bfc6d4ae3775ad0f2eb1d0b -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1463d830cefd58198bfc6d4ae3775ad0f2eb1d0b) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -33,6 +33,7 @@ #include "Pressures.h" #include "Reservoirs.h" #include "RTC.h" +#include "Switches.h" #include "SystemComm.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" @@ -1210,6 +1211,33 @@ /*********************************************************************//** * @brief + * The broadcastSwitchesData function sends out switches data. + * @details Inputs: none + * @details Outputs: switches data msg constructed and queued + * @param SWITCHES_DATA_T which is switches msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastSwitchesData( SWITCHES_DATA_T *switchesData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_SWITCHES_DATA; + msg.hdr.payloadLen = sizeof( SWITCHES_DATA_T ); + + memcpy( payloadPtr, switchesData, sizeof( SWITCHES_DATA_T ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_2_UI, ACK_NOT_REQUIRED ); + + return result; +} + +/*********************************************************************//** + * @brief * The sendDGSystemRecord function sends out the DG system record. * @details Inputs: none * @details Outputs: DG system record msg constructed and queued @@ -2320,6 +2348,70 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/************************************************************************* + * @brief + * The handleSetSwitchesStatusOverrideRequest function handles a + * request to override the status of a switch in DG. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetSwitchesStatusOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetSwitchesStatusOverride( payload.index, payload.state.u32 ); + } + else + { + result = testResetSwitchesStatusOverride( payload.index ); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/************************************************************************* + * @brief + * The handleTestSwitchesPublishIntervalOverrideRequest function handles a + * request to override the the switches data publish interval. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestSwitchesPublishIntervalOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetSwitchesDataPublishIntervalOverride( payload.state.u32 ); + } + else + { + result = testResetSwitchesDataPublishIntervalOverrid(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /*********************************************************************//** * @brief * The handleTestDGAccelOverrideRequest function handles a request to Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r1463d830cefd58198bfc6d4ae3775ad0f2eb1d0b -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 1463d830cefd58198bfc6d4ae3775ad0f2eb1d0b) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -31,6 +31,7 @@ #include "NVDataMgmt.h" #include "Reservoirs.h" #include "ROPump.h" +#include "Switches.h" #include "TemperatureSensors.h" #include "Thermistors.h" #include "UVReactors.h" @@ -129,6 +130,9 @@ // MSG_ID_DG_HEAT_DISINFECT_TO_UI_DATA_PUBLISH BOOL broadcastHeatDisinfectData2UI( MODE_HEAT_DISINFECT_UI_DATA_T *heatDisinfectUIData ); +// MSG_ID_DG_SWITCHES_DATA +BOOL broadcastSwitchesData( SWITCHES_DATA_T *switchesData ); + // MSG_ID_DG_COMMAND_RESPONSE void sendCommandResponseMsg( DG_CMD_RESPONSE_T *cmdResponsePtr ); @@ -266,6 +270,12 @@ // MSG_ID_DRAIN_PUMP_SET_DELTA_PRESSURE_OVERRIDE void handleSetDrainPumpDeltaPressureOverrideRequest( MESSAGE_T *message ); +// MSG_ID_DG_SWITCHES_STATUS_OVERRIDE +void handleSetSwitchesStatusOverrideRequest( MESSAGE_T *message ); + +// MSG_ID_DG_SWITCHES_PUBLISH_INTERVAL_OVERRIDE +void handleTestSwitchesPublishIntervalOverrideRequest( MESSAGE_T *message ); + // MSG_ID_CONDUCTIVITY_OVERRIDE void handleTestSetConductivityOverrideRequest( MESSAGE_T *message ); Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -re94cf93f66b011ca994fa768b523a80fd36e00ec -rc55d371408bdf962de525a47bc8541d5b43414a3 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision e94cf93f66b011ca994fa768b523a80fd36e00ec) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) @@ -26,7 +26,8 @@ #include "OperationModes.h" #include "Reservoirs.h" #include "ROPump.h" -#include "RTC.h" +#include "RTC.h" +#include "Switches.h" #include "SystemComm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -106,6 +107,9 @@ // Manage UV reactors controller execUVReactors(); + + // Manage switches monitor + execSwitches(); #endif #ifndef DISABLE_HEATERS_AND_TEMPS