Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rb925bf251dfd5584a0839cee93ccf8566a0ec2fb -r0599bd5494eb64416999de0487a9882c557b6044 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision b925bf251dfd5584a0839cee93ccf8566a0ec2fb) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 0599bd5494eb64416999de0487a9882c557b6044) @@ -268,19 +268,19 @@ { MSG_ID_DD_BICART_DRAIN_REQUEST_OVERRIDE_REQUEST, &testDryBiCartDrainRequestOverride }, { MSG_ID_DD_BICART_CARTRIDGE_SELECT_OVERRIDE_REQUEST, &testDryBiCartTypeOverride }, { MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST, &testDDGetNVRecord }, - { MSG_ID_UI_DD_NVM_SET_SYSTEM_RECORD, &testDDSetNVSystemRecord }, - { MSG_ID_UI_DD_NVM_SET_SERVICE_RECORD, &testDDSetNVServiceRecord }, - { MSG_ID_UI_DD_NVM_SET_INSTITUTIONAL_RECORD, &testDDSetNVInstitutionalRecord }, - { MSG_ID_UI_DD_NVM_SET_USAGE_INFO_RECORD, &testDDSetNVUsageInfoRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_PRESSURE_SENSOR, &testDDSetPressureSensorCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_TEMP_SENSOR, &testDDSetTempSensorCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_CONC_PUMP, &testDDSetConcPumpCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_D12_PUMP, &testDDSetD12PumpCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_D48_PUMP, &testDDSetD48CalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_ACID_CONCENTRATE, &testDDSetAcidConcCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_BICARB_CONCENTRATE, &testDDSetBicarbConcCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_ACCEL_SENSOR, &testDDSetAccelSensorCalRecord }, - { MSG_ID_UI_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR, &testDDSetBloodLeakSensorCalRecord }, + { MSG_ID_UI_DD_NVM_SET_SYSTEM_RECORD_REQUEST, &testDDSetNVSystemRecord }, + { MSG_ID_UI_DD_NVM_SET_SERVICE_RECORD_REQUEST, &testDDSetNVServiceRecord }, + { MSG_ID_UI_DD_NVM_SET_INSTITUTIONAL_RECORD_REQUEST, &testDDSetNVInstitutionalRecord }, + { MSG_ID_UI_DD_NVM_SET_USAGE_INFO_RECORD_REQUEST, &testDDSetNVUsageInfoRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_PRESSURE_SENSOR_REQUEST, &testDDSetPressureSensorCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_TEMP_SENSOR_REQUEST, &testDDSetTempSensorCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_CONC_PUMP_REQUEST, &testDDSetConcPumpCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_D12_PUMP_REQUEST, &testDDSetD12PumpCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_D48_PUMP_REQUEST, &testDDSetD48CalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_ACID_CONCENTRATE_REQUEST, &testDDSetAcidConcCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_BICARB_CONCENTRATE_REQUEST, &testDDSetBicarbConcCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_ACCEL_SENSOR_REQUEST, &testDDSetAccelSensorCalRecord }, + { MSG_ID_UI_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR_REQUEST, &testDDSetBloodLeakSensorCalRecord }, { MSG_ID_DD_NVM_RECORD_CRC_OVERRIDE_REQUEST, &testDDSetNVUsageInfoRecord }, { MSG_ID_FP_RO_REJECTION_RATIO_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testRORejectionRatioDataPublishIntervalOverride }, { MSG_ID_FP_RO_FILTERED_REJECTION_RATIO_OVERRIDE_REQUEST, &testRORejectionRatioFilteredOverride }, Index: firmware/App/Services/NVMessagingDD.c =================================================================== diff -u -rbeb95e3e8f85740707704d7089db8b3ec8574bbd -r0599bd5494eb64416999de0487a9882c557b6044 --- firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision beb95e3e8f85740707704d7089db8b3ec8574bbd) +++ firmware/App/Services/NVMessagingDD.c (.../NVMessagingDD.c) (revision 0599bd5494eb64416999de0487a9882c557b6044) @@ -13,6 +13,7 @@ ***************************************************************************/ #include // For ceilf function +#include "Messaging.h" #include "NVJobQ.h" #include "NVMessagingDD.h" #include "NVRecordsDD.h" @@ -105,11 +106,8 @@ static NVM_RECORD_TYPE_T currentRxRecordType; ///< Record type which is being processed currently for receiving static U32 recordSendDataIntervalCounter; ///< Record data send to CAN bust interval counter. static U32 sendRetryCount; ///< Counter for number of retries to send a record -static U32 previousRecordMessageNum; ///< Record previous message number. -static U32 recordUpdateAddress; ///< DD record update address for all the write operations. static U32 calRecordReceiveStartTime; ///< Time stamp the calibration record was received. static U32 institRecordReceiveStartTime; ///< Time stamp the institutional record was received. -static U32 recordReceiveStartTime; ///< Time stamp the calibration/service was received. static DD_INSTIT_REC_TYPE sendInstitRec; ///< Current Institutional Record to be sent static DD_CAL_REC_TYPE sendCalRec; ///< Current Calibration Record to be sent static U08 sendSensorIdx; ///< Current Index of sensor calibration data to be sent @@ -139,10 +137,7 @@ static BOOL sendBloodLeakSensorCalRecord( void ); static BOOL receiveCalRecord( MESSAGE_T *message, DD_CAL_REC_TYPE calRecordType, U16 recordSize ); - static BOOL verifyAndSaveReceivedRecord( NVM_RECORD_TYPE_T job, U32 currentMessage, - U32 totalMessages, U32 length, U08 *addressPtr ); -static NVM_RECORD_TYPE_T getNVMRecordJobState( MSG_ID_T msgID ); -static MSG_ID_T getNVMRecordResponseMsgId (NVM_RECORD_TYPE_T job ); +static MSG_ID_T getNVMCalRecordResponseMsgId(DD_CAL_REC_TYPE calRecordType ); static void monitorNewCalSignal( void ); /*********************************************************************//** @@ -172,8 +167,6 @@ isPublishRecordRequested[ NVM_INSTITUTIONAL_RECORD ] = FALSE; isPublishRecordRequested[ NVM_USAGE_INFO_RECORD ] = FALSE; recordSendDataIntervalCounter = 0; - previousRecordMessageNum = 0; - recordReceiveStartTime = 0; sendInstitRec = DD_INSTIT_MIN_DIALYSATE_FLOW_MLPM; sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; } @@ -367,6 +360,15 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDSystemRecord function sends the DD system record. + * It retries transmission on failure and returns to the idle state + * after a successful send or when retries are exhausted. + * @details \b Inputs: recordToPublish, sendRetryCount + * @details \b Outputs: recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDSystemRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; @@ -375,7 +377,7 @@ DD_SYSTEM_RECORD_T systemRecord; // Get the record - if( TRUE == getNVMRecord( GET_SYSTEM_RECORD, + if ( TRUE == getNVMRecord( GET_SYSTEM_RECORD, (U08*)&systemRecord, sizeof( DD_SYSTEM_RECORD_T ) , 0, @@ -384,7 +386,7 @@ // Send the record sysStatus = sendMessage( MSG_ID_DD_NVM_SYSTEM_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&systemRecord, + (U08*)&systemRecord, sizeof( DD_SYSTEM_RECORD_T ) ); } @@ -406,7 +408,7 @@ } // Utilized all the retries. Something is wrong. - if( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; @@ -421,23 +423,32 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDServiceRecord function sends the DD service record. + * It retries transmission on failure and returns to the idle state + * after a successful send or when retries are exhausted. + * @details \b Inputs: recordToPublish, sendRetryCount + * @details \b Outputs: recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDServiceRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL serStatus = FALSE; DD_SERVICE_RECORD_T serviceRecord; // Get the record - if( TRUE == getNVMRecord( GET_SERVICE_RECORD, + if ( TRUE == getNVMRecord( GET_SERVICE_RECORD, (U08*)&serviceRecord, sizeof( DD_SERVICE_RECORD_T ) , 0, - ALARM_ID_DD_NVM_INVALID_SYSTEM_RECORD_CRC ) ) + ALARM_ID_DD_NVM_INVALID_SERVICE_RECORD_CRC ) ) { // Send the record serStatus = sendMessage( MSG_ID_DD_NVM_SERVICE_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&serviceRecord, + (U08*)&serviceRecord, sizeof( DD_SERVICE_RECORD_T ) ); } @@ -459,7 +470,7 @@ } // Utilized all the retries. Something is wrong. - if( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; @@ -474,8 +485,15 @@ return state; } - - +/*********************************************************************//** + * @brief + * The handleSendDDInstitutionalRecord function sends institutional + * record data one item at a time. It builds the payload based on the + * data type and manages retries and record sequencing. + * @details \b Inputs: sendInstitRec, recordToPublish, sendRetryCount + * @details \b Outputs: sendInstitRec, recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDInstitutionalRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; @@ -489,17 +507,17 @@ dataType = getInstitRecDataType( (DD_INSTIT_REC_TYPE)sendInstitRec ); // Create the payload based on the data type - if( CRITICAL_DATA_TYPE_U32 == dataType ) + if ( CRITICAL_DATA_TYPE_U32 == dataType ) { - if ( TRUE == ( getNVMInstitRecord((DD_INSTIT_REC_TYPE)sendInstitRec , (U08*)&valueU32 ) ) ) + if ( TRUE == ( getNVMInstitRecord( (DD_INSTIT_REC_TYPE)sendInstitRec, (U08*)&valueU32 ) ) ) { memcpy( &payload.data, &valueU32, sizeof( U32 ) ); } } - if( CRITICAL_DATA_TYPE_F32 == dataType ) + if ( CRITICAL_DATA_TYPE_F32 == dataType ) { - if ( TRUE == ( getNVMInstitRecord((DD_INSTIT_REC_TYPE)sendInstitRec , (U08*)&valueF32 ) ) ) + if ( TRUE == ( getNVMInstitRecord( (DD_INSTIT_REC_TYPE)sendInstitRec, (U08*)&valueF32 ) ) ) { memcpy( &payload.data, &valueF32, sizeof( F32 ) ); } @@ -514,7 +532,7 @@ sizeof( DD_NVM_SEND_RECORD_PAYLOAD_T ) ); // Check if record was sent successfully - if ( TRUE == sendStatus) + if ( TRUE == sendStatus ) { // Reset the retry count sendRetryCount = 0; @@ -549,15 +567,24 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDUsageInfoRecord function sends the DD usage + * information record. It retries transmission on failure and returns + * to the idle state after a successful send or when retries are + * exhausted. + * @details \b Inputs: recordToPublish, sendRetryCount + * @details \b Outputs: recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDUsageInfoRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL usageStatus = FALSE; DD_USAGE_INFO_RECORD_T usageInfoRecord; - // Get the record - if( TRUE == getNVMRecord( GET_USAGE_RECORD, + if ( TRUE == getNVMRecord( GET_USAGE_RECORD, (U08*)&usageInfoRecord, sizeof( DD_USAGE_INFO_RECORD_T ), 0, @@ -566,7 +593,7 @@ // Send the record usageStatus = sendMessage( MSG_ID_DD_NVM_USAGE_INFO_RECORD_RESPONSE, COMM_BUFFER_OUT_CAN_DD_BROADCAST, - (U08 *)&usageInfoRecord, + (U08*)&usageInfoRecord, sizeof( DD_USAGE_INFO_RECORD_T ) ); } @@ -588,7 +615,7 @@ } // Utilized all the retries. Something is wrong. - if( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) + if ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) { // Reset the retry count sendRetryCount = 0; @@ -603,12 +630,24 @@ return state; } +/*********************************************************************//** + * @brief + * The handleSendDDCalibrationRecord function sends DD calibration + * records. It manages calibration record sequencing, sensor indexing, + * retries, and transitions back to the idle state when all records + * have been published or retries are exhausted. + * @details \b Inputs: sendCalRec, sendSensorIdx, + * maxSensorIdx, recordToPublish, sendRetryCount + * @details \b Outputs: sendCalRec, sendSensorIdx, + * recordToPublish, sendRetryCount + * @return state next state of the state machine + *************************************************************************/ static SEND_RECORD_STATE_T handleSendDDCalibrationRecord( void ) { SEND_RECORD_STATE_T state = NVM_SEND_RECORD_STATE_SEND; BOOL sendStatus = FALSE; - switch( sendCalRec ) + switch ( sendCalRec ) { case DD_CAL_RECORD_PRESSURE_SENSOR: sendStatus = sendPressureSensorCalRecord(); @@ -651,54 +690,60 @@ } // Check if record was sent successfully - if ( TRUE == sendStatus) + if ( TRUE == sendStatus) + { + sendSensorIdx++; + + // Check if we sent the last record of calibration component + if ( sendSensorIdx >= maxSensorIdx ) { - // Check if we sent the last record of calibration component - if ( sendSensorIdx >= maxSensorIdx ) - { - // Reset Sensor Index for the next calibration data - sendSensorIdx = 0; + // Reset Sensor Index for the next calibration data + sendSensorIdx = 0; - // Reset the retry count for the next calibration data - sendRetryCount = 0; + // Reset the retry count for the next calibration data + sendRetryCount = 0; - // Move on to publish the next calibration record - sendCalRec = (DD_CAL_REC_TYPE)( (U32)sendCalRec + 1 ); - } - else - { - sendSensorIdx++; - } + // Move on to publish the next calibration record + sendCalRec = (DD_CAL_REC_TYPE)( (U32)sendCalRec + 1 ); } - else - { - sendRetryCount ++; - } + } + else + { + sendRetryCount ++; + } - // If all the allowed retries has been utilized or - // If all the calibration records have been published - if ( ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) || - ( sendCalRec >= NUM_OF_CAL_RECORD_TYPE ) ) - { - // Reset Sensor Index for the next request - sendSensorIdx = 0; + // If all the allowed retries has been utilized or + // If all the calibration records have been published + if ( ( sendRetryCount > MAX_NUM_OF_SEND_RETRIES ) || + ( sendCalRec >= NUM_OF_CAL_RECORD_TYPE ) ) + { + // Reset Sensor Index for the next request + sendSensorIdx = 0; - // Reset Index tracker for next request. - sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; + // Reset Index tracker for next request. + sendCalRec = DD_CAL_RECORD_PRESSURE_SENSOR; - // Clear the publishing flags - recordToPublish = NUM_OF_NVM_RECORD_TYPES; + // Clear the publishing flags + recordToPublish = NUM_OF_NVM_RECORD_TYPES; - // Move to Send Idle State - state = NVM_SEND_RECORD_STATE_IDLE; + // Move to Send Idle State + state = NVM_SEND_RECORD_STATE_IDLE; - // Reset the retry count - sendRetryCount = 0; - } + // Reset the retry count + sendRetryCount = 0; + } return state; } +/*********************************************************************//** + * @brief + * The sendPressureSensorCalRecord function sends the calibration + * record of the selected pressure sensor. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendPressureSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -716,6 +761,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendTempSensorCalRecord function sends the calibration record + * of the selected temperature sensor. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendTempSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -733,6 +786,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendConcPumpCalRecord function sends the calibration record + * of the selected concentrate pump. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendConcPumpCalRecord( void ) { BOOL sendStatus = FALSE; @@ -750,6 +811,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendD12PumpCalRecord function sends the calibration record of + * the D12 dialysate pump. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendD12PumpCalRecord( void ) { BOOL sendStatus = FALSE; @@ -765,6 +834,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendD48PumpCalRecord function sends the calibration record of + * the D48 dialysate pump. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendD48PumpCalRecord( void ) { BOOL sendStatus = FALSE; @@ -780,6 +857,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendAcidConcCalRecord function sends the calibration record of + * the selected acid concentrate. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendAcidConcCalRecord( void ) { BOOL sendStatus = FALSE; @@ -797,6 +882,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendAcidConcCalRecord function sends the calibration record of + * the selected acid concentrate. + * @details \b Inputs: sendSensorIdx + * @details \b Outputs: maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendBicarbConcCalRecord( void ) { BOOL sendStatus = FALSE; @@ -814,6 +907,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendAccelSensorCalRecord function sends the calibration record + * of the accelerometer sensor. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendAccelSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -829,6 +930,14 @@ return sendStatus; } +/*********************************************************************//** + * @brief + * The sendBloodLeakSensorCalRecord function sends the calibration + * record of the blood leak sensor. + * @details \b Inputs: none + * @details \b Outputs: sendSensorIdx, maxSensorIdx + * @return TRUE if the message was successfully sent otherwise FALSE + *************************************************************************/ static BOOL sendBloodLeakSensorCalRecord( void ) { BOOL sendStatus = FALSE; @@ -844,54 +953,153 @@ return sendStatus; } -static BOOL receiveCalRecord( MESSAGE_T *message, DD_CAL_REC_TYPE calRecordType, U16 recordSize ) +/*********************************************************************//** + * @brief + * The receiveCalRecord function receives a calibration record, + * validates its CRC, updates the calibration data, and sends a + * response indicating whether the request was accepted. + * @details \b Inputs: none + * @details \b Outputs: nvmExecreceiveRecordState, + * calRecordReceiveStartTime, currentRxRecordType + * @param message Pointer to the received message + * @param calRecordType Calibration record type being received + * @param recordSize Size of the calibration record in bytes + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ +static BOOL receiveCalRecord( MESSAGE_T* message, DD_CAL_REC_TYPE calRecordType, U16 recordSize ) { - BOOL status = FALSE; -// U08 idx = 0; -// MSG_ID_T msgID = (MSG_ID_T)message->hdr.msgID; - U08* payloadPtr = message->payload; + BOOL status = FALSE; + U08* payloadPtr = message->payload; U08 expectedPayloadLen = ( sizeof(U08) + recordSize ); -// U08 tempBuffer[ recordSize ]; + MSG_ID_T msgID = getNVMCalRecordResponseMsgId( calRecordType ); + UI_RESPONSE_PAYLOAD_T response; DD_NVM_SEND_RECORD_PAYLOAD_T recvdPayload; - if ( message->hdr.payloadLen == expectedPayloadLen ) + if ( DD_MODE_SERV == getCurrentOperationMode() ) { - memcpy( &recvdPayload.idx, payloadPtr, sizeof(U32)); - payloadPtr += sizeof(U08); + if ( message->hdr.payloadLen == expectedPayloadLen ) + { + memcpy( &recvdPayload.idx, payloadPtr, sizeof(U32)); + payloadPtr += sizeof(U08); - memcpy( &recvdPayload.data, payloadPtr, recordSize ); + memcpy( &recvdPayload.data, payloadPtr, recordSize ); - // CRC assumed at end of record - U16 *recordCRC = (U16 *)( recvdPayload.data + ( recordSize - sizeof(U16) ) ); - U16 calcCRC = crc16( recvdPayload.data, recordSize - sizeof(U16) ); + // CRC assumed at end of record + U16 *recordCRC = (U16*)( recvdPayload.data + ( recordSize - sizeof(U16) ) ); + U16 calcCRC = crc16( recvdPayload.data, recordSize - sizeof(U16) ); - if (calcCRC == *recordCRC) - { - nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; - status = setNVMCalRecord( calRecordType, (U08*)&recvdPayload.data, recvdPayload.idx ); + if ( calcCRC == *recordCRC ) + { + nvmExecreceiveRecordState = NVM_RECEIVE_RECORD_STATE_RECEIVE; + status = setNVMCalRecord( calRecordType, (U08*)&recvdPayload.data, recvdPayload.idx ); - // It is possible that we receive multiple packets of cal record - // So we write it to flash when we finish receiving all packets or - // a timeout occurs. - calRecordReceiveStartTime = getMSTimerCount(); - currentRxRecordType = NVM_CALIBRATION_RECORD; + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + + // It is possible that we receive multiple packets of cal record + // So we write it to flash when we finish receiving all packets or + // a timeout occurs. + calRecordReceiveStartTime = getMSTimerCount(); + currentRxRecordType = NVM_CALIBRATION_RECORD; + } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + response.fwValue = recvdPayload.idx; + sendMessage( msgID, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return status; } /*********************************************************************//** * @brief + * The getNVMCalRecordResponseMsgId function gets the response message + * ID corresponding to the specified calibration record type. + * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT if invalid calibration + * record type is provided + * @details \b Inputs: none + * @details \b Outputs: none + * @param calRecordType Calibration record type + * @return msgId corresponding response message ID + *************************************************************************/ +static MSG_ID_T getNVMCalRecordResponseMsgId( DD_CAL_REC_TYPE calRecordType ) +{ + MSG_ID_T msgId = MSG_ID_UNUSED; + + switch ( calRecordType ) + { + case DD_CAL_RECORD_PRESSURE_SENSOR: + msgId = MSG_ID_DD_NVM_SET_CAL_PRESSURE_SENSOR_RESPONSE; + break; + + case DD_CAL_RECORD_TEMPERATURE_SENSOR: + msgId = MSG_ID_DD_NVM_SET_CAL_TEMP_SENSOR_RESPONSE; + break; + + case DD_CAL_RECORD_CONCENTRATE_PUMP: + msgId = MSG_ID_DD_NVM_SET_CAL_CONC_PUMP_RESPONSE; + break; + + case DD_CAL_RECORD_D12_PUMP: + msgId = MSG_ID_DD_NVM_SET_CAL_D12_PUMP_RESPONSE; + break; + + case DD_CAL_RECORD_D48_PUMP: + msgId = MSG_ID_DD_NVM_SET_CAL_D48_PUMP_RESPONSE; + break; + + case DD_CAL_RECORD_ACID_CONCENTRATE: + msgId = MSG_ID_DD_NVM_SET_CAL_ACID_CONCENTRATE_RESPONSE; + break; + + case DD_CAL_RECORD_BICARB_CONCENTRATE: + msgId = MSG_ID_DD_NVM_SET_CAL_BICARB_CONCENTRATE_RESPONSE; + break; + + case DD_CAL_RECORD_ACCELEROMETER_SENSOR: + msgId = MSG_ID_DD_NVM_SET_CAL_ACCEL_SENSOR_RESPONSE; + break; + + case DD_CAL_RECORD_BLLOD_LEAK_SENSOR: + msgId = MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR_RESPONSE; + break; + + default: + // Software fault + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, ( U32 )calRecordType ); + break; + } + + return msgId; +} + +/*********************************************************************//** + * @brief * The monitorNewCalSignal function monitors the new calibration signal * and clears it when the timeout has elapsed. * @details \b Inputs: isNewCalRecordAvailable, * newRecordStartTimer * @details \b Outputs: isNewCalRecordAvailable * @return none *************************************************************************/ - static void monitorNewCalSignal( void ) { // Check if new calibration record is available and @@ -923,8 +1131,9 @@ *************************************************************************/ BOOL testDDGetNVRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; NVM_RECORD_TYPE_T job; + UI_RESPONSE_PAYLOAD_T response; // verify payload length if ( 1 == message->hdr.payloadLen ) @@ -938,10 +1147,25 @@ isPublishRecordRequested[ job ] = TRUE; recordToPublish = job; result = TRUE; + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } - + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_JOB_QUEUE_BUSY; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + sendMessage( MSG_ID_DD_NVM_GET_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -957,20 +1181,20 @@ *************************************************************************/ BOOL testDDSetNVSystemRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_SYSTEM_RECORD_T ) ]; + UI_RESPONSE_PAYLOAD_T response; - // System record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) { if (message->hdr.payloadLen == sizeof( DD_SYSTEM_RECORD_T )) { memcpy( tempBuffer, message->payload, sizeof( DD_SYSTEM_RECORD_T ) ); - // CRC assumed at end of record + // CRC received at end of record U16 *recordCRC = (U16 *)( tempBuffer + ( sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ) ); - U16 calcCRC = crc16( tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ); + U16 calcCRC = crc16( tempBuffer, sizeof( DD_SYSTEM_RECORD_T ) - sizeof(U16) ); if ( calcCRC == *recordCRC ) { @@ -980,10 +1204,32 @@ setNVMRecord( NVM_SYSTEM_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_SYSTEM_RECORD ); sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + sendMessage( MSG_ID_DD_NVM_SET_SYSTEM_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -999,8 +1245,9 @@ *************************************************************************/ BOOL testDDSetNVServiceRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_SERVICE_RECORD_T ) ]; + UI_RESPONSE_PAYLOAD_T response; // Service record can be updated only in service mode if ( DD_MODE_SERV == getCurrentOperationMode() ) @@ -1021,11 +1268,32 @@ setNVMRecord( NVM_SERVICE_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_SERVICE_RECORD ); sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } - + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_OPERATION_MODE; + } + sendMessage( MSG_ID_DD_NVM_SET_SERVICE_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -1040,8 +1308,9 @@ *************************************************************************/ BOOL testDDSetNVUsageInfoRecord( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = FALSE; U08 tempBuffer[ sizeof( DD_USAGE_INFO_RECORD_T ) ]; + UI_RESPONSE_PAYLOAD_T response; if (message->hdr.payloadLen == ( sizeof( DD_USAGE_INFO_RECORD_T ) )) { @@ -1059,9 +1328,26 @@ setNVMRecord( NVM_USAGE_INFO_RECORD, tempBuffer ); result = enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); + + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_NVM_INVALID_CRC; + } } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + sendMessage( MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } @@ -1076,10 +1362,11 @@ *************************************************************************/ BOOL testDDSetNVInstitutionalRecord( MESSAGE_T *message ) { - BOOL result = FALSE; - U08 idx = 0; - U08* payloadPtr = message->payload; + BOOL result = FALSE; + U08 idx = 0; + U08* payloadPtr = message->payload; U08 expectedPayloadLen = sizeof(U08); + UI_RESPONSE_PAYLOAD_T response; if ( message->hdr.payloadLen >= expectedPayloadLen ) { @@ -1090,124 +1377,210 @@ result = setNVMInstitRecord( (DD_INSTIT_REC_TYPE)idx, payloadPtr ); + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + // It is possible that we receive multiple packets of instit record // So we write it to flash when we finish receiving all packets or // a timeout occurs. institRecordReceiveStartTime = getMSTimerCount(); currentRxRecordType = NVM_INSTITUTIONAL_RECORD; } + else + { + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + response.fwValue = idx; + sendMessage( MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD_RESPONSE, + COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + return result; } +/*********************************************************************//** + * @brief + * The testDDSetPressureSensorCalRecord function processes a request + * to update a pressure sensor calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetPressureSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_PRESSURE_SENSOR , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_PRESSURE_SENSOR, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + return result; } +/*********************************************************************//** + * @brief + * The testDDSetTempSensorCalRecord function processes a request to + * update a temperature sensor calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetTempSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_TEMPERATURE_SENSOR , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_TEMPERATURE_SENSOR, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetConcPumpCalRecord function processes a request to + * update a concentrate pump calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetConcPumpCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_CONCENTRATE_PUMP , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_CONCENTRATE_PUMP, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetD12PumpCalRecord function processes a request to + * update the D12 dialysate pump calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetD12PumpCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_D12_PUMP , sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_D12_PUMP, + sizeof( DD_D12_DIALYSATE_PUMP_RECORD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetD48PumpCalRecord function processes a request to + * update the D48 dialysate pump calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetD48CalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_D48_PUMP , sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_D48_PUMP, + sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetAcidConcCalRecord function processes a request to + * update an acid concentrate calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetAcidConcCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_ACID_CONCENTRATE , sizeof( DD_ACID_CONCENTRATE_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_ACID_CONCENTRATE, + sizeof( DD_ACID_CONCENTRATE_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetBicarbConcCalRecord function processes a request to + * update a bicarb concentrate calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ + BOOL testDDSetBicarbConcCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_BICARB_CONCENTRATE , sizeof( DD_BICARB_CONCENTRATE_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_BICARB_CONCENTRATE, + sizeof( DD_BICARB_CONCENTRATE_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetAccelSensorCalRecord function processes a request to + * update the accelerometer sensor calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetAccelSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_ACCELEROMETER_SENSOR , sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_ACCELEROMETER_SENSOR, + sizeof( DD_ACCEL_SENSOR_CAL_RECORD_T ) ); return result; } +/*********************************************************************//** + * @brief + * The testDDSetBloodLeakSensorCalRecord function processes a request + * to update the blood leak sensor calibration record. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message Pointer to the received message + * @return TRUE if the calibration record was accepted and processed + * successfully otherwise FALSE + *************************************************************************/ BOOL testDDSetBloodLeakSensorCalRecord( MESSAGE_T *message ) { BOOL result = FALSE; - if ( DD_MODE_SERV == getCurrentOperationMode() ) - { - result = receiveCalRecord( message, DD_CAL_RECORD_BLLOD_LEAK_SENSOR , sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); - } + result = receiveCalRecord( message, DD_CAL_RECORD_BLLOD_LEAK_SENSOR, + sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) ); return result; } - /*********************************************************************//** * @brief * The testSetNVRecordCRCOverride function overrides the CRC value of @@ -1225,6 +1598,4 @@ return result; } - - /**@}*/ Index: firmware/App/Services/NVMessagingDD.h =================================================================== diff -u -rb925bf251dfd5584a0839cee93ccf8566a0ec2fb -r0599bd5494eb64416999de0487a9882c557b6044 --- firmware/App/Services/NVMessagingDD.h (.../NVMessagingDD.h) (revision b925bf251dfd5584a0839cee93ccf8566a0ec2fb) +++ firmware/App/Services/NVMessagingDD.h (.../NVMessagingDD.h) (revision 0599bd5494eb64416999de0487a9882c557b6044) @@ -42,6 +42,8 @@ BOOL testDDGetNVRecord( MESSAGE_T *message ); BOOL testDDSetNVSystemRecord( MESSAGE_T *message ); BOOL testDDSetNVServiceRecord( MESSAGE_T *message ); +BOOL testDDSetNVUsageInfoRecord( MESSAGE_T *message ); +BOOL testDDSetNVInstitutionalRecord( MESSAGE_T *message ); BOOL testDDSetPressureSensorCalRecord( MESSAGE_T *message ); BOOL testDDSetTempSensorCalRecord( MESSAGE_T *message ); BOOL testDDSetConcPumpCalRecord( MESSAGE_T *message ); @@ -51,9 +53,10 @@ BOOL testDDSetBicarbConcCalRecord( MESSAGE_T *message ); BOOL testDDSetAccelSensorCalRecord( MESSAGE_T *message ); BOOL testDDSetBloodLeakSensorCalRecord( MESSAGE_T *message ); -BOOL testDDSetNVInstitutionalRecord( MESSAGE_T *message ); -BOOL testDDSetNVUsageInfoRecord( MESSAGE_T *message ); +BOOL testSetNVRecordCRCOverride( U32 job, U16 crc ); + + /**@}*/ #endif /* _NV_MESSAGING_H_ */ Index: firmware/App/Services/NVRecordsDD.c =================================================================== diff -u -rbeb95e3e8f85740707704d7089db8b3ec8574bbd -r0599bd5494eb64416999de0487a9882c557b6044 --- firmware/App/Services/NVRecordsDD.c (.../NVRecordsDD.c) (revision beb95e3e8f85740707704d7089db8b3ec8574bbd) +++ firmware/App/Services/NVRecordsDD.c (.../NVRecordsDD.c) (revision 0599bd5494eb64416999de0487a9882c557b6044) @@ -237,7 +237,6 @@ static void updateRecordPadding( NVM_RECORD_TYPE_T recType ); - /*********************************************************************//** * @brief * The initNVRecordsDD function initializes the NV records data management @@ -254,19 +253,6 @@ nvmSelfTestState = NVM_SELF_TEST_STATE_READ_RECORDS; nvmSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; usageWriteTries = 0; - -// initDDSystemRecord(); -// initDDServiceRecord(); -// initDDInstitutionalRecord(); -// initDDCalibrationRecord(); -// initDDUsageRecord(); -// -// int i; -// for( i = 0; i < NUM_OF_NVM_RECORD_TYPES; i++ ) -// { -// updateRecordPadding( (NVM_RECORD_TYPE_T)i ); -// updateRecordCRC( ( NVM_RECORD_TYPE_T )i); -// } } /*********************************************************************//** @@ -363,25 +349,21 @@ BOOL hasSystemRecordPassed = TRUE; BOOL hasServiceRecordPassed = TRUE; BOOL haveCalGroupsPassed = TRUE; + BOOL hasInstitutionalRecordPassed = TRUE; BOOL hasUsageRecordPassed = TRUE; updateRecordReadStatus( NVM_RECORDS_CRC_CHECKED ); - // Check all the calibration groups - haveCalGroupsPassed = isDDCalibrationRecordValid(); - hasServiceRecordPassed = isDDServiceRecordValid(); - hasUsageRecordPassed = isDDUsageRecordValid(); - // 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(); + hasSystemRecordPassed = isDDSystemRecordValid(); if ( FALSE == hasSystemRecordPassed ) { enqueueEraseAndWriteSector ( NVM_SYSTEM_RECORD ); - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_SYSTEM_RECORD ].nvEvent, 0, 0 ); + sendNVEvent( NVM_SYSTEM_RECORD, 0, 0 ); } // Validate service and calibration records @@ -390,22 +372,34 @@ if ( ( FALSE == hasServiceRecordPassed ) || ( FALSE == haveCalGroupsPassed ) ) { enqueueEraseAndWriteSector ( NVM_SERVICE_RECORD ); - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_SERVICE_RECORD ].nvEvent, 0, 0 ); - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_CALIBRATION_RECORD ].nvEvent, 0, 0 ); + sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); + sendNVEvent( NVM_CALIBRATION_RECORD, 0, 0 ); + + startNewCalRecordAvailableTimer(); + setNewCalibrationRecordAvailable( TRUE ); } + + // Validate institutional record + hasInstitutionalRecordPassed = isDDInstitutionalRecordValid(); + if ( FALSE == hasInstitutionalRecordPassed ) + { + enqueueEraseAndWriteSector ( NVM_INSTITUTIONAL_RECORD ); + sendNVEvent( NVM_INSTITUTIONAL_RECORD, 0, 0 ); + } + // Validate usage info record + hasUsageRecordPassed = isDDUsageRecordValid(); if ( FALSE == hasUsageRecordPassed ) { enqueueEraseAndWriteSector ( NVM_USAGE_INFO_RECORD ); - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_USAGE_INFO_RECORD ].nvEvent, 0, 0 ); + sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); } // Check if the records' entire CRCs as well as the individual CRCs passed if ( ( TRUE == hasSystemRecordPassed ) && ( TRUE == hasServiceRecordPassed ) && - ( TRUE == haveCalGroupsPassed ) && ( TRUE == hasUsageRecordPassed ) ) + ( TRUE == haveCalGroupsPassed ) && ( TRUE == hasInstitutionalRecordPassed ) && + ( TRUE == hasUsageRecordPassed ) ) { - startNewCalRecordAvailableTimer(); - setNewCalibrationRecordAvailable( TRUE ); nvmSelfTestResult = SELF_TEST_STATUS_PASSED; } else @@ -877,7 +871,15 @@ return status; } - +/*********************************************************************//** + * @brief + * The initDDSystemRecord function initializes the DD system record + * with default values. It resets configuration fields and fills + * string fields with default characters. + * @details \b Inputs: none + * @details \b Outputs: ddSystemGroup.ddSystemRecord + * @return none + *************************************************************************/ static void initDDSystemRecord( void ) { ddSystemGroup.ddSystemRecord.isROFeatured = FALSE; @@ -888,6 +890,15 @@ ddSystemGroup.ddSystemRecord.mfgDate = 0; } +/*********************************************************************//** + * @brief + * The initDDServiceRecord function initializes the DD service record + * with default values. It resets service related information and + * timestamps. + * @details \b Inputs: none + * @details \b Outputs: ddServiceGroup.ddServiceRecord + * @return none + *************************************************************************/ static void initDDServiceRecord( void ) { ddServiceGroup.ddServiceRecord.isHDFOnlineFluid = FALSE; @@ -898,6 +909,15 @@ // ddServiceGroup.ddServiceRecord.lastResetTimeEpoch = getRTCTimestamp(); } +/*********************************************************************//** + * @brief + * The initDDInstitutionalRecord function initializes the DD + * institutional record with default values. It sets configuration + * limits, alarm thresholds, and treatment options to default values. + * @details \b Inputs: none + * @details \b Outputs: ddInstitutionalGroup.ddInstitutionalRecord + * @return none + *************************************************************************/ static void initDDInstitutionalRecord( void ) { ddInstitutionalGroup.ddInstitutionalRecord.minDialysateFlowMLPM = DEFAULT_MIN_DIALYSATE_FLOW_MLPM; @@ -925,6 +945,15 @@ // ddInstitutionalGroup.ddInstitutionalRecord.calibrationTime = getRTCTimestamp(); } +/*********************************************************************//** + * @brief + * The initDDUsageRecord function initializes the DD usage record with + * default values. It resets usage information, counters, and + * maintenance timestamps. + * @details \b Inputs: none + * @details \b Outputs: ddUsageInfoGroup.ddUsageInfoRecord + * @return none + *************************************************************************/ static void initDDUsageRecord( void ) { ddUsageInfoGroup.ddUsageInfoRecord.roWaterGenTotalL = 0.0F; @@ -936,6 +965,14 @@ // ddUsageInfoGroup.ddUsageInfoRecord.lastResetTimeEpoch = getRTCTimestamp(); } +/*********************************************************************//** + * @brief + * The initDDCalibrationRecord function initializes the DD calibration record with + * default values. + * @details \b Inputs: none + * @details \b Outputs: ddCalibrationGroup.ddCalibrationRecord + * @return none + *************************************************************************/ //static void initDDCalibrationRecord( void ) //{ // U32 i; @@ -1004,11 +1041,23 @@ // ddCalibrationGroup.ddCalibrationRecord.bloodLeakSensorCalRecord.crc = crc16 ( (U08*)record, sizeof( DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ) - sizeof( U16 ) ); //} +/*********************************************************************//** + * @brief + * The updateRecordPadding function updates the padding bytes of the + * specified NV record. It clears all padding bytes to ensure + * consistent CRC calculation and record storage. + * @details \b Inputs: none + * @details \b Outputs: ddSystemGroup.padding, + * ddServiceGroup.padding, ddCalibrationGroup.padding, + * ddInstitutionalGroup.padding, ddUsageInfoGroup.padding + * @param recType Record type whose padding needs to be updated + * @return none + *************************************************************************/ static void updateRecordPadding( NVM_RECORD_TYPE_T recType ) { U32 i = 0; - switch( recType ) + switch ( recType ) { case NVM_SYSTEM_RECORD: { @@ -1058,10 +1107,25 @@ } } - +/*********************************************************************//** + * @brief + * The updateRecordCRC function updates the CRC values of the specified + * NV record and its associated group. It recalculates CRCs based on + * the current record contents. + * @details \b Inputs: none + * @details \b Outputs: ddSystemGroup.ddSystemRecord.crc, + * ddSystemGroup.crc, ddServiceGroup.ddServiceRecord.crc, + * ddServiceGroup.crc, ddCalibrationGroup.crc, + * ddInstitutionalGroup.ddInstitutionalRecord.crc, + * ddInstitutionalGroup.crc, + * ddUsageInfoGroup.ddUsageInfoRecord.crc, + * ddUsageInfoGroup.crc + * @param recType Record type whose CRC needs to be updated + * @return none + *************************************************************************/ void updateRecordCRC( NVM_RECORD_TYPE_T recType ) { - switch( recType ) + switch ( recType ) { case NVM_SYSTEM_RECORD: { @@ -1081,26 +1145,26 @@ break; case NVM_CALIBRATION_RECORD: { - ddCalibrationGroup.crc = crc16 ( (U08*)&ddCalibrationGroup, - sizeof( DD_CALIBRATION_GROUP_T ) - sizeof( U16 ) ); + ddCalibrationGroup.crc = crc16 ( (U08*)&ddCalibrationGroup, + sizeof( DD_CALIBRATION_GROUP_T ) - sizeof( U16 ) ); } break; case NVM_INSTITUTIONAL_RECORD: { ddInstitutionalGroup.ddInstitutionalRecord.crc = crc16 ( (U08*)&ddInstitutionalGroup.ddInstitutionalRecord, - sizeof( DD_INSTITUTIONAL_RECORD_T ) - sizeof( U16 ) ); - ddInstitutionalGroup.crc = crc16 ( (U08*)&ddInstitutionalGroup, - sizeof( DD_INSTITUTIONAL_GROUP_T ) - sizeof( U16 ) ); + sizeof( DD_INSTITUTIONAL_RECORD_T ) - sizeof( U16 ) ); + ddInstitutionalGroup.crc = crc16 ( (U08*)&ddInstitutionalGroup, + sizeof( DD_INSTITUTIONAL_GROUP_T ) - sizeof( U16 ) ); } break; case NVM_USAGE_INFO_RECORD: { ddUsageInfoGroup.ddUsageInfoRecord.crc = crc16 ( (U08*)&ddUsageInfoGroup.ddUsageInfoRecord, - sizeof( DD_SERVICE_RECORD_T ) - sizeof( U16 ) ); - ddUsageInfoGroup.crc = crc16 ( (U08*)&ddUsageInfoGroup, - sizeof( DD_SERVICE_GROUP_T ) - sizeof( U16 ) ); + sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + ddUsageInfoGroup.crc = crc16 ( (U08*)&ddUsageInfoGroup, + sizeof( DD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); } break; @@ -1156,7 +1220,7 @@ status = TRUE; enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_USAGE_INFO_RECORD ].nvEvent, 0, 0 ); + sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); } else if ( ++usageWriteTries > MAX_NUM_OF_WRITE_TRIES ) { @@ -1199,8 +1263,8 @@ enqueueEraseAndWriteSector( NVM_SERVICE_RECORD ); enqueueEraseAndWriteSector( NVM_USAGE_INFO_RECORD ); // Both the usage and service records have been updated - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_USAGE_INFO_RECORD ].nvEvent, 0, 0 ); - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ NVM_SERVICE_RECORD ].nvEvent, 0, 0 ); + sendNVEvent( NVM_USAGE_INFO_RECORD, 0, 0 ); + sendNVEvent( NVM_SERVICE_RECORD, 0, 0 ); status = TRUE; } @@ -1237,60 +1301,175 @@ return ddInstitutionalGroup.ddInstitutionalRecord.minInletWaterCondAlarmLimitUSPCM; } -POLYNOMIAL_CAL_PAYLOAD_T getPressureSensorCalRecord( U08 snsrIdx) +/*********************************************************************//** + * @brief + * The getPressureSensorCalRecord function gets the calibration record + * of the specified pressure sensor. + * @details \b Inputs: ddCalibrationGroup.ddCalibrationRecord + * @details \b Outputs: none + * @param snsrIdx Pressure sensor index + * @return record corresponding pressure sensor calibration record + *************************************************************************/ +POLYNOMIAL_CAL_PAYLOAD_T getPressureSensorCalRecord( U08 snsrIdx ) { + POLYNOMIAL_CAL_PAYLOAD_T record; + benignPolynomialCalRecord( &record ); + if ( snsrIdx < NUM_OF_PRESSURE_SENSORS ) { - return ( ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord.pressureSensors[ snsrIdx ] ); + record = ( ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord.pressureSensors[ snsrIdx ] ); } + + return record; } -POLYNOMIAL_CAL_PAYLOAD_T getTemperatureSensorCalRecord( U08 snsrIdx) +/*********************************************************************//** + * @brief + * The getTemperatureSensorCalRecord function gets the calibration + * record of the specified temperature sensor. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord + * @details \b Outputs: none + * @param snsrIdx Temperature sensor index + * @return record corresponding temperature sensor calibration record + *************************************************************************/ +POLYNOMIAL_CAL_PAYLOAD_T getTemperatureSensorCalRecord( U08 snsrIdx ) { + POLYNOMIAL_CAL_PAYLOAD_T record; + benignPolynomialCalRecord( &record ); + if ( snsrIdx < NUM_OF_TEMPERATURE_SENSORS ) { - return ( ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord.tempSensors[ snsrIdx ] ); + record = ( ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord.tempSensors[ snsrIdx ] ); } + + return record; } -POLYNOMIAL_CAL_PAYLOAD_T getConcPumpCalRecord( U08 pumpIdx) +/*********************************************************************//** + * @brief + * The getConcPumpCalRecord function gets the calibration record of the + * specified concentrate pump. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord + * @details \b Outputs: none + * @param pumpIdx Concentrate pump index + * @return record corresponding concentrate pump calibration record + *************************************************************************/ +POLYNOMIAL_CAL_PAYLOAD_T getConcPumpCalRecord( U08 pumpIdx ) { + POLYNOMIAL_CAL_PAYLOAD_T record; + benignPolynomialCalRecord( &record ); + if ( pumpIdx < NUM_OF_CONCENTRATE_PUMPS ) { - return ( ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord.concentratePumps[ pumpIdx ] ); + record = ( ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord.concentratePumps[ pumpIdx ] ); } + + return record; } +/*********************************************************************//** + * @brief + * The getD12PumpCalRecord function gets the calibration record of the + * D12 dialysate pump. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord.d12DialysatePumpRecord + * @details \b Outputs: none + * @return ddCalibrationGroup.ddCalibrationRecord. + * d12DialysatePumpRecord + *************************************************************************/ DD_D12_DIALYSATE_PUMP_RECORD_T getD12PumpCalRecord( void ) { return ( ddCalibrationGroup.ddCalibrationRecord.d12DialysatePumpRecord ); } + +/*********************************************************************//** + * @brief + * The getD48PumpCalRecord function gets the calibration record of the + * D48 dialysate pump. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord.d48DialysatePumpRecord + * @details \b Outputs: none + * @return ddCalibrationGroup.ddCalibrationRecord. + * d48DialysatePumpRecord + *************************************************************************/ DD_D48_DIALYSATE_PUMP_RECORD_T getD48PumpCalRecord( void ) { return ( ddCalibrationGroup.ddCalibrationRecord.d48DialysatePumpRecord ); } -DD_ACID_CONCENTRATE_T getAcidConcentrateCalRecord( U08 acidIdx) +/*********************************************************************//** + * @brief + * The getAcidConcentrateCalRecord function gets the calibration record + * of the specified acid concentrate. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord + * @details \b Outputs: none + * @param acidIdx Acid concentrate index + * @return record corresponding acid concentrate calibration record + *************************************************************************/ +DD_ACID_CONCENTRATE_T getAcidConcentrateCalRecord( U08 acidIdx ) { + DD_ACID_CONCENTRATE_T record = { 0 }; + if ( acidIdx < NUM_OF_ACID_TYPE ) { - return ( ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord.acidConcentrate[ acidIdx ] ); + record = ( ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord.acidConcentrate[ acidIdx ] ); } + + return record; } -DD_BICARB_CONCENTRATE_T getBicarbConcentrateCalRecord( U08 bicarbIdx) +/*********************************************************************//** + * @brief + * The getBicarbConcentrateCalRecord function gets the calibration + * record of the specified bicarb concentrate. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord + * @details \b Outputs: none + * @param bicarbIdx Bicarb concentrate index + * @return record corresponding bicarb concentrate calibration record + *************************************************************************/ +DD_BICARB_CONCENTRATE_T getBicarbConcentrateCalRecord( U08 bicarbIdx ) { + DD_BICARB_CONCENTRATE_T record = { 0 }; + if ( bicarbIdx < NUM_OF_BICARB_TYPE ) { - return ( ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord.bicarbConcentrate[ bicarbIdx ] ); + record = ( ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord.bicarbConcentrate[ bicarbIdx ] ); } + + return record; } +/*********************************************************************//** + * @brief + * The getAccelSensorCalRecord function gets the calibration record of + * the accelerometer sensor. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord. + * accelerometerSensorCalRecord + * @details \b Outputs: none + * @return ddCalibrationGroup.ddCalibrationRecord. + * accelerometerSensorCalRecord + *************************************************************************/ DD_ACCEL_SENSOR_CAL_RECORD_T getAccelSensorCalRecord( void ) { return ( ddCalibrationGroup.ddCalibrationRecord.accelerometerSensorCalRecord ); } +/*********************************************************************//** + * @brief + * The getBloodLeakSensorCalRecord function gets the calibration record + * of the blood leak sensor. + * @details \b Inputs: + * ddCalibrationGroup.ddCalibrationRecord. + * bloodLeakSensorCalRecord + * @details \b Outputs: none + * @return ddCalibrationGroup.ddCalibrationRecord. + * bloodLeakSensorCalRecord + *************************************************************************/ DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T getBloodLeakSensorCalRecord( void ) { return ( ddCalibrationGroup.ddCalibrationRecord.bloodLeakSensorCalRecord ); @@ -1327,59 +1506,59 @@ case GET_CAL_PRESSURE_SENOSRS: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord ); -// for ( i = 0; i < numOfSnsrs2Check; i++ ) -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord.pressureSensors[ i ].calibrationTime ? TRUE : FALSE ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord.pressureSensors[ i ].calibrationTime ? TRUE : FALSE ); break; case GET_CAL_TEMP_SENSORS: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord ); -// for ( i = 0; i < numOfSnsrs2Check; i++ ) -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord.tempSensors[ i ].calibrationTime ? TRUE : FALSE ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.tempSensorsCalRecord.tempSensors[ i ].calibrationTime ? TRUE : FALSE ); break; case GET_CAL_CONCENTRATE_PUMPS_RECORD: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord ); -// for ( i = 0; i < numOfSnsrs2Check; i++ ) -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord.concentratePumps[ i ].calibrationTime ? TRUE : FALSE ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.concentratePumpsRecord.concentratePumps[ i ].calibrationTime ? TRUE : FALSE ); break; case GET_CAL_D12_PUMP_RECORD: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.d12DialysatePumpRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.d12DialysatePumpRecord ); -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.d12DialysatePumpRecord.calibrationTime ? TRUE : FALSE ); + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.d12DialysatePumpRecord.calibrationTime ? TRUE : FALSE ); break; case GET_CAL_D48_PUMP_RECORD: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.d48DialysatePumpRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.d48DialysatePumpRecord ); -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.d48DialysatePumpRecord.d48DialysatePump.calibrationTime ? TRUE : FALSE ); + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.d48DialysatePumpRecord.d48DialysatePump.calibrationTime ? TRUE : FALSE ); break; case GET_CAL_ACID_CONCENTREATES: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord ); -// for ( i = 0; i < numOfSnsrs2Check; i++ ) -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord.acidConcentrate[ i ].calibrationTime ? TRUE : FALSE ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.acidConcentratesRecord.acidConcentrate[ i ].calibrationTime ? TRUE : FALSE ); break; case GET_CAL_BICARB_CONCENTRATES: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord ); -// for ( i = 0; i < numOfSnsrs2Check; i++ ) -// isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord.bicarbConcentrate[ i ].calibrationTime ? TRUE : FALSE ); + for ( i = 0; i < numOfSnsrs2Check; i++ ) + isNVDataInvalid |= ( 0 == ddCalibrationGroup.ddCalibrationRecord.bicarbConcentratesRecord.bicarbConcentrate[ i ].calibrationTime ? TRUE : FALSE ); break; case GET_CAL_ACCEL_SENSORS: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.accelerometerSensorCalRecord; -// isNVDataInvalid = ( 0 == ddCalibrationGroup.ddCalibrationRecord.accelerometerSensorCalRecord.calibrationTime ? TRUE : FALSE ); + isNVDataInvalid = ( 0 == ddCalibrationGroup.ddCalibrationRecord.accelerometerSensorCalRecord.calibrationTime ? TRUE : FALSE ); break; case GET_CAL_BLOOD_LEAK_SENSOR: nvDataStartPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.bloodLeakSensorCalRecord; nvDataLength = sizeof( ddCalibrationGroup.ddCalibrationRecord.bloodLeakSensorCalRecord ); -// isNVDataInvalid = ( 0 == ddCalibrationGroup.ddCalibrationRecord.bloodLeakSensorCalRecord.calibrationTime ? TRUE : FALSE ); + isNVDataInvalid = ( 0 == ddCalibrationGroup.ddCalibrationRecord.bloodLeakSensorCalRecord.calibrationTime ? TRUE : FALSE ); break; case GET_SYSTEM_RECORD: @@ -1433,13 +1612,28 @@ return ( FALSE == isNVDataInvalid ? TRUE : FALSE ); } +/*********************************************************************//** + * @brief + * The setNVMRecord function updates the specified NV record with the + * provided data buffer. It copies the record data and updates the + * corresponding CRC values. + * @details \b Inputs: none + * @details \b Outputs: ddSystemGroup.ddSystemRecord, + * ddServiceGroup.ddServiceRecord, + * ddUsageInfoGroup.ddUsageInfoRecord, + * ddSystemGroup.crc, ddServiceGroup.crc, + * ddUsageInfoGroup.crc + * @param recType Record type to update + * @param bufferAddress Pointer to the source data buffer + * @return TRUE if the record was updated successfully otherwise FALSE + *************************************************************************/ BOOL setNVMRecord( NVM_RECORD_TYPE_T recType, U08* bufferAddress ) { BOOL result = FALSE; U08* destPtr = NULL; U16 dataSize = 0; - switch( recType ) + switch ( recType ) { case NVM_SYSTEM_RECORD: destPtr = (U08*)&ddSystemGroup.ddSystemRecord; @@ -1460,25 +1654,39 @@ break; } - if ( (destPtr != NULL ) && ( bufferAddress != NULL ) && ( dataSize > 0 ) ) + if ( ( destPtr != NULL ) && ( bufferAddress != NULL ) && ( dataSize > 0 ) ) { memcpy( destPtr, bufferAddress, dataSize ); - updateRecordCRC(recType); + updateRecordCRC( recType ); result = TRUE; } return result; } +/*********************************************************************//** + * @brief + * The setNVMCalRecord function updates the specified calibration + * record with the provided data buffer. It copies the calibration + * data and updates the calibration record CRC. + * @details \b Inputs: none + * @details \b Outputs: ddCalibrationGroup.ddCalibrationRecord, + * ddCalibrationGroup.crc + * @param calRecType Calibration record type to update + * @param bufferAddress Pointer to the source data buffer + * @param idx Calibration record index + * @return TRUE if the calibration record was updated successfully + * otherwise FALSE + *************************************************************************/ BOOL setNVMCalRecord( DD_CAL_REC_TYPE calRecType, U08* bufferAddress, U08 idx ) { BOOL result = FALSE; U08* destPtr = NULL; U16 dataSize = 0; - switch (calRecType) + switch ( calRecType ) { case DD_CAL_RECORD_PRESSURE_SENSOR: destPtr = (U08*)&ddCalibrationGroup.ddCalibrationRecord.presSensorsCalRecord.pressureSensors[ idx ]; @@ -1529,7 +1737,7 @@ break; } - if ( (destPtr != NULL ) && ( bufferAddress != NULL ) && ( dataSize > 0 ) ) + if ( ( destPtr != NULL ) && ( bufferAddress != NULL ) && ( dataSize > 0 ) ) { memcpy( destPtr, bufferAddress, dataSize ); updateRecordCRC( NVM_CALIBRATION_RECORD ); @@ -1539,11 +1747,30 @@ return result; } +/*********************************************************************//** + * @brief + * The getInstitRecDataType function gets the data type associated with + * the specified institutional record item. + * @details \b Inputs: institRecDataTypeTable + * @details \b Outputs: none + * @param institRecType Institutional record type + * @return Data type of the institutional record component + *************************************************************************/ CRITICAL_DATA_TYPES_T getInstitRecDataType( DD_INSTIT_REC_TYPE institRecType ) { return institRecDataTypeTable[ institRecType ]; } +/*********************************************************************//** + * @brief + * The getNVMInstitRecord function gets the value of the specified + * institutional record item. + * @details \b Inputs: ddInstitutionalGroup.ddInstitutionalRecord + * @details \b Outputs: none + * @param institRecType Institutional record item to retrieve + * @param valuePtr Pointer to the buffer where the value will be copied + * @return TRUE if the value was retrieved successfully otherwise FALSE + *************************************************************************/ BOOL getNVMInstitRecord( DD_INSTIT_REC_TYPE institRecType, U08 *valuePtr ) { BOOL result = FALSE; @@ -1686,137 +1913,146 @@ return result; } - +/*********************************************************************//** + * @brief + * The setNVMInstitRecord function updates the specified institutional + * record item with the provided value. It updates the institutional + * record CRC after the value is written. + * @details \b Inputs: none + * @details \b Outputs: ddInstitutionalGroup.ddInstitutionalRecord, + * ddInstitutionalGroup.crc + * @param institRecType Institutional record item to update + * @param valuePtr Pointer to the value to be written + * @return TRUE if the value was updated successfully otherwise FALSE + *************************************************************************/ BOOL setNVMInstitRecord( DD_INSTIT_REC_TYPE institRecType, U08 *valuePtr ) { - BOOL result = FALSE; - + BOOL result = FALSE; U08 *destPtr = NULL; U16 dataSize = 0; switch (institRecType) { case DD_INSTIT_MIN_DIALYSATE_FLOW_MLPM: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minDialysateFlowMLPM; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minDialysateFlowMLPM; dataSize = sizeof(U32); break; case DD_INSTIT_MAX_DIALYSATE_FLOW_MLPM: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxDialysateFlowMLPM; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxDialysateFlowMLPM; dataSize = sizeof(U32); break; case DD_INSTIT_MIN_DIALYSATE_TEMP_C: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minDialysateTempC; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minDialysateTempC; dataSize = sizeof(F32); break; case DD_INSTIT_MAX_DIALYSATE_TEMP_C: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxDialysateTempC; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxDialysateTempC; dataSize = sizeof(F32); break; case DD_INSTIT_MIN_ACID_CONCENTRATE: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minAcidConcentrate; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minAcidConcentrate; dataSize = sizeof(U32); break; case DD_INSTIT_MAX_ACID_CONCENTRATE: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxAcidConcentrate; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxAcidConcentrate; dataSize = sizeof(U32); break; case DD_INSTIT_MIN_BICARB_CARTRIDGE_SIZE_G: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minBicarbCartridgeSizeG; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minBicarbCartridgeSizeG; dataSize = sizeof(U32); break; case DD_INSTIT_MAX_BICARB_CARTRIDGE_SIZE_G: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxBicarbCartridgeSizeG; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxBicarbCartridgeSizeG; dataSize = sizeof(U32); break; case DD_INSTIT_MIN_SODIUM_MEQL: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minSodiumMEQL; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minSodiumMEQL; dataSize = sizeof(U32); break; case DD_INSTIT_MAX_SODIUM_MEQL: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxSodiumMEQL; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxSodiumMEQL; dataSize = sizeof(U32); break; case DD_INSTIT_MIN_BICARBONATE_MEQL: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minBicarbonateMEQL; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minBicarbonateMEQL; dataSize = sizeof(U32); break; case DD_INSTIT_MAX_BICARBONATE_MEQL: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxBicarbonateMEQL; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxBicarbonateMEQL; dataSize = sizeof(U32); break; case DD_INSTIT_MIN_RO_REJECTION_RATIO_PCT: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minRORejectionRatioPCT; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minRORejectionRatioPCT; dataSize = sizeof(U32); break; case DD_INSTIT_DISINFECTION_FREQUENCY: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.disinfectionFrequency; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.disinfectionFrequency; dataSize = sizeof(U32); break; case DD_INSTIT_DISINFECTION_CYCLE_TIME: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.disinfectionCycleTime; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.disinfectionCycleTime; dataSize = sizeof(F32); break; case DD_INSTIT_MIN_INLET_WATER_COND_ALARM_LIMIT_USPCM: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minInletWaterCondAlarmLimitUSPCM; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minInletWaterCondAlarmLimitUSPCM; dataSize = sizeof(F32); break; case DD_INSTIT_MAX_INLET_WATER_COND_ALARM_LIMIT_USPCM: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxInletWaterCondAlarmLimitUSPCM; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.maxInletWaterCondAlarmLimitUSPCM; dataSize = sizeof(F32); break; case DD_INSTIT_ACID_CONCENTRATE_JUG_SIZE_L: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.acidConcentrateJugSizeL; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.acidConcentrateJugSizeL; dataSize = sizeof(F32); break; case DD_INSTIT_MIN_ACID_ALARM_LIMIT_PCT: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minAcidAlarmLimitPCT; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minAcidAlarmLimitPCT; dataSize = sizeof(F32); break; case DD_INSTIT_MIN_BICARB_ALARM_LIMIT_PCT: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minBicarbAlarmLimitPCT; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.minBicarbAlarmLimitPCT; dataSize = sizeof(F32); break; case DD_INSTIT_POST_TREAT_DRAIN_OPTION: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.postTreatDrainOption; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.postTreatDrainOption; dataSize = sizeof(U32); break; case DD_INSTIT_POST_TREAT_DRY_BICARB_OPTION: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.postTreatDryBicarbOption; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.postTreatDryBicarbOption; dataSize = sizeof(U32); break; case DD_INSTIT_CALIBRATION_TIME: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.calibrationTime; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.calibrationTime; dataSize = sizeof(U32); break; case DD_INSTIT_CRC: - destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.crc; + destPtr = (U08*)&ddInstitutionalGroup.ddInstitutionalRecord.crc; dataSize = sizeof(U16); break; - default: break; } @@ -1834,10 +2070,20 @@ return result; } -void sendNVEvent( NVM_RECORD_TYPE_T recType, U32 d1, U32 d2 ) +/*********************************************************************//** + * @brief + * The sendNVEvent function sends the event associated with the + * specified NV record type. + * @details \b Inputs: RECORDS_SPECS + * @details \b Outputs: none + * @param recType NV record type whose event will be sent + * @param d1 First event data + * @param d2 Second event data + * @return none + *************************************************************************/ +void sendNVEvent( NVM_RECORD_TYPE_T recType, U32 d1, U32 d2 ) { - - SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[recType].nvEvent, d1, d2 ); + SEND_EVENT_WITH_2_U32_DATA( RECORDS_SPECS[ recType ].nvEvent, d1, d2 ); } /*********************************************************************//** @@ -1883,7 +2129,6 @@ } - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/NVRecordsDD.h =================================================================== diff -u -rbeb95e3e8f85740707704d7089db8b3ec8574bbd -r0599bd5494eb64416999de0487a9882c557b6044 --- firmware/App/Services/NVRecordsDD.h (.../NVRecordsDD.h) (revision beb95e3e8f85740707704d7089db8b3ec8574bbd) +++ firmware/App/Services/NVRecordsDD.h (.../NVRecordsDD.h) (revision 0599bd5494eb64416999de0487a9882c557b6044) @@ -328,13 +328,13 @@ U32 getMinRORejectionRatioInInstitRecordPCT( void ); F32 getMinInletWaterConductivityLimitInstitRecordUSPCM( void ); -POLYNOMIAL_CAL_PAYLOAD_T getPressureSensorCalRecord( U08 snsrIdx); -POLYNOMIAL_CAL_PAYLOAD_T getTemperatureSensorCalRecord( U08 snsrIdx); -POLYNOMIAL_CAL_PAYLOAD_T getConcPumpCalRecord( U08 pumpIdx); +POLYNOMIAL_CAL_PAYLOAD_T getPressureSensorCalRecord( U08 snsrIdx ); +POLYNOMIAL_CAL_PAYLOAD_T getTemperatureSensorCalRecord( U08 snsrIdx ); +POLYNOMIAL_CAL_PAYLOAD_T getConcPumpCalRecord( U08 pumpIdx ); DD_D12_DIALYSATE_PUMP_RECORD_T getD12PumpCalRecord( void ); DD_D48_DIALYSATE_PUMP_RECORD_T getD48PumpCalRecord( void ); -DD_ACID_CONCENTRATE_T getAcidConcentrateCalRecord( U08 acidIdx); -DD_BICARB_CONCENTRATE_T getBicarbConcentrateCalRecord( U08 bicarbIdx); +DD_ACID_CONCENTRATE_T getAcidConcentrateCalRecord( U08 acidIdx ); +DD_BICARB_CONCENTRATE_T getBicarbConcentrateCalRecord( U08 bicarbIdx ); DD_ACCEL_SENSOR_CAL_RECORD_T getAccelSensorCalRecord( void ); DD_BLOOD_LEAK_SENSOR_CAL_RECORD_T getBloodLeakSensorCalRecord( void ); @@ -346,7 +346,7 @@ CRITICAL_DATA_TYPES_T getInstitRecDataType( DD_INSTIT_REC_TYPE institRecType ); BOOL getNVMInstitRecord( DD_INSTIT_REC_TYPE institRecType, U08 *valuePtr ); BOOL setNVMInstitRecord(DD_INSTIT_REC_TYPE institRecType, U08 *valuePtr); -void sendNVEvent( NVM_RECORD_TYPE_T recType, U32 d1, U32 d2 ); +void sendNVEvent( NVM_RECORD_TYPE_T recType, U32 d1, U32 d2 ); void updateRecordCRC( NVM_RECORD_TYPE_T recType ); void updateNVSelfTestResult( SELF_TEST_STATUS_T result ); void updateNVSelfTestState( NVM_SELF_TEST_STATE_T state );