Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r5e85dc21e918ecdae841f8398bca20ff8823c52b -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 5e85dc21e918ecdae841f8398bca20ff8823c52b) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -161,8 +161,6 @@ static MOTOR_DIR_T bloodPumpDirectionSet = MOTOR_DIR_FORWARD; ///< Currently set blood flow direction static PUMP_CONTROL_MODE_T bloodPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested blood pump control mode. static PUMP_CONTROL_MODE_T bloodPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Currently set blood pump control mode. -static F32 bloodFlowCalGain = 1.0; ///< Blood flow calibration gain. -static F32 bloodFlowCalOffset = 0.0; ///< Blood flow calibration offset. /// Interval (in task intervals) at which to publish blood flow data to CAN bus. static OVERRIDE_U32_T bloodFlowDataPublishInterval = { BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, 0 }; @@ -195,6 +193,7 @@ static U08 lastBloodFlowSlowPacketReadCtr = 0; ///< Previous read counter for the blood flow slow packets. static U08 lastBloodPumpDirectionCount = 0; ///< Previous pump direction error count reported by FPGA. static U08 lastBloodFlowCommErrorCount = 0; ///< Previous BP flow sensor comm error count. +static HD_FLOW_SENSORS_CAL_RECORD_T bloodFlowCalRecord; ///< Blood flow sensor calibration record. // ********** private function prototypes ********** @@ -215,7 +214,8 @@ static void checkBloodPumpSpeeds( void ); static void checkBloodPumpFlowAgainstSpeed( void ); static void checkBloodPumpMCCurrent( void ); -static void checkBloodFlowSensorSignalStrength( void ); +static void checkBloodFlowSensorSignalStrength( void ); +static BOOL processCalibrationData( void ); static U32 getPublishBloodFlowDataInterval( void ); /*********************************************************************//** @@ -438,20 +438,34 @@ * @brief * The execBloodFlowMonitor function executes the blood flow monitor. * @details Inputs: none - * @details Outputs: measuredBloodFlowRate, adcBloodPumpMCSpeedRPM, adcBloodPumpMCCurrentmA + * @details Outputs: measuredBloodFlowRate, adcBloodPumpMCSpeedRPM, + * adcBloodPumpMCCurrentmA * @return none *************************************************************************/ void execBloodFlowMonitor( void ) { + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // Get the new calibration data and check its validity + processCalibrationData(); + } + HD_OP_MODE_T opMode = getCurrentOperationMode(); U16 bpRPM = getIntADCReading( INT_ADC_BLOOD_PUMP_SPEED ); U16 bpmA = getIntADCReading( INT_ADC_BLOOD_PUMP_MOTOR_CURRENT ); - F32 bpFlow = ( getFPGABloodFlow() * bloodFlowCalGain ) + bloodFlowCalOffset; U08 fpReadCtr = getFPGABloodFlowFastPacketReadCounter(); U08 spReadCtr = getFPGABloodFlowSlowPacketReadCounter(); U08 flowErrorCtr = getFPGABloodFlowErrorCounter(); U08 flowStatus = getFPGABloodFlowMeterStatus(); + F32 fpgaBloodFlow = getFPGABloodFlow(); + F32 bpFlow = pow(fpgaBloodFlow, 4) * bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].fourthOrderCoeff + + pow(fpgaBloodFlow, 3) * bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].thirdOrderCoeff + + pow(fpgaBloodFlow, 2) * bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].secondOrderCoeff + + fpgaBloodFlow * bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].gain + + bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].offset; + #ifndef DISABLE_PUMP_FLOW_CHECKS if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_FLOW_SENSOR_ERROR, ( flowErrorCtr != lastBloodFlowCommErrorCount ) ) ) { @@ -1232,6 +1246,52 @@ } } #endif +} + +/*********************************************************************//** + * @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: bloodFlowCalRecord + * @return TRUE if the calibration record is valid, otherwise FALSE + *************************************************************************/ +static BOOL processCalibrationData( void ) +{ + BOOL status = TRUE; + + // Get the calibration record from NVDataMgmt + HD_FLOW_SENSORS_CAL_RECORD_T calData = getHDFlowSensorsCalibrationRecord(); + + // 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 blood flow sensors data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].calibrationTime ) + { +#ifndef SKIP_CAL_CHECK + activateAlarmNoData( ALARM_ID_HD_BLOOD_FLOW_INVALID_CAL_RECORD ); + status = FALSE; +#endif + } + + // The calibration data was valid, update the local copy + bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].fourthOrderCoeff = + calData.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].fourthOrderCoeff; + + bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].thirdOrderCoeff = + calData.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].thirdOrderCoeff; + + bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].secondOrderCoeff = + calData.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].secondOrderCoeff; + + bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].gain = + calData.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].gain; + + bloodFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].offset = + calData.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].offset; + + return status; } /*********************************************************************//** @@ -1244,27 +1304,21 @@ *************************************************************************/ SELF_TEST_STATUS_T execBloodFlowTest( void ) { - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; U08 const bfmStatus = getFPGABloodFlowMeterStatus(); - // Get the flow sensors calibration record - HD_FLOW_SENSORS_CAL_RECORD_T cal = getHDFlowSensorsCalibrationRecord(); - // Retrieve blood flow sensor calibration data and check for sensor connected status if ( BFM_SENSOR_PARAM_CORRUPT_STATUS != bfmStatus ) { -#ifndef DISABLE_CAL_CHECK - if ( cal.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].calibrationTime == 0 ) + BOOL calStatus = processCalibrationData(); + + if ( TRUE == calStatus ) { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_BLOOD_FLOW_INVALID_CALIBRATION, cal.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].calibrationTime, - cal.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].crc ); + result = SELF_TEST_STATUS_PASSED; } else -#endif { - bloodFlowCalGain = cal.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].gain; - bloodFlowCalOffset = cal.hdFlowSensors[ CAL_DATA_HD_BLOOD_FLOW_SENSOR ].offset; - result = SELF_TEST_STATUS_PASSED; + result = SELF_TEST_STATUS_FAILED; } } else Index: firmware/App/Controllers/BloodFlow.h =================================================================== diff -u -r70d33c50c8c3fd987f39eaa1f3b294860d569830 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Controllers/BloodFlow.h (.../BloodFlow.h) (revision 70d33c50c8c3fd987f39eaa1f3b294860d569830) +++ firmware/App/Controllers/BloodFlow.h (.../BloodFlow.h) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -74,8 +74,6 @@ F32 getMeasuredBloodPumpMCSpeed( void ); F32 getMeasuredBloodPumpMCCurrent( void ); -BOOL setBloodFlowCalibration( F32 gain, F32 offset ); -void getBloodFlowCalibration( F32 *gain, F32 *offset ); BOOL testSetBloodFlowDataPublishIntervalOverride( U32 value ); BOOL testResetBloodFlowDataPublishIntervalOverride( void ); BOOL testSetTargetBloodFlowRateOverride( S32 value, U32 bloodPumpControlMode ); Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r44a100f8e5210a02c23b8fcc4527d8e96d577381 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -163,8 +163,6 @@ static MOTOR_DIR_T dialInPumpDirectionSet = MOTOR_DIR_FORWARD; ///< Currently set dialysate flow direction static PUMP_CONTROL_MODE_T dialInPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested dialIn pump control mode. static PUMP_CONTROL_MODE_T dialInPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP;///< Currently set dialIn pump control mode. -static F32 dialInFlowCalGain = 1.0; ///< Dialysate flow calibration gain. -static F32 dialInFlowCalOffset = 0.0; ///< Dialysate flow calibration offset. /// Interval (in ms) at which to publish dialIn flow data to CAN bus static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; @@ -203,6 +201,7 @@ static U08 lastDialysateFlowSlowPacketReadCtr = 0; ///< Previous read counter for the dialysate flow slow packets. static U08 lastDialInPumpDirectionCount = 0; ///< Previous pump direction error count reported by FPGA. static U08 lastDialysateFlowCommErrorCount = 0; ///< Previous DPi flow sensor comm error count. +static HD_FLOW_SENSORS_CAL_RECORD_T dialysateFlowCalRecord; ///< Dialysate flow sensor calibration record. // ********** private function prototypes ********** @@ -224,7 +223,8 @@ static void checkDialInPumpFlowAgainstSpeed( void ); static void checkDialInPumpMCCurrent( void ); static void checkDialInFlowSensorSignalStrength( void ); -static U32 getPublishDialInFlowDataInterval( void ); +static U32 getPublishDialInFlowDataInterval( void ); +static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -414,16 +414,29 @@ * @return none *************************************************************************/ void execDialInFlowMonitor( void ) -{ +{ + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // Get the new calibration data and check its validity + processCalibrationData(); + } + HD_OP_MODE_T opMode = getCurrentOperationMode(); U16 dipRPM = getIntADCReading( INT_ADC_DIAL_IN_PUMP_SPEED ); U16 dipmA = getIntADCReading( INT_ADC_DIAL_IN_PUMP_MOTOR_CURRENT ); - F32 dipFlow = ( getFPGADialysateFlow() * dialInFlowCalGain ) + dialInFlowCalOffset; U08 fpReadCtr = getFPGADialysateFlowFastPacketReadCounter(); U08 spReadCtr = getFPGADialysateFlowSlowPacketReadCounter(); U08 flowErrorCtr = getFPGADialysateFlowErrorCounter(); U08 flowStatus = getFPGADialysateFlowMeterStatus(); + F32 fpgaDialysateFlow = getFPGADialysateFlow(); + F32 dipFlow = pow(fpgaDialysateFlow, 4) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff + + pow(fpgaDialysateFlow, 3) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff + + pow(fpgaDialysateFlow, 2) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff + + fpgaDialysateFlow * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain + + dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset; + #ifndef DISABLE_PUMP_FLOW_CHECKS if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR, ( flowErrorCtr != lastDialysateFlowCommErrorCount ) ) ) { @@ -748,6 +761,52 @@ 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: dialysateFlowCalRecord + * @return TRUE if the calibration record is valid, otherwise FALSE + *************************************************************************/ +static BOOL processCalibrationData( void ) +{ + BOOL status = TRUE; + + // Get the calibration record from NVDataMgmt + HD_FLOW_SENSORS_CAL_RECORD_T calData = getHDFlowSensorsCalibrationRecord(); + + // 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 dialysate flow sensors data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].calibrationTime ) + { +#ifndef SKIP_CAL_CHECK + activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_INVALID_CAL_RECORD ); + status = FALSE; +#endif + } + + // The calibration data was valid, update the local copy + dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff = + calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff; + + dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff = + calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff; + + dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff = + calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff; + + dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain = + calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain; + + dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset = + calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset; + + return status; +} /*********************************************************************//** * @brief @@ -1288,25 +1347,20 @@ *************************************************************************/ SELF_TEST_STATUS_T execDialInFlowTest( void ) { - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; U08 const dfmStatus = getFPGADialysateFlowMeterStatus(); - // Get the flow sensors calibration record - HD_FLOW_SENSORS_CAL_RECORD_T cal = getHDFlowSensorsCalibrationRecord(); if ( DFM_SENSOR_PARAM_CORRUPT_STATUS != dfmStatus ) { -#ifndef DISABLE_CAL_CHECK - if ( cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].calibrationTime == 0 ) + BOOL calStatus = processCalibrationData(); + + if ( TRUE == calStatus ) { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_DIALYSATE_FLOW_INVALID_CALIBRATION, cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].calibrationTime, - cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].crc ); + result = SELF_TEST_STATUS_PASSED; } else -#endif { - dialInFlowCalGain = cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].gain; - dialInFlowCalOffset = cal.hdFlowSensors[ CAL_DATA_HD_DIALYZER_FLOW_SENSOR ].offset; - result = SELF_TEST_STATUS_PASSED; + result = SELF_TEST_STATUS_FAILED; } } else Index: firmware/App/Controllers/DialInFlow.h =================================================================== diff -u -r933a18d740285e70be9d00696ed0f5a5381bc8e4 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Controllers/DialInFlow.h (.../DialInFlow.h) (revision 933a18d740285e70be9d00696ed0f5a5381bc8e4) +++ firmware/App/Controllers/DialInFlow.h (.../DialInFlow.h) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -70,8 +70,6 @@ F32 getMeasuredDialInPumpMCSpeed( void ); F32 getMeasuredDialInPumpMCCurrent( void ); -BOOL setDialInFlowCalibration( F32 gain, F32 offset ); -void getDialInFlowCalibration( F32 *gain, F32 *offset ); BOOL testSetDialInFlowDataPublishIntervalOverride( U32 value ); BOOL testResetDialInFlowDataPublishIntervalOverride( void ); BOOL testSetTargetDialInFlowRateOverride( S32 value, U32 ctrlMode ); Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -r898f53e09092ab452b518c737c3c8381641d3d2d -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 898f53e09092ab452b518c737c3c8381641d3d2d) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -14,10 +14,12 @@ * @date (original) 02-Mar-2021 * ***************************************************************************/ +#include #include "AlarmMgmt.h" #include "FPGA.h" -#include "ModeTreatmentParams.h" +#include "ModeTreatmentParams.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "SafetyShutdown.h" @@ -216,6 +218,7 @@ static U32 syringePumpStallCtr; ///< Counts time when position is not changing during ramp. static U32 syringePumpStallRetryCount; ///< Counts pump ramp up stall retries. +static HD_HEPARIN_FORCE_SENSOR_CAL_RECORD_T forceSensorCalRecord; ///< HD heparin force sensor calibration record. // ********** private function prototypes ********** @@ -251,6 +254,7 @@ static BOOL checkVolumeVsSafetyVolume( BOOL stopPump, F32 pctMargin ); static BOOL checkForStall( BOOL stopPump ); static void publishSyringePumpData( void ); +static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -944,6 +948,20 @@ *************************************************************************/ static void execSyringePumpMonitor( void ) { + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // Get the new calibration data and check its validity + processCalibrationData(); + } + + F32 forceSensorBeforCal = ( (F32)getFPGASyringePumpADCChannel0() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; + syringePumpMeasForce.data = pow(forceSensorBeforCal, 4) * forceSensorCalRecord.hdHeparinForceSensor.fourthOrderCoeff + + pow(forceSensorBeforCal, 3) * forceSensorCalRecord.hdHeparinForceSensor.thirdOrderCoeff + + pow(forceSensorBeforCal, 2) * forceSensorCalRecord.hdHeparinForceSensor.secondOrderCoeff + + forceSensorBeforCal * forceSensorCalRecord.hdHeparinForceSensor.gain + + forceSensorCalRecord.hdHeparinForceSensor.offset; + S32 encPosition = getFPGASyringePumpEncoderPosition(); // Get latest FPGA status @@ -955,7 +973,7 @@ // Get latest ADC data and convert to V syringePumpMeasHome.data = ( (F32)getFPGASyringePumpADCChannel2() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; syringePumpMeasSyringeDetectionSwitch.data = ( (F32)getFPGASyringePumpADCChannel1() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; - syringePumpMeasForce.data = ( (F32)getFPGASyringePumpADCChannel0() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; + // Apply home offset to encoder position syringePumpLastPosition = getSyringePumpPosition(); syringePumpPosition.data = encPosition - syringePumpHomePositionOffset; @@ -1057,6 +1075,33 @@ // Publish syringe pump data on interval publishSyringePumpData(); +} + +/*********************************************************************//** + * @brief + * The execSyringePumpSelfTest function executes the state machine for the + * syringe pump self-test. + * @details Inputs: none + * @details Outputs: none + * @return the current state of the BloodFlow self-test. + *************************************************************************/ +SELF_TEST_STATUS_T execSyringePumpSelfTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + BOOL calStatus = processCalibrationData(); + + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + activateAlarmNoData( ALARM_ID_HD_SYRINGE_PUMP_SELF_TEST_FAILURE ); + } + + return result; } /*********************************************************************//** @@ -1811,6 +1856,43 @@ broadcastHeparinData( data.syringePumpVolumeDelivered ); syringePumpDataPublicationTimerCounter = 0; } +} + +/*********************************************************************//** + * @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: forceSensorCalRecord + * @return TRUE if the calibration record is valid, otherwise FALSE + *************************************************************************/ +static BOOL processCalibrationData( void ) +{ + BOOL status = TRUE; + + // Get the calibration record from NVDataMgmt + HD_HEPARIN_FORCE_SENSOR_CAL_RECORD_T calData = getHDHeparinForceSensorCalibrationRecord(); + + // 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 heparin force sensors data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.hdHeparinForceSensor.calibrationTime ) + { +#ifndef SKIP_CAL_CHECK + activateAlarmNoData( ALARM_ID_HD_HEPARIN_FORCE_SENSOR_INVALID_CAL_RECORD ); + status = FALSE; +#endif + } + + // The calibration data was valid, update the local copy + forceSensorCalRecord.hdHeparinForceSensor.fourthOrderCoeff = calData.hdHeparinForceSensor.fourthOrderCoeff; + forceSensorCalRecord.hdHeparinForceSensor.thirdOrderCoeff = calData.hdHeparinForceSensor.thirdOrderCoeff; + forceSensorCalRecord.hdHeparinForceSensor.secondOrderCoeff = calData.hdHeparinForceSensor.secondOrderCoeff; + forceSensorCalRecord.hdHeparinForceSensor.gain = calData.hdHeparinForceSensor.gain; + forceSensorCalRecord.hdHeparinForceSensor.offset = calData.hdHeparinForceSensor.offset; + + return status; } Index: firmware/App/Controllers/SyringePump.h =================================================================== diff -u -r5fef605363d4f8023b3db2989b097b6c5f58db1a -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Controllers/SyringePump.h (.../SyringePump.h) (revision 5fef605363d4f8023b3db2989b097b6c5f58db1a) +++ firmware/App/Controllers/SyringePump.h (.../SyringePump.h) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -73,6 +73,8 @@ void initSyringePump( void ); void execSyringePump( void ); +SELF_TEST_STATUS_T execSyringePumpSelfTest( void ); + BOOL userHeparinRequest( HEPARIN_CMD_T cmd ); void setHeparinOff( void ); void setHeparinStopped( void ); Index: firmware/App/HDCommon.h =================================================================== diff -u -r1eac55db00559965a7dc6752fc42a2c54d56f4b9 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/HDCommon.h (.../HDCommon.h) (revision 1eac55db00559965a7dc6752fc42a2c54d56f4b9) +++ firmware/App/HDCommon.h (.../HDCommon.h) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -38,8 +38,8 @@ // #define SIMULATE_UI 1 // Build w/o requirement that UI be there // #define TASK_TIMING_OUTPUT_ENABLED 1 // Re-purposes alarm lamp pins for task timing #define DISABLE_ALARM_AUDIO 1 // Disable alarm audio -// #define SKIP_POST 1 // Skip POST tests - all pass - #define DONT_SKIP_NV_POST 1 // Do not skip NV Data POST + #define SKIP_POST 1 // Skip POST tests - all pass + #define IGNORE_CAL_TIMESTAMP 1 // Ignores calibration time stamp by setting an epoch time temporarily // #define USE_LIBRARY_TIME_FUNCTIONS 1 // Use the C library functions mktime() and gmtime() for epoch<=>date conversions #define DISABLE_AIR_TRAP_LEVELING_ALARM 1 // Disable air trap level control alarms // #define DISABLE_3WAY_VALVES 1 // Disable 3-way valves @@ -56,7 +56,7 @@ #define DISABLE_PRESSURE_CHECKS 1 // Do not error on HD pressure checks // #define DISABLE_UF_ALARMS 1 // Do not error on HD ultrafiltration checks // #define DISABLE_VALVE_ALARMS 1 // Do not error on HD valve position - #define DISABLE_CAL_CHECK 1 // Disable calibration checks + #define SKIP_CAL_CHECK 1 // #define RUN_PUMPS_OPEN_LOOP 1 // BP and DPi pumps will be run open loop (no flow sensor feedback) // #define RAW_FLOW_SENSOR_DATA 1 // Test build will not filter flow sensor data // #define READ_FPGA_ASYNC_DATA 1 // Test build reads non-priority register page every other time Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r78cee9347b3766ac7c14d413ed848be758c7e9cd -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 78cee9347b3766ac7c14d413ed848be758c7e9cd) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -23,11 +23,11 @@ #include "CPLD.h" #include "DialInFlow.h" #include "FPGA.h" -#include "Integrity.h" #include "ModeInitPOST.h" #include "NVDataMgmt.h" #include "OperationModes.h" #include "RTC.h" +#include "SyringePump.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Valves.h" @@ -97,7 +97,8 @@ /*********************************************************************//** * @brief - * The execInitAndPOSTMode function executes the Initialize & POST Mode state machine. + * The execInitAndPOSTMode function executes the Initialize & POST Mode + * state machine. * @details Inputs: postState * @details Outputs: postState, postPassed, postCompleted * @return current state (sub-mode) @@ -119,13 +120,6 @@ { case POST_STATE_START: postState = POST_STATE_FW_COMPATIBILITY; -#ifdef SKIP_POST - postState = POST_STATE_COMPLETED; -#endif -#ifdef DONT_SKIP_NV_POST - // Only run NVDataMgmt POST - postState = POST_STATE_NVDATAMGMT; -#endif break; case POST_STATE_FW_COMPATIBILITY: @@ -134,15 +128,23 @@ break; case POST_STATE_FW_INTEGRITY: - testStatus = execIntegrityTest(); + //testStatus = execIntegrityTest(); TODO what happened to this module? + testStatus = SELF_TEST_STATUS_PASSED; postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_BATTERY: + // TODO implement the battery self test + testStatus = SELF_TEST_STATUS_PASSED; + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_WATCHDOG: testStatus = execWatchdogTest(); postState = handlePOSTStatus( testStatus ); break; + // NOTE: RTC's POST must go before NVDataMgmt case POST_STATE_RTC: testStatus = execRTCSelfTest(); postState = handlePOSTStatus( testStatus ); @@ -153,6 +155,9 @@ postState = handlePOSTStatus( testStatus ); break; + // NOTE: all the actuators and sensors must execute their POST after NVDataMgmt + // NVDataMgmt must load all the calibration data into RAM so the actuators + // can query their corresponding calibration values successfully case POST_STATE_BLOOD_FLOW: testStatus = execBloodFlowTest(); postState = handlePOSTStatus( testStatus ); @@ -168,25 +173,27 @@ postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_SYRINGE_PUMP: + testStatus = execSyringePumpSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_ALARM_AUDIO: -#ifdef DONT_SKIP_NV_POST - // Skip the rest of the POSTs - postState = POST_STATE_COMPLETED; +#ifdef SKIP_POST testStatus = SELF_TEST_STATUS_PASSED; #else testStatus = execAlarmAudioSelfTest(); - postState = handlePOSTStatus( testStatus ); #endif + postState = handlePOSTStatus( testStatus ); break; case POST_STATE_ALARM_LAMP: -#ifdef DONT_SKIP_NV_POST - // Skip the rest of the POSTs - postState = POST_STATE_COMPLETED; +#ifdef SKIP_POST + testStatus = SELF_TEST_STATUS_PASSED; #else testStatus = execAlarmLampTest(); - postState = handlePOSTStatus( testStatus ); #endif + postState = handlePOSTStatus( testStatus ); break; case POST_STATE_ACCELEROMETER: @@ -203,6 +210,12 @@ postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_UI_POST: + // TODO implement the UI POST self test + testStatus = SELF_TEST_STATUS_PASSED; + postState = handlePOSTStatus( testStatus ); + break; + // Should be last POST (and last POST test must be a test that completes in a single call) case POST_STATE_FPGA: testStatus = execFPGATest(); Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r78cee9347b3766ac7c14d413ed848be758c7e9cd -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 78cee9347b3766ac7c14d413ed848be758c7e9cd) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -1156,7 +1156,8 @@ break; case MSG_ID_REQUEST_FW_VERSIONS: - handleFWVersionRequest( message ); + handleFWVersionRequest( message ); + handleHDSerialNumberRequest( message ); break; case MSG_ID_DG_TEMPERATURE_DATA: @@ -1311,6 +1312,14 @@ handleSetHDStandbyDisinfectSubmodeRequest( message ); break; + case MSG_ID_UI_REQUEST_SERVICE_INFO: + handleHDServiceScheduleRequest( message ); + break; + + case MSG_ID_REQUEST_HD_USAGE_INFO: + handleHDUsageInfoRequest( message ); + break; + // NOTE: this always must be the last case case MSG_ID_TESTER_LOGIN_REQUEST: handleTesterLogInRequest( message ); Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r1eac55db00559965a7dc6752fc42a2c54d56f4b9 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1eac55db00559965a7dc6752fc42a2c54d56f4b9) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -26,6 +26,7 @@ #include "FPGA.h" #include "ModeStandby.h" #include "ModeTreatmentParams.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "RTC.h" #include "SampleWater.h" @@ -3837,9 +3838,11 @@ /*********************************************************************//** * @brief - * The handleFWVersionRequest function handles a request for HD f/w version. + * The handleFWVersionRequest function handles a request for HD f/w + * version. * @details Inputs: none - * @details Outputs: message handled, response constructed and queued for transmit. + * @details Outputs: message handled, response constructed and queued + * for transmit. * @param message a pointer to the message to handle. * @return none *************************************************************************/ @@ -3866,6 +3869,96 @@ // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); +} + +/*********************************************************************//** + * @brief + * The handleHDSerialNumberRequest function handles a request for HD serial + * number request. + * @details Inputs: none + * @details Outputs: message handled, response constructed and queued + * for transmit. + * @param message a pointer to the message to handle. + * @return none + *************************************************************************/ +void handleHDSerialNumberRequest( MESSAGE_T *message ) +{ + MESSAGE_T msg; + HD_SYSTEM_RECORD_T system = getHDSystemRecord(); + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_SERIAL_NUMBER; + + // Add 1 byte for null terminator + msg.hdr.payloadLen = MAX_TOP_LEVEL_SN_CHARS + 1; + + // Fill message payload + memcpy( payloadPtr, &system.topLevelSN, MAX_TOP_LEVEL_SN_CHARS ); + payloadPtr += MAX_TOP_LEVEL_SN_CHARS; + *payloadPtr = 0; + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); +} + +/*********************************************************************//** + * @brief + * The handleHDServiceScheduleRequest function handles a request for HD + * service information. + * @details Inputs: none + * @details Outputs: message handled, response constructed and queued for + * transmit. + * @param message a pointer to the message to handle. + * @return none + *************************************************************************/ +void handleHDServiceScheduleRequest( MESSAGE_T *message ) +{ + MESSAGE_T msg; + HD_SERVICE_RECORD_T payload = getHDServiceRecord(); + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_SERVICE_SCHEDULE_DATA; + msg.hdr.payloadLen = sizeof( U32 ) + sizeof( U32 ); + + // Fill message payload + memcpy( payloadPtr, &payload.lastServiceEpochDate, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &payload.serviceIntervalSeconds, sizeof( U32 ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); +} + +/*********************************************************************//** + * @brief + * The handleHDUsageInfoRequest function handles a request for HD + * usage information. + * @details Inputs: none + * @details Outputs: message handled, response constructed and queued for + * transmit. + * @param message a pointer to the message to handle. + * @return none + *************************************************************************/ +void handleHDUsageInfoRequest( MESSAGE_T *message ) +{ + MESSAGE_T msg; + U32 payload = getTreatmentTime(); + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_USAGE_DATA; + msg.hdr.payloadLen = sizeof( U32 ); + + // Fill message payload + memcpy( payloadPtr, &payload, sizeof( U32 ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); } Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r3d8fdd44ca1d0ba87e0564d124b4a15ca18bc612 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 3d8fdd44ca1d0ba87e0564d124b4a15ca18bc612) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -65,7 +65,16 @@ void handleUICheckIn( MESSAGE_T *message ); // MSG_ID_REQUEST_FW_VERSIONS -void handleFWVersionRequest( MESSAGE_T *message ); +void handleFWVersionRequest( MESSAGE_T *message ); + +// MSG_ID_REQUEST_FW_VERSIONS +void handleHDSerialNumberRequest( MESSAGE_T *message ); + +// MSG_ID_UI_REQUEST_SERVICE_INFO +void handleHDServiceScheduleRequest( MESSAGE_T *message ); + +// MSG_ID_REQUEST_HD_USAGE_INFO +void handleHDUsageInfoRequest( MESSAGE_T *message ); // MSG_ID_OFF_BUTTON_PRESS BOOL sendOffButtonMsgToUI( U08 cmd ); Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -59,7 +59,10 @@ checkInWithWatchdogMgmt( TASK_GENERAL ); // Do this first to keep timing consistent with watchdog management // Manage data received from other sub-systems - execSystemCommRx(); + execSystemCommRx(); + + // Manage RTC + execRTC(); // Prevent most processing until UI has started communicating #ifndef SIMULATE_UI @@ -91,10 +94,7 @@ // Control dialysate outlet pump execDialOutFlowController(); -#endif - - // Manage RTC - execRTC(); +#endif // Manage NVDataMgmt process record state machine execNVDataMgmtProcessRecord(); Index: firmware/hd_build_history.txt =================================================================== diff -u --- firmware/hd_build_history.txt (revision 0) +++ firmware/hd_build_history.txt (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -0,0 +1,10 @@ +************************************************************************************************ +Bamboo Build Number: +Bamboo Build Date: +Bug Fixes: DEN-8819 fixed load cells inaccurate value beyond 3rd decimal overriding values. +New Feature: None +Known Bugs: Fans RPM monitor and Temperature sensors ADC range check are disabled for further +investigations +Changes: Added calibration to flow sensor, temeperature sensors, pressure sensors, conductivity +sensors, drain line volume, reservoirs, and acid and bicarb constants +************************************************************************************************ \ No newline at end of file Index: firmware/source/sys_main.c =================================================================== diff -u -rc353566e2c78f0f42ff80abf2097b10b098010cf -rabbad386f4cc94f315300dffef321fe8c03fbd52 --- firmware/source/sys_main.c (.../sys_main.c) (revision c353566e2c78f0f42ff80abf2097b10b098010cf) +++ firmware/source/sys_main.c (.../sys_main.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) @@ -77,7 +77,6 @@ #include "DialOutFlow.h" #include "FluidLeak.h" #include "FPGA.h" -#include "Integrity.h" #include "InternalADC.h" #include "Interrupts.h" #include "MsgQueues.h" @@ -182,7 +181,7 @@ initRTC(); // Initialize services initCommBuffers(); - initIntegrity(); + //initIntegrity(); TODO what happened to this driver? initFPGA(); initMsgQueues(); initNVDataMgmt();