Index: NVDataMgmt.c =================================================================== diff -u -r53cdbd6fcdef7f41e93968cd120d4ad9b5ed184f -rdfd2821ec7c2bc50a00818bca901415f9f841114 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 53cdbd6fcdef7f41e93968cd120d4ad9b5ed184f) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision dfd2821ec7c2bc50a00818bca901415f9f841114) @@ -8,7 +8,7 @@ * @file NVDataMgmt.c * * @author (last) Dara Navaei -* @date (last) 04-Jan-2022 +* @date (last) 02-Mar-2022 * * @author (original) Dara Navaei * @date (original) 12-Feb-2020 @@ -106,13 +106,13 @@ - RECORD_BYTE_SIZE(rcrd)) /// DG padding length macro. #define RECORD_DEFAULT_TIME 0U ///< Record default time (calibration/set). -#define RECORD_FOURTH_ORDER_COEFF 0.0 ///< Record fourth order coefficient. -#define RECORD_THIRD_ORDER_COEFF 0.0 ///< Record third order coefficient. -#define RECORD_SECOND_ORDER_COEFF 0.0 ///< Record second order coefficient. -#define RECORD_DEFAULT_GAIN 1.0 ///< Record default gain. -#define RECORD_DEFAULT_OFFSET 0.0 ///< Record default offset. -#define RECORD_DEFAULT_CONST 0.0 ///< Record default constant. -#define RECORD_DEFAULT_RATIO 1.0 ///< Record default ratio. +#define RECORD_FOURTH_ORDER_COEFF 0.0F ///< Record fourth order coefficient. +#define RECORD_THIRD_ORDER_COEFF 0.0F ///< Record third order coefficient. +#define RECORD_SECOND_ORDER_COEFF 0.0F ///< Record second order coefficient. +#define RECORD_DEFAULT_GAIN 1.0F ///< Record default gain. +#define RECORD_DEFAULT_OFFSET 0.0F ///< Record default offset. +#define RECORD_DEFAULT_CONST 0.0F ///< Record default constant. +#define RECORD_DEFAULT_RATIO 1.0F ///< Record default ratio. // The service record interval is equivalent to 6 months #define RECORD_DEFAULT_SERVICE_INTERVAL_S 15768000U ///< Record default service interval in seconds. #define RECORD_DEFAULT_CHARACTER ' ' ///< Record default character. @@ -127,16 +127,16 @@ // DG specific defines #ifdef _DG_ -#define FLUSH_LINES_DEFAULT_VOLUME_L 0.01 ///< Water volume to flush when starting re-circulate mode in liters. +#define FLUSH_LINES_DEFAULT_VOLUME_L 0.01F ///< Water volume to flush when starting re-circulate mode in liters. #define ACID_CONC_DEFAULT_MIXING_RATIO ( 2.35618 / FRACTION_TO_PERCENT_FACTOR ) ///< Ratio between RO water and acid concentrate mixing ratio. #define BICARB_CONC_DEFAULT_MIXING_RATIO ( 4.06812 / FRACTION_TO_PERCENT_FACTOR ) ///< Ratio between RO water and bicarbonate concentrate mixing ratio. #define PRES_SENSORS_RESERVED_SPACE_COUNT 6 ///< Pressure sensors reserved space count. #define FLOW_SENSROS_RESERVED_SPACE_COUNT 2 ///< Flow sensors reserved space count. #define TEMP_SENSORS_RESERVED_SPACE_COUNT 5 ///< Temperature sensors reserved space count. #define COND_SENSORS_RESERVED_SPACE_COUNT 2 ///< Conductivity sensors reserved space count. #define GENERIC_VOL_RESERVED_SPACE_COUNT 4 ///< Generic volumes reserved space count. -#define RESERVOIR_TEMPERATURE_TAU_C_PER_MIN -0.512 ///< Reservoir temperature time constant C/min. -#define ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN -4.565 ///< Ultrafilter temperature time constant C/min. +#define RESERVOIR_TEMPERATURE_TAU_C_PER_MIN -0.512F ///< Reservoir temperature time constant C/min. +#define ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN -4.565F ///< Ultrafilter temperature time constant C/min. #define ULTRAFILTER_VOLUME_ML 700 ///< Ultrafilter volume in milliliters. #endif @@ -347,15 +347,18 @@ U16 crc; ///< CRC for the DG heaters info structure. } DG_HEATERS_INFO_GROUP_T; +#ifndef _RELEASE_ /// DG software configurations group typedef struct { DG_SW_CONFIG_RECORD_T dgSWConfigsRecord; ///< Software configurations record. + // Since the software configurations are one byte, Num_of was used for the length of the lists U08 padding[ RECORD_PADDING_LENGTH(DG_SW_CONFIG_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< Software configurations group padding. U16 crc; ///< Software configurations CRC. } DG_SW_CONFIG_GROUP_T; #endif +#endif #ifdef _HD_ /// HD calibration groups structure @@ -403,6 +406,7 @@ U16 crc; ///< CRC for the HD usage info structure. } HD_USAGE_INFO_GROUP_T; +#ifndef _RELEASE_ /// HD software configurations group typedef struct { @@ -411,6 +415,7 @@ U08 padding[ RECORD_PADDING_LENGTH(HD_SW_CONFIG_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< Software configurations group padding. U16 crc; ///< Software configurations CRC. } HD_SW_CONFIG_GROUP_T; +#endif #endif #pragma pack(pop) @@ -441,13 +446,17 @@ static HD_SYSTEM_GROUP_T hdSystemGroup; ///< HD system group structure (including padding and final CRC). static HD_SERVICE_GROUP_T hdServiceGroup; ///< HD service group structure (including padding and final CRC). static HD_USAGE_INFO_GROUP_T hdUsageInfoGroup; ///< HD usage info group structure (including padding and final CRC). +#ifndef _RELEASE_ static HD_SW_CONFIG_GROUP_T hdSWConfigGroup; ///< HD Software configurations structure(including padding and final CRC). +#endif // Process records specifications const PROCESS_RECORD_SPECS_T RECORDS_SPECS [ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_CALIBRATION_RECORD_T), (U08*)&hdCalibrationRecord, (U08*)&hdCalibrationRecord.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_CALIBRATION_RECORD {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(HD_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(HD_SYSTEM_GROUP_T), (U08*)&hdSystemGroup, (U08*)&hdSystemGroup.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_SYSTEM_RECORD {SERVICE_RECORD_START_ADDRESS, sizeof(HD_SERVICE_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdServiceGroup, (U08*)&hdServiceGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_PROCESS_LAST_SERVICE_RECORD +#ifndef _RELEASE_ {SW_CONFIGS_START_ADDRESS, sizeof(HD_SW_CONFIG_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&hdSWConfigGroup, (U08*)&hdSWConfigGroup.crc, NVDATAMGMT_RTC} // NVDATAMGMT_SW_CONFIG_RECORD +#endif }; #endif @@ -546,11 +555,14 @@ static BOOL areRecordsValid( void ); static BOOL isPolynomialRecordValid( POLYNOMIAL_CAL_PAYLOAD_T* record ); +#ifndef _RELEASE_ +static BOOL isSWConfigRecordValid( void ); +#endif + #ifdef _DG_ static BOOL isDGSystemRecordValid( void ); static BOOL isDGServiceRecordValid( void ); static BOOL isDGCalibrationRecordValid( void ); -static BOOL isSWConfigRecordValid( void ); static BOOL isDGConcPumpRecordValid( DG_CONC_PUMPS_CAL_DATA_T* record ); static BOOL isDGDrainPumpRecordValid( DG_DRAIN_PUMP_CAL_RECORD_T* record ); static BOOL isDGROPumpRecordValid( DG_RO_PUMP_CAL_RECORD_T* record ); @@ -570,7 +582,6 @@ static BOOL isHDSystemRecordValid( void ); static BOOL isHDServiceRecordValid( void ); static BOOL isHDCalibrationRecordValid( void ); -static BOOL isSWConfigRecordValid( void ); static BOOL isHDValveRecordValid( HD_VALVE_CAL_PAYLOAD_T* record ); static BOOL isHDPumpRecordValid( HD_PUMP_CAL_PAYLOAD_T* record ); static BOOL isHDAccelerometerSensorValid( HD_ACCELEROMETER_SENSOR_CAL_RECORD_T* record ); @@ -1216,6 +1227,7 @@ return isNVDataValid; } +#ifndef _RELEASE_ /*********************************************************************//** * @brief * The getSoftwareConfigStatus function returns the status of a software @@ -1232,17 +1244,16 @@ // If the build is not a release, get the value from the software configurations list // If the build is a release, the configuration not matter what its value is kept in // the NV RAM, it returns a 0 which is the configuration is disabled -#ifndef _RELEASE_ #ifdef _DG_ value = dgSWConfigGroup.dgSWConfigsRecord.swConfigs[ config ]; #endif #ifdef _HD_ value = hdSWConfigGroup.hdSWConfigsRecord.swConfigs[ config ]; #endif -#endif return value; } +#endif #ifdef _DG_ /*********************************************************************//** @@ -1735,12 +1746,12 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadSWConfigRecord( void ) { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_SW_CONFIG_RECORD; - BOOL timeoutStatus = didCommandTimeout( ALARM_ID_RTC_RAM_OPS_ERROR, (U08*)&state ); + BOOL timeoutStatus = didCommandTimeout( ALARM_ID_RTC_RAM_OPS_ERROR, (U08*)&state ); + PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS[ NVDATAMGMT_SW_CONFIG_RECORD ]; #ifndef _RELEASE_ if ( ( RTC_RAM_STATUS_IDLE == getRTCRAMStatus() ) || ( TRUE == timeoutStatus ) ) { - PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS[ NVDATAMGMT_SW_CONFIG_RECORD ]; U08* bufferAddress = specs.structAddressPtr; U32 maxBufferLength = specs.maxReadBufferSize; @@ -1782,14 +1793,18 @@ haveCalGroupsPassed = TRUE; //isDGCalibrationRecordValid(); hasSystemRecordPassed = isDGSystemRecordValid(); hasServiceRecordPassed = isDGServiceRecordValid(); +#ifndef _RELEASE_ hasSWConfigRecordPassed = isSWConfigRecordValid(); #endif +#endif #ifdef _HD_ haveCalGroupsPassed = isHDCalibrationRecordValid(); hasSystemRecordPassed = isHDSystemRecordValid(); hasServiceRecordPassed = isHDServiceRecordValid(); +#ifndef _RELEASE_ hasSWConfigRecordPassed = isSWConfigRecordValid(); #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 @@ -2845,7 +2860,60 @@ return status; } +#ifndef _RELEASE_ +/*********************************************************************//** + * @brief + * The isSWConfigRecordValid function checks the validity of the software + * configuration record. + * @details Inputs: dgSWConfigGroup, hdSWConfigGroup + * @details Outputs: dgSWConfigGroup, hdSWConfigGroup + * @return TRUE if the DG system record is valid otherwise FALSE + *************************************************************************/ +static BOOL isSWConfigRecordValid( void ) +{ + BOOL status = TRUE; + #ifdef _DG_ + U16 calcCRC = crc16( (U08*)&dgSWConfigGroup, sizeof( DG_SW_CONFIG_GROUP_T ) - sizeof(U16) ); + U16 recordCRC = dgSWConfigGroup.crc; + + if ( calcCRC != recordCRC ) + { + memset( (U08*)&dgSWConfigGroup, 0, sizeof( DG_SW_CONFIG_GROUP_T ) ); + + // Recalculate the CRC with the default values + dgSWConfigGroup.crc = crc16( (U08*)&dgSWConfigGroup, sizeof( DG_SW_CONFIG_GROUP_T ) - sizeof(U16) ); + + //activateAlarmNoData( ALARM_ID_DG_SW_CONFIG_RECORD_INVALID_CRC ); // TODO remove + + // Set the to FALSE since the record is not valid + status = FALSE; + } +#endif + +#ifdef _HD_ + U16 calcCRC = crc16( (U08*)&hdSWConfigGroup, sizeof( HD_SW_CONFIG_GROUP_T ) - sizeof(U16) ); + U16 recordCRC = hdSWConfigGroup.crc; + + if ( calcCRC != recordCRC ) + { + memset( (U08*)&hdSWConfigGroup, SW_CONFIG_DISABLE_VALUE, sizeof( HD_SW_CONFIG_GROUP_T ) ); + + // Recalculate the CRC with the default values + hdSWConfigGroup.crc = crc16( (U08*)&hdSWConfigGroup, sizeof( HD_SW_CONFIG_GROUP_T ) - sizeof(U16) ); + + //activateAlarmNoData( ALARM_ID_HD_SW_CONFIG_RECORD_INVALID_CRC ); // TODO remove + + // Set the to FALSE since the record is not valid + status = FALSE; + } +#endif + + return status; +} +#endif + +#ifdef _DG_ /*********************************************************************//** * @brief * The isDGSystemRecordValid function checks the validity of the DG system @@ -3110,36 +3178,6 @@ /*********************************************************************//** * @brief - * The isSWConfigRecordValid function checks the validity of the software - * configuration record. - * @details Inputs: dgSWConfigGroup - * @details Outputs: dgSWConfigGroup - * @return TRUE if the DG system record is valid otherwise FALSE - *************************************************************************/ -static BOOL isSWConfigRecordValid( void ) -{ - BOOL status = TRUE; - U16 calcCRC = crc16( (U08*)&dgSWConfigGroup, sizeof( DG_SW_CONFIG_GROUP_T ) - sizeof(U16) ); - U16 recordCRC = dgSWConfigGroup.crc; - - if ( calcCRC != recordCRC ) - { - memset( (U08*)&dgSWConfigGroup, 0, sizeof( DG_SW_CONFIG_GROUP_T ) ); - - // Recalculate the CRC with the default values - dgSWConfigGroup.crc = crc16( (U08*)&dgSWConfigGroup, sizeof( DG_SW_CONFIG_GROUP_T ) - sizeof(U16) ); - - //activateAlarmNoData( ALARM_ID_DG_SW_CONFIG_RECORD_INVALID_CRC ); // TODO remove - - // Set the to FALSE since the record is not valid - status = FALSE; - } - - return status; -} - -/*********************************************************************//** - * @brief * The isDGConcPumpRecordValid function checks whether the calibration * record of concentrate pump is valid or not. * @details Inputs: none @@ -3675,36 +3713,6 @@ /*********************************************************************//** * @brief - * The isSWConfigRecordValid function checks the validity of the software - * configuration record. - * @details Inputs: hdSWConfigGroup - * @details Outputs: hdSWConfigGroup - * @return TRUE if the DG system record is valid otherwise FALSE - *************************************************************************/ -static BOOL isSWConfigRecordValid( void ) -{ - BOOL status = TRUE; - U16 calcCRC = crc16( (U08*)&hdSWConfigGroup, sizeof( HD_SW_CONFIG_GROUP_T ) - sizeof(U16) ); - U16 recordCRC = hdSWConfigGroup.crc; - - if ( calcCRC != recordCRC ) - { - memset( (U08*)&hdSWConfigGroup, SW_CONFIG_DISABLE_VALUE, sizeof( HD_SW_CONFIG_GROUP_T ) ); - - // Recalculate the CRC with the default values - hdSWConfigGroup.crc = crc16( (U08*)&hdSWConfigGroup, sizeof( HD_SW_CONFIG_GROUP_T ) - sizeof(U16) ); - - //activateAlarmNoData( ALARM_ID_HD_SW_CONFIG_RECORD_INVALID_CRC ); // TODO remove - - // Set the to FALSE since the record is not valid - status = FALSE; - } - - return status; -} - -/*********************************************************************//** - * @brief * The isHDPumpRecordValid function checks whether the calibration record * of HD pump(s) is valid or not. * @details Inputs: none