Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r031627883dbd40abd52312d64a1a3b811478d1c3 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 031627883dbd40abd52312d64a1a3b811478d1c3) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 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 DGInterface.c +* @file DGInterface.c * -* @author (last) Sean Nash -* @date (last) 24-Sep-2020 +* @author (last) Quang Nguyen +* @date (last) 24-Aug-2021 * -* @author (original) Sean -* @date (original) 08-Apr-2020 +* @author (original) Sean +* @date (original) 08-Apr-2020 * ***************************************************************************/ @@ -23,6 +23,7 @@ #include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "Timers.h" @@ -33,15 +34,22 @@ // ********** private definitions ********** -#define START_DG_CMD TRUE ///< Parameter for DG start/stop command function. True = start. -#define STOP_DG_CMD FALSE ///< Parameter for DG start/stop command function. False = stop. +#define START_DG_CMD TRUE ///< Parameter for DG start/stop command function. True = start. +#define STOP_DG_CMD FALSE ///< Parameter for DG start/stop command function. False = stop. -#define RESERVOIR_SETTLE_TIME_MS 5000 ///< Time (in ms) allotted for reservoir to settle (after fill, before drain). +#define RESERVOIR_SETTLE_TIME_MS 5000 ///< Time (in ms) allotted for reservoir to settle (after fill, before drain). -#define MAX_RESERVOIR_VOLUME_ML 1950.0 ///< Maximum reservoir volume. Switch reservoirs if active reservoir exceeds this volume. +#define MAX_RESERVOIR_VOLUME_ML 1950.0 ///< Maximum reservoir volume. Switch reservoirs if active reservoir exceeds this volume. -#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. +#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. +#define DIALYSATE_TEMP_PERSISTENCE_PERIOD ( 3 * MS_PER_SECOND ) ///< Persistence period for dialysate temperature alarm. + +#define DIALYSATE_TEMP_RECOVERY_TOLERANCE_C 2.0 ///< Dialysate temperature recovery tolerance in degree C. +#define DIALYSATE_TEMP_TOLERANCE_C 4.0 ///< Dialysate temperature tolerance in degree C. +#define DIALYSATE_TEMP_HIGH_LIMIT_C 42.0 ///< Dialysate high temperature limit in degree C. +#define DIALYSATE_TEMP_LOW_LIMIT_C 33.0 ///< Dialysate low temperature limit in degree C. + /// States of the treatment reservoir management state machine. typedef enum TreatmentReservoirMgmt_States { @@ -161,6 +169,9 @@ lgLoadCellReadingsIdx = 0; lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; + + initPersistentAlarm( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, DIALYSATE_TEMP_PERSISTENCE_PERIOD, DIALYSATE_TEMP_PERSISTENCE_PERIOD ); + initPersistentAlarm( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, DIALYSATE_TEMP_PERSISTENCE_PERIOD, DIALYSATE_TEMP_PERSISTENCE_PERIOD ); } /*********************************************************************//** @@ -543,18 +554,6 @@ /*********************************************************************//** * @brief - * The getDialysateTemperature function gets the latest dialysate temperature. - * @details Inputs: dgDialysateTemp - * @details Outputs: none - * @return the current dialysate temperature - *************************************************************************/ -F32 getDialysateTemperature( void ) -{ - return dgDialysateTemp; -} - -/*********************************************************************//** - * @brief * The getDGDisinfectsStates function returns the DG disinfects readings. * @details Inputs: none * @details Outputs: disinfectsStatus @@ -567,6 +566,18 @@ /*********************************************************************//** * @brief + * The getDialysateTemperature function gets the latest dialysate temperature. + * @details Inputs: dgDialysateTemp + * @details Outputs: none + * @return the current dialysate temperature + *************************************************************************/ +F32 getDialysateTemperature( void ) +{ + return dgDialysateTemp; +} + +/*********************************************************************//** + * @brief * The getReservoirWeight function gets the load cell weight of a given reservoir. * @details Inputs: loadCellWeightInGrams[] * @details Outputs: none @@ -1114,6 +1125,47 @@ /*********************************************************************//** * @brief + * The checkDialysateTemperature function checks the dialysate temperature + * reported by DG and alarm if temperature is out of range. + * @details Inputs: dgTrimmerTempSet, dgDialysateTemp, dgRedundantDialysateTemp + * @details Outputs: alarm if dialysate temperature is out of accepted range + * @return none + *************************************************************************/ +void checkDialysateTemperature( void ) +{ + BOOL const dialysateHighTemp = ( ( ( dgDialysateTemp - dgTrimmerTempSet ) > DIALYSATE_TEMP_TOLERANCE_C ) || + ( dgDialysateTemp > DIALYSATE_TEMP_HIGH_LIMIT_C ) ); + + BOOL const dialysateLowTemp = ( ( ( dgTrimmerTempSet - dgDialysateTemp ) > DIALYSATE_TEMP_TOLERANCE_C ) || + ( dgDialysateTemp < DIALYSATE_TEMP_LOW_LIMIT_C ) ); + + BOOL const dialysateTempRecovered = fabs( dgDialysateTemp - dgTrimmerTempSet ) < DIALYSATE_TEMP_RECOVERY_TOLERANCE_C ? TRUE : FALSE; + +#ifndef DISABLE_DIALYSATE_TEMP_CHECK + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dialysateHighTemp ) ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dgTrimmerTempSet, dgDialysateTemp ); + } + + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dialysateLowTemp ) ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dgTrimmerTempSet, dgDialysateTemp ); + } + + if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dialysateHighTemp ) ) + { + clearAlarmCondition( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH ); + } + + if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dialysateTempRecovered ) ) + { + clearAlarmCondition( ALARM_ID_DIALYSATE_TEMPERATURE_LOW ); + } +#endif +} + +/*********************************************************************//** + * @brief * The checkDGRestart function checks to see if DG has restarted after started * by HD and triggers appropriate alarm. * @details Inputs: dgStarted Index: firmware/App/Modes/BloodPrime.c =================================================================== diff -u -rec348bf3bbbe48b5a5e25d563a0aa5686bfcd237 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision ec348bf3bbbe48b5a5e25d563a0aa5686bfcd237) +++ firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -5,13 +5,13 @@ * 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 TreatmentEnd.c +* @file BloodPrime.c * -* @author (last) Sean Nash -* @date (last) 04-Feb-2021 +* @author (last) Sean Nash +* @date (last) 13-Aug-2021 * -* @author (original) Sean -* @date (original) 04-Feb-2021 +* @author (original) Sean Nash +* @date (original) 06-Feb-2021 * ***************************************************************************/ Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -r031627883dbd40abd52312d64a1a3b811478d1c3 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 031627883dbd40abd52312d64a1a3b811478d1c3) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 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 ModePostTreat.c +* @file ModePostTreat.c * -* @author (last) Sean Nash -* @date (last) 08-Oct-2020 +* @author (last) Quang Nguyen +* @date (last) 24-Aug-2021 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -rec348bf3bbbe48b5a5e25d563a0aa5686bfcd237 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision ec348bf3bbbe48b5a5e25d563a0aa5686bfcd237) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 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 TreatmentStop.c +* @file TreatmentStop.c * -* @author (last) Sean Nash -* @date (last) 24-Sep-2020 +* @author (last) Sean Nash +* @date (last) 19-Aug-2021 * -* @author (original) Sean -* @date (original) 15-Jan-2020 +* @author (original) Sean +* @date (original) 15-Jan-2020 * ***************************************************************************/ Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -214,7 +214,7 @@ if ( ( len <= ( COMM_BUFFER_LENGTH * DOUBLE_BUFFERS ) ) && ( len <= numberOfBytesInCommBuffer( buffer ) ) ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); U32 bytesInInactiveBuffer = commBufferByteCount[ buffer ][ inactiveBuffer ]; U32 sizeOfFirstConsumption = MIN( len, bytesInInactiveBuffer ); @@ -223,7 +223,7 @@ // Will return # of bytes consumed result = sizeOfFirstConsumption; // Do we need more from active buffer? - if ( len > bytesInInactiveBuffer ) + if ( len > sizeOfFirstConsumption ) { U32 remNumOfBytes = len - sizeOfFirstConsumption; U08 *remPtr = data + sizeOfFirstConsumption; @@ -272,7 +272,7 @@ if ( ( len <= ( COMM_BUFFER_LENGTH * DOUBLE_BUFFERS ) ) && ( len <= numberOfBytesInCommBuffer( buffer ) ) ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); U32 bytesInInactiveBuffer = commBufferByteCount[ buffer ][ inactiveBuffer ]; if ( len <= bytesInInactiveBuffer ) @@ -345,7 +345,7 @@ static U32 switchDoubleBuffer( COMM_BUFFER_T buffer ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); // Ensure inactive buffer is reset before making active commBufferByteCount[ buffer ][ inactiveBuffer ] = 0; @@ -371,7 +371,7 @@ static void getDataFromInactiveBuffer( COMM_BUFFER_T buffer, U08 *data, U32 len ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); U32 bytesInInactiveBuffer = commBufferByteCount[ buffer ][ inactiveBuffer ]; // Get the requested data from inactive buffer Index: firmware/App/Tasks/TaskBG.c =================================================================== diff -u -r031627883dbd40abd52312d64a1a3b811478d1c3 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Tasks/TaskBG.c (.../TaskBG.c) (revision 031627883dbd40abd52312d64a1a3b811478d1c3) +++ firmware/App/Tasks/TaskBG.c (.../TaskBG.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 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 TaskBG.c +* @file TaskBG.c * -* @author (last) Sean Nash -* @date (last) 24-Sep-2020 +* @author (last) Quang Nguyen +* @date (last) 06-Apr-2021 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/