Index: firmware/App/Controllers/ConcentratePumps.c =================================================================== diff -u -rf5dc98b3d5fcd39e3ab502fbe81110e188ce0ec5 -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision f5dc98b3d5fcd39e3ab502fbe81110e188ce0ec5) +++ firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -101,7 +101,6 @@ static CONCENTRATE_PUMP_STATE_T handleConcentratePumpOnState( CONCENTRATE_PUMPS_T pumpId ); static void calcMeasuredPumpsSpeed( CONCENTRATE_PUMPS_T pumpId, U16 pulseWidthCount ); -static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -149,8 +148,15 @@ // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + // Get the calibration values of acid and bicarb + // NOTE: since only the first acid and bicarb are used the number of sensors to check is acid or bicarb + 1 since the for loop + // starts from 0 and goes to sizeof the array so target sensor + 1 to just check the calibration time of the calibration values + // that are calibrated + getNVRecord2Driver( GET_CAL_ACID_CONCENTREATES, (U08*)&acidConcentrateCalRecord, sizeof( acidConcentrateCalRecord ), + ( CAL_DATA_ACID_CONCENTRATE_1 + 1 ), ALARM_ID_DG_ACID_CONCENTRATE_INVALID_CAL_RECORD ); + + getNVRecord2Driver( GET_CAL_BICARB_CONCENTRATES, (U08*)&bicarbConcentrateCalRecord, sizeof( bicarbConcentrateCalRecord ), + ( CAL_DATA_BICARB_CONCENTRATE_1 + 1 ), ALARM_ID_DG_BICARB_CONCENTRATE_INVALID_CAL_RECORD ); } if ( ++concentratePumpMonitorTimerCounter >= getU32OverrideValue( &concentratePumpDataPublishInterval ) ) @@ -236,9 +242,14 @@ SELF_TEST_STATUS_T execConcenratePumpsSelfTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + BOOL calStatus = FALSE; - BOOL calStatus = processCalibrationData(); + calStatus |= getNVRecord2Driver( GET_CAL_ACID_CONCENTREATES, (U08*)&acidConcentrateCalRecord, sizeof( acidConcentrateCalRecord ), + ( CAL_DATA_ACID_CONCENTRATE_1 + 1 ), ALARM_ID_DG_ACID_CONCENTRATE_INVALID_CAL_RECORD ); + calStatus |= getNVRecord2Driver( GET_CAL_BICARB_CONCENTRATES, (U08*)&bicarbConcentrateCalRecord, sizeof( bicarbConcentrateCalRecord ), + ( CAL_DATA_BICARB_CONCENTRATE_1 + 1 ), ALARM_ID_DG_BICARB_CONCENTRATE_INVALID_CAL_RECORD ); + if ( TRUE == calStatus ) { result = SELF_TEST_STATUS_PASSED; @@ -533,67 +544,7 @@ } } -/*********************************************************************//** - * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: acidConcentrateCalRecord, bicarbConcentrateCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - // Get the calibration record from NVDataMgmt - DG_ACID_CONCENTRATES_RECORD_T acidCalRecord = getDGAcidConcentratesRecord(); - DG_BICARB_CONCENTRATES_RECORD_T bicarbCalRecord = getDGBicarbConcentratesRecord(); - - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the data is not stored in the NV memory or it was corrupted. - if ( 0 == acidCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].calibrationTime ) - { -#ifndef SKIP_CAL_CHECK - activateAlarmNoData( ALARM_ID_DG_ACID_CONCENTRATE_INVALID_CAL_RECORD ); - status = FALSE; -#endif - } - - // NOTE: Right now only acid concentrate 1 is used, therefore there is no for loop - acidConcentrateCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].startVolume = - acidCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].startVolume; - - acidConcentrateCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio = - acidCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio; - - acidConcentrateCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].reserverdSpace = - acidCalRecord.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].reserverdSpace; - - // Check the validity of the bicarb concentrate values - if ( 0 == bicarbCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].calibrationTime ) - { -#ifndef SKIP_CAL_CHECK - activateAlarmNoData( ALARM_ID_DG_BICARB_CONCENTRATE_INVALID_CAL_RECORD ); - status = FALSE; -#endif - } - - // NOTE: Right now only bicarb concentrate 1 is used, therefore there is no for loop - bicarbConcentrateCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].startVolume = - bicarbCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].startVolume; - - bicarbConcentrateCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbConcMixRatio = - bicarbCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbConcMixRatio; - - bicarbConcentrateCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].reservedSpace = - bicarbCalRecord.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].reservedSpace; - - return status; -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Controllers/DialysateFlow.c =================================================================== diff -u -r1aeab08c1baf6445514b81fe51fc60a3e536e782 -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision 1aeab08c1baf6445514b81fe51fc60a3e536e782) +++ firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -58,7 +58,6 @@ // ********** private function prototypes ********** static void publishDialysateFlowData( void ); -static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -90,7 +89,8 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - BOOL calStatus = processCalibrationData(); + BOOL calStatus = getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); if ( TRUE == calStatus ) { @@ -126,8 +126,8 @@ // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); } // Read flow at the control set @@ -162,48 +162,6 @@ /*********************************************************************//** * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: flowSensorsCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - U32 sensor; - - // Get the calibration record from NVDataMgmt - DG_FLOW_SENSORS_CAL_RECORD_T calData = getDGFlowSensorsCalibrationRecord(); - - for ( sensor = 0; sensor < NUM_OF_CAL_DATA_FLOW_SENSORS; sensor++ ) - { -#ifndef SKIP_CAL_CHECK - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the flow sensors data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.flowSensors[ sensor ].calibrationTime ) - { - - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD, (U32)sensor ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy - flowSensorsCalRecord.flowSensors[ sensor ].fourthOrderCoeff = calData.flowSensors[ sensor ].fourthOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].thirdOrderCoeff = calData.flowSensors[ sensor ].thirdOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].secondOrderCoeff = calData.flowSensors[ sensor ].secondOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].gain = calData.flowSensors[ sensor ].gain; - flowSensorsCalRecord.flowSensors[ sensor ].offset = calData.flowSensors[ sensor ].offset; - } - - return status; -} - -/*********************************************************************//** - * @brief * The publishDialysateFlowData function publishes Dialysate flow data at the set interval. * @details Inputs: dialysateFlowDataPublicationTimerCounter * @details Outputs: dialysateFlowDataPublicationTimerCounter Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -r94a190522ce398399c7b93c59f788d7666ec0060 -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 94a190522ce398399c7b93c59f788d7666ec0060) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -84,7 +84,6 @@ // ********** private function prototypes ********** -static BOOL processCalibrationData( void ); static void monitorLoadCellsWeightOutOfRange( LOAD_CELL_ID_T loadCell ); static void monitorLoadCellsPrimaryBackupDriftOutOfRange( void ); @@ -178,8 +177,8 @@ // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + getNVRecord2Driver( GET_CAL_LOAD_CELL_SENSORS, (U08*)&loadCellsCalRecord, sizeof( DG_LOAD_CELLS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_LOAD_CELLS, ALARM_ID_DG_LOAD_CELLS_INVALID_CALIBRATION ); // Zero the current tare values when new calibration data is available loadcells[ LOAD_CELL_RESERVOIR_1_PRIMARY ].autoCalOffset = 0.0; @@ -270,7 +269,8 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - BOOL calStatus = processCalibrationData(); + BOOL calStatus = getNVRecord2Driver( GET_CAL_LOAD_CELL_SENSORS, (U08*)&loadCellsCalRecord, sizeof( DG_LOAD_CELLS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_LOAD_CELLS, ALARM_ID_DG_LOAD_CELLS_INVALID_CALIBRATION ); if ( TRUE == calStatus ) { @@ -440,47 +440,6 @@ /*********************************************************************//** * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: loadCellsCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - U32 cell; - - // Get the calibration record from NVDataMgmt - DG_LOAD_CELLS_CAL_RECORD_T calData = getDGLoadCellsCalibrationRecord(); - - for ( cell = 0; cell < NUM_OF_CAL_DATA_LOAD_CELLS; cell++ ) - { -#ifndef SKIP_CAL_CHECK - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the load cells data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.loadCells[ cell ].calibrationTime ) - { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_LOAD_CELLS_INVALID_CALIBRATION, (U32)cell ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy - loadCellsCalRecord.loadCells[ cell ].fourthOrderCoeff = calData.loadCells[ cell ].fourthOrderCoeff; - loadCellsCalRecord.loadCells[ cell ].thirdOrderCoeff = calData.loadCells[ cell ].thirdOrderCoeff; - loadCellsCalRecord.loadCells[ cell ].secondOrderCoeff = calData.loadCells[ cell ].secondOrderCoeff; - loadCellsCalRecord.loadCells[ cell ].gain = calData.loadCells[ cell ].gain; - loadCellsCalRecord.loadCells[ cell ].offset = calData.loadCells[ cell ].offset; - } - - return status; -} - -/*********************************************************************//** - * @brief * The monitorLoadCellsWeightOutOfRange function monitors the weight of the * load cells and if they are not in range, it raises an alarm. * @details Inputs: none Index: firmware/App/Controllers/Pressures.c =================================================================== diff -u -r94a190522ce398399c7b93c59f788d7666ec0060 -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision 94a190522ce398399c7b93c59f788d7666ec0060) +++ firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -88,7 +88,6 @@ static PRESSURE_STATE_T handlePressuresInitState( void ); static PRESSURE_STATE_T handlePressuresContReadState( void ); static void publishPressuresData( void ); -static BOOL processCalibrationData( void ); static SELF_TEST_STATUS_T handleSelfTestADCCheck( void ); @@ -223,7 +222,8 @@ switch ( pressuresSelfTestState ) { case PRESSURE_SELF_TEST_STATE_START: - processCalibrationData(); + getNVRecord2Driver( GET_CAL_PRESSURE_SENOSRS, (U08*)&pressuresCalRecord, sizeof( DG_PRES_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_PRES_SENSORS, ALARM_ID_DG_PRESSURE_SENSORS_INVALID_CAL_RECORD ); pressuresSelfTestState = PRESSURE_TEST_STATE_IN_PROGRESS; pressuresSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; break; @@ -274,21 +274,21 @@ F32 pressureReading; // get latest raw pressure readings - measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_INLET ] = (S32)getIntADCReading( INT_ADC_RO_PUMP_INLET_PRESSURE ) - PUMP_PRESSURE_ZERO; - measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] = (S32)getIntADCReading( INT_ADC_RO_PUMP_OUTLET_PRESSURE ) - PUMP_PRESSURE_ZERO; - measuredPressureReadingsRaw[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = (S32)getIntADCReading( INT_ADC_DRAIN_PUMP_INLET_PRESSURE ) - PUMP_PRESSURE_ZERO; + measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_INLET ] = (S32)getIntADCReading( INT_ADC_RO_PUMP_INLET_PRESSURE ) - PUMP_PRESSURE_ZERO; + measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] = (S32)getIntADCReading( INT_ADC_RO_PUMP_OUTLET_PRESSURE ) - PUMP_PRESSURE_ZERO; + measuredPressureReadingsRaw[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = (S32)getIntADCReading( INT_ADC_DRAIN_PUMP_INLET_PRESSURE ) - PUMP_PRESSURE_ZERO; measuredPressureReadingsRaw[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] = (S32)getIntADCReading( INT_ADC_DRAIN_PUMP_OUTLET_PRESSURE ) - PUMP_PRESSURE_ZERO; // update sums for pressure average calculations - measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_INLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_INLET ]; - measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_OUTLET ]; - measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ]; + measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_INLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_INLET ]; + measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_RO_PUMP_OUTLET ]; + measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ]; measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] += measuredPressureReadingsRaw[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ]; // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + getNVRecord2Driver( GET_CAL_PRESSURE_SENOSRS, (U08*)&pressuresCalRecord, sizeof( DG_PRES_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_PRES_SENSORS, ALARM_ID_DG_PRESSURE_SENSORS_INVALID_CAL_RECORD ); } // filter every 200ms @@ -298,15 +298,15 @@ F32 pressuresBeforeCal[ NUM_OF_PRESSURE_SENSORS ]; // Calculate average pressures - F32 avgRoIn = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_INLET ] * PRESSURE_AVERAGE_MULTIPLIER; - F32 avgRoOut = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] * PRESSURE_AVERAGE_MULTIPLIER; - F32 avgDrnIn = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] * PRESSURE_AVERAGE_MULTIPLIER; + F32 avgRoIn = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_INLET ] * PRESSURE_AVERAGE_MULTIPLIER; + F32 avgRoOut = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] * PRESSURE_AVERAGE_MULTIPLIER; + F32 avgDrnIn = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] * PRESSURE_AVERAGE_MULTIPLIER; F32 avgDrnOut = (F32)measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] * PRESSURE_AVERAGE_MULTIPLIER; // Convert average pressure readings to PSI - pressuresBeforeCal[ PRESSURE_SENSOR_RO_PUMP_INLET ] = avgRoIn * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; - pressuresBeforeCal[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] = avgRoOut * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; - pressuresBeforeCal[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = avgDrnIn * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; + pressuresBeforeCal[ PRESSURE_SENSOR_RO_PUMP_INLET ] = avgRoIn * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; + pressuresBeforeCal[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] = avgRoOut * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; + pressuresBeforeCal[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = avgDrnIn * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; pressuresBeforeCal[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] = avgDrnOut * PUMP_PRESSURE_PSIA_PER_COUNT - PUMP_PRESSURE_PSIA_TO_PSI_OFFSET; // Reset average counter @@ -323,9 +323,9 @@ } // reset sums for next averaging - measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_INLET ] = 0; - measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] = 0; - measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = 0; + measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_INLET ] = 0; + measuredPressureReadingsSum[ PRESSURE_SENSOR_RO_PUMP_OUTLET ] = 0; + measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = 0; measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] = 0; } @@ -341,48 +341,6 @@ return result; } -/*********************************************************************//** - * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: pressuresCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - U32 sensor; - - // Get the calibration record from NVDataMgmt - DG_PRES_SENSORS_CAL_RECORD_T calData = getDGPressureSensorsCalibrationRecord(); - - for ( sensor = 0; sensor < NUM_OF_CAL_DATA_PRES_SENSORS; sensor++ ) - { -#ifndef SKIP_CAL_CHECK - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.pressureSensors[ sensor ].calibrationTime ) - { - - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_PRESSURE_SENSORS_INVALID_CAL_RECORD, (U32)sensor ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy - pressuresCalRecord.pressureSensors[ sensor ].fourthOrderCoeff = calData.pressureSensors[ sensor ].fourthOrderCoeff; - pressuresCalRecord.pressureSensors[ sensor ].thirdOrderCoeff = calData.pressureSensors[ sensor ].thirdOrderCoeff; - pressuresCalRecord.pressureSensors[ sensor ].secondOrderCoeff = calData.pressureSensors[ sensor ].secondOrderCoeff; - pressuresCalRecord.pressureSensors[ sensor ].gain = calData.pressureSensors[ sensor ].gain; - pressuresCalRecord.pressureSensors[ sensor ].offset = calData.pressureSensors[ sensor ].offset; - } - - return status; -} - /*********************************************************************//** * @brief * The publishPressuresData function publishes DG pressures data at a set interval. Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -151,7 +151,6 @@ static void setROPumpControlSignalDutyCycle( F32 dutyCycle ); static void stopROPump( void ); static void publishROPumpData( void ); -static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -321,7 +320,7 @@ /*********************************************************************//** * @brief - * The execROPumpMonitor function executes the RO pump monitor. The RO flow + * The execROPumpMonitor function executes the RO pump monitor. The RO flow * sensor is read, filtered, converted to L/min and calibrated. * @details Inputs: measuredFlowReadingsSum, flowFilterCounter, * measuredROFlowRateLPM, measuredROFlowRateLPM, roPumpState, @@ -347,8 +346,8 @@ // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); } // Read flow at the control set @@ -492,7 +491,8 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - BOOL calStatus = processCalibrationData(); + BOOL calStatus = getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); if ( TRUE == calStatus ) { @@ -796,48 +796,6 @@ /*********************************************************************//** * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: flowSensorsCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - U32 sensor; - - // Get the calibration record from NVDataMgmt - DG_FLOW_SENSORS_CAL_RECORD_T calData = getDGFlowSensorsCalibrationRecord(); - - for ( sensor = 0; sensor < NUM_OF_CAL_DATA_FLOW_SENSORS; sensor++ ) - { -#ifndef SKIP_CAL_CHECK - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the flow sensors data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.flowSensors[ sensor ].calibrationTime ) - { - - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD, (U32)sensor ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy - flowSensorsCalRecord.flowSensors[ sensor ].fourthOrderCoeff = calData.flowSensors[ sensor ].fourthOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].thirdOrderCoeff = calData.flowSensors[ sensor ].thirdOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].secondOrderCoeff = calData.flowSensors[ sensor ].secondOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].gain = calData.flowSensors[ sensor ].gain; - flowSensorsCalRecord.flowSensors[ sensor ].offset = calData.flowSensors[ sensor ].offset; - } - - return status; -} - -/*********************************************************************//** - * @brief * The publishROPumpData function publishes RO pump data at the set interval. * @details Inputs: roPumpDataPublicationTimerCounter * @details Outputs: roPumpDataPublicationTimerCounter Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -73,16 +73,17 @@ * @brief * The initDrainMode function initializes the drain mode module. * @details Inputs: none - * @details Outputs: drainState, drainEmptyTareTimerCtr, dialysateDrainStartTime + * @details Outputs: drainState, drainEmptyTareTimerCtr, dialysateDrainStartTime, + * rinseConcentrateLines, rinseConcentrateLinesTimerCtr * @return none *************************************************************************/ void initDrainMode( void ) { - drainState = DG_DRAIN_STATE_START; - drainEmptyTareTimerCtr = 0; - rinseConcentrateLines = FALSE; + drainState = DG_DRAIN_STATE_START; + drainEmptyTareTimerCtr = 0; + rinseConcentrateLines = FALSE; rinseConcentrateLinesTimerCtr = 0; - dialysateDrainStartTime = 0; + dialysateDrainStartTime = 0; } /*********************************************************************//** Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r70031fe2d788c19ba0ec4779f144751b2ba3d3f9 -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 70031fe2d788c19ba0ec4779f144751b2ba3d3f9) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -15,6 +15,8 @@ * ***************************************************************************/ +#include // For fabs + #include "ConcentratePumps.h" #include "ConductivitySensors.h" #include "FPGA.h" @@ -43,7 +45,6 @@ // ********** private definitions ********** #define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. -#define TARGET_RO_FLOW_RATE_L 0.8 //TODO do we need to use this as default? ///< Target flow rate for RO pump. #define DIALYSATE_FILL_TIME_OUT ( 5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Time out period when reservoir is not filled with correct dialysate. #define EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ( 5 * MS_PER_SECOND ) ///< Persistent period for empty bottle detect. @@ -58,6 +59,8 @@ #define WATER_QUALITY_CHECK_TIME_OUT_MS ( 30 * MS_PER_SECOND ) ///< Inlet water quality check time out period in ms. #define DIALYSATE_TEMPERATURE_TOLERANCE_C 2.0 ///< Dialysate temperature tolerance in degree C. +#define DIALYSATE_TEMPERATURE_SENSORS_MAX_DRIFT_C 2.0 ///< Dialysate temperature sensors maximum allowed drift in C. +#define DIALYSATE_TEMPERATURE_SENSORS_DRIFT_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Dialysate temperature sensors drift timeout in milliseconds. #define ACID_CONCENTRATION_BOTTLE_VOLUME_ML 3000.0 ///< Volume of acid concentration in ml. #define BICARB_CONCENTRATION_BOTTLE_VOLUME_ML 3000.0 ///< Volume of bicarb concentration in ml. @@ -107,6 +110,7 @@ static DG_FILL_MODE_STATE_T handlePausedState( void ); static BOOL isWaterQualityGood( void ); +static void checkDialysateTemperatureSensorsDrift( void ); static BOOL checkDialysateTemperature( void ); static void handleDialysateMixing( F32 measuredROFlowRate_mL_min ); static void setFillInfoToRTCRAM( void ); @@ -115,7 +119,10 @@ * @brief * The initFillMode function initializes the fill mode module. * @details Inputs: none - * @details Outputs: Fill mode module initialized + * @details Outputs: fillState, dialysateFillStartTime, reservoirBaseWeight, + * totalROFlowRateMLPM, concentrateTestStartTime, acidConductivityTotal, + * dialysateConductivityTotal, conductivitySampleCount, + * concentratePumpPrimeCount * @return none *************************************************************************/ void initFillMode( void ) @@ -132,6 +139,7 @@ initPersistentAlarm( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE, 0, EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ); initPersistentAlarm( ALARM_ID_BICARB_CONDUCTIVITY_OUT_OF_RANGE, 0, EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ); + initPersistentAlarm( ALARM_ID_DG_DIALYSATE_TEMPERATURE_SENSORS_DRFIT_TIMEOUT, 0, DIALYSATE_TEMPERATURE_SENSORS_DRIFT_TIMEOUT_MS ); } /*********************************************************************//** @@ -182,6 +190,7 @@ checkInletWaterTemperature(); checkInletPressure(); checkRORejectionRatio(); + checkDialysateTemperatureSensorsDrift(); // TODO: Check for open straw door status and alarm if closed // Check if run out of time to fill the reservoir @@ -280,8 +289,12 @@ *************************************************************************/ void resetFillStatusParameters( void ) { - // Get the heaters info form the NV data management - DG_HEATERS_RECORD_T heaterInfo = getHeatersInfoReocrd(); + DG_HEATERS_RECORD_T heaterInfo; + // There is no number of NV data to check for the heaters info so it is passed as 0 + U08 numOfNVData2Check = 0; + // Get the heaters info from the NV data management. Do not alarm on the status of the data since it has already been checked in NV POST + getNVRecord2Driver( GET_INF_HEATERS_RECORD, (U08*)&heaterInfo, sizeof( DG_HEATERS_RECORD_T ), numOfNVData2Check, ALARM_ID_NO_ALARM ); + // If the data in the NV data management was not initialized properly, set it to 0 otherwise, set the average flow rate fillStatus.fillFlowRateAverage = ( heaterInfo.averageFillFlow < NEARLY_ZERO ? 0.0 : heaterInfo.averageFillFlow ); fillStatus.fillFlowRateRunningSum = 0.0; @@ -323,14 +336,24 @@ if ( TRUE == isWaterQualityGood() ) #endif { - concentrateTestStartTime = getMSTimerCount(); -#ifndef DISABLE_MIXING + // If this is the first fill of a treatment, prime and acid and bicarb lines, otherwise transition + // to dialysate production directly + if ( TRUE == isThisTheFirstFill() ) + { + concentrateTestStartTime = getMSTimerCount(); + #ifndef DISABLE_MIXING - setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, CONCENTRATE_PUMP_MAX_SPEED ); - requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); - requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); -#endif - result = DG_FILL_MODE_STATE_BICARB_PUMP_CHECK; + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, CONCENTRATE_PUMP_MAX_SPEED ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); + requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); + #endif + result = DG_FILL_MODE_STATE_BICARB_PUMP_CHECK; + } + else + { + result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + } + } if ( TRUE == didTimeout( waterQualityCheckStartTime, WATER_QUALITY_CHECK_TIME_OUT_MS ) ) @@ -660,6 +683,29 @@ /*********************************************************************//** * @brief + * The checkDialysateTemperatureSensorsDrift function checks whether the + * dialysate temperature sensors have drifted. If they are drifted, it raises + * an alarm. + * @details Inputs: none + * @details Outputs: None + * @return none + *************************************************************************/ +static void checkDialysateTemperatureSensorsDrift( void ) +{ +#ifndef THD_USING_TRO_CONNECTOR // Do not use until TRo is back in line + F32 TDi = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); + F32 TRo = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); + BOOL isDriftOut = ( fabs( TDi - TRo ) >= DIALYSATE_TEMPERATURE_SENSORS_MAX_DRIFT_C ? TRUE : FALSE ); + + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DG_DIALYSATE_TEMPERATURE_SENSORS_DRFIT_TIMEOUT, isDriftOut ) ) + { + activateAlarmNoData( ALARM_ID_DG_DIALYSATE_TEMPERATURE_SENSORS_DRFIT_TIMEOUT ); + } +#endif +} + +/*********************************************************************//** + * @brief * The checkDialysateTemperature function checks dialysate temperature after * it gets heated up by primary heater. * @details Inputs: TPo temperature value Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r33d5acc68ffe045546a4fa9a7d381950619ea45d -ra069eb423b26296eb95214e18383c81adae07497 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 33d5acc68ffe045546a4fa9a7d381950619ea45d) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision a069eb423b26296eb95214e18383c81adae07497) @@ -532,7 +532,9 @@ DG_ACID_CONCENTRATES_RECORD_T acid = getAcidConcentrateCalRecord(); DG_BICARB_CONCENTRATES_RECORD_T bicarb = getBicarbConcentrateCalRecord(); - U32 fillPrepTimeMS = 9000; // TODO make a get for this in mode fill + // By the time these are requested, the prepare time is no longer needed since the concentrate lines are + // primed before the actual treatment starts + U32 fillPrepTimeMS = 0; U08 *payloadPtr = msg.payload;