Index: firmware/App/Controllers/ConductivitySensors.c =================================================================== diff -u -re0eeafdfe3efec528a5ba8bb0f2f7c0f682b32da -r969ec174d1d6254ef5b7f90723d5b5313cfa3932 --- firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision e0eeafdfe3efec528a5ba8bb0f2f7c0f682b32da) +++ firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 969ec174d1d6254ef5b7f90723d5b5313cfa3932) @@ -18,8 +18,9 @@ #include "ConductivitySensors.h" #include "FPGA.h" -#include "PersistentAlarm.h" +#include "NVDataMgmt.h" #include "MessageSupport.h" +#include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TaskPriority.h" @@ -61,6 +62,7 @@ #define EMSTAT_PICO_GOOD_STATUS 0x10 ///< Measurement good status. #define EMSTAT_PICO_TIMING_NOT_MET_STATUS 0x11 ///< Measurement takes too long status. #define EMSTAT_PICO_FIFO_EMPTY_MASK 0x8000 ///< Emstat Pico buffer empty indication bit. +#define DATA_PUBLISH_COUNTER_START_COUNT 40 ///< Data publish counter start count. #pragma pack(push,1) /// Emstat pico measurement data package structure @@ -89,11 +91,12 @@ static U08 readCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Read count for conductivity readings. static U32 internalErrorCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Internal error count for conductivity readings. static OVERRIDE_F32_T compensatedConductivityValues[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Latest compensated conductivity values. +static F32 rawConductivityValues[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Latest raw conductivity values. static F32 roRejectionRatio; ///< Latest RO rejection ratio. static OVERRIDE_U32_T conductivityDataPublishInterval = { COND_SENSOR_REPORT_PERIOD, COND_SENSOR_REPORT_PERIOD, 0, 0 }; ///< Conductivity sensors publish time interval override. -static U32 conductivityDataPublicationTimerCounter = 0; ///< Conductivity sensors data publish timer counter. +static U32 conductivityDataPublicationTimerCounter; ///< Conductivity sensors data publish timer counter. static BOOL packageStarted = FALSE; ///< Flag to indicate the start of a package measurement data. static U08 packageIndex = 0U; ///< Current package measurement data bytes index. @@ -109,7 +112,6 @@ static U32 prefixStrToSIFactor( U08 prefix ); static void processMeasurementDataPackage( U32 sensorId ); static void processCD1CD2SensorRead( U16 fpgaReadCount, U08 fpgaErrorCount ); -static BOOL processCalibrationData( void ); static F32 getCalibrationAppliedConductivityValue( U32 sensorId, F32 compensatedValue ); /*********************************************************************//** @@ -122,7 +124,8 @@ void initConductivitySensors( void ) { U32 i; - roRejectionRatio = 0.0; + roRejectionRatio = 0.0; + conductivityDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; for ( i = 0; i < NUM_OF_CONDUCTIVITY_SENSORS; i++ ) { @@ -133,6 +136,8 @@ compensatedConductivityValues[ i ].ovData = 0.0; compensatedConductivityValues[ i ].ovInitData = 0.0; compensatedConductivityValues[ i ].override = OVERRIDE_RESET; + + rawConductivityValues[ i ] = 0.0; } setFPGACPiProbeType( COND_CPI_SENSOR_PROBE_TYPE ); @@ -158,8 +163,8 @@ // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + getNVRecord2Driver( GET_CAL_CONDUCTIVITY_SENSORS, (U08*)&condSensorsCalRecord, sizeof( condSensorsCalRecord ), + NUM_OF_CAL_DATA_COND_SENSORS, ALARM_ID_DG_COND_SENSORS_INVALID_CAL_RECORD ); } processCPiCPoSensorRead( CONDUCTIVITYSENSORS_CPI_SENSOR, getFPGACPi(), getFPGACPiReadCount(), getFPGACPiErrorCount(), getFPGACPiFault() ); @@ -173,12 +178,18 @@ calcRORejectionRatio(); conductivityDataPublicationTimerCounter = 0; - data.roRejectionRatio = roRejectionRatio; + data.roRejectionRatio = roRejectionRatio; + data.cpi = getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ); data.cpo = getConductivityValue( CONDUCTIVITYSENSORS_CPO_SENSOR ); data.cd1 = getConductivityValue( CONDUCTIVITYSENSORS_CD1_SENSOR ); data.cd2 = getConductivityValue( CONDUCTIVITYSENSORS_CD2_SENSOR ); + data.cpiRaw = rawConductivityValues[ CONDUCTIVITYSENSORS_CPI_SENSOR ]; + data.cpoRaw = rawConductivityValues[ CONDUCTIVITYSENSORS_CPO_SENSOR ]; + data.cd1Raw = rawConductivityValues[ CONDUCTIVITYSENSORS_CD1_SENSOR ]; + data.cd2Raw = rawConductivityValues[ CONDUCTIVITYSENSORS_CD2_SENSOR ]; + broadcastData( MSG_ID_DG_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( CONDUCTIVITY_DATA_T ) ); } } @@ -195,7 +206,8 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - BOOL calStatus = processCalibrationData(); + BOOL calStatus = getNVRecord2Driver( GET_CAL_CONDUCTIVITY_SENSORS, (U08*)&condSensorsCalRecord, sizeof( condSensorsCalRecord ), + NUM_OF_CAL_DATA_COND_SENSORS, ALARM_ID_DG_COND_SENSORS_INVALID_CAL_RECORD ); if ( TRUE == calStatus ) { @@ -289,7 +301,7 @@ * @brief * The calcCompensatedConductivity function calculates the compensated * conductivity based on given temperature and conductivity taken at - * reference temperature of 25 Celcius. + * reference temperature of 25 degree Celsius. * @details Inputs: conductivity, temperature * @details Outputs: none * @param conductivity conductivity value @@ -298,8 +310,8 @@ *************************************************************************/ static F32 calcCompensatedConductivity( F32 conductivity, F32 temperature ) { - // EC = EC_25 * (1 + temp_coef * (temperature - 25)) - F32 const compensatedCoef = ( 1.0 + ( COND_SENSOR_TEMPERATURE_COEF * ( temperature - COND_SENSOR_REFERENCE_TEMPERATURE ) ) ); + // EC = EC_25 * (1 + temp_coef * ( 25 - temperature )) + F32 const compensatedCoef = ( 1.0 + ( COND_SENSOR_TEMPERATURE_COEF * ( COND_SENSOR_REFERENCE_TEMPERATURE - temperature ) ) ); return conductivity * compensatedCoef; } @@ -352,6 +364,7 @@ readCount[ sensorId ] = fpgaReadCount; internalErrorCount[ sensorId ] = 0; compensatedConductivityValues[ sensorId ].data = getCalibrationAppliedConductivityValue( sensorId, compensatedCond ); + rawConductivityValues[ sensorId ] = conductivity; // store raw conductivity data from CPi and CPo } else { @@ -420,7 +433,7 @@ EMSTAT_VARIABLE_T const * const measurementPtr = (EMSTAT_VARIABLE_T *)&package; U32 const status = hexStrToDec( (U08 *)&measurementPtr->status, sizeof( measurementPtr->status ) ); - if ( EMSTAT_PICO_GOOD_STATUS == status ) + // if ( EMSTAT_PICO_GOOD_STATUS == status ) { U32 const prefix = prefixStrToSIFactor( measurementPtr->prefix ); F32 const resistance = ( ( F32 )( hexStrToDec( measurementPtr->value, sizeof( measurementPtr->value ) ) - EMSTAT_PICO_MEASUREMENT_OFFSET ) / prefix ); @@ -430,11 +443,14 @@ internalErrorCount[ sensorId ] = 0; compensatedConductivityValues[ sensorId ].data = getCalibrationAppliedConductivityValue( sensorId, compensatedCond ); + rawConductivityValues[ sensorId ] = conductivity; // store raw conductivity data from CD1 and CD2 + } - else + /*else { compensatedConductivityValues[ sensorId ].data = 0.0; - } + rawConductivityValues[ sensorId ] = 0.0; + }*/ if ( EMSTAT_PICO_TIMING_NOT_MET_STATUS == status ) { @@ -514,47 +530,6 @@ /*********************************************************************//** * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: condSensorsCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - U32 sensor; - - // Get the calibration record from NVDataMgmt - DG_COND_SENSORS_CAL_RECORD_T calData = getDGConducitivitySensorsCalibrationRecord(); - - for ( sensor = 0; sensor < NUM_OF_CAL_DATA_COND_SENSORS; sensor++ ) - { -#ifndef SKIP_CAL_CHECK - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.condSensors[ sensor ].calibrationTime ) - { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_COND_SENSORS_INVALID_CAL_RECORD, (U32)sensor ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy - condSensorsCalRecord.condSensors[ sensor ].fourthOrderCoeff = calData.condSensors[ sensor ].fourthOrderCoeff; - condSensorsCalRecord.condSensors[ sensor ].thirdOrderCoeff = calData.condSensors[ sensor ].thirdOrderCoeff; - condSensorsCalRecord.condSensors[ sensor ].secondOrderCoeff = calData.condSensors[ sensor ].secondOrderCoeff; - condSensorsCalRecord.condSensors[ sensor ].gain = calData.condSensors[ sensor ].gain; - condSensorsCalRecord.condSensors[ sensor ].offset = calData.condSensors[ sensor ].offset; - } - - return status; -} - -/*********************************************************************//** - * @brief * The getCalibrationAppliedConductivityValue function gets the temperature * compensated conductivity value and applies calibration to it. * @details Inputs: condSensorsCalRecord Index: firmware/App/Controllers/ConductivitySensors.h =================================================================== diff -u -r19ad0476e0344d806ed84d5c40a416320f621090 -r969ec174d1d6254ef5b7f90723d5b5313cfa3932 --- firmware/App/Controllers/ConductivitySensors.h (.../ConductivitySensors.h) (revision 19ad0476e0344d806ed84d5c40a416320f621090) +++ firmware/App/Controllers/ConductivitySensors.h (.../ConductivitySensors.h) (revision 969ec174d1d6254ef5b7f90723d5b5313cfa3932) @@ -46,17 +46,12 @@ // ********** public definitions ********** -#define MIN_ACID_CONCENTRATE_CONDUCTIVITY 11000 ///< Minimum conductivity for acid concentrate. -#define MAX_ACID_CONCENTRATE_CONDUCTIVITY 11850 ///< Maximum conductivity for acid concentrate. +#define MIN_ACID_CONCENTRATE_CONDUCTIVITY 11062.80 ///< Minimum conductivity for acid concentrate 11645.05 - 5%. +#define MAX_ACID_CONCENTRATE_CONDUCTIVITY 12227.30 ///< Maximum conductivity for acid concentrate 11645.05 + 5%. -#define MIN_BICARB_CONCENTRATE_CONDUCTIVITY 2000 ///< Minimum conductivity for bicarbonate concentrate. -#define MAX_BICARB_CONCENTRATE_CONDUCTIVITY 3000 ///< Maximum conductivity for bicarbonate concentrate. +#define MIN_BICARB_CONCENTRATE_CONDUCTIVITY 13048.14 ///< Minimum conductivity for bicarbonate concentrate 13734.88 - 5%. +#define MAX_BICARB_CONCENTRATE_CONDUCTIVITY 14421.62 ///< Maximum conductivity for bicarbonate concentrate 13734.88 + 5%. -///< Minimum conductivity value for dialysate solution. -#define MIN_DIALYSATE_CONDUCTIVITY ( MIN_ACID_CONCENTRATE_CONDUCTIVITY + MIN_BICARB_CONCENTRATE_CONDUCTIVITY ) -///< Maximum conductivity value for dialysate solution. -#define MAX_DIALYSATE_CONDUCTIVITY ( MAX_ACID_CONCENTRATE_CONDUCTIVITY + MAX_BICARB_CONCENTRATE_CONDUCTIVITY ) - /// Enumeration of conductivity sensors. typedef enum ConductivitySensors { Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -re0eeafdfe3efec528a5ba8bb0f2f7c0f682b32da -r969ec174d1d6254ef5b7f90723d5b5313cfa3932 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision e0eeafdfe3efec528a5ba8bb0f2f7c0f682b32da) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 969ec174d1d6254ef5b7f90723d5b5313cfa3932) @@ -86,6 +86,7 @@ #define TEMP_SENSORS_MAX_ALLOWED_DEGREE_C 120.0 ///< Temperature sensors maximum allowed temperature in C. #define NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C 80.0 ///< Non fluid temperature sensors path maximum allowed temperature in C. #define TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS ( 5 * MS_PER_SECOND ) ///< Temperature sensor out of range persistent period in milliseconds. +#define DATA_PUBLISH_COUNTER_START_COUNT 30 ///< Data publish counter start count. // The count cannot be within 0.1V of the rail on both sides therefore: // ADC count = ((2^12) - 1 / ref voltage) * voltage @@ -130,6 +131,7 @@ static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override. +static DG_TEMP_SENSORS_CAL_RECORD_T tempSensorCalRecord; ///< Temperature sensors calibration record. static const F32 POSITIVE_TC_EXP_A0 = 0.118597600000E0; ///< K TC positive temperature exponent coefficient A0. static const F32 POSITIVE_TC_EXP_A1 = -0.118343200000E-3; ///< K TC positive temperature exponent coefficient A1. @@ -167,7 +169,7 @@ static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ); static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); -static void monitorTemperatureSnsrs( U32 sensorIndex ); +static void monitorTemperatureSnsrs( U32 sensorIndex, F32 temperature ); /*********************************************************************//** * @brief @@ -186,7 +188,7 @@ tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; elapsedTime = 0; internalHeatersConversionTimer = 0; - dataPublicationTimerCounter = 0; + dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; fpgaRawADCReadInterval = 0; /* NOTE: The temperature sensors do not have conversion coefficient. @@ -303,14 +305,21 @@ *************************************************************************/ SELF_TEST_STATUS_T execTemperatureSensorsSelfTest( void ) { - SELF_TEST_STATUS_T status = SELF_TEST_STATUS_IN_PROGRESS; + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - // TODO implement the calibration processing function. - // It returns a pass for now + BOOL calStatus = getNVRecord2Driver( GET_CAL_TEMP_SENSORS, (U08*)&tempSensorCalRecord, sizeof( DG_TEMP_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_TEMP_SENSORS, ALARM_ID_NO_ALARM ); - status = SELF_TEST_STATUS_PASSED; + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } - return status; + return result; } /*********************************************************************//** @@ -396,7 +405,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( OVERRIDE_KEY == tempSensors[ sensorIndex ].temperatureValues.override ) + if ( tempSensors[ sensorIndex ].temperatureValues.override == OVERRIDE_KEY ) { temperature = tempSensors[ sensorIndex ].temperatureValues.ovData; } @@ -736,7 +745,7 @@ tempSensors[ sensorIndex ].temperatureValues.data = temperature; // Monitor the temperature value - monitorTemperatureSnsrs( sensorIndex ); + monitorTemperatureSnsrs( sensorIndex, temperature ); } /*********************************************************************//** @@ -903,14 +912,17 @@ * @details Inputs: tempSensors * @details Outputs: tempSensors * @param sensorIndex the index of the temperature sensor + * @param temperature the temperature value to be checked * @return none *************************************************************************/ -static void monitorTemperatureSnsrs( U32 sensorIndex ) +static void monitorTemperatureSnsrs( U32 sensorIndex, F32 temperature ) { - F32 temperature = getTemperatureValue( sensorIndex ); + // The maximum allowed temperature is different for the sensors that are in the fluid path + // with the ones that are not in the fluid path + F32 maxLimit = tempSensors[ sensorIndex ].maxAllowedTemperature; // Check both temperature and to be in range - if ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ sensorIndex ].maxAllowedTemperature ) ) + if ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > maxLimit ) ) { // TODO investigate //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, TRUE, sensorIndex, temperature ); @@ -939,7 +951,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { result = TRUE; tempSensors[ sensorIndex ].temperatureValues.ovData = temperature; @@ -965,7 +977,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { result = TRUE; tempSensors[ sensorIndex ].temperatureValues.override = OVERRIDE_RESET; @@ -989,7 +1001,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { U32 interval = value / TASK_PRIORITY_INTERVAL; @@ -1013,7 +1025,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { result = TRUE; tempSensorsPublishInterval.override = OVERRIDE_RESET; Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r27cf459aaabea8e98188e929d2d762942b3e78e1 -r969ec174d1d6254ef5b7f90723d5b5313cfa3932 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 27cf459aaabea8e98188e929d2d762942b3e78e1) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 969ec174d1d6254ef5b7f90723d5b5313cfa3932) @@ -52,7 +52,6 @@ #define DIALYSATE_FILL_TIME_OUT ( 5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Time out period when reservoir is not filled with correct dialysate. #define EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ( 5 * MS_PER_SECOND ) ///< Persistent period for empty bottle detect. - #define CONCENTRATE_PUMP_PRIME_INTERVAL ( 3 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Persistent time interval for concentrate pumps prime. #define ACID_BICARB_CONCENTRATE_ADDITION_MULTIPLER 1.06 ///< Acid and bicarbonate concentrates make up around 6% to total volume. @@ -603,13 +602,9 @@ #ifndef DISABLE_MIXING requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); - - if ( concentratePumpPrimeCount++ > CONCENTRATE_PUMP_PRIME_INTERVAL ) #endif - { - setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); - result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; - } + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); + result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; } else { @@ -887,9 +882,10 @@ static void setFillInfoToRTCRAM( void ) { DG_HEATERS_RECORD_T record; + record.averageFillFlow = fillStatus.fillFlowRateAverage; - setHeatersInfoRecord( (U08*)&record ); + setHeatersInfoRecord( (U08*)&record, sizeof( DG_HEATERS_RECORD_T ) ); } /**@}*/