/************************************************************************** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file NVDataMgmt.h * * @author (last) Dara Navaei * @date (last) 24-Aug-2020 * * @author (original) Dara Navaei * @date (original) 12-Feb-2020 * ***************************************************************************/ #ifndef FWCOMMON_NVDATAMGMT_H_ #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. * * @addtogroup NVDataMgmt * @{ */ // ********** public definitions ********** #define MAX_TOP_LEVEL_PN_CHARS 10U ///< Max number of characters for top level part 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 /// Manufacturing location enumeration. typedef enum mfg_location { MFG_LOC_FACTORY = 0, ///< Manufacturing location (HD/DG). NUM_OF_MFG_LOC ///< Number of manufacturing location. } MFG_LOCATION_T; typedef enum last_service_location { LAST_SERVICE_LOC_FACTORY = 0, ///< Last service location factory (HD/DG). LAST_SERVICE_LOC_FIELD, ///< Last service location field (HD/DG). NUM_OF_LAST_SERVICE_LOC ///< Number of last service location. } LAST_SERVICE_LOCATION_T; /// Log event enumeration. typedef enum log_event { NVDATAMGMT_MODE_CHANGE = 0, ///< Mode change. NVDATAMGMT_ALARM, ///< Alarm. NVDATAMGMT_DISINFECTION_STARTED, ///< Disinfection started. NVDATAMGMT_DISINFECTION_ENDED, ///< Disinfection ended. NVDATAMGMT_DEVICE_TURNED_ON, ///< Device turned on. NVDATAMGMT_DEVICE_TURNED_OFF, ///< Device turned off. NVDATAMGMT_UI_CRASHED ///< UI crashed. } NVDATAMGMT_LOG_EVENT_T; /// Read status enumeration. typedef enum read_status { NVDATAMGMT_READ_IDLE = 0, ///< Read status idle. NVDATAMGMT_READ_IN_PROGRESS, ///< Read status in progress. 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, ///< 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. 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, CAL_DATA_LOAD_CELL_A2, CAL_DATA_LOAD_CELL_B1, CAL_DATA_LOAD_CELL_B2, 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, CAL_DATA_LOAD_CELL_A1_B1_TEMP, CAL_DATA_LOAD_CELL_A2_B2_TEMP, CAL_DATA_INTERNAL_THDO_RTD_TEMP, CAL_DATA_INTERNAL_TDI_RTD_TEMP, CAL_DATA_INTERNAL_COND_SENSOR_TEMP, CAL_DATA_THERMISTOR_DG_ONBOARD_NTC_TEMP, CAL_DATA_THERMISTOR_POWER_SUPPLY_1_TEMP, CAL_DATA_THERMISTOR_POWER_SUPPLY_2_TEMP, CAL_DATA_OUTLET_REDUNDANT_TEMP, CAL_DATA_INLET_DIALYSATE_TEMP, CAL_DATA_INLET_PRIMARY_HEATER_TEMP, CAL_DATA_OUTLET_PRIMARY_HEATER_TEMP, CAL_DATA_COND_SENSOR_1_TEMP, CAL_DATA_COND_SENSOR_2_TEMP, 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, CAL_DATA_CPO_COND_SENSOR, CAL_DATA_CD1_COND_SENSOR, CAL_DATA_CD2_COND_SENSOR, 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, CAL_DATA_CONC_PUMP_2, CAL_DATA_DRAIN_PUMP, CAL_DATA_RO_PUMP, 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; 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 { 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. 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 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. // 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; /// Drain line volume calibration structure typedef struct { 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; ///< 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; ///< 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; ///< Volume. U32 calibrationTime; ///< Calibration time. U16 crc; ///< CRC. } DG_GENERIC_VOLUME_T; /// 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. char HWSerialNumber [ MAX_HW_SERIAL_NUMBER_CHARACTERS ]; ///< HW serial number. char mfgDate [ MAX_DATE_CHARACTERS ]; ///< Manufacturing date. } MFG_DATA_T; /// Calibration data structure. typedef struct calibration_Data { U32 calRecordRevision; ///< Revision of calibration record (rev when structure changes to determine compatibility with f/w version) F32 accelXOffset; ///< Accelerometer X axis offset F32 accelYOffset; ///< Accelerometer Y axis offset F32 accelZOffset; ///< Accelerometer Z axis offset #ifdef _HD_ F32 bloodFlowGain; ///< Gain for blood flow sensor F32 bloodFlowOffset_mL_min; ///< Offset for blood flow sensor F32 dialysateFlowGain; ///< Gain for dialysate flow sensor F32 dialysateFlowOffset_mL_min; ///< Offset for dialysate flow sensor char calDateBloodFlow[ MAX_DATE_CHARACTERS ]; ///< Last calibration date of blood flow sensor char calDateDialysateFlow[ MAX_DATE_CHARACTERS ]; ///< Last calibration date of blood flow sensor #endif char calDateAccel[ MAX_DATE_CHARACTERS ]; ///< Last calibration date of accelerometer } CALIBRATION_DATA_T; /// 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 { NVDATAMGMT_READ_STATUS_T status; ///< Read data status U08* externalBuffer; ///< External buffer address } READ_DATA_T; /// Log data structure. typedef struct { U32 epochTime; ///< Log data time in epoch U32 eventCode; ///< Log data event code U32 subCode; ///< Log data sub code F32 data1; ///< Log data 1 F32 data2; ///< Log data 2 F32 data3; ///< Log data 3 F32 data4; ///< Log data 4 F32 data5; ///< Log data 5 } LOG_DATA_T; /// Disinfection date structure. typedef struct { char disinfectionDate [ MAX_DATE_CHARACTERS ]; ///< Disinfection Date } DISINFECTION_DATE_T; #pragma pack(pop) void initNVDataMgmt ( void ); void signalPowerOffWarning( void ); void execNVDataMgmt ( void ); SELF_TEST_STATUS_T execNVDataMgmtSelfTest ( void ); void execNVDataMgmtProcessRecord( void ); BOOL getCalibrationRecord( void ); BOOL setCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); 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 ); U32 getBootloaderFlag ( void ); BOOL setMfgData ( MFG_DATA_T data ); BOOL getMfgData ( MFG_DATA_T* buffer ); BOOL setCalibrationData ( CALIBRATION_DATA_T data ); //TODO remove BOOL getCalibrationData ( CALIBRATION_DATA_T* buffer ); //TODO remove BOOL testResetCalibrationData( U32 key ); BOOL setServiceDate ( SERVICE_DATA_T data ); BOOL getServiceDate ( SERVICE_DATA_T* buffer ); BOOL setTreatmentTime ( U32 hours ); U32 getTreatmentTime ( void ); BOOL setWaterConsumption ( U32 liters ); U32 getWaterConsumption ( void ); BOOL setDisinfectionDate ( DISINFECTION_DATE_T date ); BOOL getDisinfectionDate ( DISINFECTION_DATE_T* buffer ); BOOL writeLogData ( LOG_DATA_T* data ); BOOL readLogData ( READ_DATA_T* buffer, U32 length ); /**@}*/ #endif