Index: NVDataMgmt.c =================================================================== diff -u -r1e95db41aa41a5b06b50ad876509a4eb168ce274 -r99d6815c44fd6e27f135e8c422d1ab88696cd5eb --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 1e95db41aa41a5b06b50ad876509a4eb168ce274) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 99d6815c44fd6e27f135e8c422d1ab88696cd5eb) @@ -95,10 +95,16 @@ #define CAL_RECORD_NV_MEM_START_ADDRESS BANK7_SECTOR0_START_ADDRESS + 4096 ///< Calibration record storage start address in NV memory. #define RECORD_BYTE_SIZE(r) (sizeof(r) + sizeof(U16)) ///< Record byte size macro. -// Padding length calculation: (DG struct size % bytes to write(16) == 0 ? 0 : (DG struct size / bytes to write(16)) + 1) * bytes to write(16) -/// DG padding length macro that is calculated with the size of the provided structure. -#define RECORD_PADDING_LENGTH(rcrd, buf) (RECORD_BYTE_SIZE(rcrd) % buf == 0 ? 0 : ((U32)(RECORD_BYTE_SIZE(rcrd) / buf) + 1)) * buf +// Padding length calculation: (DG struct size % bytes to write(16) == 0 ? 0 : ((DG struct size / bytes to write(16)) + 1) * bytes to write(16)) - DG struct size. +// NOTE: assuming the macro is calculating the padding length for a non-volatile memory. For NV, 16 bytes is used and buffer and for the RTC RAM 64 bytes is used. +// If the size of the structure + a 2-byte crc mod 16 is 0, then the size of the padding is 0 +// Otherwise, the (((structure size + crc) / 16) + 1) * 16. In the calculations, a + 1 is added since the division has a decimal so + 1 is used +// to round up. The result is then multiplied by 16 bytes to get the number of bytes needed and is subtracted from the size of the structure and CRC. +#define RECORD_PADDING_LENGTH(rcrd, buf) (RECORD_BYTE_SIZE(rcrd) % buf == 0 ? 0 : \ + ((((RECORD_BYTE_SIZE(rcrd) / buf) + 1)) * buf) \ + - 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. @@ -297,53 +303,47 @@ typedef struct { DG_CALIBRATION_GROUPS_T dgCalibrationGroups; ///< DG calibration groups. - U08 padding[ RECORD_PADDING_LENGTH(DG_CALIBRATION_GROUPS_T, MAX_EEPROM_WRITE_BUFFER_BYTES) - - RECORD_BYTE_SIZE(DG_CALIBRATION_GROUPS_T) ]; ///< DG calibration record padding byte array. + U08 padding[ RECORD_PADDING_LENGTH(DG_CALIBRATION_GROUPS_T, MAX_EEPROM_WRITE_BUFFER_BYTES) ]; ///< DG calibration record padding byte array. U16 crc; ///< CRC for the DG calibration record structure. } DG_CALIBRATION_RECORD_T; /// DG system group structure typedef struct { DG_SYSTEM_RECORD_T dgSystemRecord; ///< DG system record. - U08 padding[ RECORD_PADDING_LENGTH(DG_SYSTEM_RECORD_T, MAX_EEPROM_WRITE_BUFFER_BYTES) - - RECORD_BYTE_SIZE(DG_SYSTEM_RECORD_T) ]; ///< DG system group padding byte array. + U08 padding[ RECORD_PADDING_LENGTH(DG_SYSTEM_RECORD_T, MAX_EEPROM_WRITE_BUFFER_BYTES) ]; ///< DG system group padding byte array. U16 crc; ///< CRC for the DG system group structure. } DG_SYSTEM_GROUP_T; /// DG service record structure typedef struct { DG_SERVICE_RECORD_T dgServiceRecord; ///< DG service record. - U08 padding[ RECORD_PADDING_LENGTH(DG_SERVICE_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(DG_SERVICE_RECORD_T) ]; ///< DG service group padding. + U08 padding[ RECORD_PADDING_LENGTH(DG_SERVICE_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< DG service group padding. U16 crc; ///< CRC for the DG service structure. } DG_SERVICE_GROUP_T; /// DG scheduler record structure typedef struct { DG_SCHEDULED_RUN_RECORD_T dgScheduledRun; ///< DG scheduled runs. - U08 padding[ RECORD_PADDING_LENGTH(DG_SCHEDULED_RUN_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(DG_SCHEDULED_RUN_RECORD_T) ]; ///< DG scheduled run group padding. + U08 padding[ RECORD_PADDING_LENGTH(DG_SCHEDULED_RUN_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< DG scheduled run group padding. U16 crc; ///< CRC for the DG scheduled runs structure. } DG_SCHEDULED_RUNS_GROUP_T; /// DG usage record structure typedef struct { DG_USAGE_INFO_RECORD_T dgUsageInfo; ///< DG usage info record. - U08 padding[ RECORD_PADDING_LENGTH(DG_USAGE_INFO_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(DG_USAGE_INFO_RECORD_T) ]; ///< DG scheduled run group padding. + U08 padding[ RECORD_PADDING_LENGTH(DG_USAGE_INFO_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< DG scheduled run group padding. U16 crc; ///< CRC for the DG usage info structure. } DG_USAGE_INFO_GROUP_T; /// DG heaters record typedef struct { DG_HEATERS_RECORD_T dgHeatersInfo; ///< DG heaters info record. - U08 padding[ RECORD_PADDING_LENGTH(DG_HEATERS_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(DG_HEATERS_RECORD_T) ]; ///< DG heater info group padding. + U08 padding[ RECORD_PADDING_LENGTH(DG_HEATERS_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< DG heater info group padding. U16 crc; ///< CRC for the DG heaters info structure. } DG_HEATERS_INFO_GROUP_T; @@ -352,8 +352,7 @@ { 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) - - RECORD_BYTE_SIZE(DG_SW_CONFIG_RECORD_T) ]; ///< Software configurations group padding. + 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 @@ -365,7 +364,6 @@ HD_PUMPS_CAL_RECORD_T pumpsCalRecord; ///< HD pumps. HD_VALVES_CAL_RECORD_T valvesCalRecord; ///< HD valves. HD_OCCLUSION_SENSORS_CAL_RECORD_T occlusionSensorsCalRecord; ///< HD occlusion sensors. - HD_FLOW_SENSORS_CAL_RECORD_T flowSensorsCalRecord; ///< HD flow sensors. HD_PRESSURE_SENSORS_CAL_RECORD_T pressureSensorsCalRecord; ///< HD pressure sensors. HD_TEMP_SENSORS_CAL_RECORD_T tempSensorsCalRecord; ///< HD temperature sensors. HD_HEPARIN_FORCE_SENSOR_CAL_RECORD_T heparinForceSensorCalRecord; ///< HD heparin force sensor. @@ -377,35 +375,31 @@ typedef struct { HD_CALIBRATION_GROUPS hdCalibrationGroups; ///< HD calibration groups. - U08 padding[ RECORD_PADDING_LENGTH(HD_CALIBRATION_GROUPS, MAX_EEPROM_WRITE_BUFFER_BYTES) - - RECORD_BYTE_SIZE(HD_CALIBRATION_GROUPS) ]; ///< HD calibration record padding byte array. + U08 padding[ RECORD_PADDING_LENGTH(HD_CALIBRATION_GROUPS, MAX_EEPROM_WRITE_BUFFER_BYTES) ]; ///< HD calibration record padding byte array. U16 crc; ///< CRC for the DG calibration record structure. } HD_CALIBRATION_RECORD_T; /// HD system group structure typedef struct { HD_SYSTEM_RECORD_T hdsystemRecord; ///< HD system record. - U08 padding[ RECORD_PADDING_LENGTH(HD_SYSTEM_RECORD_T, MAX_EEPROM_WRITE_BUFFER_BYTES) - - RECORD_BYTE_SIZE(HD_SYSTEM_RECORD_T) ]; ///< HD system group padding. + U08 padding[ RECORD_PADDING_LENGTH(HD_SYSTEM_RECORD_T, MAX_EEPROM_WRITE_BUFFER_BYTES) ]; ///< HD system group padding. U16 crc; ///< CRC for the HD system group structure. } HD_SYSTEM_GROUP_T; /// HD service record structure typedef struct { HD_SERVICE_RECORD_T hdServiceRecord; ///< HD service record. - U08 padding[ RECORD_PADDING_LENGTH(HD_SERVICE_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(HD_SERVICE_RECORD_T) ]; ///< HD service group padding. + U08 padding[ RECORD_PADDING_LENGTH(HD_SERVICE_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< HD service group padding. U16 crc; ///< CRC for the HD service structure. } HD_SERVICE_GROUP_T; /// HD usage info record structure typedef struct { HD_USAGE_INFO_RECORD_T hdUsageInfo; ///< HD usage info record. - U08 padding[ RECORD_PADDING_LENGTH(HD_USAGE_INFO_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(HD_USAGE_INFO_RECORD_T) ]; ///< HD scheduled run group padding. + U08 padding[ RECORD_PADDING_LENGTH(HD_USAGE_INFO_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) ]; ///< HD scheduled run group padding. U16 crc; ///< CRC for the HD usage info structure. } HD_USAGE_INFO_GROUP_T; @@ -414,8 +408,7 @@ { HD_SW_CONFIG_RECORD_T hdSWConfigsRecord; ///< 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(HD_SW_CONFIG_RECORD_T, MAX_RTC_RAM_OPS_BUFFER_BYTES) - - RECORD_BYTE_SIZE(HD_SW_CONFIG_RECORD_T) ]; ///< Software configurations group padding. + 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; @@ -826,331 +819,6 @@ /*********************************************************************//** * @brief - * The getDGCalibrationRecord function sets the calibration state machine - * to read and publish calibration record. - * @details Inputs: hasPublishRecordBeenRequested, recordToPublish - * nvDataMgmtExecProcessRecordState - * @details Outputs: hasPublishRecordBeenRequested, recordToPublish - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL getCalibrationRecord( void ) -{ - BOOL status = FALSE; - - // Check if the state machine is in idle state and then set the request - if ( nvDataMgmtExecProcessRecordState == NVDATAMGMT_PROCESS_RECORD_STATE_IDLE ) - { - hasPublishRecordBeenRequested = TRUE; - recordToPublish = NVDATAMGMT_CALIBRATION_RECORD; - status = TRUE; - } - - return status; -} - -/*********************************************************************//** - * @brief - * The setCalibrationRecord function writes the calibration record that - * is received from Dialin into the calibration structure. - * @details Inputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @details Outputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @param currentMessage: current message number that is received from - * Dialin - * @param totalMessages: total number of messages from Dialin - * @param length: message length in bytes - * @param *addressPtr: address to the beginning of the calibration data from Dialin - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL setCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ) -{ - BOOL status = TRUE; - - // If the calibration message number is the first message number and receive exec state is idle, switch to idle - if ( ( RECORD_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage ) && ( NVDATAMGMT_RECEIVE_RECORD_IDLE == nvDataMgmtExecReceiveRecordState ) ) - { - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; - recordReceiveStartTime = getMSTimerCount(); - previousCalMessageNum = 0; - recordUpdateAddress = 0; - } - - // Check if there is still a message left to be received - if ( ( NVDATAMGMT_RECEIVE_RECORD_RECEIVE == nvDataMgmtExecReceiveRecordState ) && ( currentMessage <= totalMessages ) ) - { - // Check if the current message is different from the previous message by 1 - if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousCalMessageNum ) ) - { - // Define a pointer that points to the DG calibration record - PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS[ NVDATAMGMT_CALIBRATION_RECORD ]; - U08* ptr = recordSpec.structAddressPtr; - - // Offset the pointer to length that we should start writing from - ptr += recordUpdateAddress; - - // Copy the data into the buffer - memcpy(ptr, addressPtr, length); - - // Check if the current message is total messages - // and 0 everything out since we are done writing - if ( currentMessage == totalMessages ) - { - U16 calcCRC = crc16( recordSpec.structAddressPtr, recordSpec.sizeofJob - sizeof(U16) ); - U16 recordCRC = *(U16*)recordSpec.structCRCPtr; - - if ( calcCRC != recordCRC ) - { - // CRC failed, request a read to read the data back from NV memory and update the structure - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - status = FALSE; - } - else - { - // CRC passed, enqueue an erase, a write of calibration data and a write of service record - BOOL scheduleStatus = enqueueSector0Records(); - - // Signal that there is a new calibration record available. - newCalStartTimer = getMSTimerCount(); - isNewCalAvailable = TRUE; - } - // Done with receiving data, go back to idle - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - } - else - { - // Update the length as it has successfully been written - recordUpdateAddress += length; - - // Now the current message is the previous message - previousCalMessageNum = currentMessage; - } - } - else - { - status = FALSE; - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - } - } - - return status; -} - -/*********************************************************************//** - * @brief - * The getSystemRecord function sets the system state machine to read - * and publish system record. - * @details Inputs: hasPublishRecordBeenRequested, recordToPublish - * nvDataMgmtExecProcessRecordState - * @details Outputs: hasPublishRecordBeenRequested, recordToPublish - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL getSystemRecord( void ) -{ - BOOL status = FALSE; - - // Check if the state machine is in idle state and then set the request - if ( nvDataMgmtExecProcessRecordState == NVDATAMGMT_PROCESS_RECORD_STATE_IDLE ) - { - hasPublishRecordBeenRequested = TRUE; - recordToPublish = NVDATAMGMT_SYSTEM_RECORD; - status = TRUE; - } - - return status; -} - -/*********************************************************************//** - * @brief - * The setSystemRecord function writes the system record that is received - * from Dialin into the system structure. - * @details Inputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @details Outputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @param currentMessage: current message number that is received from - * Dialin - * @param totalMessages: total number of messages from Dialin - * @param length: message length in bytes - * @param *addressPtr: address to the beginning of the calibration data - * from Dialin - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL setSystemRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ) -{ - BOOL status = TRUE; - - // If the calibration message number is the first message number and receive exec state is idle, switch to idle - if ( ( RECORD_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage ) && ( NVDATAMGMT_RECEIVE_RECORD_IDLE == nvDataMgmtExecReceiveRecordState ) ) - { - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; - recordReceiveStartTime = getMSTimerCount(); - previousCalMessageNum = 0; - recordUpdateAddress = 0; - } - - // Check if there is still a message left to be received - if ( ( NVDATAMGMT_RECEIVE_RECORD_RECEIVE == nvDataMgmtExecReceiveRecordState ) && ( currentMessage <= totalMessages ) ) - { - // Check if the current message is different from the previous message by 1 - if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousCalMessageNum ) ) - { - // Define a pointer that points to the DG calibration record - PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS [ NVDATAMGMT_SYSTEM_RECORD ]; - U08* ptr = recordSpec.structAddressPtr; - - // Offset the pointer to length that we should start writing from - ptr += recordUpdateAddress; - - memcpy(ptr, addressPtr, length); - - // Check if the current message is total messages - // and 0 everything out since we are done writing - if ( currentMessage == totalMessages ) - { - U16 calcCRC = crc16 ( recordSpec.structAddressPtr, recordSpec.sizeofJob - sizeof(U16) ); - // Get the CRC of the structure without the last 16 bits which is the CRC as well as the padding values - U16 recordCRC = *(U16*)recordSpec.structCRCPtr; - - if ( calcCRC != recordCRC ) - { - // CRC failed, request a read to read the data back from NV memory and update the structure - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_SYSTEM_RECORD ); - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - status = FALSE; - } - else - { - // CRC passed, enqueue an erase, a write of calibration data and a write of service record - BOOL scheduleStatus = enqueueSector0Records(); - - // Done with receiving data, go back to idle - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - } - } - else - { - // Update the length as it has successfully been written - recordUpdateAddress += length; - - // Now the current message is the previous message - previousCalMessageNum = currentMessage; - } - } - } - - return status; -} - -/*********************************************************************//** - * @brief - * The getServiceRecord function sets the system state machine to read - * and publish service record. - * @details Inputs: hasPublishRecordBeenRequested, recordToPublish - * hasPublishRecordBeenRequested - * @details Outputs: hasPublishRecordBeenRequested, recordToPublish - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL getServiceRecord( void ) -{ - BOOL status = FALSE; - - // Check if the state machine is in idle state and then set the request - if ( NVDATAMGMT_PROCESS_RECORD_STATE_IDLE == nvDataMgmtExecProcessRecordState ) - { - hasPublishRecordBeenRequested = TRUE; - recordToPublish = NVDATAMGMT_SERVICE_RECORD; - status = TRUE; - } - - return status; -} - -/*********************************************************************//** - * @brief - * The setServiceRecord function writes the service record that - * is received from Dialin into the service structure. - * @details Inputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @details Outputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @param currentMessage: current message number that is received from - * Dialin - * @param totalMessages: total number of messages from Dialin - * @param length: message length in bytes - * @param *addressPtr: address to the beginning of the calibration data - * from Dialin - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL setServiceRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ) -{ - BOOL status = TRUE; - - // If the calibration message number is the first message number and receive exec state is idle, switch to idle - if ( RECORD_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage && nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_IDLE ) - { - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; - recordReceiveStartTime = getMSTimerCount(); - previousCalMessageNum = 0; - recordUpdateAddress = 0; - } - - // Check if there is still a message left to be received - if ( nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_RECEIVE && currentMessage <= totalMessages ) - { - // Check if the current message is different from the previous message by 1 - if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousCalMessageNum ) ) - { - // Define a pointer that points to the DG calibration record - PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS [ NVDATAMGMT_SERVICE_RECORD ]; - U08* ptr = recordSpec.structAddressPtr; - - // Offset the pointer to length that we should start writing from - ptr += recordUpdateAddress; - - memcpy(ptr, addressPtr, length); - - // Check if the current message is total messages - // and 0 everything out since we are done writing - if ( currentMessage == totalMessages ) - { - U16 calcCRC = crc16 ( recordSpec.structAddressPtr, recordSpec.sizeofJob - sizeof(U16) ); - // Get the CRC of the structure without the last 16 bits which is the CRC as well as the padding values - U16 recordCRC = *(U16*)recordSpec.structCRCPtr; - - if ( calcCRC != recordCRC ) - { - // CRC failed, request a read to read the data back from NV memory and update the structure - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_SERVICE_RECORD ); - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - status = FALSE; - } - else - { - // CRC passed write the last service record to the RTC RAM - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, NVDATAMGMT_SERVICE_RECORD ); - - // Done with receiving data, go back to idle - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - } - } - else - { - // Update the length as it has successfully been written - recordUpdateAddress += length; - - // Now the current message is the previous message - previousCalMessageNum = currentMessage; - } - } - } - - return status; -} - -/*********************************************************************//** - * @brief * The sendRecordToDialin function prepares the process record state machine * to send a record to Dialin. * @details Inputs: nvDataMgmtExecProcessRecordState @@ -1262,116 +930,8 @@ return status; } -#ifdef _DG_ /*********************************************************************//** * @brief - * The getScheduledRunsRecord function sets the system state machine - * to read and publish the scheduled runs record. - * @details Inputs: hasPublishRecordBeenRequested, recordToPublish - * hasPublishRecordBeenRequested - * @details Outputs: hasPublishRecordBeenRequested, recordToPublish - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL getScheduledRunsRecord( void ) -{ - BOOL status = FALSE; - - // Check if the state machine is in idle state and then set the request - if ( nvDataMgmtExecProcessRecordState == NVDATAMGMT_PROCESS_RECORD_STATE_IDLE ) - { - hasPublishRecordBeenRequested = TRUE; - recordToPublish = NVDATAMGMT_SCHEDULED_RUNS_RECORD; - status = TRUE; - } - - return status; -} - -/*********************************************************************//** - * @brief - * The setScheduledRunsRecord function writes the scheduled runs record that - * is received from Dialin into the scheduled runs structure. - * @details Inputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @details Outputs: nvDataMgmtExecReceiveRecordState, recordUpdateAddress - * recordReceiveStartTime, previousCalMessageNum - * @param currentMessage: current message number that is received from - * Dialin - * @param totalMessages: total number of messages from Dialin - * @param length: message length in bytes - * @param *addressPtr: address to the beginning of the calibration data - * from Dialin - * @return TRUE if the request was successfully registered - *************************************************************************/ -BOOL setScheduledRunsRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ) -{ - BOOL status = TRUE; - - // If the calibration message number is the first message number and receive exec state is idle, switch to idle - if ( RECORD_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage && nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_IDLE ) - { - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; - recordReceiveStartTime = getMSTimerCount(); - previousCalMessageNum = 0; - recordUpdateAddress = 0; - } - - // Check if there is still a message left to be received - if ( nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_RECEIVE && currentMessage <= totalMessages ) - { - // Check if the current message is different from the previous message by 1 - if ( RECORD_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousCalMessageNum ) ) - { - // Define a pointer that points to the DG calibration record - PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS [ NVDATAMGMT_SCHEDULED_RUNS_RECORD ]; - U08* ptr = recordSpec.structAddressPtr; - - // Offset the pointer to length that we should start writing from - ptr += recordUpdateAddress; - - memcpy(ptr, addressPtr, length); - - // Check if the current message is total messages - // and 0 everything out since we are done writing - if ( currentMessage == totalMessages ) - { - U16 calcCRC = crc16 ( recordSpec.structAddressPtr, recordSpec.sizeofJob - sizeof(U16) ); - // Get the CRC of the structure without the last 16 bits which is the CRC as well as the padding values - U16 recordCRC = *(U16*)recordSpec.structCRCPtr; - - if ( calcCRC != recordCRC ) - { - // CRC failed, request a read to read the data back from NV memory and update the structure - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_RTC, NVDATAMGMT_SCHEDULED_RUNS_RECORD ); - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - status = FALSE; - } - else - { - // CRC passed write the last service record to the RTC RAM - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, NVDATAMGMT_SCHEDULED_RUNS_RECORD ); - - // Done with receiving data, go back to idle - nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; - } - } - else - { - // Update the length as it has successfully been written - recordUpdateAddress += length; - - // Now the current message is the previous message - previousCalMessageNum = currentMessage; - } - } - } - - return status; -} -#endif - -/*********************************************************************//** - * @brief * The isNewCalibrationRecordAvailable function returns the status of a * new calibration availability. * @details Inputs: none @@ -1402,8 +962,6 @@ *************************************************************************/ BOOL getNVRecord2Driver( NV_DATA_T nvData, U08* bufferAddress, U32 bufferLength, U08 numOfSnsrs2Check, ALARM_ID_T nvAlarm ) { - // TODO NOTE: This function is the replacement to the processCalibrationData functions in the drivers - // Also, remove the get functions in this driver once this function is used instead of get functions in the NVDataMgmt.h U08 i; U08* nvDataStartPtr = 0; BOOL isNVDataValid = FALSE; @@ -1438,6 +996,34 @@ isNVDataValid = ( 0 == hdCalibrationRecord.hdCalibrationGroups.heparinForceSensorCalRecord.hdHeparinForceSensor.calibrationTime ? FALSE : TRUE ); break; + case GET_CAL_PUMPS: + nvDataStartPtr = (U08*)&hdCalibrationRecord.hdCalibrationGroups.pumpsCalRecord; + nvDataLength = sizeof( hdCalibrationRecord.hdCalibrationGroups.pumpsCalRecord ); + for ( i = 0; i < NUM_OF_CAL_DATA_HD_PUMPS; i++ ) + isNVDataValid = ( 0 == hdCalibrationRecord.hdCalibrationGroups.pumpsCalRecord.hdPumps[ i ].calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_PRESSURE_SENSORS: + nvDataStartPtr = (U08*)&hdCalibrationRecord.hdCalibrationGroups.pressureSensorsCalRecord; + nvDataLength = sizeof( hdCalibrationRecord.hdCalibrationGroups.pressureSensorsCalRecord ); + for ( i = 0; i < NUM_OF_CAL_DATA_HD_PRESSURE_SESNSORS; i++ ) + isNVDataValid = ( 0 == hdCalibrationRecord.hdCalibrationGroups.pressureSensorsCalRecord.hdPressureSensors[ i ].calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_OCCLUSION_SESNSORS: + nvDataStartPtr = (U08*)&hdCalibrationRecord.hdCalibrationGroups.occlusionSensorsCalRecord; + nvDataLength = sizeof( hdCalibrationRecord.hdCalibrationGroups.occlusionSensorsCalRecord ); + for ( i = 0; i < NUM_OF_CAL_DATA_OCCLUSION_SENSORS; i++ ) + isNVDataValid = ( 0 == hdCalibrationRecord.hdCalibrationGroups.occlusionSensorsCalRecord.hdOcclusionSensors[ i ].calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_VALVES: + nvDataStartPtr = (U08*)&hdCalibrationRecord.hdCalibrationGroups.valvesCalRecord; + nvDataLength = sizeof( hdCalibrationRecord.hdCalibrationGroups.valvesCalRecord ); + for ( i = 0; i < NUM_OF_CAL_DATA_HD_VALVES; i++ ) + isNVDataValid = ( 0 == hdCalibrationRecord.hdCalibrationGroups.valvesCalRecord.hdvalves[ i ].calibrationTime ? FALSE : TRUE ); + break; + case GET_SYS_RECORD: nvDataStartPtr = (U08*)&hdSystemGroup.hdsystemRecord; nvDataLength = sizeof( hdSystemGroup.hdsystemRecord ); @@ -1517,14 +1103,58 @@ case GET_CAL_HEATING_RECORD: nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.heatingCalRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.heatingCalRecord ); isNVDataValid = ( 0 == dgCalibrationRecord.dgCalibrationGroups.heatingCalRecord.calibrationTime ? FALSE : TRUE ); break; case GET_CAL_DRAIN_LINE_VOLUME_RECORD: nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.drainLineVolumeRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.drainLineVolumeRecord ); isNVDataValid = ( 0 == dgCalibrationRecord.dgCalibrationGroups.drainLineVolumeRecord.calibrationTime ? FALSE : TRUE ); break; + case GET_CAL_RO_PUMP_RECORD: + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.roPumpRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.roPumpRecord ); + isNVDataValid = ( 0 == dgCalibrationRecord.dgCalibrationGroups.roPumpRecord.calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_CONCENTRATE_PUMPS_RECORD: + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.concentratePumpsRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.concentratePumpsRecord ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.concentratePumpsRecord.concentratePumps[ i ].calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_DRAIN_PUMP_RECORD: + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.drainPumpRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.drainPumpRecord ); + isNVDataValid = ( 0 == dgCalibrationRecord.dgCalibrationGroups.drainPumpRecord.calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_FANS_RECORD: + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.fansRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.fansRecord ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.fansRecord.fans[ i ].calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_PRE_RO_PURGE_VOLUME_RECORD: + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.preROPurgeVolumeRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.preROPurgeVolumeRecord ); + isNVDataValid = ( 0 == dgCalibrationRecord.dgCalibrationGroups.preROPurgeVolumeRecord.calibrationTime ? FALSE : TRUE ); + break; + + case GET_CAL_FILTERS_RECORD: + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.filtersRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.filtersRecord ); + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.carbonFilter.calibrationTime ? FALSE : TRUE ); + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.carbonPolishFilter.calibrationTime ? FALSE : TRUE ); + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.roFilter.calibrationTime ? FALSE : TRUE ); + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.sedimentFilter.calibrationTime ? FALSE : TRUE ); + isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.ultraFilter.calibrationTime ? FALSE : TRUE ); + break; + case GET_INF_HEATERS_RECORD: nvDataStartPtr = (U08*)&dgHeatersInfoGroup.dgHeatersInfo; nvDataLength = sizeof( dgHeatersInfoGroup.dgHeatersInfo ); @@ -1540,6 +1170,11 @@ nvDataLength = sizeof( dgServiceGroup.dgServiceRecord ); break; + case GET_SRR_RECORD: + nvDataStartPtr = (U08*)&dgScheduledRunsGroup; + nvDataLength = sizeof( dgScheduledRunsGroup.dgScheduledRun ); + break; + default: // TODO software fault break; @@ -1611,44 +1246,6 @@ #ifdef _DG_ /*********************************************************************//** * @brief - * The getDGROPumpRecord function returns the DG RO pump calibration record. - * @details Inputs: none - * @details Outputs: none - * @return DG RO pump calibration record - *************************************************************************/ -DG_RO_PUMP_CAL_RECORD_T getDGROPumpRecord( void ) -{ - return dgCalibrationRecord.dgCalibrationGroups.roPumpRecord; -} - -/*********************************************************************//** - * @brief - * The getDGConcetnratePumpsRecord function returns the DG concentrate - * pumps calibration record. - * @details Inputs: none - * @details Outputs: none - * @return DG concentrate pumps calibration record - *************************************************************************/ -DG_CONC_PUMPS_CAL_RECORD_T getDGConcetnratePumpsRecord( void ) -{ - return dgCalibrationRecord.dgCalibrationGroups.concentratePumpsRecord; -} - -/*********************************************************************//** - * @brief - * The getDGDrainPumpRecord function returns the DG drain pump calibration - * record. - * @details Inputs: none - * @details Outputs: none - * @return DG drain pump calibration record - *************************************************************************/ -DG_DRAIN_PUMP_CAL_RECORD_T getDGDrainPumpRecord( void ) -{ - return dgCalibrationRecord.dgCalibrationGroups.drainPumpRecord; -} - -/*********************************************************************//** - * @brief * The getDGFiltersRecord function returns the DG filters record. * @details Inputs: none * @details Outputs: none @@ -1658,115 +1255,10 @@ { return dgCalibrationRecord.dgCalibrationGroups.filtersRecord; } - -/*********************************************************************//** - * @brief - * The getDGFansRecord function returns the DG fans record. - * @details Inputs: none - * @details Outputs: none - * @return DG fans record - *************************************************************************/ -DG_FANS_CAL_RECORD_T getDGFansRecord( void ) -{ - return dgCalibrationRecord.dgCalibrationGroups.fansRecord; -} - -/*********************************************************************//** - * @brief - * The getDGScheduledRunsRecord function returns the DG scheduled runs record. - * @details Inputs: none - * @details Outputs: none - * @return DG scheduled runs record - *************************************************************************/ -DG_SCHEDULED_RUN_RECORD_T getDGScheduledRunsRecord( void ) -{ - return dgScheduledRunsGroup.dgScheduledRun; -} #endif -#ifdef _HD_ /*********************************************************************//** * @brief - * The getHDPumpsCalibrationRecord function returns the HD pumps calibration - * record. - * @details Inputs: none - * @details Outputs: none - * @return HD pumps calibration record - *************************************************************************/ -HD_PUMPS_CAL_RECORD_T getHDPumpsCalibrationRecord( void ) -{ - return hdCalibrationRecord.hdCalibrationGroups.pumpsCalRecord; -} - -/*********************************************************************//** - * @brief - * The getHDValvesCalibrationRecord function returns the HD valves calibration - * record. - * @details Inputs: none - * @details Outputs: none - * @return HD valves calibration record - *************************************************************************/ -HD_VALVES_CAL_RECORD_T getHDValvesCalibrationRecord( void ) -{ - return hdCalibrationRecord.hdCalibrationGroups.valvesCalRecord; -} - -/*********************************************************************//** - * @brief - * The getHDOcclusionSensrosCalibrationRecord function returns the HD - * occlusion sensors calibration record. - * @details Inputs: none - * @details Outputs: none - * @return HD occlusion sensors calibration record - *************************************************************************/ -HD_OCCLUSION_SENSORS_CAL_RECORD_T getHDOcclusionSensrosCalibrationRecord( void ) -{ - return hdCalibrationRecord.hdCalibrationGroups.occlusionSensorsCalRecord; -} - -/*********************************************************************//** - * @brief - * The getHDFlowSensorsCalibrationRecord function returns the HD flow - * sensors calibration record. - * @details Inputs: none - * @details Outputs: none - * @return HD flow sensors calibration record - *************************************************************************/ -HD_FLOW_SENSORS_CAL_RECORD_T getHDFlowSensorsCalibrationRecord( void ) -{ - return hdCalibrationRecord.hdCalibrationGroups.flowSensorsCalRecord; -} - -/*********************************************************************//** - * @brief - * The getHDPressureSensorsCalibrationRecord function returns the HD pressure - * sensors calibration record. - * @details Inputs: none - * @details Outputs: none - * @return HD pressure sensors calibration record - *************************************************************************/ -HD_PRESSURE_SENSORS_CAL_RECORD_T getHDPressureSensorsCalibrationRecord( void ) -{ - return hdCalibrationRecord.hdCalibrationGroups.pressureSensorsCalRecord; -} - -/*********************************************************************//** - * @brief - * The getHDTemperatureSensorsCalibrationRecord function returns the HD - * temperature sensors calibration record. - * @details Inputs: none - * @details Outputs: none - * @return HD temperature sensors calibration record - *************************************************************************/ -HD_TEMP_SENSORS_CAL_RECORD_T getHDTemperatureSensorsCalibrationRecord( void ) -{ - return hdCalibrationRecord.hdCalibrationGroups.tempSensorsCalRecord; -} - -#endif - -/*********************************************************************//** - * @brief * The writeLogData checks if the queue is not full and if it is not, it calls * enqueue to schedule a job for writing the log data. * @details Inputs: logRecord @@ -2301,7 +1793,7 @@ // If any of the records did not pass, they should be filled // with benign values. After that, schedule a write to sector 0 // to re-write the records with the benign values - if ( FALSE == haveCalGroupsPassed ) + if ( ( FALSE == haveRecordsPassed ) || ( FALSE == haveCalGroupsPassed ) || ( FALSE == hasSystemRecordPassed ) ) { enqueueSector0Records(); } @@ -3408,13 +2900,11 @@ // Recalculate the CRC with the default values dgServiceGroup.dgServiceRecord.crc = crc16 ( (U08*)&dgServiceGroup.dgServiceRecord, sizeof(DG_SERVICE_RECORD_T) - sizeof(U16) ); - #ifndef DISABLE_SERVICE_RECORD // Service record failure is also considered as RTC RAM failure activateAlarmNoData( ALARM_ID_DG_INVALID_SERVICE_RECORD_CRC ); // Set the to FALSE since the record is not valid status = FALSE; -#endif } return status; @@ -3584,12 +3074,12 @@ isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; DG_FANS_CAL_RECORD_T* fan = &dgCalibrationRecord.dgCalibrationGroups.fansRecord; - isHardwareRecordValid = isDGFanRecordValid( &fan->fan1 ); + for ( i = 0; i < NUM_OF_CAL_DATA_BICARB_CONCENTRATES; i++ ) + { + isHardwareRecordValid = isDGFanRecordValid( &fan->fans[ i ] ); + isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; + } - isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; - isHardwareRecordValid = isDGFanRecordValid( &fan->fan2 ); - isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; - DG_ACCEL_SENSOR_CAL_RECORD_T* accelerometer = &dgCalibrationRecord.dgCalibrationGroups.accelerometerSensorCalRecord; isHardwareRecordValid = isDGAccelerometerSensorRecordValid( accelerometer ); isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; @@ -4089,13 +3579,11 @@ // Recalculate the CRC with the default values hdServiceGroup.hdServiceRecord.crc = crc16 ( (U08*)&hdServiceGroup.hdServiceRecord, sizeof( HD_SERVICE_RECORD_T ) - sizeof( U16 ) ); -#ifndef DISABLE_SERVICE_RECORD // Service record failure is also considered as RTC RAM failure activateAlarmNoData( ALARM_ID_HD_INVALID_SERVICE_RECORD_CRC ); // Set the to FALSE since the record is not valid status = FALSE; -#endif } return status; @@ -4144,14 +3632,6 @@ isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; } - HD_FLOW_SENSORS_CAL_RECORD_T* flow = &hdCalibrationRecord.hdCalibrationGroups.flowSensorsCalRecord; - for ( i = 0; i < NUM_OF_CAL_DATA_HD_FLOW_SENSORS; i++ ) - { - record = (POLYNOMIAL_CAL_PAYLOAD_T*)&flow->hdFlowSensors[ i ]; - isHardwareRecordValid = isPolynomialRecordValid( record ); - isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; - } - HD_PRESSURE_SENSORS_CAL_RECORD_T* pressure = &hdCalibrationRecord.hdCalibrationGroups.pressureSensorsCalRecord; for ( i = 0; i < NUM_OF_CAL_DATA_HD_PRESSURE_SESNSORS; i++ ) {