Index: firmware/App/Controllers/ConcentratePumps.c =================================================================== diff -u -re7fe0454b5b2d39009dc784dc8c156856df8bc86 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision e7fe0454b5b2d39009dc784dc8c156856df8bc86) +++ firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -36,7 +36,7 @@ #define CONCENTRATE_PUMP_REVERSE_DIR 0x0 ///< Concentrate pump reverse direction configuration. #define CONCENTRATE_PUMP_SPEED_INCREMENT 2.0F ///< Speed increase (mL/min) when controlling concentrate pump to target step speed. -#define CONCENTRATE_PUMP_MIN_SPEED 3.0F ///< Minimum speed for concentrate pump in mL per min. +#define CONCENTRATE_PUMP_MIN_SPEED 0.1F ///< Minimum speed for concentrate pump in mL per min. #define CONCENTRATE_PUMP_SPD_OUT_OF_RANGE_TOL_WHEN_ON_PCT 0.02F ///< Concentrate pump speed out of range tolerance when on in percentage. #define CONCENTRATE_PUMP_SPD_OUT_OF_RANGE_TOL_WHEN_SLOW_MLPM 1.0F ///< Concentrate pump speed out of range tolerance when slow in mL/min. #define CONCENTRATE_PUMP_LOW_SPEED_THRESHOLD_MLPM 10.0F ///< Concentrate pump low speed threshold in mL/min. @@ -115,6 +115,13 @@ BOOL isConcPumpParkInProgress; ///< Concentrate pump park progress boolean flag (T/F). } CONCENTRATE_PUMP_T; +/// Payload record structure for concentrate pump start request +typedef struct +{ + U32 pumpID; ///< Concentrate pump ID (0:Acid ,1:Bicarb) + F32 speed; ///< Speed range from 0.1 ml/min to 48.0 ml/min. +} CONC_PUMP_START_CMD_PAYLOAD_T; + // ********** private data ********** static U32 concentratePumpMonitorTimerCounter; ///< Timer counter to perform monitor on concentrate pump. @@ -459,8 +466,8 @@ } /* - * If 3 <= speed <= 48 set it - * If speed < 3 set to 0 + * If 0.1 <= speed <= 48 set it + * If speed < 0.1 set to 0 * else speed > 48 set to 48 */ if ( ( CONCENTRATE_PUMP_MIN_SPEED <= targetSpeed_ml_min ) && ( targetSpeed_ml_min <= CONCENTRATE_PUMP_MAX_SPEED ) ) @@ -1140,6 +1147,44 @@ /*********************************************************************//** * @brief + * The testConcentratePumpStartOverride function starts a given concentrate pump + * at mentioned speed/flowrate ( ml/min). + * @details \b Inputs: tester logged in + * @details \b Outputs: concentratePumps[] + * @param message set message from Dialin which includes the concentrate pump to set + * and the state to set the concentratet pump to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testConcentratePumpStartOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( CONC_PUMP_START_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + CONC_PUMP_START_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(CONC_PUMP_START_CMD_PAYLOAD_T) ); + + // Speed range is 0.1 ml/min to 40 ml/min. + if ( ( (CONCENTRATE_PUMPS_T)payload.pumpID < NUM_OF_CONCENTRATE_PUMPS ) && + ( ( payload.speed >= CONCENTRATE_PUMP_MIN_SPEED ) && ( payload.speed <= CONCENTRATE_PUMP_MAX_SPEED ) ) ) + { + setConcentratePumpTargetSpeed( (CONCENTRATE_PUMPS_T)payload.pumpID, payload.speed ); + requestConcentratePumpOn ( (CONCENTRATE_PUMPS_T)payload.pumpID ); + result = TRUE; + } + } + } + + return result; +} + +/*********************************************************************//** + * @brief * The testConcentratePumpParkRequestOverride function overrides the given pump * to park request. * @details \b Inputs: concentratePumps Index: firmware/App/Controllers/ConcentratePumps.h =================================================================== diff -u -re3699de422fa3ba1b8145c4cc44257702c9e336f -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/ConcentratePumps.h (.../ConcentratePumps.h) (revision e3699de422fa3ba1b8145c4cc44257702c9e336f) +++ firmware/App/Controllers/ConcentratePumps.h (.../ConcentratePumps.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -90,8 +90,10 @@ BOOL testConcentratePumpMeasuredSpeedOverride( MESSAGE_T *message ); BOOL testConcentratePumpParkedOverride( MESSAGE_T *message ); BOOL testConcentratePumpParkCmdFaultedOverride( MESSAGE_T *message ); -BOOL testConcentratePumpParkRequestOverride( MESSAGE_T *message ); +BOOL testConcentratePumpStartOverride( MESSAGE_T *message ); // Concentrate pump start request +BOOL testConcentratePumpParkRequestOverride( MESSAGE_T *message ); // Concentrate pump stop/park request + /**@}*/ #endif Index: firmware/App/Controllers/DialysatePumps.c =================================================================== diff -u -rc85d9f0a8023fabdf1cd557965958d225e2b9085 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/DialysatePumps.c (.../DialysatePumps.c) (revision c85d9f0a8023fabdf1cd557965958d225e2b9085) +++ firmware/App/Controllers/DialysatePumps.c (.../DialysatePumps.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -114,6 +114,19 @@ U08 control; ///< Dialysate pump control } DIALYSATE_PUMP_DATA_T; +/// Payload record structure for dialysate pump start request +typedef struct +{ + U32 pumpID; ///< Pump ID Fresh(DGP) : 0, Spent ( SDP) : 1 + U32 rpm; ///< Speed range from 300 to 4500 RPM range +} DIAL_PUMP_START_CMD_PAYLOAD_T; + +/// Payload record structure for dialysate pump stop request +typedef struct +{ + U32 pumpID; ///< Pump ID Fresh(DGP) : 0, Spent ( SDP) : 1 +} DIAL_PUMP_STOP_CMD_PAYLOAD_T; + // ********** private data ********** static U32 dialysatePumpDataPublicationTimerCounter; ///< Used to schedule dialysate pump data publication to CAN bus. @@ -1029,4 +1042,74 @@ return result; } +/*********************************************************************//** + * @brief + * The testDialysatePumpStartOverride function starts a given dialysate pump + * at mentioned RPM. + * @details \b Inputs: tester logged in + * @details \b Outputs: dialysatePumps[] + * @param message set message from Dialin which includes the dialysate pump to set + * and the state to set the dialysate pump to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testDialysatePumpStartOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( DIAL_PUMP_START_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + DIAL_PUMP_START_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(DIAL_PUMP_START_CMD_PAYLOAD_T) ); + + if ( ( (DIALYSATE_PUMPS_T)payload.pumpID < NUM_OF_DIALYSATE_PUMPS ) && + ( ( payload.rpm >= MIN_DIALYSATE_PUMP_RPM ) && ( payload.rpm <= MAX_DIALYSATE_PUMP_RPM ) ) ) + { + setDialysatePumpTargetRPM( (DIALYSATE_PUMPS_T) payload.pumpID, payload.rpm ); + result = TRUE; + } + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testDialysatePumpStopOverride function stops a given dialysate pump. + * @details \b Inputs: tester logged in + * @details \b Outputs: dialysatePumps[] + * @param message set message from Dialin which includes the dialysate pump to set + * and the state to set the dialysate pump to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testDialysatePumpStopOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( DIAL_PUMP_STOP_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + DIAL_PUMP_STOP_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(DIAL_PUMP_STOP_CMD_PAYLOAD_T) ); + + if ( (DIALYSATE_PUMPS_T)payload.pumpID < NUM_OF_DIALYSATE_PUMPS ) + { + signalDialysatePumpHardStop( (DIALYSATE_PUMPS_T)payload.pumpID ); + result = TRUE; + } + } + } + + return result; +} + /**@}*/ Index: firmware/App/Controllers/DialysatePumps.h =================================================================== diff -u -rbbcdba8850dd6f6a53044eca6a5ece611654653a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/DialysatePumps.h (.../DialysatePumps.h) (revision bbcdba8850dd6f6a53044eca6a5ece611654653a) +++ firmware/App/Controllers/DialysatePumps.h (.../DialysatePumps.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -91,6 +91,8 @@ BOOL testDialysatePumpTargetPressureOverride( MESSAGE_T *message ); BOOL testDialysatePumpMeasuredCurrentOverride( MESSAGE_T *message ); BOOL testDialysatePumpMeasuredDirectionOverride( MESSAGE_T *message ); +BOOL testDialysatePumpStartOverride( MESSAGE_T *message ); +BOOL testDialysatePumpStopOverride( MESSAGE_T *message ); /**@}*/ Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rc85d9f0a8023fabdf1cd557965958d225e2b9085 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision c85d9f0a8023fabdf1cd557965958d225e2b9085) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -87,6 +87,19 @@ F32 prevDiaTargetFlowLPM; ///< Heater previous target dialysate flow in L/min. } HEATER_STATUS_T; +/// Payload record structure for heaters start request +typedef struct +{ + U32 heaterID; ///< Heater ID (0: Primary, 1: Trimmer) + F32 temperature; ///< Temperature range ( 10.0 to 90.0 deg ) +} HEATER_START_CMD_PAYLOAD_T; + +/// Payload record structure for heaters stop request +typedef struct +{ + U32 heaterID; ///< Heater ID (0: Primary, 1: Trimmer) +} HEATER_STOP_CMD_PAYLOAD_T; + static HEATER_STATUS_T heatersStatus[ NUM_OF_DD_HEATERS ]; ///< Heaters status. static U32 dataPublicationTimerCounter; ///< Data publication timer counter. static OVERRIDE_U32_T heatersDataPublishInterval = { HEATERS_DATA_PUBLISH_INTERVAL, HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. @@ -662,4 +675,75 @@ return result; } +/*********************************************************************//** + * @brief + * The testHeaterStartOverride function starts a given heater + * at mentioned temperature. + * @details \b Inputs: tester logged in + * @details \b Outputs: heatersStatus[] + * @param message set message from Dialin which includes the heater to set + * and the state to set the heater to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testHeaterStartOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( HEATER_START_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + HEATER_START_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(HEATER_START_CMD_PAYLOAD_T) ); + + if ( ( (DD_HEATERS_T)payload.heaterID < NUM_OF_DD_HEATERS ) && + ( ( payload.temperature >= HEATER_TARGET_TEMPERATURE_MIN ) && ( payload.temperature <= HEATER_TARGET_TEMPERATURE_MAX ) ) ) + { + setHeaterTargetTemperature( (DD_HEATERS_T)payload.heaterID, payload.temperature ); + startHeater( (DD_HEATERS_T)payload.heaterID ); + result = TRUE; + } + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testHeaterStopOverride function stops a given heater. + * @details \b Inputs: tester logged in + * @details \b Outputs: heatersStatus[] + * @param message set message from Dialin which includes the heater to set + * and the state to set the heater to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testHeaterStopOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( HEATER_STOP_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + HEATER_STOP_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(HEATER_STOP_CMD_PAYLOAD_T) ); + + if ( (DD_HEATERS_T)payload.heaterID < NUM_OF_DD_HEATERS ) + { + stopHeater( (DD_HEATERS_T)payload.heaterID ); + result = TRUE; + } + } + } + + return result; +} + /**@}*/ Index: firmware/App/Controllers/Heaters.h =================================================================== diff -u -rc85d9f0a8023fabdf1cd557965958d225e2b9085 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/Heaters.h (.../Heaters.h) (revision c85d9f0a8023fabdf1cd557965958d225e2b9085) +++ firmware/App/Controllers/Heaters.h (.../Heaters.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -69,6 +69,8 @@ BOOL testHeatersDataPublishIntervalOverride( MESSAGE_T *message ); BOOL testHeaterDutyCycleOverride( MESSAGE_T *message ); +BOOL testHeaterStartOverride( MESSAGE_T *message ); +BOOL testHeaterStopOverride( MESSAGE_T *message ); /**@}*/ Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r48c75a394c56b82886760e9a136b638edecf7572 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 48c75a394c56b82886760e9a136b638edecf7572) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -39,6 +39,13 @@ #define VALVES_STATE_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval ( ms / task time) at which valves states are published on CAN bus. #define DATA_PUBLISH_COUNTER_START_COUNT 50 ///< Data publish counter start count. + +/// Payload record structure for valve open/close request +typedef struct +{ + U32 valveID; ///< ValveID ( valid range 0 to 28 ) + U32 valveState; ///< Valve state ( Open : 0, closed :1) +} VALVE_CMD_PAYLOAD_T; // ********** private data ********** @@ -488,5 +495,41 @@ return result; } + +/*********************************************************************//** + * @brief + * The testValveOpenCloseStateOverride function overrides the value of the + * specified valve with a given value. + * @details \b Inputs: tester logged in + * @details \b Outputs: valveStates[] + * @param message set message from Dialin which includes the valve Id to set + * and the state to set the valves to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testValveOpenCloseStateOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( VALVE_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + VALVE_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(VALVE_CMD_PAYLOAD_T) ); + + if ( ( (VALVES_T)payload.valveID < NUM_OF_VALVES ) && + ( (VALVE_STATE_NAMES_T)payload.valveState < NUM_OF_VALVE_STATES ) ) + { + setValveState( (VALVES_T)payload.valveID, (VALVE_STATE_NAMES_T)payload.valveState ); + result = TRUE; + } + } + } + + return result; +} /**@}*/ Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -r48c75a394c56b82886760e9a136b638edecf7572 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision 48c75a394c56b82886760e9a136b638edecf7572) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -33,38 +33,38 @@ typedef enum Valves { FIRST_HYD_VALVE = 0, ///< Start of Hydraulics valve group - VDR = FIRST_HYD_VALVE, ///< Valve Drain - VTD, ///< Valve Thermal Disinfect - VHB, ///< Valve Hydraulics Bypass - VRP, ///< Valve Rinse Port - VHO, ///< Valve Hydraulics Outlet - VDB1, ///< Valve DryBcarb Inlet - VP1, ///< Valve Purge 1 - VPT, ///< Valve Pressure Test - VDB2, ///< Valve Dialyzer Bypass - VDI, ///< Valve Dialyzer Inlet - VDO, ///< Valve Dialyzer Outlet - VP2, ///< Valve Dialysate Out Purge 2 - VHI, ///< Valve Hydraulics Inlet - VWI, ///< Valve Water Inlet + VDR = FIRST_HYD_VALVE, ///< Valve Drain (D53) + VTD, ///< Valve Thermal Disinfect (D52) + VHB, ///< Valve Hydraulics Bypass (D8) + VRP, ///< Valve Rinse Port (D54) + VHO, ///< Valve Hydraulics Outlet (D14) + VDB1, ///< Valve DryBcarb Inlet (D65) + VP1, ///< Valve Purge 1 (D64) + VPT, ///< Valve Pressure Test (D31) + VDB2, ///< Valve Dialyzer Bypass (D34) + VDI, ///< Valve Dialyzer Inlet (D35) + VDO, ///< Valve Dialyzer Outlet (D40) + VP2, ///< Valve Dialysate Out Purge 2 (D47) + VHI, ///< Valve Hydraulics Inlet (D3) + VWI, ///< Valve Water Inlet (M4) LAST_HYD_VALVE = VWI, ///< End of Hydraulics valve of group RSRVD_SPACE1, ///< This space has been reserved RSRVD_SPACE2, ///< This space has been reserved FIRST_BC_VALVE, ///< Start of Balancing Chamber valve group - BCV1 = FIRST_BC_VALVE, ///< Balancing chamber Valve 1 - BCV2, ///< Balancing chamber Valve 2 - BCV3, ///< Balancing chamber Valve 3 - BCV4, ///< Balancing chamber Valve 4 - BCV5, ///< Balancing chamber Valve 5 - BCV6, ///< Balancing chamber Valve 6 - BCV7, ///< Balancing chamber Valve 7 - BCV8, ///< Balancing chamber Valve 8 + BCV1 = FIRST_BC_VALVE, ///< Balancing chamber Valve 1 (D23) + BCV2, ///< Balancing chamber Valve 2 (D19) + BCV3, ///< Balancing chamber Valve 3 (D25) + BCV4, ///< Balancing chamber Valve 4 (D21) + BCV5, ///< Balancing chamber Valve 5 (D24) + BCV6, ///< Balancing chamber Valve 6 (D20) + BCV7, ///< Balancing chamber Valve 7 (D26) + BCV8, ///< Balancing chamber Valve 8 (D22) LAST_BC_VALVE = BCV8, ///< End of Balancing Chamber valve group FIRST_UF_VALVE, ///< Start of Ultrafiltration valve group - UFI1 = FIRST_UF_VALVE, ///< Ultrafiltration Valve 1 Inlet - UFI2, ///< Ultrafiltration Valve 2 Inlet - UFO1, ///< Ultrafiltration Valve 1 Outlet - UFO2, ///< Ultrafiltration Valve 2 Outlet + UFI1 = FIRST_UF_VALVE, ///< Ultrafiltration Valve 1 Inlet (D69) + UFI2, ///< Ultrafiltration Valve 2 Inlet (D71) + UFO1, ///< Ultrafiltration Valve 1 Outlet (D70) + UFO2, ///< Ultrafiltration Valve 2 Outlet (D72) LAST_UF_VALVE = UFO2, ///< End of Ultrafiltration valve group NUM_OF_VALVES ///< Number of valves } VALVES_T; @@ -100,6 +100,7 @@ BOOL testValvesStatesPublishIntervalOverride( MESSAGE_T *message ); BOOL testValveStateOverride( MESSAGE_T *message ); BOOL testValveSensedStateOverride( MESSAGE_T *message ); +BOOL testValveOpenCloseStateOverride( MESSAGE_T *message ); /**@}*/ Index: firmware/App/Modes/BalancingChamber.c =================================================================== diff -u --- firmware/App/Modes/BalancingChamber.c (revision 0) +++ firmware/App/Modes/BalancingChamber.c (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -0,0 +1,706 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file BalancingChamber.c +* +* @author (last) Vinayakam Mani +* @date (last) 24-Oct-2024 +* +* @author (original) Vinayakam Mani +* @date (original) 24-Oct-2024 +* +***************************************************************************/ + +#include "BalancingChamber.h" +#include "Conductivity.h" +#include "ConcentratePumps.h" +#include "FpgaDD.h" +#include "OperationModes.h" +#include "Pressure.h" +#include "Temperature.h" +#include "TDInterface.h" +#include "TaskGeneral.h" +#include "Valves.h" + +/** + * @addtogroup BalancingChamber + * @{ + */ + +// ********** private definitions ********** +#define BAL_CHAMBER_FILL_VOLUME_ML 30.0 ///< Balancing chamber fill/drain volume per batch operation. +#define FRESH_DIAL_PRESSURE_MIN_PSIG 23.0 ///< Minimum fresh dialysate pressure (PDf) limit for balancing chamber fill operations. +#define FRESH_DIAL_PRESSURE_MAX_PSIG 25.0 ///< Maximum fresh dialysate pressure (PDf) limit for balancing chamber fill operations. +#define SPENT_DIAL_PRESSURE_MIN_PSIG 29.0 ///< Minimum spent dialysate pressure (PDs) limit for balancing chamber fill operations. +#define SPENT_DIAL_PRESSURE_MAX_PSIG 30.0 ///< Maximum spent dialysate pressure (PDs) limit for balancing chamber fill operations. +#define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. + +// ********** private data ********** + +static BAL_CHAMBER_EXEC_STATE_T balChamberExecState = BAL_CHAMBER_STATE_START; ///< Current balancing chamber executive state. +static OVERRIDE_F32_T balChamberSwitchingFreq; ///< Balancing chamber switching rate based on the dialysate flow rate ( overrideable) +static U32 balChamberSwitchingPeriod = 0; ///< Periodic balancing chamber switching time in task interval count. +static U32 currentBalChamberSwitchingCounter = 0; ///< Counter (in task interval) to monitor the timing spent during balancing chamber fill/drain operation. +static BOOL isBalChamberFillInProgress = FALSE; ///< Flag indicating balancing chamber fill/drain is in progress. +static BOOL isPressureStalbilizedDuringFill = FALSE; ///< Flag indicating that the pressure is stablized due to fill complete. +static BOOL readyToDeliverDialysate = FALSE; ///< Flag indicating whether ready to deliver dialysate or not. +static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) +static BAL_CHAMBER_SW_STATE_T balChamberSWState = BAL_CHAMBER_SW_STATE1; ///< Current balancing chamber switching state ( state 1 or state 2). +static U32 balChamberDataPublicationTimerCounter; ///< Used to schedule balancing chamber data publication to CAN bus. +static OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. + +// ********** private function prototypes ********** + +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl(void); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd(); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd(); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberDialDeliveryBypassCheck( void ); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberDialDeliveryPause( void ); +static void publishBalChamberData( void ); +static U32 getBalChamberDataPublishInterval( void ); + +/*********************************************************************//** + * @brief + * The initBalanceChamber function initializes the balancing chamber unit. + * @details \b Inputs: none + * @details \b Outputs: unit variables initialized + * @return none + *************************************************************************/ +void initBalanceChamber( void ) +{ + balChamberExecState = BAL_CHAMBER_STATE_START; + balChamberSWState = BAL_CHAMBER_SW_STATE1; + balChamberSwitchingFreq.data = 0.0F; + balChamberSwitchingFreq.ovData = 0.0F; + balChamberSwitchingFreq.ovInitData = 0.0F; + balChamberSwitchingFreq.override = OVERRIDE_RESET; + isDialDeliveryInProgress.data = FALSE; + isDialDeliveryInProgress.ovData = FALSE; + isDialDeliveryInProgress.ovInitData = FALSE; + isDialDeliveryInProgress.override = OVERRIDE_RESET; + balChamberDataPublishInterval.data = BAL_CHAMBER_DATA_PUBLISH_INTERVAL; + balChamberDataPublishInterval.ovData = BAL_CHAMBER_DATA_PUBLISH_INTERVAL; + balChamberDataPublishInterval.ovInitData = 0; + balChamberDataPublishInterval.override = OVERRIDE_RESET; + balChamberSwitchingPeriod = 0; + isBalChamberFillInProgress = FALSE; + currentBalChamberSwitchingCounter = 0; + isPressureStalbilizedDuringFill = FALSE; + readyToDeliverDialysate = FALSE; + balChamberDataPublicationTimerCounter = 0; +} + +/*********************************************************************//** + * @brief + * The transitionToBalChamberFill function prepares for transition to + * balancing chamber fill/switching operations. + * @details \b Inputs: none + * @details \b Outputs: balChamberSwitchingFreq ,balChamberSwitchingPeriod + * @return none + *************************************************************************/ +void transitionToBalChamberFill( void ) +{ + initBalanceChamber(); + updateBalChamberSwitchingPeriod(); +} + +/*********************************************************************//** + * @brief + * The updateBalChamberSwitchingPeriod function updates the periodic + * balancing chamber switching time based on the dialysis flow rate. + * @details \b Inputs: Dialysis flow rate. + * @details \b Outputs: balChamberSwitchingFreq,balChamberSwitchingPeriod + * @return none + *************************************************************************/ +void updateBalChamberSwitchingPeriod( void ) +{ + // update the balancing chamber switching frequency + balChamberSwitchingFreq.data = getTDDialysateFlowrate() / BAL_CHAMBER_FILL_VOLUME_ML; + + //update the switching period in task interval for balancing chamber fill timeout check + balChamberSwitchingPeriod = (U32)( (F32)SEC_PER_MIN / getBalChamberSwitchingFreq() * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); + + // finish the balancing chamber fill 50 ms prior completing the regular cycle time. + balChamberSwitchingPeriod -= 1; +} + +/*********************************************************************//** + * @brief + * The execBalancingChamber function executes the balancing chamber state machine. + * @details \b Inputs: balChamberExecState + * @details \b Outputs: balChamberExecState + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong balancing chamber state invoked. + * @return current state. + *************************************************************************/ +U32 execBalancingChamber( void ) +{ + // Increment counter during fill time only + if ( TRUE == isBalChamberFillInProgress ) + { + currentBalChamberSwitchingCounter += 1; + } + + // execute current balancing chamber exec state + switch ( balChamberExecState ) + { + case BAL_CHAMBER_STATE_START: + balChamberExecState = BAL_CHAMBER_STATE1_FILL_START; + break; + + case BAL_CHAMBER_STATE1_FILL_START: + balChamberExecState = handleBalChamberState1FillStart(); + break; + + case BAL_CHAMBER_STATE1_BICARB_ACID_DOSING_CNTRL: + balChamberExecState = handleBalChamberConcentrateControl(); + break; + + case BAL_CHAMBER_STATE1_FILL_END: + balChamberExecState = handleBalChamberState1FillEnd(); + break; + + case BAL_CHAMBER_STATE2_FILL_START: + balChamberExecState = handleBalChamberState2FillStart(); + break; + + case BAL_CHAMBER_STATE2_BICARB_ACID_DOSING_CNTRL: + balChamberExecState = handleBalChamberConcentrateControl(); + break; + + case BAL_CHAMBER_STATE2_FILL_END: + balChamberExecState = handleBalChamberState2FillEnd(); + break; + + case BAL_CAHMBER_DIAL_DELVIERY_BYPASS_CHECK: + balChamberExecState = handleBalChamberDialDeliveryBypassCheck(); + break; + + case BAL_CHAMBER_DIAL_DELIVERY_PAUSE: + balChamberExecState = handleBalChamberDialDeliveryPause(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BAL_CHAMBER_INVALID_EXEC_STATE, balChamberExecState ) + balChamberExecState = BAL_CHAMBER_STATE_START; + break; + } + + //Publish balancing chamber data + publishBalChamberData(); + + return balChamberExecState; +} + +/*********************************************************************//** + * @brief + * The valveControlForBCState1FillStart function actuates the valve combination + * for state 1 fill/drain process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static void valveControlForBCState1FillStart( void ) +{ + // Close balancing chamber valve combinations V1,V6 and V4,V7 + setValveState( BCV1, VALVE_STATE_CLOSED ); + setValveState( BCV6, VALVE_STATE_CLOSED ); + setValveState( BCV4, VALVE_STATE_CLOSED ); + setValveState( BCV7, VALVE_STATE_CLOSED ); + + //Open balancing chamber valve combinations V2,V5 and V3,V8 + setValveState( BCV2, VALVE_STATE_OPEN ); + setValveState( BCV5, VALVE_STATE_OPEN ); + setValveState( BCV3, VALVE_STATE_OPEN ); + setValveState( BCV8, VALVE_STATE_OPEN ); +} + +/*********************************************************************//** + * @brief + * The valveControlForBCState1FillEnd function closes the valve opened + * for state 1 fill/drain process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static void valveControlForBCState1FillEnd( void ) +{ + //Close balancing chamber valve combinations V2,V5 and V3,V8 + setValveState( BCV2, VALVE_STATE_CLOSED ); + setValveState( BCV5, VALVE_STATE_CLOSED ); + setValveState( BCV3, VALVE_STATE_CLOSED ); + setValveState( BCV8, VALVE_STATE_CLOSED ); +} + +/*********************************************************************//** + * @brief + * The valveControlForBCState2FillStart function actuates the valve combination + * for state 2 fill/drain process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static void valveControlForBCState2FillStart( void ) +{ + //Close balancing chamber valve combinations V2,V5 and V3,V8 + setValveState( BCV2, VALVE_STATE_CLOSED ); + setValveState( BCV5, VALVE_STATE_CLOSED ); + setValveState( BCV3, VALVE_STATE_CLOSED ); + setValveState( BCV8, VALVE_STATE_CLOSED ); + + // Open balancing chamber valve combinations V1,V6 and V4,V7 + setValveState( BCV1, VALVE_STATE_OPEN ); + setValveState( BCV6, VALVE_STATE_OPEN ); + setValveState( BCV4, VALVE_STATE_OPEN ); + setValveState( BCV7, VALVE_STATE_OPEN ); +} + +/*********************************************************************//** + * @brief + * The valveControlForBCState2FillEnd function closes the valve opened + * for state 2 fill/drain process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static void valveControlForBCState2FillEnd( void ) +{ + // Close balancing chamber valve combinations V1,V6 and V4,V7 + setValveState( BCV1, VALVE_STATE_CLOSED ); + setValveState( BCV6, VALVE_STATE_CLOSED ); + setValveState( BCV4, VALVE_STATE_CLOSED ); + setValveState( BCV7, VALVE_STATE_CLOSED ); +} + +/*********************************************************************//** + * @brief + * The valveControlForBCClosedState function closes the all balancing + * chamber valves. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +void valveControlForBCClosedState( void ) +{ + // Close balancing chamber valve combinations V1,V6 and V4,V7 + setValveState( BCV1, VALVE_STATE_CLOSED ); + setValveState( BCV6, VALVE_STATE_CLOSED ); + setValveState( BCV4, VALVE_STATE_CLOSED ); + setValveState( BCV7, VALVE_STATE_CLOSED ); + + //Close balancing chamber valve combinations V2,V5 and V3,V8 + setValveState( BCV2, VALVE_STATE_CLOSED ); + setValveState( BCV5, VALVE_STATE_CLOSED ); + setValveState( BCV3, VALVE_STATE_CLOSED ); + setValveState( BCV8, VALVE_STATE_CLOSED ); +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState1FillStart function handles the balancing chamber + * state 1 fill and time to fill chamber counter being updated. + * @details \b Inputs: Pressure + * @details \b Outputs: valve states + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_START; + currentBalChamberSwitchingCounter = 0; + isBalChamberFillInProgress = FALSE; + isPressureStalbilizedDuringFill = FALSE; + balChamberSWState = BAL_CHAMBER_SW_STATE1; + + F32 freshDialPressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); + F32 spentDialPressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + + // Check fresh and spent dialysate pressure in range + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + { + //Valve control for state 1 fill + valveControlForBCState1FillStart(); + + // Update fill status flag to true + isBalChamberFillInProgress = TRUE; + currentBalChamberSwitchingCounter += 1; + + state = BAL_CHAMBER_STATE1_BICARB_ACID_DOSING_CNTRL; + } + else + { + //TODO : Alarm handling when pressure is not in range + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberConcentrateControl function handles the Acid and Bicarb + * concentrate doisng and checks the conductivity of the dialysate for the treatment. + * @details \b Inputs: balChamberSWState , Concentrate volume + * @details \b Outputs: state + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state; + // TODO : start acid and bicarb pump with the expected quantity + + // On completion of dosing, transition to next state based on the current switching state + if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) + { + state = BAL_CHAMBER_STATE1_FILL_END; + } + else + { + state = BAL_CHAMBER_STATE2_FILL_END; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState1FillEnd function check for the balancing chamber + * fill complete and close the currently opened valves. + * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure + * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_END; + + F32 freshDialPressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); + F32 spentDialPressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + + // Check fresh and spent dialysate pressure back in range to indicate fill complete. + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + } + + // Check switching cycle time or pressure check for valve closure + if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + ( TRUE == isPressureStalbilizedDuringFill ) ) + { + // close the state 1 opened valves + valveControlForBCState1FillEnd(); + } + + // On completion of cycle time, transition to next state + if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) + { + isBalChamberFillInProgress = FALSE; + state = BAL_CHAMBER_STATE2_FILL_START; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState2FillStart function handles the balancing chamber + * state 2 fill and time to fill chamber counter being updated. + * @details \b Inputs: fresh and spent dialysate pressure + * @details \b Outputs: valve states + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_FILL_START; + currentBalChamberSwitchingCounter = 0; + isBalChamberFillInProgress = FALSE; + isPressureStalbilizedDuringFill = FALSE; + balChamberSWState = BAL_CHAMBER_SW_STATE2; + + F32 freshDialPressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); + F32 spentDialPressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + + // Check fresh and spent dialysate pressure in range + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + { + // Valve control for state 2 fill + valveControlForBCState2FillStart(); + + // Update fill status flag to true + isBalChamberFillInProgress = TRUE; + currentBalChamberSwitchingCounter += 1; + + state = BAL_CHAMBER_STATE2_BICARB_ACID_DOSING_CNTRL; + } + else + { + //TODO : Alarm handling when pressure is not in range + } + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState2FillEnd function check for the balancing chamber + * fill complete and close the currently opened valves. + * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure + * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_FILL_END; + + F32 freshDialPressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); + F32 spentDialPressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + + // Check fresh and spent dialysate pressure back in range to indicate fill complete. + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + } + + // Check switching cycle time or pressure check for valve closure + if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + ( TRUE == isPressureStalbilizedDuringFill ) ) + { + // close the valves + valveControlForBCState2FillEnd(); + } + + // On completion of cycle time, transition to next state + if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) && + ( TRUE == getDialDeliveryProgressStatus() ) ) + { + // do periodic dialysate delivery + state = BAL_CHAMBER_STATE1_FILL_START; + isBalChamberFillInProgress = FALSE; + } + else if( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) + { + state = BAL_CAHMBER_DIAL_DELVIERY_BYPASS_CHECK; + isBalChamberFillInProgress = FALSE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberDialDeliveryBypassCheck function decides closing the + * bypass valve and open up the dialyzer valves for treatment. + * @details \b Inputs: readyToDeliverDialysate + * @details \b Outputs: readyToDeliverDialysate,isDialDeliveryInProgress + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberDialDeliveryBypassCheck( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_START; + + // TODO: Make sure the pressure, temperature and conductivity in range + // Also TD confirms the delivery of dialysate. + readyToDeliverDialysate = TRUE; + + if ( TRUE == readyToDeliverDialysate ) + { + // Close By pass valve and Open VDI, VDo valves + setValveState( VDB2, VALVE_STATE_CLOSED ); + setValveState( VDI, VALVE_STATE_OPEN ); + setValveState( VDO, VALVE_STATE_OPEN ); + + // update dialysate delivery is in progress. + isDialDeliveryInProgress.data = TRUE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberDialDeliveryPause function pauses the dialysate + * delivery due to alarm conditions. + * @details \b Inputs: none + * @details \b Outputs: none + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberDialDeliveryPause( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_DIAL_DELIVERY_PAUSE; + + //TODO : handle any pause state actions + + return state; +} + +/*********************************************************************//** + * @brief + * The getCurrentBalancingChamberExecState function returns the current state + * of the balancing chamber. + * @details \b Inputs: balChamberExecState + * @details \b Outputs: none + * @return the current state of balancing chamber states. + *************************************************************************/ +BAL_CHAMBER_EXEC_STATE_T getCurrentBalancingChamberExecState( void ) +{ + return balChamberExecState; +} + +/*********************************************************************//** + * @brief + * The getBalChamberSwitchingFreq function gets the balancing chamber switching + * frequency value. + * @details \b Inputs: balChamberSwitchingFreq + * @details \b Outputs: none + * @return balancing chamber switching frequency + *************************************************************************/ +F32 getBalChamberSwitchingFreq( void ) +{ + F32 result = balChamberSwitchingFreq.data; + + if ( OVERRIDE_KEY == balChamberSwitchingFreq.override ) + { + result = balChamberSwitchingFreq.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getDialDeliveryProgressStatus function gets the dialysate delivery + * progress status. + * @details \b Inputs: isDialDeliveryInProgress + * @details \b Outputs: none + * @return the current status of dialysate delivery + *************************************************************************/ +U32 getDialDeliveryProgressStatus( void ) +{ + U32 result = isDialDeliveryInProgress.data; + + if ( OVERRIDE_KEY == isDialDeliveryInProgress.override ) + { + result = isDialDeliveryInProgress.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBalChamberDataPublishInterval function gets the balancing chamber + * data publish interval. + * @details \b Inputs: balChamberDataPublishInterval + * @details \b Outputs: none + * @return the interval at balancing chamber data being published. + *************************************************************************/ +static U32 getBalChamberDataPublishInterval( void ) +{ + U32 result = balChamberDataPublishInterval.data; + + if ( OVERRIDE_KEY == balChamberDataPublishInterval.override ) + { + result = balChamberDataPublishInterval.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The publishBalChamberData function broadcasts the balancing chamber + * execution data at defined interval. + * @details \b Inputs: balChamberDataPublicationTimerCounter + * @details \b Outputs: DD balancing chamber data broadcast message sent + * @details \b Message \Sent: MSG_ID_DD_BAL_CHAMBER_DATA to publish the balancing + * chamber data. + * @return none + *************************************************************************/ +static void publishBalChamberData( void ) +{ + if ( ++balChamberDataPublicationTimerCounter >= getBalChamberDataPublishInterval() ) + { + BAL_CHAMBER_DATA_T data; + + data.balChamberExecState = (U32)balChamberExecState; + data.balChamberSWState = (U32)balChamberSWState; + data.balChamberSWFreq = getBalChamberSwitchingFreq(); + data.isDialDelInProgress = getDialDeliveryProgressStatus(); + data.balChamberSwPeriod = balChamberSwitchingPeriod; + data.isBalChamberFillInProgress = isBalChamberFillInProgress; + data.currentBalChamberSwitchingCounter = currentBalChamberSwitchingCounter; + data.isPressureStalbilizedDuringFill = isPressureStalbilizedDuringFill; + data.readyToDeliverDialysate = readyToDeliverDialysate; + + broadcastData( MSG_ID_DD_BAL_CHAMBER_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( BAL_CHAMBER_DATA_T ) ); + + balChamberDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testDDBalChamberDataPublishIntervalOverride function overrides the + * DD balancing chamber data publish interval. + * @details \b Inputs: balChamberDataPublishInterval + * @details \b Outputs: balChamberDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the DD balancing chamber data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDDBalChamberDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &balChamberDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDialDeliveryInProgressOverride function sets the override value + * of the dialysate delivery In progress flag. + * @details Inputs: isDialDeliveryInProgress + * @details Outputs: isDialDeliveryInProgress + * @param message Override message from Dialin which includes the override + * value to override the dialysate delivery in progress flag. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &isDialDeliveryInProgress, 0, TRUE ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testBalChamberSwFreqOverride function sets the override value + * of the balancing chamber switching frequency. + * @details Inputs: balChamberSwitchingFreq + * @details Outputs: balChamberSwitchingFreq + * @param message Override message from Dialin which includes the override + * value to override the balancing chamber switching frequency. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testBalChamberSwFreqOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &balChamberSwitchingFreq ); + + return result; +} + +/**@}*/ Index: firmware/App/Modes/BalancingChamber.h =================================================================== diff -u --- firmware/App/Modes/BalancingChamber.h (revision 0) +++ firmware/App/Modes/BalancingChamber.h (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -0,0 +1,66 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file BalancingChamber.h +* +* @author (last) Vinayakam Mani +* @date (last) 06-Aug-2024 +* +* @author (original) Vinayakam Mani +* @date (original) 06-Aug-2024 +* +***************************************************************************/ + +#ifndef __BAL_CHAMBER_H__ +#define __BAL_CHAMBER_H__ + +#include "DDCommon.h" +#include "DDDefs.h" + +/** + * @defgroup BalancingChamber BalancingChamber + * @brief Balancing Chamber unit. Performs balancing chamber functions via a state machine. + * + * @addtogroup BalancingChamber + * @{ + */ + +// ********** public definitions ********** + +/// balancing chamber data structure +typedef struct +{ + U32 balChamberExecState; ///< Balancing chamber execution state + U32 balChamberSWState; ///< Balancing chamber switching state (state 1 or state 2) + F32 balChamberSWFreq; ///< Balancing chamber switching frequency + U32 isDialDelInProgress; ///< Whether Dialysate Delivery in progress or not + U32 balChamberSwPeriod; ///< Balancing chamber switching period + U32 isBalChamberFillInProgress; ///< Whether balancing chamber fill in progress or not + U32 currentBalChamberSwitchingCounter; ///< Current balancing chamber switching counter + U32 isPressureStalbilizedDuringFill; ///< Whether pressure stabilized during fill or not + U32 readyToDeliverDialysate; ///< Ready to deliver dialysate or not +} BAL_CHAMBER_DATA_T; + +// ********** public function prototypes ********** + +void initBalanceChamber( void ); // Initialize balancing chamber unit +void transitionToBalChamberFill( void ); // Prepares for transition to balancing chamber execution +U32 execBalancingChamber( void ); // Execute the balancing chamber state machine + +void updateBalChamberSwitchingPeriod( void ); // Update the balancing chamber switching period +BAL_CHAMBER_EXEC_STATE_T getCurrentBalancingChamberExecState( void ); // Get the current state of the balancing chamber execution +F32 getBalChamberSwitchingFreq( void ); // Get the balancing chamber switching frequency +U32 getDialDeliveryProgressStatus( void ); // Get the dialysate delivery in progress status +void valveControlForBCClosedState( void ); // Closes all balancing chamber valves + +BOOL testDDBalChamberDataPublishIntervalOverride( MESSAGE_T *message ); // To override the balancing chamber data publish interval +BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ); // To override the dialysate delivery in progress flag +BOOL testBalChamberSwFreqOverride( MESSAGE_T *message ); // To override the balancing chamber switching frequency + +/**@}*/ + +#endif Index: firmware/App/Modes/ModeFault.c =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeFault.c (.../ModeFault.c) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/ModeFault.c (.../ModeFault.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -15,9 +15,12 @@ * ***************************************************************************/ -#include "OperationModes.h" +#include "ConcentratePumps.h" +#include "DialysatePumps.h" +#include "Heaters.h" #include "ModeFault.h" #include "Messaging.h" +#include "OperationModes.h" #include "Utilities.h" #include "Valves.h" @@ -62,7 +65,7 @@ *************************************************************************/ U32 transitionToFaultMode( void ) { - //deenergizeActuators( PARK_CONC_PUMPS ); + deenergizeActuators( PARK_CONC_PUMPS ); initFaultMode(); setCurrentSubState( NO_SUB_STATE ); @@ -85,7 +88,7 @@ *************************************************************************/ U32 execFaultMode( void ) { -// deenergizeActuators( NO_PARK_CONC_PUMPS ); + deenergizeActuators( NO_PARK_CONC_PUMPS ); // execute current fault state switch ( faultState ) @@ -156,6 +159,7 @@ setValveStateDelayed( VDO, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VP2, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); setValveStateDelayed( VHI, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); + setValveStateDelayed( VWI, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); // De-energize Balancing chamber and Ultrafiltration valves for ( i = FIRST_BC_VALVE; i <= LAST_BC_VALVE; i++ ) @@ -168,11 +172,12 @@ setValveStateDelayed( (VALVES_T)i, VALVE_STATE_CLOSED, DELAY_VALVE_MS ); } -// requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, parkPumps ); -// requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, parkPumps ); -// signalROPumpHardStop(); -// stopHeater( DD_PRIMARY_HEATER ); -// stopHeater( DD_TRIMMER_HEATER ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, parkPumps ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, parkPumps ); + signalDialysatePumpHardStop( FRESH_DIALYSATE_PUMP ); + signalDialysatePumpHardStop( SPENT_DIALYSATE_PUMP ); + stopHeater( DD_PRIMARY_HEATER ); + stopHeater( DD_TRIMMER_HEATER ); } /*********************************************************************//** Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u --- firmware/App/Modes/ModeGenDialysate.c (revision 0) +++ firmware/App/Modes/ModeGenDialysate.c (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -0,0 +1,573 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file ModeGenDialysate.c +* +* @author (last) Vinayakam Mani +* @date (last) 30-Oct-2024 +* +* @author (original) Vinayakam Mani +* @date (original) 30-Oct-2024 +* +***************************************************************************/ + +#include "BalancingChamber.h" +#include "ConcentratePumps.h" +#include "Conductivity.h" +#include "DialysatePumps.h" +#include "FpgaDD.h" +#include "Level.h" +#include "ModeGenDialysate.h" +#include "ModeStandby.h" +#include "OperationModes.h" +#include "Pressure.h" +#include "TaskGeneral.h" +#include "Temperature.h" +#include "Timers.h" +#include "Valves.h" + +/** + * @addtogroup DDGenDialysateMode + * @{ + */ + +// ********** private definitions ********** + +#define FRESH_DIAL_PUMP_INITIAL_RPM 2500 ///< Nominal RPM target for fresh dialysate pump to maintain required pressure. +#define SPENT_DIAL_PUMP_INITIAL_RPM 2500 ///< Nominal RPM target for spent dialysate pump to maintain required pressure. +#define HYD_CHAMBER_FLUID_TEMP_C_MIN 35.0 ///< Minimum hydraulics fluid temperature in deg celcius +#define HYD_CHAMBER_PRES_CHECK_TIME_OUT ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< Time out period when hydraulics chamber pressure check initiated +#define SPENT_DIAL_PRES_CHECK_TIME_OUT ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< Time out period when spent dialysate pressure check initiated +#define HYD_CHAMBER_TARGET_NEG_PRESS_MIN_PSI (-11.7877F) ///< Hydraulics chamber minimum negative pressure(D9/PHo) in psi. +#define HYD_CHAMBER_TARGET_NEG_PRESS_MAX_PSI (-12.2789F) ///< Hydraulics chamber maximum negative pressure(D9/PHo) in psi. +#define HYD_CHAMBER_TARGET_POS_PRESS_MIN_PSI ( 23.0F ) ///< Hydraulics chamber or fresh dialysate minimum positive pressure(D18/PDf) in psi. +#define HYD_CHAMBER_TARGET_POS_PRESS_MAX_PSI ( 25.0F ) ///< Hydraulics chamber or fresh dialysate maximum positive pressure(D18/PDf) in psi. +#define SPENT_DIAL_TARGET_POS_PRESS_MIN_PSI ( 29.0F ) ///< Spent dialysate minimum positive pressure(D51/PDs) in psi. +#define SPENT_DIAL_TARGET_POS_PRESS_MAX_PSI ( 30.0F ) ///< Spent dialysate maximum positive pressure(D18/PDs) in psi. +#define GEN_DIALYSATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen dialysate mode data published. + +// ********** private data ********** + +static DD_GEND_MODE_STATE_T genDialysateState = DD_GEND_STATE_START; ///< Currently active gen dialysate state. +//static OVERRIDE_F32_T targetHydChamberFluidTemp; ///< Target hydraulics chamber fluid temperature. +//static BOOL isHydChamberTempinRange = FALSE; ///< Flag indicating hydraulics chamber water temperature is in range. +static U32 hydChamberPressureCheckStartTimeMS; ///< Current time when hydraulics chamber pressure check satrted in milliseconds. +static U32 spentDialPressureCheckStartTimeMS; ///< Current time when spent dialysate pressure check started in milliseconds. +static U32 genDialysateDataPublicationTimerCounter; ///< Used to schedule generate dialysate data publication to CAN bus. +static OVERRIDE_U32_T genDialysateDataPublishInterval; ///< Generate dialysate mode data publish interval. + +// ********** private function prototypes ********** + +static void setModeGenDStateTransition( DD_GEND_MODE_STATE_T state ); +static BOOL hydChamberWaterInletControl( void ); +static DD_GEND_MODE_STATE_T handleGendHydraulicsChamberWaterInletCheckState( void ); +static DD_GEND_MODE_STATE_T handleGendHydChamberPressureCheckState( void ); +static DD_GEND_MODE_STATE_T handleGendFreshDialysatePressureCheckState( void ); +static DD_GEND_MODE_STATE_T handleGendSpentDialysatePressureCheckState( void ); +static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryState( void ); +static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryPauseState( void ); +static void publishGenDialysateModeData( void ); + +/*********************************************************************//** + * @brief + * The initGenDialysateMode function initializes the dialysis generation mode unit. + * @details \b Inputs: none + * @details \b Outputs: Gen dialysate mode unit initialized + * @return none + *************************************************************************/ +void initGenDialysateMode( void ) +{ +// targetHydChamberFluidTemp.data = HYD_CHAMBER_FLUID_TEMP_C_MIN; +// targetHydChamberFluidTemp.ovInitData = HYD_CHAMBER_FLUID_TEMP_C_MIN; +// targetHydChamberFluidTemp.ovData = HYD_CHAMBER_FLUID_TEMP_C_MIN; +// targetHydChamberFluidTemp.override = OVERRIDE_RESET; +// isHydChamberTempinRange = FALSE; + genDialysateState = DD_GEND_STATE_START; + hydChamberPressureCheckStartTimeMS = 0; + spentDialPressureCheckStartTimeMS = 0; + genDialysateDataPublishInterval.data = GEN_DIALYSATE_DATA_PUBLISH_INTERVAL; + genDialysateDataPublishInterval.ovData = GEN_DIALYSATE_DATA_PUBLISH_INTERVAL; + genDialysateDataPublishInterval.ovInitData = 0; + genDialysateDataPublishInterval.override = OVERRIDE_RESET; + genDialysateDataPublicationTimerCounter = 0; +} + +/*********************************************************************//** + * @brief + * The transitionToGenDialysateMode function prepares for transition to gen + * dialysate mode. + * @details \b Inputs: none + * @details \b Outputs: none + * @return initial state + *************************************************************************/ +U32 transitionToGenDialysateMode( void ) +{ + initGenDialysateMode(); + setCurrentSubState( NO_SUB_STATE ); + + return genDialysateState; +} + +/*********************************************************************//** + * @brief + * The setModeGenDStateTransition function sets the actuators and variables + * for the state transition in generate dialysis mode. + * @details Inputs: Valve states, Pump speed + * @details Outputs: Actuate valves, pumps as desired. + * @param state gen dialysate state enum + * @return none + *************************************************************************/ +static void setModeGenDStateTransition( DD_GEND_MODE_STATE_T state ) +{ + // Execute on running state + switch( state ) + { + case DD_GEND_STATE_START: + // Do nothing + break; + + case DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE: + // Close all balancing chamber and hydraulics valves + valveControlForBCClosedState(); + setValveState( VHI, VALVE_STATE_CLOSED ); //D03 + setValveState( VHB, VALVE_STATE_CLOSED ); //D08 + setValveState( VHO, VALVE_STATE_CLOSED ); //D14 + setValveState( VTD, VALVE_STATE_CLOSED ); //D52 + setValveState( VDR, VALVE_STATE_CLOSED ); //D53 + setValveState( VP2, VALVE_STATE_CLOSED ); //D47 + + // Get the target temperature from TD + //targetHydChamberFluidTemp.data = HYD_CHAMBER_FLUID_TEMP_C_MIN; + break; + + case DD_GEND_HYD_CHAMBER_PRESSURE_CHECK_STATE: + // Open up VHo valve + setValveState( VHO, VALVE_STATE_OPEN ); //D14 + // Start timer for hyd chamber negative pressure check state + hydChamberPressureCheckStartTimeMS = getMSTimerCount(); + // Start D12/DGP pump + setDialysatePumpTargetRPM( FRESH_DIALYSATE_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM ); + break; + + case DD_GEND_FRESH_DIALYSATE_PRESSURE_CHECK_STATE: + // Lets be DGP continue running since pressure relief valve was set/ tuned part of priming process + hydChamberPressureCheckStartTimeMS = getMSTimerCount(); + break; + + case DD_GEND_SPENT_DIALYSATE_PRESSURE_CHECK_STATE: + // Start the timer for spent dialysate pressure check + spentDialPressureCheckStartTimeMS = getMSTimerCount(); + // Start D48/SDP pump + setDialysatePumpTargetRPM( SPENT_DIALYSATE_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM ); + break; + + case DD_GEND_DIALYSATE_DELIVERY_STATE: + // Make sure valves are in correct position + setValveState( VDR, VALVE_STATE_OPEN ); //D53 + break; + + case DD_GEND_DIALYSATE_DELIVERY_PAUSE: + // stop the motor during pause conditions + signalDialysatePumpHardStop( FRESH_DIALYSATE_PUMP ); + signalDialysatePumpHardStop( SPENT_DIALYSATE_PUMP ); + + //close the DD - water inlet and drain valves? + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_GEND_MODE_INVALID_EXEC_STATE1, state ) + break; + } +} + +/*********************************************************************//** + * @brief + * The execGenDialysateMode function executes the Gen dialysate mode state machine. + * @details \b Inputs: none + * @details \b Outputs: Gen dialysate mode state machine executed + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong gen dialysate state invoked. + * @return current state. + *************************************************************************/ +U32 execGenDialysateMode( void ) +{ + // Continuous water inlet pressure check + if ( genDialysateState != DD_GEND_DIALYSATE_DELIVERY_PAUSE ) + { + if ( TRUE == areInletWaterConditionsAlarmsActive() ) // Check RO alarms as required + { + setModeGenDStateTransition( DD_GEND_DIALYSATE_DELIVERY_PAUSE ); + genDialysateState = DD_GEND_DIALYSATE_DELIVERY_PAUSE; + } + } + + if ( genDialysateState > DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE ) + { + hydChamberWaterInletControl(); + } + + // execute current gen dialysate state + switch ( genDialysateState ) + { + case DD_GEND_STATE_START: + setModeGenDStateTransition( DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE ); + genDialysateState = DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE; + break; + + case DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE: + genDialysateState = handleGendHydraulicsChamberWaterInletCheckState(); + break; + + case DD_GEND_HYD_CHAMBER_PRESSURE_CHECK_STATE: + genDialysateState = handleGendHydChamberPressureCheckState(); + break; + + case DD_GEND_FRESH_DIALYSATE_PRESSURE_CHECK_STATE: + genDialysateState = handleGendFreshDialysatePressureCheckState(); + break; + + case DD_GEND_SPENT_DIALYSATE_PRESSURE_CHECK_STATE: + genDialysateState = handleGendSpentDialysatePressureCheckState(); + break; + + case DD_GEND_DIALYSATE_DELIVERY_STATE: + genDialysateState = handleGendDialysateDeliveryState(); + break; + + case DD_GEND_DIALYSATE_DELIVERY_PAUSE: + genDialysateState = handleGendDialysateDeliveryPauseState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_GEND_MODE_INVALID_EXEC_STATE, genDialysateState ) + genDialysateState = DD_GEND_STATE_START; + break; + } + + //Publish Gen dialysate mode data + publishGenDialysateModeData(); + + return genDialysateState; +} + +/*********************************************************************//** + * @brief + * The hydChamberWaterInletControl function checks the water level and allow + * the water into hydraulics for dialysate generation. + * @details \b Inputs: floater levels. + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +static BOOL hydChamberWaterInletControl( void ) +{ + // Read floater switch + BOOL result = FALSE; + LEVEL_STATE_T floaterLevel1 = getLevelStatus( FLOATER_1 ); + LEVEL_STATE_T floaterLevel2 = getLevelStatus( FLOATER_2 ); + //F32 hydChamberTemperature = getTemperatureValue( TEMPSENSORS_HYDRAULICS_PRIMARY_HEATER ); + + // High level is met + if ( STATE_HIGH == floaterLevel2 ) + { + //turn off inlet water valve + setValveState( VHO, VALVE_STATE_CLOSED ); + +// // read latest fluid temperature +// hydChamberTemperature = getTemperatureValue( TEMPSENSORS_HYDRAULICS_PRIMARY_HEATER ); +// +// if ( hydChamberTemperature < HYD_CHAMBER_FLUID_TEMP_C_MIN ) +// { +// //if fluid temp is lesser, turn on heater +// setHeaterTargetTemperature( DD_PRIMARY_HEATER, targetHydChamberFluidTemp ); +// startHeater( DD_PRIMARY_HEATER ); +// } +// else +// { +// //Turn heater off +// if ( TRUE == isHeaterOn( DD_PRIMARY_HEATER ) ) +// { +// stopHeater( DD_PRIMARY_HEATER ); +// } +// } + + // For now, lets not wait for temperature to reach target, as soon as water level is high + // enough, update results to true. + result = TRUE; + } + else + { + // if level is not met,allow inlet water to hydraulics chamber + setValveState( VHO, VALVE_STATE_OPEN ); + } + + // Invlaid levels + if ( ( STATE_LOW == floaterLevel1 ) && ( STATE_HIGH == floaterLevel2 ) ) + { + //TODO : check for invalid levels and trigger alarm + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleGendHydraulicsChamberWaterInletCheckState function checks the + * water level and allow the water into hydraulics for dialysate generation. + * @details \b Inputs: floater levels. + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendHydraulicsChamberWaterInletCheckState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE; + + // Allow water inlet to hydraulics chamber + if ( TRUE == hydChamberWaterInletControl() ) + { + // if water level, temp is range, move to pressure check state + setModeGenDStateTransition( DD_GEND_HYD_CHAMBER_PRESSURE_CHECK_STATE ); + state = DD_GEND_HYD_CHAMBER_PRESSURE_CHECK_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleGendHydChamberPressureCheckState function checks the + * hydraulics chamber pressure at chamber 4 of hydraulics. + * @details \b Inputs: pressure sensor readings, hydChamberPressureCheckStartTimeMS + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendHydChamberPressureCheckState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_HYD_CHAMBER_PRESSURE_CHECK_STATE; + F32 hydPressure = getFilteredPressure( PRESSURE_SENSOR_HYDRAULICS_OUTLET ); + + // Hydraulics chamber negative pressure is in range ( -24 to -25 inHg ) + if ( ( hydPressure >= HYD_CHAMBER_TARGET_NEG_PRESS_MIN_PSI ) && ( hydPressure <= HYD_CHAMBER_TARGET_NEG_PRESS_MAX_PSI ) ) + { + // Proceed to next state + setModeGenDStateTransition( DD_GEND_FRESH_DIALYSATE_PRESSURE_CHECK_STATE ); + state = DD_GEND_FRESH_DIALYSATE_PRESSURE_CHECK_STATE; + } + else if ( TRUE == didTimeout( hydChamberPressureCheckStartTimeMS, HYD_CHAMBER_PRES_CHECK_TIME_OUT ) ) + { + // time out alarm and pause the dialysate generation? + state = DD_GEND_DIALYSATE_DELIVERY_PAUSE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleGendFreshDialysatePressureCheckState function checks the + * positive pressure level ( chamber 5) of hydraulics chamber or fresh + * dialysate side. + * @details \b Inputs: pressure sensor readings,hydChamberPressureCheckStartTimeMS + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendFreshDialysatePressureCheckState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_FRESH_DIALYSATE_PRESSURE_CHECK_STATE; + F32 hydPressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); + + // Hydraulics chamber postive pressure is in range ( 23 to 25 psi ) + if ( ( hydPressure >= HYD_CHAMBER_TARGET_POS_PRESS_MIN_PSI ) && ( hydPressure <= HYD_CHAMBER_TARGET_POS_PRESS_MAX_PSI ) ) + { + // Proceed to next state + setModeGenDStateTransition( DD_GEND_SPENT_DIALYSATE_PRESSURE_CHECK_STATE ); + state = DD_GEND_SPENT_DIALYSATE_PRESSURE_CHECK_STATE; + } + else if ( TRUE == didTimeout( hydChamberPressureCheckStartTimeMS, HYD_CHAMBER_PRES_CHECK_TIME_OUT ) ) + { + // time out alarm and pause the dialysate generation? + state = DD_GEND_DIALYSATE_DELIVERY_PAUSE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleGendSpentDialysatePressureCheckState function checks the + * spent dialyaste pressure is in range to begin balancing chamber dialysate + * delivery. + * @details \b Inputs: pressure sensor readings,spentDialPressureCheckStartTimeMS. + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendSpentDialysatePressureCheckState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_SPENT_DIALYSATE_PRESSURE_CHECK_STATE; + F32 spentdialPressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + + // Spent dialysate pressure is in range ( 29 to 30 psi ) + if ( ( spentdialPressure >= SPENT_DIAL_TARGET_POS_PRESS_MIN_PSI ) && ( spentdialPressure <= SPENT_DIAL_TARGET_POS_PRESS_MAX_PSI ) ) + { + // Proceed to next state + transitionToBalChamberFill(); + setModeGenDStateTransition( DD_GEND_DIALYSATE_DELIVERY_STATE ); + state = DD_GEND_DIALYSATE_DELIVERY_STATE; + } + else if ( TRUE == didTimeout( spentDialPressureCheckStartTimeMS, SPENT_DIAL_PRES_CHECK_TIME_OUT ) ) + { + // time out alarm and pause the dialysate generation? + state = DD_GEND_DIALYSATE_DELIVERY_PAUSE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleGendDialysateDeliveryState function performing dialysate + * delivery by executing balacning chamber. + * @details \b Inputs: none + * @details \b Outputs: balancing chamber state. + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; + U32 balChamberstate; + + //Execute balancing chamber + balChamberstate = execBalancingChamber(); + + if ( BAL_CHAMBER_DIAL_DELIVERY_PAUSE == balChamberstate ) + { + //handle if balancing chamber is paused for some reasons. + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleGendDialysateDeliveryPauseState function pause the dialysate + * delivery due to alarms conditions or some control asked to be in + * paused state. + * @details \b Inputs: none + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryPauseState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_PAUSE; + + //TODO : Handle pause state. + + return state; +} + +/*********************************************************************//** + * @brief + * The getCurrentGenDialysateState function returns the current state of the + * gen dialysate mode. + * @details \b Inputs: genDialysateState + * @details \b Outputs: none + * @return the current state of gen dialysate mode + *************************************************************************/ +DD_GEND_MODE_STATE_T getCurrentGenDialysateState( void ) +{ + return genDialysateState; +} + +/*********************************************************************//** + * @brief + * The getGenDilaysateDataPublishInterval function gets the generate dialysate + * mode data publish interval. + * @details \b Inputs: genDialysateDataPublishInterval + * @details \b Outputs: none + * @return the interval at generate dialysate mode data being published. + *************************************************************************/ +static U32 getGenDilaysateDataPublishInterval( void ) +{ + U32 result = genDialysateDataPublishInterval.data; + + if ( OVERRIDE_KEY == genDialysateDataPublishInterval.override ) + { + result = genDialysateDataPublishInterval.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The publishGenDialysateModeData function broadcasts the generate dialysate + * mode data at defined interval. + * @details \b Inputs: genDialysateDataPublicationTimerCounter + * @details \b Outputs: DD generate dialysate data broadcast message sent + * @details \b Message \Sent: MSG_ID_DD_GEN_DIALYSATE_MODE_DATA to publish the + * generate dialysate mode data. + * @return none + *************************************************************************/ +static void publishGenDialysateModeData( void ) +{ + if ( ++genDialysateDataPublicationTimerCounter >= getGenDilaysateDataPublishInterval() ) + { + GEN_DIALYSATE_MODE_DATA_T data; + + data.genDialysateExecState = (U32)getCurrentGenDialysateState(); + data.floaterLevel1 = (U32)getLevelStatus( FLOATER_1 ); + data.floaterLevel2 = (U32)getLevelStatus( FLOATER_2 ); + data.BiCarbLevel = (U32)getLevelStatus( BICARB_LEVEL ); + data.SpentChamberLevel = (U32)getLevelStatus( SPENT_DIALYSATE_LEVEL ); + data.hydNegativePressure = getFilteredPressure( PRESSURE_SENSOR_HYDRAULICS_OUTLET ); + data.hydPositivePressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); + data.spentDialysatePressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + + broadcastData( MSG_ID_DD_GEN_DIALYSATE_MODE_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( GEN_DIALYSATE_MODE_DATA_T ) ); + + genDialysateDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testDDGenDialysateDataPublishIntervalOverride function overrides the + * DD generate dialysate mode data publish interval. + * @details \b Inputs: genDialysateDataPublishInterval + * @details \b Outputs: genDialysateDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the DD generate dialysate data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDDGenDialysateDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &genDialysateDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testGenDHydChamberFluidTempOverride function sets the override value + * of the hydraulics chamber fluid temperature. + * @details Inputs: targetHydChamberFluidTemp + * @details Outputs: targetHydChamberFluidTemp + * @param message Override message from Dialin which includes the override + * value of the hydraulics chamber fluid temperature. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +//BOOL testGenDHydChamberFluidTempOverride( MESSAGE_T *message ) +//{ +// BOOL result = f32Override( message, &targetHydChamberFluidTemp ); +// +// return result; +//} +/**@}*/ Index: firmware/App/Modes/ModeGenDialysate.h =================================================================== diff -u --- firmware/App/Modes/ModeGenDialysate.h (revision 0) +++ firmware/App/Modes/ModeGenDialysate.h (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -0,0 +1,60 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file ModeGenDialysate.h +* +* @author (last) Vinayakam Mani +* @date (last) 30-Oct-2024 +* +* @author (original) Vinayakam Mani +* @date (original) 30-Oct-2024 +* +***************************************************************************/ + +#ifndef __MODE_GEN_DIALYSATE_H__ +#define __MODE_GEN_DIALYSATE_H__ + +#include "DDCommon.h" +#include "DDDefs.h" + +/** + * @defgroup DDGenDialysateMode DDGenDialysateMode + * @brief Generate Dialysate unit. Manages dialysate generation functions via a state machine. + * + * @addtogroup DDGenDialysateMode + * @{ + */ + +// ********** public definitions ********** + +/// Generate dialysate mode data structure +typedef struct +{ + U32 genDialysateExecState; ///< Generate dialysate execution state + U32 floaterLevel1; ///< Floater level 1 (low or medium) + U32 floaterLevel2; ///< Floater level 2 (medium or high) + U32 BiCarbLevel; ///< BiCarb Chamber level + U32 SpentChamberLevel; ///< Spent dialysate chamber level + F32 hydNegativePressure; ///< Hydraulics chamber negative pressure + F32 hydPositivePressure; ///< Hydraulics chamber positive pressure + F32 spentDialysatePressure; ///< Spent Dialysate positive pressure +} GEN_DIALYSATE_MODE_DATA_T; + +// ********** public function prototypes ********** + +void initGenDialysateMode( void ); // initialize this gen dialysate mode unit +U32 transitionToGenDialysateMode( void ); // prepares for transition to gen dialysate mode +U32 execGenDialysateMode( void ); // execute the gen dialysate mode state machine (call from OperationModes) + +DD_GEND_MODE_STATE_T getCurrentGenDialysateState( void ); // get the current state of the gen dialysate mode. + +BOOL testDDGenDialysateDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testGenDHydChamberFluidTempOverride( MESSAGE_T *message ); // Override the hydraulics chamber fluid temperature + +/**@}*/ + +#endif Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -18,19 +18,18 @@ #include "reg_crc.h" // Used to hold reset reason code at startup before bits get cleared #include "reg_system.h" // Used to access exception status registers for reset reason code at startup -//#include "ConcentratePumps.h" -//#include "ConductivitySensors.h" +#include "ConcentratePumps.h" +#include "ConductivitySensors.h" #include "FpgaDD.h" //#include "Integrity.h" #include "Messaging.h" #include "ModeInitPOST.h" //#include "NVDataMgmt.h" #include "OperationModes.h" -//#include "Pressures.h" +#include "Pressure.h" #include "SafetyShutdown.h" #include "TaskGeneral.h" -//#include "TemperatureSensors.h" -//#include "Thermistors.h" +#include "Temperature.h" #include "WatchdogMgmt.h" /** @@ -84,11 +83,11 @@ U32 transitionToInitAndPOSTMode( void ) { initInitAndPOSTMode(); -// setCurrentSubState( NO_SUB_STATE ); + setCurrentSubState( NO_SUB_STATE ); // resetNVDataMgmtPOSTState(); // resetPressuresPOSTState(); -// resetWatchdogPOSTState(); -// resetSafetyShutdownPOSTState(); + resetWatchdogPOSTState(); + resetSafetyShutdownPOSTState(); return postState; } @@ -117,7 +116,7 @@ break; case DD_POST_STATE_FW_COMPATIBILITY: - //testStatus = execFWCompatibilityTest(); + testStatus = execFWCompatibilityTest(); postState = handlePOSTStatus( testStatus ); break; @@ -127,7 +126,7 @@ break; case DD_POST_STATE_FPGA: - //testStatus = execFPGATest(); + testStatus = execFPGATest(); postState = handlePOSTStatus( testStatus ); break; @@ -159,11 +158,6 @@ postState = handlePOSTStatus( testStatus ); break; - case DD_POST_STATE_THERMISTORS: - //testStatus = execThermistorsSelfTest(); - postState = handlePOSTStatus( testStatus ); - break; - case DD_POST_STATE_WATCHDOG: //testStatus = execWatchdogTest(); postState = handlePOSTStatus( testStatus ); @@ -185,9 +179,9 @@ break; case DD_POST_STATE_COMPLETED: - // Set overall HD POST status to "passed" + // Set overall DD POST status to "passed" postPassed = TRUE; - // Set overall HD POST completed status to TRUE + // Set overall DD POST completed status to TRUE postCompleted = TRUE; // Broadcast final POST passed //sendPOSTFinalResult( TRUE ); Index: firmware/App/Modes/ModeInitPOST.h =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeInitPOST.h (.../ModeInitPOST.h) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/ModeInitPOST.h (.../ModeInitPOST.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -34,7 +34,7 @@ // ********** public function prototypes ********** void initInitAndPOSTMode( void ); // initialize this unit -U32 transitionToInitAndPOSTMode( void ); // prepares for transition to init. & POST mode +U32 transitionToInitAndPOSTMode( void ); // prepares for transition to init. & POST mode U32 execInitAndPOSTMode( void ); // execute the init. & POST mode state machine (call from OperationModes) DD_POST_STATE_T getCurrentInitAndPOSTState( void ); // get the current state of the init. & POST mode. Index: firmware/App/Modes/ModeService.c =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeService.c (.../ModeService.c) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/ModeService.c (.../ModeService.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -15,9 +15,10 @@ * ***************************************************************************/ -//#include "ConcentratePumps.h" +#include "ConcentratePumps.h" #include "FpgaDD.h" #include "ModeService.h" +#include "ModeFault.h" #include "OperationModes.h" /** @@ -55,7 +56,7 @@ U32 transitionToServiceMode( void ) { // Deenergize all the actuators -// deenergizeActuators( NO_PARK_CONC_PUMPS ); + deenergizeActuators( NO_PARK_CONC_PUMPS ); initServiceMode(); setCurrentSubState( NO_SUB_STATE ); Index: firmware/App/Modes/ModeService.h =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeService.h (.../ModeService.h) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/ModeService.h (.../ModeService.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -33,7 +33,7 @@ // ********** public function prototypes ********** -void initServiceMode( void ); // initialize this unit +void initServiceMode( void ); // initialize this service mode unit U32 transitionToServiceMode( void ); // prepares for transition to service mode U32 execServiceMode( void ); // execute the service mode state machine (call from OperationModes) Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -ra14bc308c72272ce0275d263cf010c90d8a37355 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision a14bc308c72272ce0275d263cf010c90d8a37355) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -15,18 +15,16 @@ * ***************************************************************************/ -//#include "ConcentratePumps.h" -//#include "ConductivitySensors.h" -//#include "Heaters.h" +#include "ConcentratePumps.h" +#include "ConductivitySensors.h" +#include "Heaters.h" #include "ModeFault.h" -//#include "ModeHeatDisinfect.h" #include "ModeStandby.h" #include "MessageSupport.h" #include "Messaging.h" //#include "NVDataMgmt.h" #include "OperationModes.h" -//#include "Pressures.h" -//#include "ROPump.h" +#include "Pressure.h" #include "SystemCommDD.h" #include "TaskGeneral.h" //#include "Timers.h" @@ -39,39 +37,20 @@ // ********** private definitions ********** -#define FILTER_FLUSH_TIME_MS ( 120 * MS_PER_SECOND ) ///< Duration of filter flush state (in ms). -#define MAX_WATER_SAMPLE_TIME_MS ( 10 * MS_PER_SECOND ) ///< Maximum duration of water sample state (in ms). -#define FLUSH_EXPIRATION_TIME_MS ( 10 * SEC_PER_MIN * MS_PER_SECOND ) ///< Duration in which a filter flush is valid (in ms). -#define FILTER_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Filter flush data broadcast interval. // ********** private data ********** static DD_STANDBY_MODE_STATE_T standbyState; ///< Currently active standby state. -//static BOOL stopSampleWaterRequest; ///< Flag indicating TD has requested to stop sample water -//static BOOL startSampleWaterRequest; ///< Flag indicating TD has requested to start sample water -//static BOOL flushFilterRequest; ///< Flag indicating TD has requested to flush filters -//static BOOL endSampleWaterRequest; ///< Flag indicating TD has requested to end sample water -//static BOOL pendingStartDDRequest; ///< Flag indicating TD has requested DD start (go to generation idle mode). -//static U32 waterSampleStartTime; ///< Time stamp for start of water sample state. -//static U32 filterFlushStartTime; ///< Time stamp for start of filter flush state. -//static U32 filterFlushPublishTimerCounter; ///< Filter flush data publish timer counter. +static OVERRIDE_U32_T pendingStartDDRequest; ///< Flag indicating TD has requested DD start the dialysis delivery(Overridable). //static BOOL pendingStartDDFlushRequest; ///< Flag indicating TD has requested DD start flush. //static BOOL pendingStartDDHeatDisinfectRequest; ///< Flag indicating TD has requested DD start heat disinfect. //static BOOL pendingStartDDHeatDisinfectActiveCoolRequest; ///< Flag indicating TD has requested DD start heat disinfect active cool. -//static BOOL pendingStartDDROPermeateSampleRequest; ///< Flag indicating TD has requested DD start RO permeate sample. +//static BOOL pendingStartDGROPermeateSampleRequest; ///< Flag indicating TD has requested DD to command RO to start permeate sample. -static OVERRIDE_U32_T filterFlushTimePeriod = { FILTER_FLUSH_TIME_MS, - FILTER_FLUSH_TIME_MS, 0, 0 }; ///< Filter flush time period in ms. - // ********** private function prototypes ********** -static BOOL areInletWaterConditionsAlarmsActive( void ); - static DD_STANDBY_MODE_STATE_T handleStandbyIdleState( void ); -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterState( void ); -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterIdleState( void ); -static DD_STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ); static DD_STANDBY_MODE_STATE_T handleStandbyPauseState( void ); /*********************************************************************//** @@ -84,21 +63,14 @@ void initStandbyMode( void ) { standbyState = DD_STANDBY_MODE_STATE_IDLE; -// stopSampleWaterRequest = FALSE; -// startSampleWaterRequest = FALSE; -// flushFilterRequest = FALSE; -// endSampleWaterRequest = FALSE; -// waterSampleStartTime = 0; -// filterFlushStartTime = 0; -// filterFlushPublishTimerCounter = 0; -// pendingStartDDRequest = FALSE; + pendingStartDDRequest.data = FALSE; + pendingStartDDRequest.ovData = FALSE; + pendingStartDDRequest.ovInitData = FALSE; + pendingStartDDRequest.override = OVERRIDE_RESET; // pendingStartDDFlushRequest = FALSE; // pendingStartDDHeatDisinfectRequest = FALSE; // pendingStartDDHeatDisinfectActiveCoolRequest = FALSE; // pendingStartDDROPermeateSampleRequest = FALSE; - - // Reset the heaters efficiency for another treatment - //resetHeatersEstimationGain(); } /*********************************************************************//** @@ -116,18 +88,13 @@ // re-initialize standby mode each time we transition to standby mode initStandbyMode(); -// deenergizeActuators( PARK_CONC_PUMPS ); -// -// + deenergizeActuators( PARK_CONC_PUMPS ); + // // Upon transition to mode standby set CD1 and CD2 calibration records to be picked to the normal // // table. If the chemical disinfect fails, the mode transitions back to mode standby. // setCondcutivitySensorCalTable( CONDUCTIVITYSENSORS_CD1_SENSOR, CAL_DATA_CD1_COND_SENSOR ); // setCondcutivitySensorCalTable( CONDUCTIVITYSENSORS_CD2_SENSOR, CAL_DATA_CD2_COND_SENSOR ); // -//#ifndef _RELEASE_ -// setHeatNelsonSupportMode( NELSON_NONE ); -// setChemNelsonSupportMode( NELSON_NONE ); -//#endif // // Send DD usage data to TD // The message ID will not be put here because the messages list script will pick this up for another send command @@ -151,7 +118,6 @@ { if ( TRUE == areInletWaterConditionsAlarmsActive() ) { - //setValveState( VSP, VALVE_STATE_CLOSED ); standbyState = DD_STANDBY_MODE_STATE_PAUSE; } @@ -162,18 +128,6 @@ standbyState = handleStandbyIdleState(); break; - case DD_STANDBY_MODE_STATE_FLUSH_FILTER: - standbyState = handleStandbyFlushFilterState(); - break; - - case DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE: - standbyState = handleStandbyFlushFilterIdleState(); - break; - - case DD_STANDBY_MODE_STATE_SAMPLE_WATER: - standbyState = handleStandbySampleWaterState(); - break; - case DD_STANDBY_MODE_STATE_PAUSE: standbyState = handleStandbyPauseState(); break; @@ -190,27 +144,23 @@ /*********************************************************************//** * @brief * The areInletWaterConditionsAlarmsActive function checks whether the inlet - * water conditions are out of range and any of their alarms are active. - * @details \b Inputs: none + * water pressure conditions are out of range and any of their alarms are active. + * @details \b Inputs: Input and Output pressure of water inlet pressur regulator. * @details \b Outputs: None * @return TRUE if any of the alarms are active, otherwise, FALSE *************************************************************************/ -static BOOL areInletWaterConditionsAlarmsActive( void ) +BOOL areInletWaterConditionsAlarmsActive( void ) { - // Check inlet water conductivity, temperature, pressure, and RO rejection ratio BOOL status = FALSE; -// checkInletWaterConductivity(); -// checkInletWaterTemperature(); -// checkInletWaterPressure(); + // Check Inlet Water Pressure - both Water inlet pressure Input, pressure Output after pressure regulator. + checkInletWaterPressure(); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_CONDUCTIVITY_IN_LOW_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_CONDUCTIVITY_IN_HIGH_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_TEMPERATURE_IN_HIGH_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_TEMPERATURE_IN_LOW_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_OUTLET_PRIMARY_CONDUCTIVITY_OUT_OF_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_HIGH_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_LOW_RANGE ); + // Check any active alarms + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_OUT_LOW_RANGE ); + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_OUT_HIGH_RANGE ); + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_HIGH_RANGE ); + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_LOW_RANGE ); return status; } @@ -225,6 +175,8 @@ * @details \b Outputs: Idle state of the standby mode executed, * pendingStartDDFlushRequest, pendingStartDDHeatDisinfectRequest, * pendingStartDDChemicalDisinfectRequest + * @details \b Message \Sent: DD_EVENT_TD_COMMUNICATION_LOSS ( Evend Id:8 ) + * updates TD communication loss. * @return the next state *************************************************************************/ static DD_STANDBY_MODE_STATE_T handleStandbyIdleState( void ) @@ -233,23 +185,15 @@ // go to standby solo mode if TD is turned off or stops communicating. if ( FALSE == isTDCommunicating() ) - { // TODO if TD comm loss, should we wait an hour or so before going to solo standby? + { // TODO if TD comm loss, do we need solo standby? + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_TD_COMMUNICATION_LOSS, 0, 0 ) //requestNewOperationMode( DD_MODE_SOLO ); } - // if TD requests water sample, go to water sample state -// else if ( TRUE == flushFilterRequest ) -// { -// setValveState( VPI, VALVE_STATE_OPEN ); -// flushFilterRequest = FALSE; -// filterFlushStartTime = getMSTimerCount(); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER; -// } -// else if ( TRUE == pendingStartDDRequest ) -// { -// pendingStartDDRequest = FALSE; -// signalSyncToHD(); -// requestNewOperationMode( DD_MODE_GENE ); -// } + else if ( TRUE == getU32OverrideValue( &pendingStartDDRequest ) ) + { + pendingStartDDRequest.data = FALSE; + requestNewOperationMode( DD_MODE_GEND ); + } // else if ( TRUE == pendingStartDDFlushRequest ) // { // pendingStartDDFlushRequest = FALSE; @@ -277,126 +221,28 @@ /*********************************************************************//** * @brief - * The handleStandbyFilterFlushState function executes the flush filter state - * of the standby mode state machine. - * @details \b Inputs: filterFLushStartTime - * @details \b Outputs: Flushed the filters + * The handleStandbyPauseState function executes the standby pause state. + * @details \b Inputs: Water inlet pressure alarms + * @details \b Outputs: state * @return the next state *************************************************************************/ -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterState( void ) -{ - DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_FLUSH_FILTER; -// U32 filterFlushTimePeriod_ms = getU32OverrideValue( &filterFlushTimePeriod ); -// -// if ( TRUE == didTimeout( filterFlushStartTime, filterFlushTimePeriod_ms ) ) -// { -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; -// } -// -// if ( ++filterFlushPublishTimerCounter >= FILTER_FLUSH_DATA_PUBLISH_INTERVAL ) -// { -// STANDBY_MODE_DATA_T data; -// -// data.timeout = filterFlushTimePeriod_ms / MS_PER_SECOND; -// data.countdown = data.timeout - ( calcTimeSince( filterFlushStartTime ) / MS_PER_SECOND ); -// filterFlushPublishTimerCounter = 0; -// -// broadcastData( MSG_ID_DD_FILTER_FLUSH_PROGRESS_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( STANDBY_MODE_DATA_T ) ); -// } -// -// if ( TRUE == endSampleWaterRequest ) -// { -// endSampleWaterRequest = FALSE; -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_IDLE; -// } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleStandbyFlushFilterIdleState function executes the flush filter - * idle state of the standby mode state machine. - * @details \b Inputs: filterFLushStartTime, startSampleWaterRequest, endSampleWaterRequest - * @details \b Outputs: Flushed the filters, startSampleWaterRequest, endSampleWaterRequest, - * waterSampleStartTime - * @return the next state - *************************************************************************/ -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterIdleState( void ) -{ - DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; - -// if ( TRUE == startSampleWaterRequest ) -// { -// waterSampleStartTime = getMSTimerCount(); -// setValveState( VPI, VALVE_STATE_OPEN ); -// setValveState( VSP, VALVE_STATE_OPEN ); -// state = DD_STANDBY_MODE_STATE_SAMPLE_WATER; -// } -// -// if ( TRUE == endSampleWaterRequest ) -// { -// endSampleWaterRequest = FALSE; -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_IDLE; -// } -// -// startSampleWaterRequest = FALSE; - - return state; -} - -/*********************************************************************//** - * @brief - * The handleStandbySampleWaterState function executes the sample water state - * of the standby mode state machine. - * @details \b Inputs: stopSampleWaterRequest, waterSampleStartTime - * @details \b Outputs: Finished sample water and closed valve - * @return the next state - *************************************************************************/ -static DD_STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ) -{ - DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_SAMPLE_WATER; - -// // After TD requests to stop or 10 seconds has elapsed, close and return to idle state -// if ( ( TRUE == stopSampleWaterRequest ) || ( TRUE == didTimeout( waterSampleStartTime, MAX_WATER_SAMPLE_TIME_MS ) ) ) -// { -// stopSampleWaterRequest = FALSE; -// setValveState( VSP, VALVE_STATE_CLOSED ); -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; -// } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleStandbyPauseState function executes the pause state. - * @details \b Inputs: none - * @details \b Outputs: filterFlushStartTime - * @return the next state - *************************************************************************/ static DD_STANDBY_MODE_STATE_T handleStandbyPauseState( void ) { DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_PAUSE; -// if ( FALSE == areInletWaterConditionsAlarmsActive() ) -// { -// filterFlushStartTime = getMSTimerCount(); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER; -// } + if ( FALSE == areInletWaterConditionsAlarmsActive() ) + { + state = DD_STANDBY_MODE_STATE_IDLE; + } return state; } /*********************************************************************//** * @brief - * The requestDDStart function handles an TD request to start (go to generation idle mode). + * The requestDDStart function handles an TD request to start (go to generation dialysis mode). * @details \b Inputs: standbyState - * @details \b Outputs: pendingSampleWaterRequest + * @details \b Outputs: pendingStartDDRequest * @return TRUE if request accepted, FALSE if not. *************************************************************************/ BOOL requestDDStart( void ) @@ -405,41 +251,15 @@ if ( DD_STANDBY_MODE_STATE_IDLE == standbyState ) { - result = TRUE; - //pendingStartDDRequest = TRUE; - - // Reset the volume accumulator for the next run -// resetROGenerateVolumeL(); + result = TRUE; + pendingStartDDRequest.data = TRUE; } return result; } /*********************************************************************//** * @brief - * The signalAbortWaterSampling function handles an TD request to abort water - * sampling (return to standby idle state). - * @details \b Inputs: none - * @details \b Outputs: standby mode variable initialized - * @return TRUE if request accepted, FALSE if not - *************************************************************************/ -BOOL signalAbortWaterSampling( void ) -{ - BOOL result = FALSE; - - if ( ( DD_MODE_STAN == getCurrentOperationMode() ) && ( standbyState != DD_STANDBY_MODE_STATE_IDLE ) ) - { - result = TRUE; - initStandbyMode(); -// setValveState( VSP, VALVE_STATE_CLOSED ); -// setValveState( VPI, VALVE_STATE_CLOSED ); - } - - return result; -} - -/*********************************************************************//** - * @brief * The startDDFlush function starts DD flush mode. * @details \b Inputs: standbyState * @details \b Outputs: none @@ -621,71 +441,6 @@ /*********************************************************************//** * @brief - * The startDDROPermeateSample function starts RO permeate sample mode. - * @details \b Inputs: standbyState - * @details \b Outputs: pendingStartDDChemicalDisinfectFlushRequest - * @return: TRUE if the switch was successful - *************************************************************************/ -BOOL startDDROPermeateSample( void ) -{ - BOOL status = FALSE; -// DD_CMD_RESPONSE_T cmdResponse; -// -// cmdResponse.commandID = DD_CMD_START_RO_PERMEATE_SAMPLE; -// cmdResponse.rejected = FALSE; -// cmdResponse.rejectCode = DD_CMD_REQUEST_REJECT_REASON_NONE; -// -// // If DD is in standby mode and the standby mode is in Idle, request RO permeate sample -// if ( ( DD_MODE_STAN == getCurrentOperationMode() ) && ( DD_STANDBY_MODE_STATE_IDLE == standbyState ) ) -// { -// DD_USAGE_INFO_RECORD_T usageInfo; -// OPN_CLS_STATE_T concCap = getSwitchStatus( CONCENTRATE_CAP ); -// OPN_CLS_STATE_T diaCap = getSwitchStatus( DIALYSATE_CAP ); -// -// getNVRecord2Driver( GET_USAGE_RECORD, (U08*)&usageInfo, sizeof( DD_USAGE_INFO_RECORD_T ), 0, ALARM_ID_NO_ALARM ); -// -//#ifndef _RELEASE_ -// if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_CAPS_MONITOR ) ) -// { -// concCap = STATE_CLOSED; -// diaCap = STATE_CLOSED; -// // Using the caps switch to disable the chemical disinfect date checks. -// // This is for debug builds only to simulate that a chem flush has been done after chem -// usageInfo.lastChemDisFlushCompleteDateEpoch = 40; -// usageInfo.lastChemDisStartDateEpoch = 32; -// } -//#endif -// -// if ( ( STATE_OPEN == concCap ) || ( STATE_OPEN == diaCap ) ) -// { -// cmdResponse.rejected = TRUE; -// cmdResponse.rejectCode = ( STATE_OPEN == getSwitchStatus( DIALYSATE_CAP ) ? REQUEST_REJECT_REASON_DD_DIALYSATE_CAP_OPEN : -// REQUEST_REJECT_REASON_DD_CONCENTRATE_CAP_OPEN ); -// } -// else if ( usageInfo.lastChemDisFlushCompleteDateEpoch < usageInfo.lastChemDisStartDateEpoch ) -// { -// cmdResponse.rejected = TRUE; -// cmdResponse.rejectCode = REQUEST_REJECT_REASON_DD_CHEM_FLUSH_NOT_COMPLETED; -// } -// else -// { -// pendingStartDDROPermeateSampleRequest = TRUE; -// status = TRUE; -// } -// } -// else -// { -// cmdResponse.rejected = TRUE; -// cmdResponse.rejectCode = REQUEST_REJECT_REASON_DD_NOT_IN_STANDBY_IDLE_STATE; -// } -// -// sendCommandResponseMsg( &cmdResponse ); - - return status; -} - -/*********************************************************************//** - * @brief * The getCurrentStandbyState function returns the current state of standby mode. * @details \b Inputs: standbyState * @details \b Outputs: none @@ -704,47 +459,19 @@ /*********************************************************************//** * @brief - * The testSetFilterFlushTimePeriodOverride function overrides the filter - * flush time period. - * @details \b Inputs: none - * @details \b Outputs: filterFlushTimePeriod - * @param value override concentrate pump data publish interval with (in ms) + * The testDDstartGenDialysateOverride function sets the override value + * to start the gen dialysate operation mode. + * @details Inputs: pendingStartDDRequest + * @details Outputs: pendingStartDDRequest + * @param message Override message from Dialin which includes the flag + * to override the operation mode. * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetFilterFlushTimePeriodOverride( U32 value ) +BOOL testDDstartGenDialysateOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, &pendingStartDDRequest, FALSE, TRUE ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - filterFlushTimePeriod.override = OVERRIDE_KEY; - filterFlushTimePeriod.ovData = value; - } - return result; } -/*********************************************************************//** - * @brief - * The testResetFilterFlushTimePeriodOverride function resets the - * override of the filter flush time period. - * @details \b Inputs: none - * @details \b Outputs: filterFlushTimePeriod - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetFilterFlushTimePeriodOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - filterFlushTimePeriod.override = OVERRIDE_RESET; - filterFlushTimePeriod.ovData = filterFlushTimePeriod.ovInitData; - } - - return result; -} - /**@}*/ Index: firmware/App/Modes/ModeStandby.h =================================================================== diff -u -ra14bc308c72272ce0275d263cf010c90d8a37355 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/ModeStandby.h (.../ModeStandby.h) (revision a14bc308c72272ce0275d263cf010c90d8a37355) +++ firmware/App/Modes/ModeStandby.h (.../ModeStandby.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -42,21 +42,18 @@ void initStandbyMode( void ); // initialize this unit U32 transitionToStandbyMode( void ); // prepares for transition to standby mode -U32 execStandbyMode( void ); // execute the standby mode state machine (call from OperationModes) +U32 execStandbyMode( void ); // execute the standby mode state machine (call from OperationModes) +BOOL areInletWaterConditionsAlarmsActive( void ); // checks water inlet pressure, temperature and conductivity alarms. BOOL requestDDStart( void ); // TD requests DD start (go to generation idle mode) -BOOL signalAbortWaterSampling( void ); // TD signal to abort water sampling. BOOL startDDFlush( void ); // TD start flush mode BOOL startDDHeatDisinfect( void ); // TD start heat disinfect mode BOOL startDDHeatDisinfectActiveCool( void ); DD_STANDBY_MODE_STATE_T getCurrentStandbyState( void ); // get the current state of the standby mode. -BOOL startDDROPermeateSample( void ); // TD start RO permeate sample +BOOL testDDstartGenDialysateOverride( MESSAGE_T *message ); // Overide start gen dialysate mode -BOOL testSetFilterFlushTimePeriodOverride( U32 value ); // set filter flush time period override. -BOOL testResetFilterFlushTimePeriodOverride( void ); // reset filter flush time period override. - /**@}*/ #endif Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -17,6 +17,7 @@ #include "ModeFault.h" #include "ModeInitPOST.h" +#include "ModeGenDialysate.h" #include "ModeService.h" #include "ModeStandby.h" #include "MessageSupport.h" @@ -177,9 +178,9 @@ currentSubMode = execStandbyMode(); break; -// case DD_MODE_GENE: -// currentSubMode = execGenIdleMode(); -// break; + case DD_MODE_GEND: + currentSubMode = execGenDialysateMode(); + break; // // case DD_MODE_FLUS: // currentSubMode = execFlushMode(); @@ -351,9 +352,9 @@ currentSubMode = transitionToStandbyMode(); break; -// case DD_MODE_GENE: -// currentSubMode = transitionToGenIdleMode(); -// break; + case DD_MODE_GEND: + currentSubMode = transitionToGenDialysateMode(); + break; // case DD_MODE_FLUS: // currentSubMode = transitionToFlushMode(); @@ -514,15 +515,23 @@ * mode if the transition is legal. * @details \b Inputs: MODE_TRANSITION_TABLE[][] * @details \b Outputs: modeRequest[], result - * @param newMode ID of requested mode to transition to + * @param message a pointer to the message to handle which includes the + * override value for the new mode change. * @return TRUE if request successful, FALSE if not *************************************************************************/ -BOOL testSetOperationMode( DD_OP_MODE_T newMode ) +BOOL testSetOperationMode( MESSAGE_T *message ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { + DD_OP_MODE_T newMode; + + if( message->hdr.payloadLen == sizeof(DD_OP_MODE_T) ) + { + memcpy( &newMode, message->payload, sizeof(DD_OP_MODE_T) ); + } + DD_OP_MODE_T check = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; // Is mode transition legal? @@ -538,49 +547,19 @@ /*********************************************************************//** * @brief - * The testSetDDOpModePublishIntervalOverride function overrides the + * The testDDOpModePublishIntervalOverride function overrides the * DD operation mode publish interval. * @details \b Inputs: none * @details \b Outputs: ddOpModePublishInterval - * @param value override DD operation mode publish interval with (in ms) + * @param Override message from Dialin which includes the interval + * (in ms) to override the DD operation mode publish interval to. * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetDDOpModePublishIntervalOverride( U32 value ) +BOOL testDDOpModePublishIntervalOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32BroadcastIntervalOverride( message, &ddOpModePublishInterval, TASK_GENERAL_INTERVAL ); - if ( TRUE == isTestingActivated() ) - { - U32 intvl = value / TASK_GENERAL_INTERVAL; - - result = TRUE; - ddOpModePublishInterval.ovData = intvl; - ddOpModePublishInterval.override = OVERRIDE_KEY; - } - return result; } -/*********************************************************************//** - * @brief - * The testResetDDOpModePublishIntervalOverride function resets the - * override of the DD operation mode publish interval. - * @details \b Inputs: none - * @details \b Outputs: ddOpModePublishInterval - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetDDOpModePublishIntervalOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - ddOpModePublishInterval.override = OVERRIDE_RESET; - ddOpModePublishInterval.ovData = ddOpModePublishInterval.ovInitData; - } - - return result; -} - /**@}*/ Index: firmware/App/Modes/OperationModes.h =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Modes/OperationModes.h (.../OperationModes.h) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Modes/OperationModes.h (.../OperationModes.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -60,9 +60,8 @@ void setTDOperationMode( U32 mode, U32 subMode ); // set TD operation mode which is received from TD void getTDOperationMode( TD_MODE_SUB_MODE_T* mode ); // get TD operation mode -BOOL testSetOperationMode( DD_OP_MODE_T newMode ); // Force transition to a given mode (if allowed) -BOOL testSetDDOpModePublishIntervalOverride( U32 value ); -BOOL testResetDDOpModePublishIntervalOverride( void ); +BOOL testSetOperationMode( MESSAGE_T *message ); // Force transition to a given mode (if allowed) +BOOL testDDOpModePublishIntervalOverride( MESSAGE_T *message ); // DD Opmode publish interval override /**@}*/ Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -ra14bc308c72272ce0275d263cf010c90d8a37355 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision a14bc308c72272ce0275d263cf010c90d8a37355) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -128,6 +128,12 @@ SW_FAULT_ID_HEATERS_INVALID_EXEC_STATE = 97, SW_FAULT_ID_INVALID_LEVEL_SELECTED = 98, SW_FAULT_ID_DD_INVALID_LEVEL_ID = 99, + SW_FAULT_ID_BAL_CHAMBER_INVALID_EXEC_STATE = 100, + SW_FAULT_ID_INVALID_TD_OPERATING_MODE = 101, + SW_FAULT_ID_GEND_MODE_INVALID_EXEC_STATE = 102, + SW_FAULT_ID_GEND_MODE_INVALID_EXEC_STATE1 = 103, + + NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rc85d9f0a8023fabdf1cd557965958d225e2b9085 -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision c85d9f0a8023fabdf1cd557965958d225e2b9085) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -26,6 +26,8 @@ #include "Heaters.h" #include "Level.h" #include "Messaging.h" +#include "ModeStandby.h" +#include "ModeGenDialysate.h" #include "OperationModes.h" #include "PAL.h" #include "Pressure.h" @@ -117,6 +119,17 @@ MSG_ID_DD_HEATERS_DUTY_CYCLE_OVERRIDE_REQUEST, MSG_ID_DD_LEVELS_PUBLISH_INTERVAL_OVERRIDE_REQUEST, MSG_ID_DD_LEVELS_STATUS_OVERRIDE_REQUEST, + MSD_ID_DD_TD_COMMUNICATION_STATUS_OVERRIDE_REQUEST, //40 + MSG_ID_DD_OP_MODE_STATUS_OVERRIDE_REQUEST, + MSG_ID_DD_SET_OPERATION_MODE_OVERRIDE_REQUEST, + MSG_ID_DD_START_GEN_DIALYSATE_MODE_OVERRIDE_REQUEST, + MSG_ID_DD_DIALYSATE_PUMPS_START_OVERRIDE_REQUEST, + MSG_ID_DD_DIALYSATE_PUMPS_STOP_OVERRIDE_REQUEST, //45 + MSG_ID_DD_GEND_MODE_DATA_PUBLISH_OVERRIDE_REQUEST, + MSG_ID_DD_CONCENTRATE_PUMPS_START_OVERRIDE_REQUEST, + MSG_ID_DD_HEATERS_START_OVERRIDE_REQUEST, + MSG_ID_DD_HEATERS_STOP_OVERRIDE_REQUEST, + MSG_ID_DD_VALVES_OPEN_CLOSE_STATE_OVERRIDE_REQUEST, //50 }; /// Message handling function table @@ -160,6 +173,17 @@ &testHeaterDutyCycleOverride, &testLevelsDataPublishIntervalOverride, &testLevelStatusOverride, + &testTDCommunicationStatus, //40 + &testDDOpModePublishIntervalOverride, + &testSetOperationMode, + &testDDstartGenDialysateOverride, + &testDialysatePumpStartOverride, + &testDialysatePumpStopOverride, //45 + &testDDGenDialysateDataPublishIntervalOverride, + &testConcentratePumpStartOverride, + &testHeaterStartOverride, + &testHeaterStopOverride, + &testValveOpenCloseStateOverride, //50 }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) Index: firmware/App/Services/SystemCommDD.c =================================================================== diff -u -r121912c6c7b1d21d5e4f2f8d9386a9f51ee68f1f -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Services/SystemCommDD.c (.../SystemCommDD.c) (revision 121912c6c7b1d21d5e4f2f8d9386a9f51ee68f1f) +++ firmware/App/Services/SystemCommDD.c (.../SystemCommDD.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -265,46 +265,19 @@ /*********************************************************************//** * @brief - * The testSetTDCommunicationStatus function sets the override + * The testTDCommunicationStatus function sets the override * of the TD communication status. * @details \b Inputs: none * @details \b Outputs: tdCommunicationStatus - * @return TRUE if reset successful, FALSE if not + * @param message Override message from Dialin which includes the flag + * value to override for the Td communication status. + * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTDCommunicationStatus( U32 value ) +BOOL testTDCommunicationStatus( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, &tdCommunicationStatus, FALSE, TRUE ); - if (TRUE == isTestingActivated() ) - { - result = TRUE; - tdCommunicationStatus.ovData = value; - tdCommunicationStatus.override = OVERRIDE_KEY; - - } return result; } -/*********************************************************************//** - * @brief - * The testResetTDCommuncationStatus function resets the override - * of the TD communication status. - * @details \b Inputs: none - * @details \b Outputs: tdCommunicationStatus - * @return TRUE if reset successful, FALSE if not - *************************************************************************/ -BOOL testResetTDCommuncationStatus( void ) -{ - BOOL result = FALSE; - - if (TRUE == isTestingActivated() ) - { - result = TRUE; - tdCommunicationStatus.override = OVERRIDE_RESET; - tdCommunicationStatus.ovData = tdCommunicationStatus.ovInitData; - - } - return result; -} - /**@}*/ Index: firmware/App/Services/SystemCommDD.h =================================================================== diff -u -rf7c714a1a09b10d85a8b013712532d37b4d7b97a -r48ca7fd644c67920acc29a80b7af379d0a134d1a --- firmware/App/Services/SystemCommDD.h (.../SystemCommDD.h) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) +++ firmware/App/Services/SystemCommDD.h (.../SystemCommDD.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -52,8 +52,7 @@ void checkForCommTimeouts( void ); void checkTooManyBadMsgCRCs( void ); -BOOL testSetTDCommunicationStatus( U32 value ); -BOOL testResetTDCommuncationStatus( void ); +BOOL testTDCommunicationStatus( MESSAGE_T *message ); /**@}*/ Index: firmware/App/Services/TDInterface.c =================================================================== diff -u --- firmware/App/Services/TDInterface.c (revision 0) +++ firmware/App/Services/TDInterface.c (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -0,0 +1,181 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file TDInterface.c +* +* @author (last) Vinayakam Mani +* @date (last) 28-Oct-2024 +* +* @author (original) Vinayakam Mani +* @date (original) 28-Oct-2024 +* +***************************************************************************/ + +#include "TDInterface.h" +#include "Messaging.h" +#include "ModeInitPOST.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" +#include "SystemCommDD.h" +#include "TaskGeneral.h" +#include "Timers.h" + +/** + * @addtogroup TDInterface + * @{ + */ + +// ********** private definitions ********** + +#define TD_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< TD data freshness timeout (in ms). +#define TD_MAX_DIALYSIS_FLOW_RATE ( 600.0F ) ///< TD Max dialysis flow rate + +// ********** private data ********** + +// TD status +static TD_OP_MODE_T tdCurrentOpMode; ///< Current TD operation mode. +static U32 tdSubMode; ///< Current state (sub-mode) of current TD operation mode. +static F32 tdDialysisFlowrate; ///< TD dialysis flow rate + +static BOOL tdOpModeDataFreshFlag = FALSE; ///< Flag to signal/process fresh TD op mode data + +// ********** private function prototypes ********** + +static void checkTDDataFreshness( ALARM_ID_T alarmID, BOOL *tdFreshDataFlag ); + +/*********************************************************************//** + * @brief + * The initTDInterface function initializes the TDInterface unit. + * @details \b Inputs: none + * @details \b Outputs: TDInterface unit initialized. + * @return none + *************************************************************************/ +void initTDInterface( void ) +{ + // Initialize unit variables + tdCurrentOpMode = MODE_INIT; + tdSubMode = 0; + tdDialysisFlowrate = TD_MAX_DIALYSIS_FLOW_RATE; // Will update later based on the TD value +} + +/**********************************************************************//** + * @brief + * The checkTDDataFreshness function checks the freshness of data coming from + * the TD sub-system. + * @details \b Alarm: Given alarm is triggered if TD is communicating but has + * not published new data for too long. + * @details \b Inputs: TD communicating flag + * @details \b Outputs: none + * @param alarm ID of alarm to check + * @param tdFreshDataFlag Pointer to flag indicating whether new data has been + * received since last time this function has seen it. + * @return None + *************************************************************************/ +static void checkTDDataFreshness( ALARM_ID_T alarmID, BOOL *tdFreshDataFlag ) +{ + if ( TRUE == *tdFreshDataFlag ) + { + *tdFreshDataFlag = FALSE; + checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); + } + else + { // Alarm if not receiving TD fresh data message in timely manner + if ( TRUE == isTDCommunicating() ) + { + checkPersistentAlarm( alarmID, TRUE, 0.0, 0.0 ); + } + else + { + checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); + } + } +} + +/*********************************************************************//** + * @brief + * The execTDInterfaceMonitor function executes the TD Interface monitoring + * function. Ensures TD is sending fresh data in a timely manner. + * @details \b Inputs: none + * @details \b Outputs: none + * @return none + *************************************************************************/ +void execTDInterfaceMonitor( void ) +{ + +} + +/*********************************************************************//** + * @brief + * The getTDOpMode function gets the current latest reported TD operating mode. + * @details \b Inputs: tdCurrentOpMode + * @details \b Outputs: none + * @return Latest reported TD operating mode. + *************************************************************************/ +TD_OP_MODE_T getTDOpMode( void ) +{ + return tdCurrentOpMode; +} + +/*********************************************************************//** + * @brief + * The getTDSubMode function gets the latest reported TD operating sub-mode. + * @details \b Inputs: tdSubMode + * @details \b Outputs: none + * @return Latest reported TD operating sub-mode. + *************************************************************************/ +U32 getTDSubMode( void ) +{ + return tdSubMode; +} + +/*********************************************************************//** + * @brief + * The setTDOpMode function sets the latest TD operating mode reported by + * the TD (called by TD published message handler). + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if reported TD mode is invalid. + * @details \b Inputs: none + * @details \b Outputs: tdCurrentOpMode, ddSubMode, tdOpModeDataFreshFlag + * @param opMode The operating mode reported by DD + * @param subMode The sub-mode of operating mode reported by TD + * @return none + *************************************************************************/ +void setTDOpMode( U32 opMode, U32 subMode ) +{ + if ( opMode < NUM_OF_MODES ) + { + // update TD op mode and sub-mode + tdCurrentOpMode = (TD_OP_MODE_T)opMode; + tdSubMode = subMode; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_TD_OPERATING_MODE, opMode ); + } + + tdOpModeDataFreshFlag = TRUE; +} + +/*********************************************************************//** + * @brief + * The getTDDialysateFlowrate function gets the latest TD dialysis flow + * rate. + * @details \b Inputs: tdDialysisFlowrate + * @details \b Outputs: none + * @return Latest TD dialysis flow rate. + *************************************************************************/ +F32 getTDDialysateFlowrate( void ) +{ + return tdDialysisFlowrate; +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/**@}*/ Index: firmware/App/Services/TDInterface.h =================================================================== diff -u --- firmware/App/Services/TDInterface.h (revision 0) +++ firmware/App/Services/TDInterface.h (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) @@ -0,0 +1,51 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file TDInterface.h +* +* @author (last) Vinayakam Mani +* @date (last) 28-Oct-2024 +* +* @author (original) Vinayakam Mani +* @date (original) 28-Oct-2024 +* +***************************************************************************/ + +#ifndef __TD_INTERFACE_H__ +#define __TD_INTERFACE_H__ + +#include "DDCommon.h" +#include "TDDefs.h" + +/** + * @defgroup TDInterface TDInterface + * @brief TD interface & monitor unit. Interfaces with and monitors the + * TD (Treatment Delivery) sub-system. + * + * @addtogroup TDInterface + * @{ + */ + +// ********** public definitions ********** + + + +// ********** public function prototypes ********** + +void initTDInterface( void ); + +void execTDInterfaceMonitor( void ); + +TD_OP_MODE_T getTDOpMode( void ); +U32 getTDSubMode( void ); +void setTDOpMode( U32 opMode, U32 subMode ); +F32 getTDDialysateFlowrate( void ); + + +/**@}*/ + +#endif