Index: NVDataMgmt.c =================================================================== diff -u -ra7a02bc7f05ca6b400db99501fcd37b56510519d -re053a222c52e84f31503ed106cf64c2ca920029e --- NVDataMgmt.c (.../NVDataMgmt.c) (revision a7a02bc7f05ca6b400db99501fcd37b56510519d) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision e053a222c52e84f31503ed106cf64c2ca920029e) @@ -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. @@ -365,7 +371,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 +382,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 +415,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 +826,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 @@ -1438,6 +1113,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 ); @@ -1684,89 +1387,8 @@ } #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 +1923,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(); } @@ -4144,14 +3766,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++ ) { Index: NVDataMgmt.h =================================================================== diff -u -r7c9f9588d709e4b394b05499224bfafe5abefdf9 -re053a222c52e84f31503ed106cf64c2ca920029e --- NVDataMgmt.h (.../NVDataMgmt.h) (revision 7c9f9588d709e4b394b05499224bfafe5abefdf9) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision e053a222c52e84f31503ed106cf64c2ca920029e) @@ -129,38 +129,19 @@ BOOL setHeatersInfoRecord( U08 *addressPtr, U32 infoLength ); #endif #ifdef _HD_ -HD_PUMPS_CAL_RECORD_T getHDPumpsCalibrationRecord( void ); -HD_VALVES_CAL_RECORD_T getHDValvesCalibrationRecord( void ); -HD_OCCLUSION_SENSORS_CAL_RECORD_T getHDOcclusionSensrosCalibrationRecord( void ); // TODO is this going away? Blood stays -HD_FLOW_SENSORS_CAL_RECORD_T getHDFlowSensorsCalibrationRecord( void ); // TODO is this going away? Yes -HD_PRESSURE_SENSORS_CAL_RECORD_T getHDPressureSensorsCalibrationRecord( void ); -HD_TEMP_SENSORS_CAL_RECORD_T getHDTemperatureSensorsCalibrationRecord( void ); BOOL setTreatmentTime ( U32 hours ); U32 getTreatmentTime ( void ); #endif BOOL writeLogData( LOG_DATA_T* data ); BOOL readLogData( READ_DATA_T* buffer, U32 length ); -// From Dialin -BOOL getCalibrationRecord( void ); -BOOL setCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); - -// From Dialin -BOOL getSystemRecord( void ); -BOOL setSystemRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); - -// From Dialin -BOOL getServiceRecord( void ); -BOOL setServiceRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); - #ifdef _DG_ // From Dialin BOOL getScheduledRunsRecord( void ); BOOL setScheduledRunsRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); #endif -// TODO the below functions are written in a way that they can generally send and receive data to Dialin BOOL sendRecordToDialin( RECORD_JOBS_STATE_T job ); BOOL receiveRecordFromDialin( RECORD_JOBS_STATE_T job, U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); Index: NVDataMgmtHDRecords.h =================================================================== diff -u -r7c9f9588d709e4b394b05499224bfafe5abefdf9 -re053a222c52e84f31503ed106cf64c2ca920029e --- NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision 7c9f9588d709e4b394b05499224bfafe5abefdf9) +++ NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision e053a222c52e84f31503ed106cf64c2ca920029e) @@ -75,6 +75,10 @@ GET_CAL_TEMPERATURE_SESNORS, ///< Get temperature sensors calibration data. GET_CAL_ACCEL_SENSORS, ///< Get accelerometers calibration data. GET_CAL_HEPARIN_FORCE_SENSOR, ///< Get heparin force sensor calibration data. + GET_CAL_PUMPS, ///< Get pumps calibration data. + GET_CAL_PRESSURE_SENSORS, ///< Get pressure sensors calibration data. + GET_CAL_OCCLUSION_SESNSORS, ///< Get occlusion sensors calibration data. + GET_CAL_VALVES, ///< Get valves calibration data. GET_SYS_RECORD, ///< Get system record data. GET_SRV_RECORD, ///< Get service record data. NUM_OF_NV_HD_DATA ///< Number of non-volatile data. @@ -103,19 +107,9 @@ typedef enum hd_occlusion_sensors { CAL_DATA_BLOOD_PUMP_OCCLUSION_SENSOR = 0, ///< Blood pump occlusion sensor. - CAL_DATA_DIALYSATE_INLET_PUMP_OCCLUSION_SENSOR, ///< Dialysate inlet occlusion sensor. - CAL_DATA_DIALYSATE_OUTLET_PUMP_OCCLUSION_SENSOR, ///< Dialysate outlet occlusion sensor. NUM_OF_CAL_DATA_OCCLUSION_SENSORS, ///< Number of occlusion sensors. } CAL_DATA_HD_OCCLUSION_SENSORS_T; -/// HD flow sensors enumeration. -typedef enum hd_flow_sensors -{ - CAL_DATA_HD_BLOOD_FLOW_SENSOR = 0, ///< Blood flow sensor. - CAL_DATA_HD_DIALYSATE_FLOW_SENSOR, ///< Dialyzer flow sensor. - NUM_OF_CAL_DATA_HD_FLOW_SENSORS, ///< Number of HD flow sensors. -} CAL_DATA_HD_FLOW_SENSORS_T; - /// HD pressure sensors enumeration. typedef enum hd_pressure_sensors { @@ -127,10 +121,11 @@ /// HD temperature sensors enumeration. typedef enum hd_temperature_sensors { - CAL_DATA_HD_BOARD_TEMP_SENSOR_1 = 0, ///< Board temperature sensor 1. - CAL_DATA_HD_BOARD_TEMP_SENSOR_2, ///< Board temperature sensor 2. - CAL_DATA_HD_BOARD_TEMP_SENSOR_3, ///< Board temperature sensor 3. - CAL_DATA_HD_POWER_SUPPLY_TEMP_SENSOR, ///< Power supply temperature sensor. + CAL_DATA_HD_THERMISTOR_ONBOARD_NTC = 0, ///< Onboard NTC thermistor. + CAL_DATA_HD_THERMISTOR_POWER_SUPPLY_1, ///< Power supply 1 therimstor. + CAL_DATA_HD_TEMPSENSOR_FPGA_BOARD, ///< FPGA board temperature sensor. + CAL_DATA_HD_TEMPSENSOR_VENOUS_PRESSURE, ///< Venous pressure sensor temperature sensor. + CAL_DATA_HD_TEMPSENSOR_PBA_ADC, ///< PBA ADC Temperature sensor. NUM_OF_CAL_DATA_HD_TEMP_SENSORS, ///< Number of HD temperature sensors. } CAL_DATA_HD_TEMEPERATURE_SENSORS_T; @@ -184,12 +179,6 @@ POLYNOMIAL_CAL_PAYLOAD_T hdOcclusionSensors[ NUM_OF_CAL_DATA_OCCLUSION_SENSORS ]; ///< HD occlusion sensors calibration data. } HD_OCCLUSION_SENSORS_CAL_RECORD_T; -/// HD flow sensors calibration record -typedef struct -{ - POLYNOMIAL_CAL_PAYLOAD_T hdFlowSensors[ NUM_OF_CAL_DATA_HD_FLOW_SENSORS ]; ///< HD flow sensors calibration data. -} HD_FLOW_SENSORS_CAL_RECORD_T; - /// HD pressure sensors calibration record typedef struct { Index: RTC.c =================================================================== diff -u -r8dc8551a200e8353a563828ccc8dcb4ad9f47bfb -re053a222c52e84f31503ed106cf64c2ca920029e --- RTC.c (.../RTC.c) (revision 8dc8551a200e8353a563828ccc8dcb4ad9f47bfb) +++ RTC.c (.../RTC.c) (revision e053a222c52e84f31503ed106cf64c2ca920029e) @@ -458,11 +458,13 @@ RTC_RAM_STATUS_T writeToRAM( U32 address, U08* data, U32 length ) { RTC_RAM_STATUS_T status = RTCRAMStatus; - U16 castedAddress = (U16)( address & MASK_OFF_MSW ); + U16 maskedAddress = (U16)( address & MASK_OFF_MSW ); + U16 castedHighAddress = maskedAddress / BITS_8_FULL_SCALE; + U16 castedLowAddress = maskedAddress % BITS_8_FULL_SCALE; if ( status == RTC_RAM_STATUS_IDLE ) { - if ( castedAddress > MAX_ALLOWED_RTC_RAM_ADDRESS ) + if ( maskedAddress > MAX_ALLOWED_RTC_RAM_ADDRESS ) { status = RTC_RAM_STATUS_ILLEGAL_ADDRESS; } @@ -474,14 +476,16 @@ { U08 i; - RTCRAMStatus = status = RTC_RAM_STATUS_IN_PROGRESS; - RTCRAMState = RTC_RAM_STATE_BUSY; - hasWriteToRAMRequested = TRUE; - RAMBufferLength = length; + RTCRAMStatus = RTC_RAM_STATUS_IN_PROGRESS; + status = RTC_RAM_STATUS_IN_PROGRESS; + RTCRAMState = RTC_RAM_STATE_BUSY; + hasWriteToRAMRequested = TRUE; + RAMBufferLength = length; prepRAMBuffer [ RTC_PREP_RAM_INDEX ] = RTC_PREP_RAM_READ_WRITE; - prepRAMBuffer [ RTC_RAM_HIGH_ADDRESS_INDEX ] = 0x0000; - prepRAMBuffer [ RTC_RAM_LOW_ADDRESS_INDEX ] = castedAddress; - txBuffer [ BUFFER_INDEX_0 ] = RTC_WRITE_TO_RAM; + prepRAMBuffer [ RTC_RAM_HIGH_ADDRESS_INDEX ] = castedHighAddress; + prepRAMBuffer [ RTC_RAM_LOW_ADDRESS_INDEX ] = castedLowAddress; + txBuffer [ BUFFER_INDEX_0 ] = RTC_WRITE_TO_RAM; + for ( i = 0; i < RAMBufferLength; i++ ) { txBuffer [ i + BUFFER_INDEX_1 ] = data [ i ]; @@ -509,11 +513,13 @@ RTC_RAM_STATUS_T readFromRAM( U32 address, U32 length ) { RTC_RAM_STATUS_T status = RTCRAMStatus; - U16 castedAddress = (U16)( address & MASK_OFF_MSW ); + U16 maskedAddress = (U16)( address & MASK_OFF_MSW ); + U16 castedHighAddress = maskedAddress / BITS_8_FULL_SCALE; + U16 castedLowAddress = maskedAddress % BITS_8_FULL_SCALE; if ( status == RTC_RAM_STATUS_IDLE ) { - if ( castedAddress > MAX_ALLOWED_RTC_RAM_ADDRESS ) + if ( maskedAddress > MAX_ALLOWED_RTC_RAM_ADDRESS ) { status = RTC_RAM_STATUS_ILLEGAL_ADDRESS; } @@ -525,14 +531,16 @@ { U08 i; - status = RTCRAMStatus = RTC_RAM_STATUS_IN_PROGRESS; - RTCRAMState = RTC_RAM_STATE_BUSY; - hasReadFromRAMRequested = TRUE; - RAMBufferLength = length; + status = RTC_RAM_STATUS_IN_PROGRESS; + RTCRAMStatus = RTC_RAM_STATUS_IN_PROGRESS; + RTCRAMState = RTC_RAM_STATE_BUSY; + hasReadFromRAMRequested = TRUE; + RAMBufferLength = length; prepRAMBuffer[ RTC_PREP_RAM_INDEX ] = RTC_PREP_RAM_READ_WRITE; - prepRAMBuffer[ RTC_RAM_HIGH_ADDRESS_INDEX ] = 0x0000; - prepRAMBuffer[ RTC_RAM_LOW_ADDRESS_INDEX ] = castedAddress; - txBuffer[ BUFFER_INDEX_0 ] = RTC_READ_FROM_RAM; + prepRAMBuffer[ RTC_RAM_HIGH_ADDRESS_INDEX ] = castedHighAddress; + prepRAMBuffer[ RTC_RAM_LOW_ADDRESS_INDEX ] = castedLowAddress; + txBuffer[ BUFFER_INDEX_0 ] = RTC_READ_FROM_RAM; + for ( i = 0; i < RAMBufferLength; i++ ) { txBuffer[ i + BUFFER_INDEX_1 ] = 0x0000;