Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r1dd2d175ac3619bcf1c5c4c5ab863f487eb7090f -r656e6c800f80af3f5fc318051356f87832219689 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 1dd2d175ac3619bcf1c5c4c5ab863f487eb7090f) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 656e6c800f80af3f5fc318051356f87832219689) @@ -87,7 +87,7 @@ #define BLOOD_LEAK_EMB_MODE_CMD_Q_MAX_SIZE 12 ///< Blood leak embedded mode command queue maximum size. #define BLOOD_LEAK_EMB_MODE_ZERO_CMD_RQRD_Q 5 ///< Blood leak embedded mode zero command required queue count. #define BLOOD_LEAK_EMB_MODE_NUM_OF_RETRIES 3 ///< Blood leak embedded mode number of retries to enqueue. -#define BLOOD_LEAK_EMB_MODE_INFO_CMD_TIMOUE_MS ( 2 * MS_PER_SECOND ) ///< Blood leak embedded mode informative command timeout in milliseconds. +#define BLOOD_LEAK_EMB_MODE_INFO_CMD_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Blood leak embedded mode informative command timeout in milliseconds. #define BLOOD_LEAK_EMB_MODE_NUM_OF_INFO_CMDS 2 ///< Blood leak embedded mode number of informative commands. #define BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak embedded mode FPGA error timeout in milliseconds. @@ -96,8 +96,8 @@ // ***************** zeroing status *************** // #define BLD_NOMINAL_INTENSITY 930 ///< Blood leak nominal intensity. -#define BLD_MAX_INTENSITY_OUT_OF_RANGE 0.35F ///< Blood leak maximum allowed intensity. -#define BLD_MIN_INTENSITY_OUT_OF_RANGE 0.40F ///< Blood leak minimum allowed intensity. +#define BLD_MAX_INTENSITY_OUT_OF_RANGE 0.40F ///< Blood leak maximum allowed intensity. +#define BLD_MIN_INTENSITY_OUT_OF_RANGE 0.35F ///< Blood leak minimum allowed intensity. #define BLD_ZERO_MIN_INTERVAL_MS ( 30 * SEC_PER_MIN * MS_PER_SECOND ) ///< Blood leak zeroing minimum interval in milliseconds. #define BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES 16 ///< Blood leak number of moving average samples. #define BLD_ZERO_IN_RANGE_DRIFT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak zero value drift in range timeout in milliseconds. @@ -232,6 +232,7 @@ static BOOL isDialysateLineInBypass( void ); static void processBloodLeakIntensityData( void ); static void checkBloodLeakDrift( void ); +static void signalEmbModeCmdRespConsumed( U08 cmd ); /*********************************************************************//** * @brief @@ -1593,7 +1594,7 @@ *************************************************************************/ static void enqueueInfoEmbModeCmds( void ) { - if ( ( TRUE == didTimeout( bloodLeakEmbModeInfoCmdEnqLastTimeStamp, BLOOD_LEAK_EMB_MODE_INFO_CMD_TIMOUE_MS ) ) && + if ( ( TRUE == didTimeout( bloodLeakEmbModeInfoCmdEnqLastTimeStamp, BLOOD_LEAK_EMB_MODE_INFO_CMD_TIMEOUT_MS ) ) && ( bloodLeakState >= BLOOD_LEAK_INIT_STATE ) && ( bloodLeakState != BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE ) ) { // Enqueue the next command. Make sure the blood leak state is greater than init state and it is not the zero and self test state @@ -1685,6 +1686,8 @@ bloodLeakZeroingStatus.intensityRunningSum = bloodLeakZeroingStatus.intensityRunningSum - indexValue + newIntensity; bloodLeakZeroingStatus.intensityMovingAverage = (F32)bloodLeakZeroingStatus.intensityRunningSum / (F32)BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES; bloodLeakZeroingStatus.rawIntensityNextIndex = INC_WRAP( index, 0, BLD_ZERO_MVG_AVG_NUM_OF_SAMPLES - 1 ); + + signalEmbModeCmdRespConsumed( I_EMB_MODE_CMD ); } } @@ -1700,13 +1703,12 @@ { BOOL isZeroingNeeded = TRUE; U32 setPoint = bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].commandResp; - F32 driftUpper = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE ); - F32 driftLower = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE ); - F32 intensityDrift = BLD_NOMINAL_INTENSITY - bloodLeakZeroingStatus.intensityMovingAverage; + F32 driftMinFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE ); + F32 driftMaxFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE ); BOOL isZeroingAllowed = didTimeout( bloodLeakZeroingStatus.lastZeroingStartTimeMS, BLD_ZERO_MIN_INTERVAL_MS ); - isZeroingNeeded &= ( intensityDrift <= driftUpper ? TRUE : FALSE ); - isZeroingNeeded &= ( intensityDrift >= driftLower ? TRUE : FALSE ); + isZeroingNeeded &= ( bloodLeakZeroingStatus.intensityMovingAverage >= driftMinFromTop ? TRUE : FALSE ); + isZeroingNeeded &= ( bloodLeakZeroingStatus.intensityMovingAverage <= driftMaxFromTop ? TRUE : FALSE ); if ( FALSE == isZeroingNeeded ) { @@ -1719,6 +1721,19 @@ } } +/*********************************************************************//** + * @brief + * The signalEmbModeCmdRespConsumed function sets the cmd response ready flag + * to false its flag that fresh data is ready. + * @details Inputs: none + * @details Outputs: bloodLeakEmbModeCmd + * @param cmd the command to signal its data has been consumed + * @return none + *************************************************************************/ +static void signalEmbModeCmdRespConsumed( U08 cmd ) +{ + bloodLeakEmbModeCmd[ cmd ].isCmdRespRdy = FALSE; +} /************************************************************************* * TEST SUPPORT FUNCTIONS