Index: NVDataMgmt.c =================================================================== diff -u -r0df8e5e99715de10f8936a9d41c28f4c2a4dacc6 -r45f39d237e109f91b4b7e40fdb2dc00bd673eef0 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 0df8e5e99715de10f8936a9d41c28f4c2a4dacc6) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 45f39d237e109f91b4b7e40fdb2dc00bd673eef0) @@ -99,11 +99,19 @@ #define CAL_DATA_MAX_MESSAGE_DFFIRENCE 1 ///< Calibration data receive message different from the previous message. #define CAL_DATA_FIRST_RECEIVING_MSG_NUM 1 ///< Calibration data first receiving message number. #define SYSTEM_DATA_NV_MEM_START_ADDRESS BANK7_SECTOR0_START_ADDRESS + 2048 ///< System record storage start address in NV memory. -#define DG_CAL_RECORD_BYTE_SIZE ( sizeof(DG_CALIBRATION_GROUPS_T) + sizeof(U16) ) +#ifdef _DG_ +#define DG_CAL_RECORD_BYTE_SIZE ( sizeof(DG_CALIBRATION_GROUPS_T) + sizeof(U16) ) ///< DG calibration record byte size. // Padding length calculation: (DG struct size % bytes to write(16) == 0 ? 0 : (DG struct size / bytes to write(16)) + 1) * bytes to write(16) -#define DG_PADDING_LENGTH ( DG_CAL_RECORD_BYTE_SIZE % MAX_EEPROM_WRITE_BUFFER_BYTES == 0 ? \ - 0 : ( (U32)(DG_CAL_RECORD_BYTE_SIZE / MAX_EEPROM_WRITE_BUFFER_BYTES) + 1 ) )* \ - MAX_EEPROM_WRITE_BUFFER_BYTES ///< DG padding length that is calculated with the size of the cal structures. +#define DG_CAL_PADDING_LENGTH ( DG_CAL_RECORD_BYTE_SIZE % MAX_EEPROM_WRITE_BUFFER_BYTES == 0 ? \ + 0 : ( (U32)(DG_CAL_RECORD_BYTE_SIZE / MAX_EEPROM_WRITE_BUFFER_BYTES) + 1 ) )* \ + MAX_EEPROM_WRITE_BUFFER_BYTES ///< DG calibration padding length that is calculated with the size of the cal structures. +#define DG_SYS_RECORD_BYTE_SIZE ( sizeof(DG_SYSTEM_RECORD_T) + sizeof(U16) ) ///< DG system record byte size. +// Padding length calculation: (DG struct size % bytes to write(16) == 0 ? 0 : (DG struct size / bytes to write(16)) + 1) * bytes to write(16) +#define DG_SYS_PADDING_LENGTH ( DG_SYS_RECORD_BYTE_SIZE % MAX_EEPROM_WRITE_BUFFER_BYTES == 0 ? \ + 0 : ( (U32)(DG_SYS_RECORD_BYTE_SIZE / MAX_EEPROM_WRITE_BUFFER_BYTES) + 1 ) )* \ + MAX_EEPROM_WRITE_BUFFER_BYTES ///< DG system padding length that is calculated with the size of the system structure. +#else if _HD_ +#endif /// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States @@ -174,12 +182,10 @@ /// NVDataMgmt records' jobs states typedef enum NVDataMgmt_Records_Jobs { - NVDATAMGMT_WRITE_CALIBRATION_RECORD = 0, ///< NVDataMgmt process write calibration record. - NVDATAMGMT_WRITE_SYSTEM_RECORD, ///< NVDataMgmt process write system record. - NVDATAMGMT_READ_CALIBRATION_RECORD, ///< NVDataMgmt process read calibration record. - NVDATAMGMT_READ_SYSTEM_RECORD, ///< NVDataMgmt process read system record. - NVDATAMGMT_PROCESS_LAST_SERVICE_RECORD, ///< NVDATAMgmt process last service record. - NVDATAMGMT_PROCESS_SCHEDULER_RECORD, ///< NVDataMgmt process scheduler record. + NVDATAMGMT_CALIBRATION_RECORD = 0, ///< NVDataMgmt process write calibration record. + NVDATAMGMT_SYSTEM_RECORD, ///< NVDataMgmt process write system record. + NVDATAMGMT_LAST_SERVICE_RECORD, ///< NVDATAMgmt process last service record. + NVDATAMGMT_SCHEDULER_RECORD, ///< NVDataMgmt process scheduler record. NUM_OF_NVDATMGMT_RECORDS_JOBS ///< Number of NVDataMgmt records jobs. } RECORD_JOBS_STATE_T; @@ -198,7 +204,10 @@ { U32 startAddress; ///< Jobs spec start address. U32 sizeofJob; ///< Jobs spec size of job. - U32 maxBufferSize; ///< Jobs max allowed processing buffer size. + U32 maxWriteBufferSize; ///< Jobs max write allowed processing buffer size. + U32 maxReadBufferSize; ///< Jobs max read allowed processing buffer size. + U08* structAddressPtr; + U08* structCRCPtr; } PROCESS_RECORD_SPECS_T; /// Process records job structure @@ -290,69 +299,75 @@ DG_TEMP_SENSORS_CAL_RECORD_T tempSensorsCalRecord; ///< DG temperature sensors. DG_COND_SENSORS_CAL_RECORD_T condSensorsCalRecord; ///< DG conductivity sensors. DG_CONC_PUMPS_CAL_RECORD_T concentratePump[ NUM_OF_CONCENTRATE_PUMPS ]; ///< DG concentrate pumps. - DG_DRAIN_PUMP_CAL_RECORD_T drainPump; - DG_RO_PUMP_CAL_RECORD_T roPump; - DG_DRAIN_LINE_VOLUME_T drainLineVolume; - DG_PRE_RO_PURGE_VOLUME_T preROPurgeVolume; - DG_RESERVOIR_VOLUME_T reservoir[ NUM_OF_CAL_DATA_RSRVRS ]; - DG_GENERIC_VOLUME_T genericVolume[ 4 ]; + DG_DRAIN_PUMP_CAL_RECORD_T drainPump; ///< DG drain pump. + DG_RO_PUMP_CAL_RECORD_T roPump; ///< DG RO pump. + DG_DRAIN_LINE_VOLUME_T drainLineVolume; ///< DG drain line volume. + DG_PRE_RO_PURGE_VOLUME_T preROPurgeVolume; ///< DG RO purge volume. + DG_RESERVOIR_VOLUME_T reservoir[ NUM_OF_CAL_DATA_RSRVRS ]; ///< DG reservoirs volume. + DG_GENERIC_VOLUME_T genericVolume[ 4 ]; ///< DG generic volume. + DG_ACID_CONCENTRATES_T acidConcentrates; ///< DG acid concentrates. + DG_BICARB_CONCENTRATES_T bicarbConcentrates; ///< DG bicarb concentrates. + DG_FILTERS_CAL_RECORD_T filters; ///< DG filters. + DG_FANS_CAL_RECORD_T fans; ///< DG fans. } DG_CALIBRATION_GROUPS_T; /// DG calibration records structure typedef struct { - DG_CALIBRATION_GROUPS_T dgCalibrationGroups; ///< DG calibration groups. - U08 padding[ DG_PADDING_LENGTH - DG_CAL_RECORD_BYTE_SIZE]; ///< DG calibration record padding byte array. + DG_CALIBRATION_GROUPS_T dgCalibrationGroups; ///< DG calibration groups. + U08 padding[ DG_CAL_PADDING_LENGTH - DG_CAL_RECORD_BYTE_SIZE ]; ///< DG calibration record padding byte array. U16 crc; ///< CRC for the DG calibration record structure. } DG_CALIBRATION_RECORD_T; -/// DG systems record structure +/// DG system group structure typedef struct { - char topLevelPN[ MAX_TOP_LEVEL_PN_CHARS ]; ///< DG top level part number. - char topLevelSN[ MAX_TOP_LEVEL_SN_CHARS ]; ///< DG top level serial number. - MFG_LOCATION_T mfgLocation; ///< DG manufacturing location. - U32 mfgDate; ///< DG manufacturing date. - U16 crc; ///< CRC for the DG system record structure. -} DG_SYSTEM_RECORD_T; + DG_SYSTEM_RECORD_T dgSystemRecord; ///< DG system record. + U08 padding[ DG_SYS_PADDING_LENGTH - DG_SYS_RECORD_BYTE_SIZE ]; ///< DG system group padding byte array. + U16 crc; ///< CRC for the DG system group structure. +} DG_SYSTEM_GROUP_T; -/// DG last service record structure +/// DG scheduler record structure typedef struct { - LAST_SERVICE_LOCATION_T lastServiceLoc; ///< DG last service location. - U32 lastServiceDate; ///< DG last service date. - U16 crc; ///< CRC for the DG last service record structure. -} DG_LAST_SERVICE_RECORD_T; + //TODO fill up +} DG_SCHEDULER_RECORD_T; -/// DG scheduler record structure +/// HD calibration records structure typedef struct { //TODO fill up -} DG_SCHEDULER_RECORD_T; +} HD_CALIBRATION_GROUPS_T; + +typedef struct +{ + HD_CALIBRATION_GROUPS_T hdCalibratiobGroups; +} HD_CALIBRATION_RECORD_T; #pragma pack(pop) +// Calibration variables +#ifdef _DG_ +static DG_CALIBRATION_RECORD_T dgCalibrationRecord; ///< DG calibration record. +static DG_SYSTEM_GROUP_T dgSystemGroup; ///< DG system group (including padding and final CRC). // Process records specifications const PROCESS_RECORD_SPECS_T RECORDS_SPECS [ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { -#ifdef _DG_ - {BANK7_SECTOR0_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES}, // NVDATAMGMT_WRITE_CALIBRATION_RECORD - {SYSTEM_DATA_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES}, // NVDATAMGMT_WRITE_SYSTEM_RECORD - {BANK7_SECTOR0_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), sizeof(DG_CALIBRATION_RECORD_T)}, // NVDATAMGMT_READ_CALIBRATION_RECORD - {SYSTEM_DATA_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_RECORD_T), sizeof(DG_SYSTEM_RECORD_T)}, // NVDATAMGMT_READ_SYSTEM_RECORD - {LAST_SERVICE_RECORD_START_ADDRESS, sizeof(DG_LAST_SERVICE_RECORD_T), MAX_RTC_RAM_OPS_BUFFER_BYTES}, // NVDATAMGMT_PROCESS_LAST_SERVICE_RECORD - {DG_SCHEDULER_RECORD_START_ADDRESS, sizeof(DG_SCHEDULER_RECORD_T), MAX_RTC_RAM_OPS_BUFFER_BYTES} // NVDATAMGMT_PROCESS_SCHEDULER_RECORD + {BANK7_SECTOR0_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_CALIBRATION_RECORD_T), (U08*)&dgCalibrationRecord, (U08*)&(dgCalibrationRecord.crc)}, // NVDATAMGMT_CALIBRATION_RECORD + {SYSTEM_DATA_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_SYSTEM_GROUP_T), (U08*)&dgSystemGroup, (U08*)&dgSystemGroup.crc}, // NVDATAMGMT_SYSTEM_RECORD + {LAST_SERVICE_RECORD_START_ADDRESS, sizeof(DG_LAST_SERVICE_RECORD_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, 0, 0}, // NVDATAMGMT_PROCESS_LAST_SERVICE_RECORD + {DG_SCHEDULER_RECORD_START_ADDRESS, sizeof(DG_SCHEDULER_RECORD_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, 0, 0} // NVDATAMGMT_SCHEDULER_RECORD +}; +#else if _HD_ +static HD_CALIBRATION_RECORD_T hdCalibrationRecord; ///< HD calibration record. #endif - }; - -// Calibration variables -static PROCESS_RECORD_STATE_T NVDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; ///< NVDataMgmt exec process record state. -static DG_CALIBRATION_RECORD_T dgCalibrationRecord; ///< DG calibration record. -static RECEIVE_RECORD_STATE_T NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; ///< NVDataMgmt exec receive record state. -static BOOL isPublishCalRequested = FALSE; ///< Calibration state machine flag. +static RECORD_JOBS_STATE_T recordToPublish; ///< Record to publish (i.e. calibration, system) +static PROCESS_RECORD_STATE_T nvDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; ///< NVDataMgmt exec process record state. +static RECEIVE_RECORD_STATE_T nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; ///< NVDataMgmt exec receive record state. +static BOOL hasPublishRecordBeenRequested = FALSE; ///< Record state machine publish request flag. static U32 calPublishMessageCount = 1; ///< Calibration data publish message counter. static U32 calPublishTotalMessages = 1; ///< Calibration data total number of messages to be sent. static U32 calSendDataIntervalCounter = 0; ///< Calibration data send to CAN bust interval counter. static U32 previousCalMessageNum = 0; ///< Calibration previous message number. -static U32 dgCalRecordUpdateAddress = 0; ///< DG calibration record update address. +static U32 recordUpdateAddress = 0; ///< DG record update address for all the write operations. static U32 calDataReceiveStartTime = 0; ///< Time stamp the calibration/service was received. static PROCESS_RECORD_JOB_T recordJobQueue[ QUEUE_MAX_SIZE ]; ///< Record queue jobs. static U08 recordQueueRearIndex; ///< Record queue rear index. @@ -385,6 +400,7 @@ static BOOL calRecordIsValid = FALSE; ///< Flag indicates whether stored calibration record was found to be valid. static volatile BOOL powerOffIsImminent = FALSE; ///< Power off warning has been signaled. Non-volatile memory operations should be completed ASAP and then ceased. + // *** This declaration will cause a compiler error if CALIBRATION_DATA_T record size exceeds max message payload size. U08 calRecordSizeAssertion[ ( sizeof( CALIBRATION_DATA_T ) <= MAX_MSG_PAYLOAD_SIZE ? 1 : -1 ) ]; //TODO remove @@ -451,17 +467,18 @@ NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_START; NVDataMgmtExecState = NVDATAMGMT_EXEC_STATE_WAIT_FOR_POST; NVDataMgmtSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; - NVDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; - NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + nvDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; + nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; queueRearIndex = QUEUE_START_INDEX; queueFrontIndex = QUEUE_START_INDEX; queueCount = 0; - dgCalRecordUpdateAddress = 0; + recordUpdateAddress = 0; recordQueueRearIndex = QUEUE_START_INDEX; recordQueueFrontIndex = QUEUE_START_INDEX; recordQueueCount = 0; recordAddressOffset = 0; writtenRecordStatus = NVDATAMGMT_RECORD_NOT_CHECKED; + hasPublishRecordBeenRequested = FALSE; // Initialize and activate the flash bank 7 Fapi_initializeFlashBanks( ROUNDED_HCLK_FREQ ); @@ -650,49 +667,47 @@ /*********************************************************************//** * @brief - * The execNVDataMgmtSendRecord runs the NVDataMgmt send records related + * The execNVDataMgmtProcessRecord runs the NVDataMgmt send records related * tasks. - * @details Inputs: NVDataMgmtExecCalState - * @details Outputs: NVDataMgmtExecCalState, alarm if exec state was invalid + * @details Inputs: nvDataMgmtExecProcessRecordState + * @details Outputs: nvDataMgmtExecProcessRecordState * @return none *************************************************************************/ -void execNVDataMgmtSendRecord( void ) +void execNVDataMgmtProcessRecord( void ) { - switch ( NVDataMgmtExecProcessRecordState ) + switch ( nvDataMgmtExecProcessRecordState ) { case NVDATAMGMT_PROCESS_RECORD_STATE_IDLE: - NVDataMgmtExecProcessRecordState = handleExecProcessRecordIdleState(); + nvDataMgmtExecProcessRecordState = handleExecProcessRecordIdleState(); break; case NVDATAMGMT_PROCESS_RECORD_STATE_SEND_RECORD: - NVDataMgmtExecProcessRecordState = handleExecProcessRecordSendRecordState(); + nvDataMgmtExecProcessRecordState = handleExecProcessRecordSendRecordState(); break; default: #ifdef _DG_ - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NVDATAMGMT_EXEC_CAL_STATE, - NVDataMgmtExecProcessRecordState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NVDATAMGMT_EXEC_CAL_STATE, nvDataMgmtExecProcessRecordState ); #else - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NVDATAMGMT_EXEC_CAL_STATE, - NVDataMgmtExecProcessRecordState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NVDATAMGMT_EXEC_CAL_STATE, nvDataMgmtExecProcessRecordState ); #endif - NVDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; + nvDataMgmtExecProcessRecordState = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; break; } // Check if the exec receive records is not idle - if ( NVDataMgmtExecReceiveRecordState != NVDATAMGMT_RECEIVE_RECORD_IDLE ) + if ( nvDataMgmtExecReceiveRecordState != NVDATAMGMT_RECEIVE_RECORD_IDLE ) { // Check if the data receiving process has timed out. The exec receive record // state machine is asynchronous so it is checked in this state machine if ( didTimeout( calDataReceiveStartTime, CAL_DATA_RECEIVE_TIMEOUT_MS ) ) { // exec receive state machine timed out. Schedule a read to update the structure - enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_READ_CALIBRATION_RECORD ); - NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; } } } @@ -701,18 +716,19 @@ * @brief * The getDGCalibrationRecord function sets the calibration state machine * to read and publish calibration record. - * @details Inputs: isPublishCalRequested, NVDataMgmtExecCalState - * @details Outputs: isPublishCalRequested + * @details Inputs: hasPublishRecordBeenRequested, NVDataMgmtExecCalState + * @details Outputs: hasPublishRecordBeenRequested * @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 ) + if ( nvDataMgmtExecProcessRecordState == NVDATAMGMT_PROCESS_RECORD_STATE_IDLE ) { - isPublishCalRequested = TRUE; + hasPublishRecordBeenRequested = TRUE; + recordToPublish = NVDATAMGMT_CALIBRATION_RECORD; status = TRUE; } @@ -723,10 +739,8 @@ * @brief * The setCalibrationRecord function writes the calibration record that * is received from Dialin into the calibration structure. - * @details Inputs: previousCalMessageNum, dgCalRecordUpdateAddress, - * calDataReceiveTime - * @details Outputs: previousCalMessageNum, dgCalRecordUpdateAddress, - * calDataReceiveTime + * @details Inputs: none + * @details Outputs: none * @param currentMessage: current message number that is received from * Dialin * @param totalMessages: total number of messages from Dialin @@ -740,47 +754,145 @@ BOOL status = TRUE; // If the calibration message number is the first message number and receive exec state is idle, switch to idle - if ( CAL_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage && NVDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_IDLE ) + if ( CAL_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage && nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_IDLE ) { - NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; + nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; calDataReceiveStartTime = getMSTimerCount(); previousCalMessageNum = 0; - dgCalRecordUpdateAddress = 0; + recordUpdateAddress = 0; } // Check if there is still a message left to be received - if ( NVDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_RECEIVE && currentMessage <= totalMessages ) + if ( nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_RECEIVE && currentMessage <= totalMessages ) { // Check if the current message is different from the previous message by 1 if ( CAL_DATA_MAX_MESSAGE_DFFIRENCE == ( currentMessage - previousCalMessageNum ) ) { -#ifdef _DG_ // Define a pointer that points to the DG calibration record - U08* ptr = (U08*)&dgCalibrationRecord; -#else if _HD_ - // TODO add HD -#endif + 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 += dgCalRecordUpdateAddress; + 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 ) { -#ifdef _DG_ + 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(); + + // 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 getSystemRecord function sets the system state machine + * to read and publish system record. + * @details Inputs: hasPublishRecordBeenRequested, NVDataMgmtExecCalState + * @details Outputs: hasPublishRecordBeenRequested + * @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: none + * @details Outputs: none + * @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 ( CAL_DATA_FIRST_RECEIVING_MSG_NUM == currentMessage && nvDataMgmtExecReceiveRecordState == NVDATAMGMT_RECEIVE_RECORD_IDLE ) + { + nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_RECEIVE; + calDataReceiveStartTime = 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 ( CAL_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 calcCRC = crc16 ( (U08*)&dgCalibrationRecord, sizeof(DG_CALIBRATION_RECORD_T) - sizeof(dgCalibrationRecord.crc) ); - U16 recordCRC = dgCalibrationRecord.crc; -#else if _HD_ - // TODO add HD -#endif + 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_READ_CALIBRATION_RECORD ); - NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; status = FALSE; } else @@ -789,13 +901,13 @@ BOOL scheduleStatus = enqueueSector0Records(); // Done with receiving data, go back to idle - NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; + nvDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; } } else { // Update the length as it has successfully been written - dgCalRecordUpdateAddress += length; + recordUpdateAddress += length; // Now the current message is the previous message previousCalMessageNum = currentMessage; @@ -808,16 +920,15 @@ /*********************************************************************//** * @brief - * The getDGPressureSensorsCalibrationRecord function copies the DG pressure - * sensors calibration record into a buffer. + * The getDGPressureSensorsCalibrationRecord function returns the DG pressure + * sensors structure. * @details Inputs: none * @details Outputs: none - * @param buffer: address to the buffer to copy the data into it - * @return none + * @return DG pressure sensors calibration structure *************************************************************************/ -void getDGPressureSensorsCalibrationRecord( U08* buffer ) +DG_PRES_SENSORS_CAL_RECORD_T getDGPressureSensorsCalibrationRecord( void ) { - //memcpy( buffer, &dgCalibrationRecord.presSensorsCalRecord, sizeof(dgCalibrationRecord.presSensorsCalRecord)); + return dgCalibrationRecord.dgCalibrationGroups.presSensorsCalRecord; } void getDGFlowSensorsCalibrationRecord( U08* buffer ) @@ -1625,8 +1736,17 @@ location = recordCurrentJob.memoryLocation; currentTime = getMSTimerCount(); startAddress = jobSpecs.startAddress + recordAddressOffset; - bufferAddress = (U08*)&dgCalibrationRecord + recordAddressOffset; - maxBufferLength = jobSpecs.maxBufferSize; + bufferAddress = jobSpecs.structAddressPtr + recordAddressOffset; + + // Choose the right buffer size + if ( ops == NVDATAMGMT_WRITE ) + { + maxBufferLength = jobSpecs.maxWriteBufferSize; + } + else if ( ops == NVDATAMGMT_READ ) + { + maxBufferLength = jobSpecs.maxReadBufferSize; + } } // Check if a queue job is available @@ -1734,8 +1854,8 @@ // Clear the buffer from the previous content memset( writtenRecordCheckBuffer, 0, sizeof(writtenRecordCheckBuffer)); - // Issue a FAPI read command - Fapi_doMarginRead ( (U32*)startAddress, (U32*)writtenRecordCheckBuffer, jobSpecs.maxBufferSize, Fapi_NormalRead ); + // Issue a FAPI read command but only the bytes that were written, so use maxWriteBufferSize + Fapi_doMarginRead ( (U32*)startAddress, (U32*)writtenRecordCheckBuffer, jobSpecs.maxWriteBufferSize, Fapi_NormalRead ); state = NVDATAMGMT_EXEC_STATE_VERIFY_WRITE; } @@ -1750,12 +1870,13 @@ { // Update the variables and issue the next write command currentTime = getMSTimerCount(); - recordAddressOffset += jobSpecs.maxBufferSize; + recordAddressOffset += jobSpecs.maxWriteBufferSize; U32 memoryPtr = jobSpecs.startAddress + recordAddressOffset; - U08* structPtr = (U08*)&dgCalibrationRecord + recordAddressOffset; - writtenRecordStatus = NVDATAMGMT_RECORD_NOT_CHECKED; + U08* structPtr = jobSpecs.structAddressPtr + recordAddressOffset; - Fapi_issueProgrammingCommand ( (U32*)memoryPtr, structPtr, jobSpecs.maxBufferSize, 0x00, 0, Fapi_DataOnly ); + writtenRecordStatus = NVDATAMGMT_RECORD_NOT_CHECKED; + // Issue the write command + Fapi_issueProgrammingCommand ( (U32*)memoryPtr, structPtr, jobSpecs.maxWriteBufferSize, 0x00, 0, Fapi_DataOnly ); } } } @@ -1788,38 +1909,33 @@ // Check if the write job is EEPROM or RTC RAM if ( recordCurrentJob.memoryLocation == NVDATAMGMT_EEPROM && FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { - // Check if the job is write calibration or system record - if ( job == NVDATAMGMT_WRITE_CALIBRATION_RECORD ) - { - U32 i; - // Set the buffer pointer to beginning of the bytes that were written and needs to be checked - U08* bufferPtr = (U08*)&dgCalibrationRecord + recordAddressOffset; + U32 i; + U08* bufferPtr = jobSpecs.structAddressPtr + recordAddressOffset; - // Loop through the bytes in the buffer - for ( i = 0; i < jobSpecs.maxBufferSize; i++ ) + // Loop through the bytes in the buffer + for ( i = 0; i < jobSpecs.maxWriteBufferSize; i++ ) + { + // Check if data in the buffer is not the same as the data in the structure + if ( writtenRecordCheckBuffer[ i ] != *bufferPtr ) { - // Check if data in the buffer is not the same as the data in the structure - if ( writtenRecordCheckBuffer[ i ] != *bufferPtr ) - { - // Data is not valid. Schedule an erase and write of the calibration record since only a part of - // data cannot be written to EEPROM. - writtenRecordStatus = NVDATAMGMT_RECORD_NOT_VALID; - enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_CALIBRATION_RECORD ); - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_CALIBRATION_RECORD ); - state = NVDATAMGMT_EXEC_STATE_IDLE; - // Exit the loop since there is no point to check the rest of data - break; - } - else - { - // Everything is good increment the pointer to check the next byte. - bufferPtr++; - // Record data is valid so far - writtenRecordStatus = NVDATAMGMT_RECORD_VALID; - // Go back write to EEPROM state to continue writing the record data - state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; - } + // Data is not valid. Schedule an erase and write of the calibration record since only a part of + // data cannot be written to EEPROM. + writtenRecordStatus = NVDATAMGMT_RECORD_NOT_VALID; + enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + state = NVDATAMGMT_EXEC_STATE_IDLE; + // Exit the loop since there is no point to check the rest of data + break; } + else + { + // Everything is good increment the pointer to check the next byte. + bufferPtr++; + // Record data is valid so far + writtenRecordStatus = NVDATAMGMT_RECORD_VALID; + // Go back write to EEPROM state to continue writing the record data + state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; + } } } @@ -1841,7 +1957,8 @@ if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady || timeoutStatus == TRUE ) { - currentJob.externalAddress->status = NVDATAMGMT_READ_COMPLETE; + // TODO bring this back for logging + //currentJob.externalAddress->status = NVDATAMGMT_READ_COMPLETE; state = NVDATAMGMT_EXEC_STATE_IDLE; } @@ -1920,24 +2037,29 @@ * @brief * The handleExecProcessRecordIdleState handles the idle state of the * exec cal state machine. - * @details Inputs: isPublishCalRequested, isPublishCalRequested, - * calPublishTotalMessages, calPublishMessageCount, calSendDataIntervalCounter - * @details Outputs: isPublishCalRequested, calPublishTotalMessages, + * @details Inputs: hasPublishRecordBeenRequested,calPublishTotalMessages, * calPublishMessageCount, calSendDataIntervalCounter + * @details Outputs: hasPublishRecordBeenRequested, calPublishTotalMessages, + * calPublishMessageCount, calSendDataIntervalCounter * @return next state of the state machine *************************************************************************/ static PROCESS_RECORD_STATE_T handleExecProcessRecordIdleState( void ) { PROCESS_RECORD_STATE_T state = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; - if ( isPublishCalRequested ) + if ( hasPublishRecordBeenRequested ) { - // Set the calibration flag to FALSE - isPublishCalRequested = FALSE; + // Set the publish flag to FALSE + hasPublishRecordBeenRequested = FALSE; + + // Get the record specifications to find the size of the job + PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS [ recordToPublish ]; + // Calculate the total number of messages required to be sent using ceilf function. This function rounds up the // value and its result is converted to U32. - calPublishTotalMessages = (U32)ceilf( (F32)sizeof( DG_CALIBRATION_RECORD_T ) / (F32)NUM_OF_BYTES_PER_CAL_PAYLOAD ); - calPublishMessageCount = 0; + calPublishTotalMessages = (U32)ceilf( (F32)recordSpec.sizeofJob / (F32)NUM_OF_BYTES_PER_CAL_PAYLOAD ); + calPublishMessageCount = 0; + // Time interval in between data to be sent. It is set to the interval count so on the first call // of the send calibration record function, the first packet of data is sent calSendDataIntervalCounter = CAL_DATA_SEND_INTERVAL_COUNT; @@ -1970,20 +2092,44 @@ { // Set to default cal data payload length U32 length = NUM_OF_BYTES_PER_CAL_PAYLOAD; - U08* startPtr = (U08*)&dgCalibrationRecord; + PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS [ recordToPublish ]; + U08* startPtr = recordSpec.structAddressPtr; + // If this is the last calibration data payload, calculate the remainder of the bytes to send if ( ( calPublishMessageCount + 1 ) == calPublishTotalMessages ) { - length = sizeof( DG_CALIBRATION_RECORD_T ) - ( calPublishMessageCount * NUM_OF_BYTES_PER_CAL_PAYLOAD ); + length = recordSpec.sizeofJob - ( calPublishMessageCount * NUM_OF_BYTES_PER_CAL_PAYLOAD ); } // Find the new location of the pointer which is the start of the calibration payload to be sent startPtr += calPublishMessageCount * NUM_OF_BYTES_PER_CAL_PAYLOAD; - // Pass the information to be written to CAN bus - sendDGCalibrationRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); + switch( recordToPublish ) + { + case NVDATAMGMT_CALIBRATION_RECORD: + // Pass the information to be written to CAN bus + sendDGCalibrationRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); + break; + case NVDATAMGMT_SYSTEM_RECORD: + // Pass the information to be written to CAN bus + sendDGSystemRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); + break; + + case NVDATAMGMT_LAST_SERVICE_RECORD: + break; + + case NVDATAMGMT_SCHEDULER_RECORD: + break; + + default: + //Ignore + break; + } + + + calPublishMessageCount++; calSendDataIntervalCounter = 0; } @@ -2469,9 +2615,9 @@ if ( getAvailableRecordQueueCount() >= MIN_JOBS_NEEDED_FOR_SECTOR_0 ) { - enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_CALIBRATION_RECORD ); - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_CALIBRATION_RECORD ); - // TODO schedule systems record + enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_CALIBRATION_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_SYSTEM_RECORD ); status = TRUE; } Index: NVDataMgmt.h =================================================================== diff -u -r0df8e5e99715de10f8936a9d41c28f4c2a4dacc6 -r45f39d237e109f91b4b7e40fdb2dc00bd673eef0 --- NVDataMgmt.h (.../NVDataMgmt.h) (revision 0df8e5e99715de10f8936a9d41c28f4c2a4dacc6) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision 45f39d237e109f91b4b7e40fdb2dc00bd673eef0) @@ -75,11 +75,11 @@ /// DG pressure sensors enumeration. typedef enum dg_pressure_sensors { - CAL_DATA_RO_PUMP_INLET_PRES_SENSOR = 0, - CAL_DATA_RO_PUMP_OUTLET_PRES_SENSOR, - CAL_DATA_DRAIN_PUMP_INLET_PRES_SENSOR, - CAL_DATA_DRAIN_PUMP_OUTLET_PRES_SENSOR, - NUM_OF_CAL_DATA_PRES_SENSORS, + CAL_DATA_RO_PUMP_INLET_PRES_SENSOR = 0, ///< DG calibration data RO pump inlet pressure sensor. + CAL_DATA_RO_PUMP_OUTLET_PRES_SENSOR, ///< DG calibration data RO pump outlet pressure sensor. + CAL_DATA_DRAIN_PUMP_INLET_PRES_SENSOR, ///< DG calibration data drain pump inlet pressure sensor. + CAL_DATA_DRAIN_PUMP_OUTLET_PRES_SENSOR, ///< DG calibration data drain pump outlet pressure sensor. + NUM_OF_CAL_DATA_PRES_SENSORS, ///< Number of calibration data pressure sensors. } CAL_DATA_DG_PRES_SENSORS_T; /// DG flow sensors enumeration. @@ -147,6 +147,26 @@ NUM_OF_CAL_DATA_RSRVRS } CAL_DATA_DG_RESERVOIRS_T; +typedef enum dg_acid_concentrate +{ + CAL_DATA_ACID_CONCENTRATE_1 = 0, + CAL_DATA_ACID_CONCENTRATE_2, + CAL_DATA_ACID_CONCENTRATE_3, + CAL_DATA_ACID_CONCENTRATE_4, + CAL_DATA_ACID_CONCENTRATE_5, + NUM_OF_CAL_DATA_ACID_CONCENTRATES +} CAL_DATA_DG_ACID_CONCENTRATE_T; + +typedef enum dg_bicarb_concentrate +{ + CAL_DATA_BICARB_CONCENTRATE_1 = 0, + CAL_DATA_BICARB_CONCENTRATE_2, + CAL_DATA_BICARB_CONCENTRATE_3, + CAL_DATA_BICARB_CONCENTRATE_4, + CAL_DATA_BICARB_CONCENTRATE_5, + NUM_OF_CAL_DATA_BICARB_CONCENTRATES +} CAL_DATA_DG_BICARB_CONCENTRATE_T; + #pragma pack(push, 1) /// Payload record structure for a linear calibration message. TODO remove typedef struct @@ -183,7 +203,6 @@ } DG_DRAIN_PUMP_CAL_RECORD_T; /// DG RO pump calibration structure. -// TODO make this more specific once more data was defined by the systems team typedef struct { F32 gain1Ratio; @@ -196,78 +215,170 @@ /// Pressure sensors calibration structure typedef struct { - LINEAR_CAL_PAYLOAD_T pressureSensors[ NUM_OF_CAL_DATA_PRES_SENSORS ]; ///< Pressure sensors to calibrate + LINEAR_CAL_PAYLOAD_T pressureSensors[ NUM_OF_CAL_DATA_PRES_SENSORS ]; ///< Pressure sensors to calibrate. // NOTE: The reserved space is for 6 sensors. This portion of the struct should be eventually be // reduced, so #define was not used for the size of the array - LINEAR_CAL_PAYLOAD_T reservedSpace[ 6 ]; ///< Reserved space for future pressure sensors + LINEAR_CAL_PAYLOAD_T reservedSpace[ 6 ]; ///< Reserved space for future pressure sensors. } DG_PRES_SENSORS_CAL_RECORD_T; /// Flow sensors calibration structure typedef struct { - LINEAR_CAL_PAYLOAD_T flowSensors[ NUM_OF_CAL_DATA_FLOW_SENSORS ]; ///< Flow sensors to calibrate + LINEAR_CAL_PAYLOAD_T flowSensors[ NUM_OF_CAL_DATA_FLOW_SENSORS ]; ///< Flow sensors to calibrate. // NOTE: The reserved space is for 6 sensors. This portion of the struct should be eventually be // reduced, so #define was not used for the size of the array - LINEAR_CAL_PAYLOAD_T reservedSpace[ 3 ]; ///< Reserved space for future flow sensors + LINEAR_CAL_PAYLOAD_T reservedSpace[ 3 ]; ///< Reserved space for future flow sensors. } DG_FLOW_SENSORS_CAL_RECORD_T; /// Load cells calibration structure typedef struct { - LINEAR_CAL_PAYLOAD_T loadCells[ NUM_OF_CAL_DATA_LOAD_CELLS ]; ///< Load cells to calibrate + LINEAR_CAL_PAYLOAD_T loadCells[ NUM_OF_CAL_DATA_LOAD_CELLS ]; ///< Load cells to calibrate. } DG_LOAD_CELLS_CAL_RECORD_T; /// Temperature sensors calibration structure typedef struct { - LINEAR_CAL_PAYLOAD_T tempSensors[ NUM_OF_CAL_DATA_TEMP_SENSORS ]; ///< Temperature sensors to calibrate + LINEAR_CAL_PAYLOAD_T tempSensors[ NUM_OF_CAL_DATA_TEMP_SENSORS ]; ///< Temperature sensors to calibrate. // NOTE: The reserved space is for 6 sensors. This portion of the struct should be eventually be // reduced, so #define was not used for the size of the array - LINEAR_CAL_PAYLOAD_T reservedSpace[ 5 ]; ///< Reserved space for future temp sensors + LINEAR_CAL_PAYLOAD_T reservedSpace[ 5 ]; ///< Reserved space for future temperature sensors. } DG_TEMP_SENSORS_CAL_RECORD_T; /// Conductivity sensors calibration structure typedef struct { - LINEAR_CAL_PAYLOAD_T condSensors[ NUM_OF_CAL_DATA_COND_SENSORS ]; ///< Conductivity sensors to calibrate + LINEAR_CAL_PAYLOAD_T condSensors[ NUM_OF_CAL_DATA_COND_SENSORS ]; ///< Conductivity sensors to calibrate. // NOTE: The reserved space is for 6 sensors. This portion of the struct should be eventually be // reduced, so #define was not used for the size of the array - LINEAR_CAL_PAYLOAD_T reservedSpace[ 2 ]; ///< Reserved space for future conductivity sensors + LINEAR_CAL_PAYLOAD_T reservedSpace[ 2 ]; ///< Reserved space for future conductivity sensors. } DG_COND_SENSORS_CAL_RECORD_T; +/// Drain line volume calibration structure typedef struct { - F32 volume; - U32 calibrationTime; - U16 crc; + F32 volume; ///< DG Drain line volume. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. } DG_DRAIN_LINE_VOLUME_T; +/// DG pre RO purge volume calibration structure typedef struct { - F32 pressure2FlowRatio; - F32 volume; - U32 calibrationTime; - U16 crc; + F32 pressure2FlowRatio; ///< Pressure to flow ratio. + F32 volume; ///< Volume. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. } DG_PRE_RO_PURGE_VOLUME_T; +/// DG reservoir volume calibration structure typedef struct { - F32 rsrvrVolume; - F32 normalFillVolume; - F32 maxResidualFluid; - F32 rsrvrUnfilledWeight; - U32 calibrationTime; - U16 crc; + F32 rsrvrVolume; ///< Reservoir volume. + F32 normalFillVolume; ///< Normal fill volume. + F32 maxResidualFluid; ///< Max residual fluid. + F32 rsrvrUnfilledWeight; ///< Reservoir unfilled weight. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. } DG_RESERVOIR_VOLUME_T; +/// DG generic volumes (reserved space) typedef struct { - F32 volume; - U32 calibrationTime; - U16 crc; + F32 volume; ///< Volume. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. } DG_GENERIC_VOLUME_T; -/// Manufacturing data structure. +/// DG acid concentrate +typedef struct +{ + F32 acidConcMixRatio; ///< Acid concentrate mix ratio. + F32 startVolume; ///< Start volume. + F32 reserverdSpace; ///< Reserved space. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. +} DG_ACID_CONCENTRATE_T; + +/// DG bicarb concentrate +typedef struct +{ + F32 bicarbConcMixRatio; ///< Bicarb concentrate mix ratio. + F32 startVolume; ///< Start volume. + F32 reservedSpace; ///< Reserved space. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. +} DG_BICARB_CONCENTRATE_T; + +/// DG acid concentrates +typedef struct +{ + DG_ACID_CONCENTRATE_T acidConcentrate[ NUM_OF_CAL_DATA_ACID_CONCENTRATES ]; ///< DG acid concentrates. +} DG_ACID_CONCENTRATES_T; + +/// DG bicarb concentrates +typedef struct +{ + DG_BICARB_CONCENTRATE_T bicarbConcentrate[ NUM_OF_CAL_DATA_BICARB_CONCENTRATES ]; ///< DG bicarb concentrates. +} DG_BICARB_CONCENTRATES_T; + +/// DG filter calibration record +typedef struct +{ + F32 reservedSpace1; ///< DG filter reserved space 1. + F32 reservedSpace2; ///< DG filter reserved space 2. + F32 reservedSpace3; ///< DG filter reserved space 3 + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. +} DG_FILTER_CAL_RECORD_T; + +/// DG filters calibration data structure +typedef struct +{ + DG_FILTER_CAL_RECORD_T roFilter; ///< RO filter. + DG_FILTER_CAL_RECORD_T ultraFilter; ///< Ultra filter. + DG_FILTER_CAL_RECORD_T sedimentFilter; ///< Sediment filter. + DG_FILTER_CAL_RECORD_T carbonFilter; ///< Carbon filter. + DG_FILTER_CAL_RECORD_T carbonPolishFilter; ///< Carbon polish filter. +} DG_FILTERS_CAL_RECORD_T; + +/// DG fan calibration data structure +typedef struct +{ + F32 reservedSpace1; ///< Reserved space 1. + F32 reservedSpace2; ///< Reserved space 2. + U32 calibrationTime; ///< Calibration time. + U16 crc; ///< CRC. +} DG_FAN_CAL_RECORD_T; + +/// DG fans calibration data structure +typedef struct +{ + DG_FAN_CAL_RECORD_T fan1; ///< Fan 1. + DG_FAN_CAL_RECORD_T fan2; ///< Fan 2. +} DG_FANS_CAL_RECORD_T; + +/// DG systems record structure +typedef struct +{ + char topLevelPN[ MAX_TOP_LEVEL_PN_CHARS ]; ///< DG top level part number. + char topLevelSN[ MAX_TOP_LEVEL_SN_CHARS ]; ///< DG top level serial number. + MFG_LOCATION_T mfgLocation; ///< DG manufacturing location. + U32 mfgDate; ///< DG manufacturing date. + U16 crc; ///< CRC for the DG system record structure. +} DG_SYSTEM_RECORD_T; + +/// DG last service record structure +typedef struct +{ + LAST_SERVICE_LOCATION_T lastServiceLoc; ///< DG last service location. + U32 lastServiceDate; ///< DG last service date. + U16 crc; ///< CRC for the DG last service record structure. +} DG_LAST_SERVICE_RECORD_T; + + +/********************** OLD STRUCTS REMOVE ******************/ +/// Manufacturing data structure. TODO remove typedef struct mfg_Data { char SYSSerialNumber [ MAX_TOP_LEVEL_PN_CHARS ]; ///< SYS serial number. @@ -293,12 +404,13 @@ char calDateAccel[ MAX_DATE_CHARACTERS ]; ///< Last calibration date of accelerometer } CALIBRATION_DATA_T; -/// Service dates structure. +/// Service dates structure. TODo remove typedef struct service_dates { char currentServiceDate [ MAX_DATE_CHARACTERS ]; ///< Current service date char nextServiceDate [ MAX_DATE_CHARACTERS ]; ///< Next service date } SERVICE_DATA_T; +/********************** OLD STRUCTS REMOVE ******************/ /// Read data status structure. typedef struct get_data @@ -326,8 +438,6 @@ char disinfectionDate [ MAX_DATE_CHARACTERS ]; ///< Disinfection Date } DISINFECTION_DATE_T; - - #pragma pack(pop) void initNVDataMgmt ( void ); @@ -338,14 +448,15 @@ SELF_TEST_STATUS_T execNVDataMgmtSelfTest ( void ); -void execNVDataMgmtSendRecord( void ); +void execNVDataMgmtProcessRecord( void ); BOOL getCalibrationRecord( void ); - BOOL setCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); -void getDGPressureSensorsCalibrationRecord( U08* buffer ); +BOOL getSystemRecord( void ); +BOOL setSystemRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); +DG_PRES_SENSORS_CAL_RECORD_T getDGPressureSensorsCalibrationRecord( void ); void getDGFlowSensorsCalibrationRecord( U08* buffer ); BOOL setBootloaderFlag ( U32 flag );