Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r0d205f6ddf739549eb942d0b552b0a6790d4366f -r9a6e9998ef5fe9111c87e1bf948975a654d695ef --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 0d205f6ddf739549eb942d0b552b0a6790d4366f) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 9a6e9998ef5fe9111c87e1bf948975a654d695ef) @@ -45,7 +45,6 @@ #define DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C 2.0F ///< Dialysate temperature clear alarm tolerance C #define DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C 4.0F ///< Dialysate temperature out of target tolerance C. -#define DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ( 300 * MS_PER_SECOND ) ///< Dialysate temperature out of target timeout in milliseconds. #define DIALYSATE_TEMP_UPPER_MAX_SAFETY_LIMIT_C 46.0F ///< Dialysate upper bound maximum temperature limit in C. #define DIALYSATE_TEMP_UPPER_MAX_SAFETY_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Dialysate temperature upper bound maximum safety timeout in milliseconds. #define DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C 42.0F ///< Dialysate upper bound safety temperature limit in C. @@ -177,7 +176,6 @@ lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_1 ] = 0.0F; lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_2 ] = 0.0F; - initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_UPPER_MAX_SAFETY_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_HD_NEW_LOAD_CELL_DATA_MESSAGE_NOT_RECEIVE, DG_DATA_FRESHNESS_TIMEOUT_MS, DG_DATA_FRESHNESS_TIMEOUT_MS ); @@ -198,13 +196,18 @@ void resetTdiTempCounters ( void ) { //Initialize tdi temperature counter values - dgTdiTempCounter.tdiTempUpCounter = 0; - dgTdiTempCounter.tdiTempDownCounter = 0; - dgTdiTempCounter.prevTdiTempUpCounter = 0; - dgTdiTempCounter.prevTdiTempDownCounter = 0; - dgTdiTempCounter.clearAlarmStartTime = 0; - dgTdiTempCounter.dgPrevActiveReservoir = DG_RESERVOIR_2; - dgTdiTempCounter.dgCurrentActiveReservoir = DG_RESERVOIR_2; + dgTdiTempCounter.tdiHighTempUpCounter = 0; + dgTdiTempCounter.tdiHighTempDownCounter = 0; + dgTdiTempCounter.prevTdiHighTempUpCounter = 0; + dgTdiTempCounter.prevTdiHighTempDownCounter = 0; + dgTdiTempCounter.tdiHighclearAlarmStartTime = 0; + dgTdiTempCounter.tdiLowTempUpCounter = 0; + dgTdiTempCounter.tdiLowTempDownCounter = 0; + dgTdiTempCounter.prevTdiLowTempUpCounter = 0; + dgTdiTempCounter.prevTdiLowTempDownCounter = 0; + dgTdiTempCounter.tdiHighclearAlarmStartTime = 0; + dgTdiTempCounter.dgPrevActiveReservoir = DG_RESERVOIR_2; + dgTdiTempCounter.dgCurrentActiveReservoir = DG_RESERVOIR_2; } /**********************************************************************//** @@ -294,6 +297,30 @@ /*********************************************************************//** * @brief + * The getDGTdiTempCounter function gets the TDI temperature high and low counters values. + * @details Inputs: dgTdiTempCounter + * @details Outputs: none + * @return TDI temperature high and low temperature counter values. + *************************************************************************/ +DG_TDI_TEMP_COUNTER_T getDGTdiTempCounter( void ) +{ + return dgTdiTempCounter; +} + +/*********************************************************************//** + * @brief + * The getDGTdiTempetraure function gets the TDI temperature value. + * @details Inputs: dgDialysateTemp + * @details Outputs: none + * @return TDI temperature value. + *************************************************************************/ +F32 getDGTdiTempetraure( void ) +{ + return dgDialysateTemp; +} + +/*********************************************************************//** + * @brief * The getDGSubMode function gets the current DG operating sub-mode. * @details Inputs: dgSubMode * @details Outputs: none @@ -1299,65 +1326,110 @@ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_DIALYSATE_TEMP_CHECK ) != SW_CONFIG_ENABLE_VALUE ) #endif { - BOOL alarmIsActive = isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP ); + // Check Tdi High/Low temperature alarm active + BOOL alarmTdiHighIsActive = isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP ); + BOOL alarmTdiLowIsActive = isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP ); - if ( TRUE == isTempBelowTrigger ) + // Tdi high temp alarm clear + if ( dgDialysateTemp <= ( dgTrimmerTempSet + DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ) { - // clear alarm - if ( TRUE == alarmIsActive ) + if ( TRUE == alarmTdiHighIsActive ) { - if ( dgTdiTempCounter.clearAlarmStartTime == 0 ) + if ( dgTdiTempCounter.tdiHighclearAlarmStartTime == 0 ) { - dgTdiTempCounter.clearAlarmStartTime = getMSTimerCount(); + dgTdiTempCounter.tdiHighclearAlarmStartTime = getMSTimerCount(); } - else if ( TRUE == didTimeout(dgTdiTempCounter.clearAlarmStartTime, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ) ) + else if ( TRUE == didTimeout(dgTdiTempCounter.tdiHighclearAlarmStartTime, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ) ) { clearAlarmCondition( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP ); } } } else { - dgTdiTempCounter.clearAlarmStartTime = 0; + dgTdiTempCounter.tdiHighclearAlarmStartTime = 0; } - // Tdi high temp alarm handling + // Tdi Low temp alarm clear + if ( dgDialysateTemp >= ( dgTrimmerTempSet - DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ) + { + if ( TRUE == alarmTdiLowIsActive ) + { + if ( dgTdiTempCounter.tdiLowclearAlarmStartTime == 0 ) + { + dgTdiTempCounter.tdiLowclearAlarmStartTime = getMSTimerCount(); + } + else if ( TRUE == didTimeout(dgTdiTempCounter.tdiLowclearAlarmStartTime, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ) ) + { + clearAlarmCondition( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP ); + } + } + } + else + { + dgTdiTempCounter.tdiLowclearAlarmStartTime = 0; + } + if ( currentActiveRes != dgTdiTempCounter.dgPrevActiveReservoir ) { - //Increment up count when temperature is exceeded the defined threshold + // Tdi high temp alarm set if ( TRUE == isTempAboveTrigger ) { - //Increment up counter - dgTdiTempCounter.tdiTempUpCounter++; + //Increment tdi high temp up count when temperature is exceeded the defined threshold + dgTdiTempCounter.tdiHighTempUpCounter++; } - // Initiate down Counter only when temperature is crossed the threshold. otherwise do not increment down counter - else if ( dgTdiTempCounter.tdiTempUpCounter > 0 ) + // Initiate tdi high temp down Counter only when temperature is crossed the threshold. otherwise do not increment down counter + else if ( dgTdiTempCounter.tdiHighTempUpCounter > 0 ) { - //Increment down counter when temperature dips below threshold - dgTdiTempCounter.tdiTempDownCounter++; + dgTdiTempCounter.tdiHighTempDownCounter++; } + //Tdi Low temp alarm set + if ( TRUE == isTempBelowTrigger ) + { + //Increment tdi low temp down count when temperature is goes below the defined threshold + dgTdiTempCounter.tdiLowTempDownCounter++; + } + // Initiate Tdi low up Counter only when temperature is crossed the threshold. otherwise do not increment up counter + else if ( dgTdiTempCounter.tdiLowTempDownCounter > 0 ) + { + dgTdiTempCounter.tdiLowTempUpCounter++; + } + //get current reservoir value dgTdiTempCounter.dgCurrentActiveReservoir = currentActiveRes; } else { // last reservoir cycle temperature should have crossed the threshold level, // to compute next reservoir cycle temperature rise count is greater than the previous one. - if ( (dgTdiTempCounter.prevTdiTempUpCounter != 0) && - (dgTdiTempCounter.tdiTempUpCounter >= dgTdiTempCounter.prevTdiTempUpCounter ) && - (dgTdiTempCounter.tdiTempDownCounter <= dgTdiTempCounter.prevTdiTempDownCounter ) ) + if ( (dgTdiTempCounter.prevTdiHighTempUpCounter != 0) && + (dgTdiTempCounter.tdiHighTempUpCounter >= dgTdiTempCounter.prevTdiHighTempUpCounter ) && + (dgTdiTempCounter.tdiHighTempDownCounter <= dgTdiTempCounter.prevTdiHighTempDownCounter ) ) { //Activate Alarm SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, dgDialysateTemp, dgTrimmerTempSet ); } + // Tdi low temp alarm + if ( (dgTdiTempCounter.prevTdiLowTempDownCounter != 0) && + (dgTdiTempCounter.tdiLowTempDownCounter >= dgTdiTempCounter.prevTdiLowTempDownCounter ) && + (dgTdiTempCounter.tdiLowTempUpCounter <= dgTdiTempCounter.prevTdiLowTempUpCounter ) ) + { + //Activate Alarm + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, dgDialysateTemp, dgTrimmerTempSet ); + } // readiness for the next reservoir cycle - dgTdiTempCounter.prevTdiTempUpCounter = dgTdiTempCounter.tdiTempUpCounter; - dgTdiTempCounter.prevTdiTempDownCounter = dgTdiTempCounter.tdiTempDownCounter; - dgTdiTempCounter.tdiTempUpCounter = 0; - dgTdiTempCounter.tdiTempDownCounter = 0; + dgTdiTempCounter.prevTdiHighTempUpCounter = dgTdiTempCounter.tdiHighTempUpCounter; + dgTdiTempCounter.prevTdiHighTempDownCounter = dgTdiTempCounter.tdiHighTempDownCounter; + dgTdiTempCounter.tdiHighTempUpCounter = 0; + dgTdiTempCounter.tdiHighTempDownCounter = 0; + dgTdiTempCounter.prevTdiLowTempUpCounter = dgTdiTempCounter.tdiLowTempUpCounter; + dgTdiTempCounter.prevTdiLowTempDownCounter = dgTdiTempCounter.tdiLowTempDownCounter; + dgTdiTempCounter.tdiLowTempUpCounter = 0; + dgTdiTempCounter.tdiLowTempDownCounter = 0; + // assign last current reservoir to previous Active reservoir value once reservoir switch happened - dgTdiTempCounter.dgPrevActiveReservoir = dgTdiTempCounter.dgCurrentActiveReservoir; + dgTdiTempCounter.dgPrevActiveReservoir = dgTdiTempCounter.dgCurrentActiveReservoir; } // check clear condition first @@ -1366,12 +1438,6 @@ isTDiTempAboveHighSafety = ( dgDialysateTemp <= ( dgTrimmerTempSet + DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); } checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, isTDiTempAboveHighSafety, dgDialysateTemp, dgTrimmerTempSet ); - - if ( TRUE == isAlarmActive( ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP ) ) - { - isTempBelowTrigger = ( dgDialysateTemp >= ( dgTrimmerTempSet - DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); - } - checkPersistentAlarm(ALARM_ID_HD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, isTempBelowTrigger, dgDialysateTemp, dgTrimmerTempSet ); } }