Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r431e1dbb713aa2ce5529e807f86b34239b4210de -r65a0cb19291eda2643e3dd6271b9e278d8cc59ab --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 431e1dbb713aa2ce5529e807f86b34239b4210de) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 65a0cb19291eda2643e3dd6271b9e278d8cc59ab) @@ -149,13 +149,16 @@ /*********************************************************************//** * @brief * The execBloodLeak function executes the blood leak detector driver. - * @details Inputs: FPGA blood leak status GPIO pin state - * @details Outputs: bloodLeakStatus + * @details Inputs: bloodLeakGetCalStartTime + * @details Outputs: bloodLeakStatus, bloodLeakGetCalStartTime * @return none *************************************************************************/ void execBloodLeak( void ) { - // Check if there is a new calibration data available + // Check if there is a new calibration data available and whether there has been sufficient time elapsed from the last data calibration get + // The elapsed time is used to make sure the prepare buffer is not called several time when the new calibration signal is TRUE for one second + // otherwise, the prepareSetPointSeq is called multiple time and zeros the start index. In the mean time, the state might have changed to set + // the set point and with the start index being reset to 0, it keeps sending the first character of the set point ('S'). if ( ( TRUE == isNewCalibrationRecordAvailable() ) && ( calcTimeSince( bloodLeakGetCalStartTime ) > BLOOD_LEAK_MIN_WAIT_TIME_2_GET_CAL_MS ) ) { U32 length = sizeof( HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ); @@ -167,6 +170,7 @@ // the calibration data bloodLeakState = BLOOD_LEAK_SET_SET_POINT_STATE; + // Set the calibration start time to make sure the prepare buffer is not set multiple times in a row bloodLeakGetCalStartTime = getMSTimerCount(); } @@ -268,6 +272,8 @@ U32 command = BLOOD_LEAK_START_UP_SEQUENCE[ bloodLeakUARTCmdIndex ]; + // Check if ^U index <= index <= 0 to Tx index. If the current value is either ^U or the 0 to command the FIFO to stop writing + // use the transmit function otherwise, use the UART control. if ( ( bloodLeakUARTCmdIndex >= BLOOD_LEAK_START_FIFO_CTRL_U_INDEX ) && ( bloodLeakUARTCmdIndex <= BLOOD_LEAK_START_FIFO_STOP_INDEX ) ) { setFPGABloodLeakUARTTransmit( (U08)command ); @@ -277,6 +283,7 @@ setFPGABloodLeakUARTControl( (U08)command ); } + // Done with writing all the commands, reset the index and transition if ( bloodLeakUARTCmdIndex >= ( BLOOD_LEAK_STARTUP_SEQ_LENGTH - 1 ) ) { bloodLeakUARTCmdIndex = 0; @@ -573,9 +580,7 @@ static void prepareSetPointSeq( void ) { U08 i; - // Set the local variables. Create a local char buffer with the maximum possible length - // The set point can be maximum 3 digits and when it is converted to string, the null character - // is the extra character at the end of the buffer so it maximum length is 4 bytes. + // Set the local variables. U32 digitCount; U32 setPoint = bloodLeakCalRecord.setPoint; U32 bufferIndex = BLOOD_LEAK_SET_POINT_START_CHAR_INDEX;