Index: NVDataMgmt.c =================================================================== diff -u -r32d19410fc08e86e4503f6e8af5470170bb72cdf -r0df8e5e99715de10f8936a9d41c28f4c2a4dacc6 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 32d19410fc08e86e4503f6e8af5470170bb72cdf) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 0df8e5e99715de10f8936a9d41c28f4c2a4dacc6) @@ -23,6 +23,7 @@ #include "system.h" #include "F021.h" +#include "ConcentratePumps.h" #include "MsgQueues.h" #include "NVDataMgmt.h" #include "RTC.h" @@ -92,20 +93,17 @@ #define ERASE_CALIBRATION_KEY 0xD2C3B4A5 ///< 32-bit key required for clearing calibration data. // ********** Calibration data defines ********** -#define NUM_OF_CONCENTRATE_PUMPS 2U ///< Number of concentrate pumps. #define NUM_OF_BYTES_PER_CAL_PAYLOAD 150U ///< Number of bytes per calibration payload. #define CAL_DATA_SEND_INTERVAL_COUNT ( MS_PER_SECOND / ( 5 * TASK_GENERAL_INTERVAL ) ) ///< Calibration data send time interval in counts. #define CAL_DATA_RECEIVE_TIMEOUT_MS ( 4 * MS_PER_SECOND ) ///< Calibration data receive all the data packets timeout in ms. #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_STRUCTS_SIZE ( sizeof(DG_PRES_SENSORS_CAL_RECORD_T) + sizeof(DG_FLOW_SENSORS_CAL_RECORD_T) + \ - sizeof(DG_LOAD_CELLS_CAL_RECORD_T) + sizeof(DG_TEMP_SENSORS_CAL_RECORD_T) + \ - sizeof(DG_COND_SENSORS_CAL_RECORD_T) + sizeof(U16) ) ///< DG calibration data structure size (without padding). +#define DG_CAL_RECORD_BYTE_SIZE ( sizeof(DG_CALIBRATION_GROUPS_T) + sizeof(U16) ) // 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_STRUCTS_SIZE % MAX_EEPROM_WRITE_BUFFER_BYTES == 0 ? \ - 0 : ((U32)(DG_CAL_STRUCTS_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_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. /// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States @@ -176,17 +174,12 @@ /// NVDataMgmt records' jobs states typedef enum NVDataMgmt_Records_Jobs { - NVDATAMGMT_WRITE_DG_CALIBRATION_RECORD = 0, ///< NVDataMgmt process DG write calibration record. - NVDATAMGMT_WRITE_DG_SYSTEM_RECORD, ///< NVDataMgmt process DG write system record. - NVDATAMGMT_READ_DG_CALIBRATION_RECORD, ///< NVDataMgmt process DG read calibration record. - NVDATAMGMT_READ_DG_SYSTEM_RECORD, ///< NVDataMgmt process DG read system record. - NVDATAMGMT_PROCESS_DG_LAST_SERVICE_RECORD, ///< NVDATAMgmt process DG last service record. - NVDATAMGMT_PROCESS_DG_SCHEDULER_RECORD, ///< NVDataMgmt process DG scheduler record. - NVDATAMGMT_WRITE_HD_CALIBRATION_RECORD, ///< NVDataMgmt process HD write calibration record. - NVDATAMGMT_WRITE_HD_SYSTEM_RECORD, ///< NVDataMgmt process HD write system record. - NVDATAMGMT_READ_HD_CALIBRATION_RECORD, ///< NVDataMgmt process HD read calibration record. - NVDATAMGMT_READ_HD_SYSTEM_RECORD, ///< NVDataMgmt process HD read system record. - NVDATAMGMT_PROCESS_HD_SCHEDULER_RECORD, ///< NVDataMgmt process HD scheduler record. + 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. NUM_OF_NVDATMGMT_RECORDS_JOBS ///< Number of NVDataMgmt records jobs. } RECORD_JOBS_STATE_T; @@ -289,87 +282,46 @@ // ********** Calibration data struts ********** -/// Pressure sensors calibration structure typedef struct { - 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 -} 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 - // 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 -} 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 -} 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 - // 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 -} 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 - // 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 -} DG_COND_SENSORS_CAL_RECORD_T; - -/// DG pumps calibration structure -typedef struct -{ - // Enum was not used for this array because the DG pumps enum contain DG and RO pumps too - DG_CONCENTRATE_PUMPS_PAYLOAD_T concentratePump[ NUM_OF_CONCENTRATE_PUMPS ]; ///< Concentrate pumps ratios - DG_DRAIN_PUMP_PAYLOAD_T drainPump; ///< Drain pump ratios - DG_RO_PUMP_PAYLOAD_T roPump; ///< RO pump ratios (unknown for now) -} DG_PUMPS_CAL_RECORD_T; - -// TODO add more calibration data -/// DG calibration records structure -typedef struct -{ DG_PRES_SENSORS_CAL_RECORD_T presSensorsCalRecord; ///< DG pressure sensors. DG_FLOW_SENSORS_CAL_RECORD_T flowSensorsCalRecord; ///< DG flow sensors. DG_LOAD_CELLS_CAL_RECORD_T loadCellsCalRecord; ///< DG load cells. DG_TEMP_SENSORS_CAL_RECORD_T tempSensorsCalRecord; ///< DG temperature sensors. DG_COND_SENSORS_CAL_RECORD_T condSensorsCalRecord; ///< DG conductivity sensors. - //DG_PUMPS_CAL_RECORD_T pumpsCalRecord; ///< DG pumps. - U08 padding[ DG_PADDING_LENGTH - DG_CAL_STRUCTS_SIZE ]; ///< DG calibration record padding byte array. + 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_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. U16 crc; ///< CRC for the DG calibration record structure. } DG_CALIBRATION_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. + 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. + 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; /// DG scheduler record structure @@ -381,12 +333,14 @@ // Process records specifications const PROCESS_RECORD_SPECS_T RECORDS_SPECS [ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { - {BANK7_SECTOR0_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES}, // NVDATAMGMT_WRITE_DG_CALIBRATION_RECORD - {SYSTEM_DATA_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES}, // NVDATAMGMT_WRITE_DG_SYSTEM_RECORD - {BANK7_SECTOR0_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), sizeof(DG_CALIBRATION_RECORD_T)}, // NVDATAMGMT_READ_DG_CALIBRATION_RECORD - {SYSTEM_DATA_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_RECORD_T), sizeof(DG_SYSTEM_RECORD_T)}, // NVDATAMGMT_READ_DG_SYSTEM_RECORD - {LAST_SERVICE_RECORD_START_ADDRESS, sizeof(DG_LAST_SERVICE_RECORD_T), MAX_RTC_RAM_OPS_BUFFER_BYTES}, // NVDATAMGMT_PROCESS_DG_LAST_SERVICE_RECORD - {DG_SCHEDULER_RECORD_START_ADDRESS, sizeof(DG_SCHEDULER_RECORD_T), MAX_RTC_RAM_OPS_BUFFER_BYTES} // NVDATAMGMT_PROCESS_DG_SCHEDULER_RECORD +#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 +#endif }; // Calibration variables @@ -432,7 +386,7 @@ 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 ) ]; +U08 calRecordSizeAssertion[ ( sizeof( CALIBRATION_DATA_T ) <= MAX_MSG_PAYLOAD_SIZE ? 1 : -1 ) ]; //TODO remove // Private functions static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestStart ( void ); @@ -489,7 +443,7 @@ * @details Inputs: NVDataMgmtSelfTestState, NVDataMgmtExecState, NVDataMgmtSelfTestResult, * queueRearIndex, queueFrontIndex, queueCount * @details Outputs: NVDataMgmtSelfTestState, NVDataMgmtExecState, NVDataMgmtSelfTestResult, - * queueRearIndex, queueFrontIndex, queueCount + * queueRearIndex, queueFrontIndex, queueCount //TODO update the function header * @return none *************************************************************************/ void initNVDataMgmt( void ) @@ -509,20 +463,21 @@ recordAddressOffset = 0; writtenRecordStatus = NVDATAMGMT_RECORD_NOT_CHECKED; + // Initialize and activate the flash bank 7 Fapi_initializeFlashBanks( ROUNDED_HCLK_FREQ ); Fapi_setActiveFlashBank( Fapi_FlashBank7 ); Fapi_enableEepromBankSectors( BANK7_SECTOR_0_31_ENABLE_BIT_MASK, BANK7_SECTOR_32_63_ENABLE_BIT_MASK ); // TODO FOR TESTING ONLY, REMOVE - dgCalibrationRecord.presSensorsCalRecord.pressureSensors[0].offset = 5.69; - dgCalibrationRecord.presSensorsCalRecord.pressureSensors[0].gain = 15.2; - dgCalibrationRecord.presSensorsCalRecord.pressureSensors[0].calibrationTime = 12345; - dgCalibrationRecord.presSensorsCalRecord.pressureSensors[0].crc = 159; + dgCalibrationRecord.dgCalibrationGroups.presSensorsCalRecord.pressureSensors[0].offset = 5.69; + dgCalibrationRecord.dgCalibrationGroups.presSensorsCalRecord.pressureSensors[0].gain = 15.2; + dgCalibrationRecord.dgCalibrationGroups.presSensorsCalRecord.pressureSensors[0].calibrationTime = 12345; + dgCalibrationRecord.dgCalibrationGroups.presSensorsCalRecord.pressureSensors[0].crc = 159; - dgCalibrationRecord.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].gain = 56.89; - dgCalibrationRecord.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].offset = 122.3; - dgCalibrationRecord.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].calibrationTime = 567890; - dgCalibrationRecord.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].crc = 3579; + dgCalibrationRecord.dgCalibrationGroups.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].gain = 56.89; + dgCalibrationRecord.dgCalibrationGroups.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].offset = 122.3; + dgCalibrationRecord.dgCalibrationGroups.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].calibrationTime = 567890; + dgCalibrationRecord.dgCalibrationGroups.condSensorsCalRecord.condSensors[CAL_DATA_CD2_COND_SENSOR].crc = 3579; //dgCalibrationRecord.pumpsCalRecord.roPump.gain3Ratio = 56.78; //dgCalibrationRecord.pumpsCalRecord.roPump.calibrationTime = 85236; //dgCalibrationRecord.pumpsCalRecord.roPump.crc = 6789; @@ -599,11 +554,9 @@ default: #ifdef _DG_ - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, - NVDataMgmtExecState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, NVDataMgmtExecState ); #else - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, - NVDataMgmtExecState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, NVDataMgmtExecState ); #endif NVDataMgmtExecState = NVDATAMGMT_EXEC_STATE_IDLE; break; @@ -683,11 +636,9 @@ default: #ifdef _DG_ - SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, - NVDataMgmtSelfTestState ); + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, NVDataMgmtSelfTestState ); #else - SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, - NVDataMgmtSelfTestState ); + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, NVDataMgmtSelfTestState ); #endif NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_COMPLETE; NVDataMgmtSelfTestResult = SELF_TEST_STATUS_FAILED; @@ -739,7 +690,8 @@ // state machine is asynchronous so it is checked in this state machine if ( didTimeout( calDataReceiveStartTime, CAL_DATA_RECEIVE_TIMEOUT_MS ) ) { - // TODO schedule a read + // 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; } } @@ -753,7 +705,7 @@ * @details Outputs: isPublishCalRequested * @return TRUE if the request was successfully registered *************************************************************************/ -BOOL getDGCalibrationRecord( void ) +BOOL getCalibrationRecord( void ) { BOOL status = FALSE; @@ -769,7 +721,7 @@ /*********************************************************************//** * @brief - * The setDGCalibrationRecord function writes the calibration record that + * The setCalibrationRecord function writes the calibration record that * is received from Dialin into the calibration structure. * @details Inputs: previousCalMessageNum, dgCalRecordUpdateAddress, * calDataReceiveTime @@ -783,7 +735,7 @@ * Dialin * @return TRUE if the request was successfully registered *************************************************************************/ -BOOL setDGCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ) +BOOL setCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ) { BOOL status = TRUE; @@ -802,9 +754,12 @@ // 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 // Offset the pointer to length that we should start writing from ptr += dgCalRecordUpdateAddress; @@ -814,14 +769,17 @@ // and 0 everything out since we are done writing if ( currentMessage == totalMessages ) { +#ifdef _DG_ // 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 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_DG_CALIBRATION_RECORD ); + enqueueRecordJob( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, NVDATAMGMT_READ_CALIBRATION_RECORD ); NVDataMgmtExecReceiveRecordState = NVDATAMGMT_RECEIVE_RECORD_IDLE; status = FALSE; } @@ -859,12 +817,12 @@ *************************************************************************/ void getDGPressureSensorsCalibrationRecord( U08* buffer ) { - memcpy( buffer, &dgCalibrationRecord.presSensorsCalRecord, sizeof(dgCalibrationRecord.presSensorsCalRecord)); + //memcpy( buffer, &dgCalibrationRecord.presSensorsCalRecord, sizeof(dgCalibrationRecord.presSensorsCalRecord)); } void getDGFlowSensorsCalibrationRecord( U08* buffer ) { - memcpy( buffer, &dgCalibrationRecord.flowSensorsCalRecord, sizeof(dgCalibrationRecord.condSensorsCalRecord)); + //memcpy( buffer, &dgCalibrationRecord.flowSensorsCalRecord, sizeof(dgCalibrationRecord.condSensorsCalRecord)); } /*********************************************************************//** @@ -1831,7 +1789,7 @@ 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_DG_CALIBRATION_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 @@ -1846,8 +1804,8 @@ // 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_DG_CALIBRATION_RECORD ); - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_DG_CALIBRATION_RECORD ); + 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; @@ -2511,8 +2469,8 @@ if ( getAvailableRecordQueueCount() >= MIN_JOBS_NEEDED_FOR_SECTOR_0 ) { - enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_DG_CALIBRATION_RECORD ); - enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_DG_CALIBRATION_RECORD ); + enqueueRecordJob( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_CALIBRATION_RECORD ); + enqueueRecordJob( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, NVDATAMGMT_WRITE_CALIBRATION_RECORD ); // TODO schedule systems record status = TRUE; Index: NVDataMgmt.h =================================================================== diff -u -r32d19410fc08e86e4503f6e8af5470170bb72cdf -r0df8e5e99715de10f8936a9d41c28f4c2a4dacc6 --- NVDataMgmt.h (.../NVDataMgmt.h) (revision 32d19410fc08e86e4503f6e8af5470170bb72cdf) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision 0df8e5e99715de10f8936a9d41c28f4c2a4dacc6) @@ -19,11 +19,12 @@ #define FWCOMMON_NVDATAMGMT_H_ #include "Common.h" +#include "ConcentratePumps.h" /** * @defgroup NVDataMgmt NVDataMgmt * @brief Non-volatile data management module. Handles Bank 7 of the TI processor and the - * RAM of the RTC chip + * RAM of the RTC chip. * * @addtogroup NVDataMgmt * @{ @@ -32,7 +33,7 @@ // ********** public definitions ********** #define MAX_TOP_LEVEL_PN_CHARS 10U ///< Max number of characters for top level part number. -#define MAX_TOP_LEVEL_SN_CHARS 10U ///< Max number of characters for top level serial number. +#define MAX_TOP_LEVEL_SN_CHARS 15U ///< Max number of characters for top level serial number. #define MAX_HW_SERIAL_NUMBER_CHARACTERS 5U ///< Max number of characters for HD serial number TODO remove #define MAX_DATE_CHARACTERS 10U ///< Max number of characters for date TODO REMOVE @@ -71,6 +72,7 @@ NVDATAMGMT_READ_COMPLETE ///< Read status complete. } NVDATAMGMT_READ_STATUS_T; +/// DG pressure sensors enumeration. typedef enum dg_pressure_sensors { CAL_DATA_RO_PUMP_INLET_PRES_SENSOR = 0, @@ -80,12 +82,14 @@ NUM_OF_CAL_DATA_PRES_SENSORS, } CAL_DATA_DG_PRES_SENSORS_T; +/// DG flow sensors enumeration. typedef enum dg_flow_sensors { CAL_DATA_RO_PUMP_FLOW_SENSOR = 0, NUM_OF_CAL_DATA_FLOW_SENSORS, } CAL_DATA_DG_FLOW_SENSORS_T; +/// DG load cells enumeration. typedef enum dg_load_cells { CAL_DATA_LOAD_CELL_A1 = 0, @@ -95,6 +99,7 @@ NUM_OF_CAL_DATA_LOAD_CELLS, } CAL_DATA_DG_LOAD_CELLS_T; +/// DG temperature sensors enumeration. typedef enum dg_temperature_sensors { CAL_DATA_FPGA_BOARD_TEMP = 0, @@ -115,6 +120,7 @@ NUM_OF_CAL_DATA_TEMP_SENSORS, } CAL_DATA_DG_TEMP_SENSORS_T; +/// DG conductivity sensors enumeration. typedef enum dg_conductivity_sensors { CAL_DATA_CPI_COND_SENSOR = 0, @@ -124,6 +130,7 @@ NUM_OF_CAL_DATA_COND_SENSORS, } CAL_DATA_DG_COND_SENSORS_T; +/// DG pumps enumeration. typedef enum dg_pumps { CAL_DATA_CONC_PUMP_1 = 0, @@ -133,7 +140,133 @@ NUM_OF_CAL_DATA_DG_PUMPS } CAL_DATA_DG_PUMPS_T; +typedef enum dg_reservoirs +{ + CAL_DATA_RSRVR_1 = 0, + CAL_DATA_RSRVR_2, + NUM_OF_CAL_DATA_RSRVRS +} CAL_DATA_DG_RESERVOIRS_T; + #pragma pack(push, 1) +/// Payload record structure for a linear calibration message. TODO remove +typedef struct +{ + F32 gain; + F32 offset; +} LINEAR_F32_CAL_PAYLOAD_T; +// TODO remove the above structure + +/// Linear calibration structure +typedef struct +{ + F32 gain; + F32 offset; + U32 calibrationTime; + U16 crc; +} LINEAR_CAL_PAYLOAD_T; + +/// DG concentrate pumps one-gain payload +typedef struct +{ + F32 stepSpeed2FlowRatio; + U32 calibrationTime; + U16 crc; +} DG_CONC_PUMPS_CAL_RECORD_T; + +/// DG drain pump two-gain payload +typedef struct +{ + F32 voltage2SpeedRatio; + F32 stepSpeed2FlowRatio; + U32 calibrationTime; + U16 crc; +} 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; + F32 gain2Ratio; + F32 gain3Ratio; + U32 calibrationTime; + U16 crc; +} DG_RO_PUMP_CAL_RECORD_T; + +/// Pressure sensors calibration structure +typedef struct +{ + 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 +} 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 + // 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 +} 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 +} 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 + // 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 +} 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 + // 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 +} DG_COND_SENSORS_CAL_RECORD_T; + +typedef struct +{ + F32 volume; + U32 calibrationTime; + U16 crc; +} DG_DRAIN_LINE_VOLUME_T; + +typedef struct +{ + F32 pressure2FlowRatio; + F32 volume; + U32 calibrationTime; + U16 crc; +} DG_PRE_RO_PURGE_VOLUME_T; + +typedef struct +{ + F32 rsrvrVolume; + F32 normalFillVolume; + F32 maxResidualFluid; + F32 rsrvrUnfilledWeight; + U32 calibrationTime; + U16 crc; +} DG_RESERVOIR_VOLUME_T; + +typedef struct +{ + F32 volume; + U32 calibrationTime; + U16 crc; +} DG_GENERIC_VOLUME_T; + /// Manufacturing data structure. typedef struct mfg_Data { @@ -193,76 +326,8 @@ char disinfectionDate [ MAX_DATE_CHARACTERS ]; ///< Disinfection Date } DISINFECTION_DATE_T; -/// Payload record structure for a linear calibration message. TODO remove -typedef struct -{ - F32 gain; - F32 offset; -} LINEAR_F32_CAL_PAYLOAD_T; -/// Linear calibration structure -typedef struct -{ - F32 gain; - F32 offset; - U32 calibrationTime; - U16 crc; -} LINEAR_CAL_PAYLOAD_T; -/// DG concentrate pumps one-gain payload -typedef struct -{ - F32 stepSpeed2FlowRatio; - U32 calibrationTime; - U16 crc; -} DG_CONCENTRATE_PUMPS_PAYLOAD_T; - -/// DG drain pump two-gain payload -typedef struct -{ - F32 voltage2SpeedRatio; - F32 stepSpeed2FlowRatio; - U32 calibrationTime; - U16 crc; -} DG_DRAIN_PUMP_PAYLOAD_T; - -// TODO change the name of the RO pumps gains later -typedef struct -{ - F32 gain1Ratio; - F32 gain2Ratio; - F32 gain3Ratio; - U32 calibrationTime; - U16 crc; -} DG_RO_PUMP_PAYLOAD_T; - -/// One constant structure -typedef struct -{ - F32 constant; - U32 calibrationTime; - U16 crc; -} ONE_CONSTANT_PAYLOAD_T ; - -/// Two constants structure -typedef struct -{ - F32 constant1; - F32 constant2; - U32 calibrationTime; - U16 crc; -} TWO_CONSTANTS_PAYLOAD_T; - -/// Three constants structure -typedef struct -{ - F32 constant1; - F32 constant2; - F32 constant3; - U32 calibrationTime; - U16 crc; -} THREE_CONSTANTS_PAYLOAD_T; - #pragma pack(pop) void initNVDataMgmt ( void ); @@ -275,9 +340,9 @@ void execNVDataMgmtSendRecord( void ); -BOOL getDGCalibrationRecord( void ); +BOOL getCalibrationRecord( void ); -BOOL setDGCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); +BOOL setCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); void getDGPressureSensorsCalibrationRecord( U08* buffer );