Index: firmware/App/Services/NVRecordsDD.c =================================================================== diff -u -r847585d6806c22c595eb39326ded48a496b65cfb -rc0855c6b4beeedc43b020c4e106d8e379de757d9 --- firmware/App/Services/NVRecordsDD.c (.../NVRecordsDD.c) (revision 847585d6806c22c595eb39326ded48a496b65cfb) +++ firmware/App/Services/NVRecordsDD.c (.../NVRecordsDD.c) (revision c0855c6b4beeedc43b020c4e106d8e379de757d9) @@ -218,6 +218,7 @@ // Record check helper functions static BOOL isLinearRecordValid( LINEAR_CAL_PAYLOAD_T* record ); +static BOOL isDDSerialNumberValid( void ); static BOOL isDDSystemRecordValid( void ); static BOOL isDDServiceRecordValid( void ); static BOOL isDDInstitutionalRecordValid( void ); @@ -340,67 +341,102 @@ * @brief * The handleSelfTestCheckCRC function checks the CRC of records and * compares them with stored CRC values. If they don't match, it will fail POST. - * It updates the self-test result - * and schedules rewrite for invalid records. + * It updates the self-test result and schedules rewrite for invalid records. + * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_SERIAL_NUMBER invalid serial number + * ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC invalid system record crc + * ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC invalid service record crc, + * ALARM_ID_DD_NVM_INVALID_CALIBRATION_RECORD_CRC invalid cal record crc, + * ALARM_ID_DD_NVM_INVALID_INSTIT_BASIC_RECORD_CRC invalid basic instit crc, + * ALARM_ID_DD_NVM_INVALID_INSTIT_ADVANCED_RECORD_CRC invalid advanced instit crc + * ALARM_ID_DD_NVM_INVALID_INSTIT_ADDITIONAL_RECORD_CRC invalid additional instit crc, + * ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC invalid institutional crc + * ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC invalid usage record crc * @details \b Inputs: nvmSelfTestResult * @details \b Outputs: nvmSelfTestResult * @return state next self-test state *************************************************************************/ static NVM_SELF_TEST_STATE_T handleSelfTestCheckCRC ( void ) { NVM_SELF_TEST_STATE_T state = NVM_SELF_TEST_STATE_COMPLETE; - BOOL hasSystemRecordPassed = TRUE; - BOOL hasServiceRecordPassed = TRUE; - BOOL haveCalGroupsPassed = TRUE; - BOOL hasInstitutionalRecordPassed = TRUE; - BOOL hasUsageRecordPassed = TRUE; + BOOL hasSerialNumberPassed = TRUE; + BOOL hasSystemRecordPassed = TRUE; + BOOL hasServiceRecordPassed = TRUE; + BOOL hasCalRecordPassed = TRUE; + BOOL hasConductivityCalRecordPassed = TRUE; + BOOL hasInstitBasicPassed = TRUE; + BOOL hasInstitAdvancedPassed = TRUE; + BOOL hasInstitAdditionalPassed = TRUE; + BOOL hasInstitutionalRecordPassed = TRUE; + BOOL hasUsageRecordPassed = TRUE; updateRecordReadStatus( NVM_RECORDS_CRC_CHECKED ); // If any of the records did not pass, they should be filled // with benign values. After that, schedule a write to sector // to re-write the records with the benign values - // Validate system record - hasSystemRecordPassed = isDDSystemRecordValid(); + // Validate the Records + hasSerialNumberPassed = isDDSerialNumberValid(); + hasSystemRecordPassed = isDDSystemRecordValid(); + hasServiceRecordPassed = isDDServiceRecordValid(); + hasConductivityCalRecordPassed = isDDConductivitySensorValid(); + hasCalRecordPassed = isDDCalibrationRecordValid(); + hasInstitBasicPassed = isDDInstitBasicRecordValid(); + hasInstitAdvancedPassed = isDDInstitAdvancedRecordValid(); + hasInstitAdditionalPassed = isDDInstitAdditionalRecordValid(); + hasInstitutionalRecordPassed = isDDInstitutionalRecordValid(); + hasUsageRecordPassed = isDDUsageRecordValid(); + + // Activate alarm for the records that have failed + if ( FALSE == hasSerialNumberPassed ) + { + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_SERIAL_NUMBER ); + } + if ( FALSE == hasSystemRecordPassed ) { - enqueueEraseAndWriteSector ( NVM_SYSTEM_RECORD ); - sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ); } - // Validate service and calibration records - hasServiceRecordPassed = isDDServiceRecordValid(); - haveCalGroupsPassed = isDDCalibrationRecordValid(); - if ( ( FALSE == hasServiceRecordPassed ) || ( FALSE == haveCalGroupsPassed ) ) + if ( FALSE == hasServiceRecordPassed ) { - enqueueEraseAndWriteSector ( NVM_SERVICE_RECORD ); - sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); - sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ); + } - startNewCalRecordAvailableTimer(); - setNewCalibrationRecordAvailable( TRUE ); + if ( ( FALSE == hasConductivityCalRecordPassed ) || + ( FALSE == hasCalRecordPassed ) ) + { + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_CALIBRATION_RECORD_CRC ); } - // Validate institutional record - hasInstitutionalRecordPassed = isDDInstitutionalRecordValid(); + if ( FALSE == hasInstitBasicPassed ) + { + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTIT_BASIC_RECORD_CRC ); + } + + if ( FALSE == hasInstitAdvancedPassed ) + { + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTIT_ADVANCED_RECORD_CRC ); + } + + if ( FALSE == hasInstitAdditionalPassed ) + { + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTIT_ADDITIONAL_RECORD_CRC ); + } + if ( FALSE == hasInstitutionalRecordPassed ) { - enqueueEraseAndWriteSector ( NVM_INSTITUTIONAL_RECORD ); - sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC ); } - // Validate usage info record - hasUsageRecordPassed = isDDUsageRecordValid(); if ( FALSE == hasUsageRecordPassed ) { - enqueueEraseAndWriteSector ( NVM_USAGE_INFO_RECORD ); - sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); + activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ); } // Check if the records' entire CRCs as well as the individual CRCs passed if ( ( TRUE == hasSystemRecordPassed ) && ( TRUE == hasServiceRecordPassed ) && - ( TRUE == haveCalGroupsPassed ) && ( TRUE == hasInstitutionalRecordPassed ) && + ( TRUE == hasCalRecordPassed ) && ( TRUE == hasInstitutionalRecordPassed ) && ( TRUE == hasUsageRecordPassed ) ) { nvmSelfTestResult = SELF_TEST_STATUS_PASSED; @@ -459,17 +495,34 @@ /*********************************************************************//** * @brief + * The isDDSerialNumberValid function checks the validity of the DD + * serial number. + * @details \b Inputs: ddSystemGroup.ddSystemRecord + * @details \b Outputs: none + * @return TRUE if the DD serial number valid otherwise FALSE + *************************************************************************/ +static BOOL isDDSerialNumberValid( void ) +{ + BOOL status = TRUE; + + // Verify the serial number from the system record + if ( RECORD_DEFAULT_CHARACTER == ddSystemGroup.ddSystemRecord.topLevelSN[ 0 ] ) + { + status = FALSE; + } + + return status; +} + +/*********************************************************************//** + * @brief * The isDDSystemRecordValid function checks the validity of the DD * system record. It verifies CRC and updates the record with default * values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC if CRC - * check fails, ALARM_ID_DD_NVM_INVALID_SERIAL_NUMBER if serial number - * is not initialized * @details \b Inputs: ddSystemGroup.ddSystemRecord * @details \b Outputs: ddSystemGroup.ddSystemRecord, ddSystemGroup.crc * @return TRUE if the DD system record is valid otherwise FALSE *************************************************************************/ - static BOOL isDDSystemRecordValid( void ) { BOOL status = TRUE; @@ -487,18 +540,14 @@ // Recalculate the CRC with the default values updateRecordCRC( NVM_SYSTEM_RECORD ); - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_SYSTEM_RECORD ); + // Indicate that the record was updated + sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); + status = FALSE; } - else - { - // Verify the serial number from the system record - if ( RECORD_DEFAULT_CHARACTER == ddSystemGroup.ddSystemRecord.topLevelSN[ 0 ] ) - { - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_SERIAL_NUMBER ); - } - } return status; } @@ -508,8 +557,6 @@ * The isDDServiceRecordValid function checks the validity of the DD * service record. It verifies CRC and updates the record with default * values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC if CRC - * check fails * @details \b Inputs: ddServiceGroup.ddServiceRecord * @details \b Outputs: ddServiceGroup.ddServiceRecord, * ddServiceGroup.crc @@ -532,9 +579,12 @@ // Recalculate the CRC with the default values updateRecordCRC( NVM_SERVICE_RECORD ); - // Service record failure - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_SERVICE_RECORD ); + // Indicate that the record was updated + sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); + status = FALSE; } @@ -546,49 +596,43 @@ * The isDDInstitutionalRecordValid function checks the validity of the DD * institutional record. It verifies CRC and updates the record * with default values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC if CRC - * check fails * @details \b Inputs: ddInstitutionalGroup * @details \b Outputs: ddInstitutionalGroup * @return TRUE if the DD Institutional record is valid otherwise FALSE *************************************************************************/ static BOOL isDDInstitutionalRecordValid( void ) { - BOOL isRecordValid = TRUE; + BOOL status = TRUE; U16 calcCRC = crc16( (U08*)&ddInstitutionalGroup.crc, sizeof( DD_INSTITUTIONAL_GROUP_T ) - sizeof( U16 ) ); U16 recordCRC = ddInstitutionalGroup.crc; - isRecordValid = ( isRecordValid == FALSE ) ? FALSE : isDDInstitBasicRecordValid(); - isRecordValid = ( isRecordValid == FALSE ) ? FALSE : isDDInstitAdvancedRecordValid(); - isRecordValid = ( isRecordValid == FALSE ) ? FALSE : isDDInstitAdditionalRecordValid(); - - // If the sub groups failed, they are all updated to their benign values - // so the main CRC of the institutional group is calculated again - if ( ( FALSE == isRecordValid ) || ( calcCRC != recordCRC ) ) + //Check if the group crc is valid + if ( calcCRC != recordCRC ) { // Initialize the padding updateRecordPadding( NVM_INSTITUTIONAL_RECORD ); // Recalculate the CRC with the default values updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); - // // Activate alarm for Institutional record failure - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTITUTIONAL_RECORD_CRC ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_INSTITUTIONAL_RECORD ); - isRecordValid = FALSE; + // Indicate that the record was updated + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + + status = FALSE; } - return isRecordValid; + return status; } /*********************************************************************//** * @brief * The isDDInstitBasicRecordValid function checks the validity of the DD * basic institutional record. It verifies CRC and updates the record * with default values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_INSTIT_BASIC_RECORD_CRC if CRC - * check fails * @details \b Inputs: ddInstitutionalGroup * @details \b Outputs: ddInstitutionalGroup * @return TRUE if the DD Basic Institutional record is valid otherwise FALSE @@ -605,9 +649,15 @@ // CRC did not pass so set all values to default initDDInstitBasicRecord(); - // Activate alarm for basic Institutional record failure - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTIT_BASIC_RECORD_CRC ); + // Recalculate the CRC with the default values + updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); + // Write the record to flash + enqueueEraseAndWriteSector( NVM_INSTITUTIONAL_RECORD ); + + // Indicate that the record was updated + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + status = FALSE; } @@ -619,8 +669,6 @@ * The isDDInstitAdvancedRecordValid function checks the validity of the DD * advanced institutional record. It verifies CRC and updates the record * with default values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_INSTIT_ADVANCED_RECORD_CRC if CRC - * check fails * @details \b Inputs: ddInstitutionalGroup * @details \b Outputs: ddInstitutionalGroup * @return TRUE if the DD Advanced Institutional record is valid otherwise FALSE @@ -637,9 +685,15 @@ // CRC did not pass so set all values to default initDDInstitAdvancedRecord(); - // Activate alarm for advanced Institutional record failure - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTIT_ADVANCED_RECORD_CRC ); + // Recalculate the CRC with the default values + updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_INSTITUTIONAL_RECORD ); + + // Indicate that the record was updated + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + status = FALSE; } @@ -651,8 +705,6 @@ * The isDDInstitAdditionalRecordValid function checks the validity of the DD * addtional institutional record. It verifies CRC and updates the record * with default values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_INSTIT_ADDITIONAL_RECORD_CRC if CRC - * check fails * @details \b Inputs: ddInstitutionalGroup * @details \b Outputs: ddInstitutionalGroup * @return TRUE if the DD Addtional Institutional record is valid otherwise FALSE @@ -669,9 +721,15 @@ // CRC did not pass so set all values to default initDDInstitAdditionalRecord(); - // Activate alarm for additional Institutional record failure - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_INSTIT_ADDITIONAL_RECORD_CRC ); + // Recalculate the CRC with the default values + updateRecordCRC( NVM_INSTITUTIONAL_RECORD ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_INSTITUTIONAL_RECORD ); + + // Indicate that the record was updated + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + status = FALSE; } @@ -767,12 +825,6 @@ isHardwareRecordValid = isDDBloodLeakSensorValid( bloodLeak ); isCalRecordValid = ( isCalRecordValid == FALSE ) ? FALSE : isHardwareRecordValid; - // Validate Conductivity Sensor Record - if( FALSE == isDDConductivitySensorValid() ) - { - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_CALIBRATION_RECORD_CRC ); - } - // If the sub groups failed, they are all updated to their benign values // so the main CRC of the calibration group is calculated again if ( ( FALSE == isCalRecordValid ) || ( recordCRC != ddCalibrationGroup.crc ) ) @@ -785,7 +837,13 @@ // Recalculate the CRC updateRecordCRC( NVM_CALIBRATION_RECORD ); - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_CALIBRATION_RECORD_CRC ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_CALIBRATION_RECORD ); + + // Indicate that the record was updated + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + startNewCalRecordAvailableTimer(); + setNewCalibrationRecordAvailable( TRUE ); } return isCalRecordValid; @@ -1005,8 +1063,6 @@ * The isDDUsageRecordValid function checks the validity of the DD * usage information record. It verifies CRC and updates the record * with default values if invalid. - * @details \b Alarms: ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC if CRC - * check fails * @details \b Inputs: ddUsageInfoGroup * @details \b Outputs: ddUsageInfoGroup * @return TRUE if the DD usage record is valid otherwise FALSE @@ -1027,9 +1083,14 @@ // Recalculate the CRC with the default values updateRecordCRC( NVM_USAGE_INFO_RECORD ); - status = FALSE; - activateAlarmNoData( ALARM_ID_DD_NVM_INVALID_USAGE_RECORD_CRC ); + // Write the record to flash + enqueueEraseAndWriteSector ( NVM_USAGE_INFO_RECORD ); + + // Indicate that the record was updated + sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); + + status = FALSE; } return status;