Index: firmware/App/Controllers/DialysateFlow.c =================================================================== diff -u -rfea68bfb5166d12aa6e2b229872d01fbad5a8eae -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b --- firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision fea68bfb5166d12aa6e2b229872d01fbad5a8eae) +++ firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2022 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 DialysateFlow.c +* @file DialysateFlow.c * -* @author (last) H. Nguyen -* @date (last) 21-Oct-2021 +* @author (last) Dara Navaei +* @date (last) 15-Jul-2022 * -* @author (original) H. Nguyen -* @date (original) 19-Oct-2021 +* @author (original) Hung Nguyen +* @date (original) 20-Oct-2021 * ***************************************************************************/ @@ -36,29 +36,29 @@ #define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). #define FLOW_SAMPLES_TO_AVERAGE ( 1000 / TASK_PRIORITY_INTERVAL ) ///< Averaging flow data over 1000 ms intervals. -#define FLOW_AVERAGE_MULTIPLIER ( 1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. +#define FLOW_AVERAGE_MULTIPLIER ( 1.0F / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. -#define DIALYSATE_FLOW_ADC_TO_LPM_FACTOR 300 ///< Conversion factor from pulse period (2us units) to flow rate (L/min) for dialysate flow rate (divide this by pulse period). +#define DIALYSATE_FLOW_ADC_TO_LPM_FACTOR 272.72F ///< Conversion factor from pulse period (2us units) to flow rate (L/min) for dialysate flow rate (divide this by pulse period). #define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ( 12 * MS_PER_SECOND ) ///< Flow out of range time out in counts. +#define DATA_PUBLISH_COUNTER_START_COUNT 20 ///< Data publish counter start count. // ********** private data ********** -static U32 dialysateFlowDataPublicationTimerCounter = 0; ///< Used to schedule Dialysate flow data publication to CAN bus. +static U32 dialysateFlowDataPublicationTimerCounter; ///< Used to schedule Dialysate flow data publication to CAN bus. static OVERRIDE_U32_T dialysateFlowDataPublishInterval = { DIALYSATE_FLOW_DATA_PUB_INTERVAL, DIALYSATE_FLOW_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish Dialysate flow data to CAN bus. static OVERRIDE_F32_T measuredDialysateFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured Dialysate flow rate (in L/min). -static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. -static U32 flowFilterCounter = 0; ///< Flow filtering counter. +static S32 measuredFlowReadingsSum; ///< Raw flow reading sums for averaging. +static U32 flowFilterCounter; ///< Flow filtering counter. static DG_FLOW_SENSORS_CAL_RECORD_T flowSensorsCalRecord; ///< Flow sensors calibration record. // ********** private function prototypes ********** static void publishDialysateFlowData( void ); -static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -75,7 +75,7 @@ // Initialize the variables measuredFlowReadingsSum = 0; flowFilterCounter = 0; - dialysateFlowDataPublicationTimerCounter = 0; + dialysateFlowDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; } /*********************************************************************//** @@ -89,18 +89,10 @@ SELF_TEST_STATUS_T execDialysateFlowMeterSelfTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + BOOL calStatus = getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_DIALYSATE_FLOW_SENSOR_INVALID_CAL_RECORD ); + result = ( TRUE == calStatus ? SELF_TEST_STATUS_PASSED : SELF_TEST_STATUS_FAILED ); - BOOL calStatus = processCalibrationData(); - - if ( TRUE == calStatus ) - { - result = SELF_TEST_STATUS_PASSED; - } - else - { - result = SELF_TEST_STATUS_FAILED; - } - return result; } @@ -117,6 +109,7 @@ void execDialysateFlowMeterMonitor( void ) { U16 dialysateFlowReading = getFPGADialysateFlowRate(); + dialysateFlowReading = ( 0 == dialysateFlowReading ? FLOW_SENSOR_ZERO_READING : dialysateFlowReading ); F32 currentFlow; BOOL isFlowOutOfUpperRange; @@ -126,8 +119,8 @@ // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { - // Get the new calibration data and check its validity - processCalibrationData(); + getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_RO_FLOW_SENSOR_INVALID_CAL_RECORD ); } // Read flow at the control set @@ -139,7 +132,7 @@ measuredDialysateFlowRateLPM.data = pow(flow, 4) * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff + pow(flow, 3) * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff + pow(flow, 2) * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff + - flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].gain + + flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].gain + flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].offset; // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that the flow is 0. @@ -149,11 +142,11 @@ } measuredFlowReadingsSum = 0; - flowFilterCounter = 0; + flowFilterCounter = 0; } - currentFlow = getMeasuredDialysateFlowRate(); - isFlowOutOfUpperRange = currentFlow > MAX_DIALYSATE_FLOWRATE_LPM; + currentFlow = getMeasuredDialysateFlowRate(); + isFlowOutOfUpperRange = ( currentFlow > MAX_DIALYSATE_FLOWRATE_LPM ? TRUE : FALSE ); checkPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_RATE_OUT_OF_RANGE, isFlowOutOfUpperRange, currentFlow, MAX_DIALYSATE_FLOWRATE_LPM ); // Publish dialysate flow meter data on the CAN bus according to the specified interval @@ -162,48 +155,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: flowSensorsCalRecord - * @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_FLOW_SENSORS_CAL_RECORD_T calData = getDGFlowSensorsCalibrationRecord(); - - for ( sensor = 0; sensor < NUM_OF_CAL_DATA_FLOW_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 flow sensors data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.flowSensors[ sensor ].calibrationTime ) - { - - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD, (U32)sensor ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy - flowSensorsCalRecord.flowSensors[ sensor ].fourthOrderCoeff = calData.flowSensors[ sensor ].fourthOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].thirdOrderCoeff = calData.flowSensors[ sensor ].thirdOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].secondOrderCoeff = calData.flowSensors[ sensor ].secondOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].gain = calData.flowSensors[ sensor ].gain; - flowSensorsCalRecord.flowSensors[ sensor ].offset = calData.flowSensors[ sensor ].offset; - } - - return status; -} - -/*********************************************************************//** - * @brief * The publishDialysateFlowData function publishes Dialysate flow data at the set interval. * @details Inputs: dialysateFlowDataPublicationTimerCounter * @details Outputs: dialysateFlowDataPublicationTimerCounter @@ -217,8 +168,7 @@ DIALYSATE_FLOW_METER_DATA_T dialysateFlowData; dialysateFlowData.measuredDialysateFlowRate = getMeasuredDialysateFlowRate(); - broadcastData( MSG_ID_DG_DIALYSATE_FLOW_METER_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&dialysateFlowData, - sizeof( DIALYSATE_FLOW_METER_DATA_T ) ); + broadcastData( MSG_ID_DG_DIALYSATE_FLOW_METER_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&dialysateFlowData, sizeof( DIALYSATE_FLOW_METER_DATA_T ) ); dialysateFlowDataPublicationTimerCounter = 0; } } @@ -240,6 +190,7 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ + /*********************************************************************//** * @brief * The testSetDialysateFlowDataPublishIntervalOverride function overrides the