Index: NVDataMgmt.c =================================================================== diff -u -r76016122c2646fe718a67782f9a818163bf6923f -r96e4bcdf7e21468eda4f54cd504daf897f7e78b0 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 76016122c2646fe718a67782f9a818163bf6923f) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 96e4bcdf7e21468eda4f54cd504daf897f7e78b0) @@ -472,6 +472,7 @@ // Record check helper functions static BOOL areRecordsValid( void ); static BOOL isLinearRecordValid( LINEAR_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ); +static BOOL isNonlinearRecordValid( NON_LINEAR_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ); #ifdef _DG_ static BOOL isDGCalibrationRecordValid( void ); static BOOL isDGConcPumpRecordValid( DG_CONC_PUMPS_CAL_DATA_T* record, BOOL isRecordNeeded ); @@ -486,6 +487,12 @@ static BOOL isDGFanRecordValid( DG_FAN_CAL_RECORD_T* record, BOOL isRecordNeeded ); static BOOL isDGAccelerometerSensorRecordValid( DG_ACCELEROMETER_SENSOR_CAL_RECORD_T* record, BOOL isRecordNeeded ); #endif +#ifdef _HD_ +static BOOL isHDCalibrationRecordValid( void ); +static BOOL isHDValveRecordValid( HD_VALVE_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ); +static BOOL isHDPumpRecordValid( HD_PUMP_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ); +static BOOL isHDAccelerometerSensorValid( HD_ACCELEROMETER_SENSOR_CAL_RECORD_T* record, BOOL isRecordNeeded ); +#endif /*********************************************************************//** * @brief @@ -1878,19 +1885,21 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestCheckCRC ( void ) { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_COMPLETE; + BOOL haveCalGroupsPassed = TRUE; + BOOL haveRecordsPassed = TRUE; #ifndef DISABLE_CAL_CHECK // Check the integrity of the records as a whole. Check the upper layer CRC - BOOL haveRecordsPassed = areRecordsValid(); + haveRecordsPassed = areRecordsValid(); #ifdef _DG_ // Check all the calibration groups - BOOL haveCalGroupsPassed = isDGCalibrationRecordValid(); + haveCalGroupsPassed = isDGCalibrationRecordValid(); #endif -#else - BOOL haveCalGroupsPassed = TRUE; - BOOL haveRecordsPassed = TRUE; +#ifdef _HD_ + haveCalGroupsPassed = isHDCalibrationRecordValid(); #endif +#endif // If any of the records did not pass, they should be filled // with benign values. After that, schedule a write to sector 0 @@ -2768,8 +2777,8 @@ /*********************************************************************//** * @brief - * The isLinearRecordValid function checks whether the records are still valid - * by calculating the CRCs and comparing it to the strucutre's CRC. + * The isLinearRecordValid function checks whether the records are still + * valid by calculating the CRCs and comparing it to the strucutre's CRC. * @details Inputs: none * @details Outputs: none * @param record: pointer to a linear calibration payload. The actual calibration @@ -2814,6 +2823,57 @@ return status; } +/*********************************************************************//** + * @brief + * The isNonlinearRecordValid function checks whether the records are still + * valid by calculating the CRCs and comparing it to the strucutre's CRC. + * @details Inputs: none + * @details Outputs: none + * @param record: pointer to a non-linear calibration payload. The actual + * calibration data to be checked + * @param isRecordNeeded: TRUE is the calibration record is need in the + * firmware right now otherwise, FALSE + * @return TRUE if the records' data is valid otherwise FALSE + *************************************************************************/ +static BOOL isNonlinearRecordValid( NON_LINEAR_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16 ( (U08*)record, sizeof(NON_LINEAR_CAL_PAYLOAD_T) - sizeof(U16) ); + U16 recordCRC = record->crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + record->gain = RECORD_DEFAULT_GAIN; + record->offset = RECORD_DEFAULT_OFFSET; + record->reservedParam1 = RECORD_DEFAULT_CONST; + record->reservedParam2 = RECORD_DEFAULT_CONST; + record->reservedParam3 = RECORD_DEFAULT_CONST; + record->calibrationTime = RECORD_DEFAULT_TIME; + // Recalculate the CRC with the default values + record->crc = crc16 ( (U08*)record, sizeof(NON_LINEAR_CAL_PAYLOAD_T) - sizeof(U16) ); + + // Alarm if the CRC did not pass + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_CRC_INVALID ); + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + // Check if the record is needed. If it is needed, it should have a valid + // calibration time associated with it. + if ( TRUE == isRecordNeeded ) + { + // Check if the calibration time of the record is the default value + if ( record->calibrationTime == RECORD_DEFAULT_TIME ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_TIME_INVALID ); + } + } + + return status; +} + #ifdef _DG_ /*********************************************************************//** * @brief @@ -2940,6 +3000,10 @@ * record of concentrate pump is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_CONC_PUMPS_CAL_DATA_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGConcPumpRecordValid( DG_CONC_PUMPS_CAL_DATA_T* record, BOOL isRecordNeeded ) @@ -2985,6 +3049,10 @@ * record of drain pump is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_DRAIN_PUMP_CAL_RECORD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGDrainPumpRecordValid( DG_DRAIN_PUMP_CAL_RECORD_T* record, BOOL isRecordNeeded ) @@ -3031,6 +3099,10 @@ * record of RO pump is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_RO_PUMP_CAL_RECORD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGROPumpRecordValid( DG_RO_PUMP_CAL_RECORD_T* record, BOOL isRecordNeeded ) @@ -3078,6 +3150,10 @@ * record of drain line volume is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_DRAIN_LINE_VOLUME_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGDrainLineVolRecordValid( DG_DRAIN_LINE_VOLUME_T* record, BOOL isRecordNeeded ) @@ -3120,6 +3196,10 @@ * record of reservoir volume is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_RESERVOIR_VOLUME_DATA_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGReservoirVolRecordValid( DG_RESERVOIR_VOLUME_DATA_T* record, BOOL isRecordNeeded ) @@ -3165,6 +3245,10 @@ * record of generic volume is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_GENERIC_VOLUME_DATA_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGGenericVolRecordValid( DG_GENERIC_VOLUME_DATA_T* record, BOOL isRecordNeeded ) @@ -3210,6 +3294,10 @@ * record of acid concentrate is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_ACID_CONCENTRATE_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGAcidConcentrateRecordValid( DG_ACID_CONCENTRATE_T* record, BOOL isRecordNeeded ) @@ -3254,6 +3342,10 @@ * calibration record of bicarb concentrate is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_BICARB_CONCENTRATE_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGBicarbConcentrateRecordValid( DG_BICARB_CONCENTRATE_T* record, BOOL isRecordNeeded ) @@ -3298,6 +3390,10 @@ * record of filter is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_FILTER_CAL_RECORD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGFilterRecordValid( DG_FILTER_CAL_RECORD_T* record, BOOL isRecordNeeded ) @@ -3345,6 +3441,10 @@ * of fan is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_FAN_CAL_RECORD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGFanRecordValid( DG_FAN_CAL_RECORD_T* record, BOOL isRecordNeeded ) @@ -3391,6 +3491,10 @@ * calibration record of accelerometer sensor is valid or not. * @details Inputs: none * @details Outputs: none + * @param record: DG_ACCELEROMETER_SENSOR_CAL_RECORD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default * @return TRUE if the record is valid otherwise FALSE *************************************************************************/ static BOOL isDGAccelerometerSensorRecordValid( DG_ACCELEROMETER_SENSOR_CAL_RECORD_T* record, BOOL isRecordNeeded ) @@ -3432,9 +3536,234 @@ return status; } #endif +#ifdef _HD_ +/*********************************************************************//** + * @brief + * The isHDCalibrationRecordValid function checks whether HD calibration + * record is valid or not. + * @details Inputs: none + * @details Outputs: none + * @return TRUE if the record is valid otherwise FALSE + *************************************************************************/ +static BOOL isHDCalibrationRecordValid( void ) +{ + U32 i; + LINEAR_CAL_PAYLOAD_T* linearRecord; + NON_LINEAR_CAL_PAYLOAD_T* nonlinearRecord; + BOOL isRecordValid = TRUE; + HD_PUMPS_CAL_RECORD_T* pump = &hdCalibrationRecord.hdCalibrationGroups.pumpsCalRecord; + for ( i = 0; i < NUM_OF_CAL_DATA_HD_PUMPS; i++ ) + { + isRecordValid = isRecordValid == FALSE ? FALSE : isHDPumpRecordValid( &pump->hdPumps[ i ], FALSE ); + } + + HD_VALVES_CAL_RECORD_T* valve = &hdCalibrationRecord.hdCalibrationGroups.valvesCalRecord; + for ( i = 0; i < NUM_OF_CAL_DATA_HD_VALVES; i++ ) + { + isRecordValid = isRecordValid == FALSE ? FALSE : isHDValveRecordValid( &valve->hdvalves[ i ], FALSE ); + } + + HD_OCCLUSION_SENSORS_CAL_RECORD_T* occlusion = &hdCalibrationRecord.hdCalibrationGroups.occlusionSensorsCalRecord; + for ( i = 0; i < NUM_OF_CAL_DATA_OCCLUSION_SENSORS; i++ ) + { + // Get calibration payload and assign it to a pointer + linearRecord = (LINEAR_CAL_PAYLOAD_T*)&occlusion->hdOcclusionSensors[ i ]; + // Check in the validity of the calibration data + // If the variable is already FALSE, let it be FALSE. Even if one record is not + // valid, the values should be set to benign values. This variable is used to decide + // whether a write should be scheduled or not so it should not be overwritten with a TRUE + // once a record set it to FALSE + isRecordValid = isRecordValid == FALSE ? FALSE : isLinearRecordValid( linearRecord, TRUE ); + } + + HD_FLOW_SENSORS_CAL_RECORD_T* flow = &hdCalibrationRecord.hdCalibrationGroups.flowSensorsCalRecord; + for ( i = 0; i < NUM_OF_CAL_DATA_HD_FLOW_SENSORS; i++ ) + { + linearRecord = (LINEAR_CAL_PAYLOAD_T*)&flow->hdFlowSensors[ i ]; + isRecordValid = isRecordValid == FALSE ? FALSE : isLinearRecordValid( linearRecord, TRUE ); + } + + HD_PRESSURE_SENSORS_CAL_RECORD_T* pressure = &hdCalibrationRecord.hdCalibrationGroups.pressureSensorsCalRecord; + for ( i = 0; i < NUM_OF_CAL_DATA_HD_PRESSURE_SESNSORS; i++ ) + { + nonlinearRecord = (NON_LINEAR_CAL_PAYLOAD_T*)&pressure->hdPressureSensors[ i ]; + isRecordValid = isRecordValid == FALSE ? FALSE : isNonlinearRecordValid( nonlinearRecord, TRUE ); + } + + HD_TEMP_SENSORS_CAL_RECORD_T* temperature = &hdCalibrationRecord.hdCalibrationGroups.tempSensorsCalRecord; + for ( i = 0; i < NUM_OF_CAL_DATA_HD_TEMP_SENSORS; i++ ) + { + nonlinearRecord = (NON_LINEAR_CAL_PAYLOAD_T*)&temperature->hdTemperatureSensors[ i ]; + isRecordValid = isRecordValid == FALSE ? FALSE : isNonlinearRecordValid( nonlinearRecord, TRUE ); + } + + HD_HEPARIN_FORCE_SENSOR_CAL_RECORD_T* heparinForce = &hdCalibrationRecord.hdCalibrationGroups.heparinForceSensorCalRecord; + nonlinearRecord = (NON_LINEAR_CAL_PAYLOAD_T*)&heparinForce->hdHeparinForceSensor; + isRecordValid = isRecordValid == FALSE ? FALSE : isNonlinearRecordValid( nonlinearRecord, TRUE ); + + + HD_ACCELEROMETER_SENSOR_CAL_RECORD_T* accelerometer = &hdCalibrationRecord.hdCalibrationGroups.accelerometerCalRecord; + isRecordValid = isRecordValid == FALSE ? FALSE : isHDAccelerometerSensorValid( accelerometer, TRUE ); + + return isRecordValid; +} + /*********************************************************************//** * @brief + * The isHDPumpRecordValid function checks whether the calibration record + * of HD pump(s) is valid or not. + * @details Inputs: none + * @details Outputs: none + * @param record: HD_PUMP_CAL_PAYLOAD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default + * @return TRUE if the record is valid otherwise FALSE + *************************************************************************/ +static BOOL isHDPumpRecordValid( HD_PUMP_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16 ( (U08*)record, sizeof(HD_PUMP_CAL_PAYLOAD_T) - sizeof(U16) ); + U16 recordCRC = record->crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + record->maxCurrentLimit = RECORD_DEFAULT_OFFSET; + record->minCurrentLimit = RECORD_DEFAULT_OFFSET; + record->pwm2Speed = RECORD_DEFAULT_RATIO; + record->speed2Flow = RECORD_DEFAULT_RATIO; + record->calibrationTime = RECORD_DEFAULT_TIME; + record->crc = crc16 ( (U08*)record, sizeof(HD_PUMP_CAL_PAYLOAD_T) - sizeof(U16) ); + + // Alarm if the CRC did not pass and the record is needed + if ( TRUE == isRecordNeeded ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_CRC_INVALID ); + } + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + // Check if the record is needed. If it is needed, it should have a valid + // calibration time associated with it. + if ( TRUE == isRecordNeeded ) + { + // Check if the calibration time of the record is the default value + if ( record->calibrationTime == RECORD_DEFAULT_TIME ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_TIME_INVALID ); + } + } + + return status; +} + +/*********************************************************************//** + * @brief + * The isHDValveRecordValid function checks whether the calibration record + * of HD valve is valid or not. + * @details Inputs: none + * @details Outputs: none + * @param record: HD_VALVE_CAL_PAYLOAD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default + * @return TRUE if the record is valid otherwise FALSE + *************************************************************************/ +static BOOL isHDValveRecordValid( HD_VALVE_CAL_PAYLOAD_T* record, BOOL isRecordNeeded ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16 ( (U08*)record, sizeof(HD_VALVE_CAL_PAYLOAD_T) - sizeof(U16) ); + U16 recordCRC = record->crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + record->counts2Position = RECORD_DEFAULT_OFFSET; + record->calibrationTime = RECORD_DEFAULT_TIME; + record->crc = crc16 ( (U08*)record, sizeof(HD_VALVE_CAL_PAYLOAD_T) - sizeof(U16) ); + + // Alarm if the CRC did not pass and the record is needed + if ( TRUE == isRecordNeeded ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_CRC_INVALID ); + } + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + // Check if the record is needed. If it is needed, it should have a valid + // calibration time associated with it. + if ( TRUE == isRecordNeeded ) + { + // Check if the calibration time of the record is the default value + if ( record->calibrationTime == RECORD_DEFAULT_TIME ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_TIME_INVALID ); + } + } + + return status; +} + +/*********************************************************************//** + * @brief + * The isHDAccelerometerSensorValid function checks whether the + * calibration record of accelerometer sensor is valid or not. + * @details Inputs: none + * @details Outputs: none + * @param record: HD_ACCELEROMETER_SENSOR_CAL_RECORD_T pointer + * @param isRecordNeeded: flag to define whether the record has to be + * checked for cal date and raise an alarm if the CRC was not right or + * the cal date was set to default + * @return TRUE if the record is valid otherwise FALSE + *************************************************************************/ +static BOOL isHDAccelerometerSensorValid( HD_ACCELEROMETER_SENSOR_CAL_RECORD_T* record, BOOL isRecordNeeded ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16 ( (U08*)record, sizeof(HD_ACCELEROMETER_SENSOR_CAL_RECORD_T) - sizeof(U16) ); + U16 recordCRC = record->crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + record->accelXOffset = RECORD_DEFAULT_OFFSET; + record->accelYOffset = RECORD_DEFAULT_OFFSET; + record->accelZOffset = RECORD_DEFAULT_OFFSET; + record->calibrationTime = RECORD_DEFAULT_TIME; + record->crc = crc16 ( (U08*)record, sizeof(HD_ACCELEROMETER_SENSOR_CAL_RECORD_T) - sizeof(U16) ); + + // Alarm if the CRC did not pass and the record is needed + if ( TRUE == isRecordNeeded ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_CRC_INVALID ); + } + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + // Check if the record is needed. If it is needed, it should have a valid + // calibration time associated with it. + if ( TRUE == isRecordNeeded ) + { + // Check if the calibration time of the record is the default value + if ( record->calibrationTime == RECORD_DEFAULT_TIME ) + { + activateAlarmNoData( ALARM_ID_NVDATAMGMT_INDIVIDUAL_RECORD_TIME_INVALID ); + } + } + + return status; +} +#endif + +/*********************************************************************//** + * @brief * The dequeue increments the front index counter and if it is equal to * rear index, it sets it to -1, meaning that the queue is empty. * @details Inputs: queueFrontIndex, queueCount Index: NVDataMgmtHDRecords.h =================================================================== diff -u -rf2a92b265b295e93b57199a89d6491e195f74c56 -r96e4bcdf7e21468eda4f54cd504daf897f7e78b0 --- NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision f2a92b265b295e93b57199a89d6491e195f74c56) +++ NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision 96e4bcdf7e21468eda4f54cd504daf897f7e78b0) @@ -116,7 +116,7 @@ F32 pwm2Speed; ///< PWM to speed. F32 speed2Flow; ///< Speed to flow. F32 minCurrentLimit; ///< Minimum current limit. - F32 maxCurrentLinit; ///< Maximum current limit. + F32 maxCurrentLimit; ///< Maximum current limit. U32 calibrationTime; ///< Calibration time. U16 crc; ///< CRC for the HD pumps calibration payload. } HD_PUMP_CAL_PAYLOAD_T;