/************************************************************************** * * 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" /** * @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 10U ///< 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; 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_DG_PRES_SENSORS_T; typedef enum dg_flow_sensors { CAL_DATA_RO_PUMP_FLOW_SENSOR = 0, NUM_OF_CAL_DATA_FLOW_SENSORS, } CAL_DATA_DG_FLOW_SENSORS_T; 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; 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; 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; 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; #pragma pack(push, 1) /// Manufacturing data structure. 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. typedef struct service_dates { char currentServiceDate [ MAX_DATE_CHARACTERS ]; ///< Current service date char nextServiceDate [ MAX_DATE_CHARACTERS ]; ///< Next service date } SERVICE_DATA_T; /// 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; /// 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 ); void signalPowerOffWarning( void ); void execNVDataMgmt ( void ); SELF_TEST_STATUS_T execNVDataMgmtSelfTest ( void ); void execNVDataMgmtSendRecord( void ); BOOL getDGCalibrationRecord( void ); BOOL setDGCalibrationRecord( U32 currentMessage, U32 totalMessages, U32 length, U08 *addressPtr ); void getDGPressureSensorsCalibrationRecord( U08* buffer ); 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