Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r09e6cf9de34acf18f6e1138bf56ac0edb4821186 -r65a0cb19291eda2643e3dd6271b9e278d8cc59ab --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 09e6cf9de34acf18f6e1138bf56ac0edb4821186) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 65a0cb19291eda2643e3dd6271b9e278d8cc59ab) @@ -1,6 +1,6 @@ /************************************************************************** * -* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-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. @@ -14,10 +14,12 @@ * @date (original) 18-Mar-2021 * ***************************************************************************/ +#include // For sprintf and strlen #include "AlarmMgmt.h" #include "BloodLeak.h" #include "FPGA.h" +#include "NVDataMgmtHDRecords.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -30,76 +32,165 @@ // ********** private definitions ********** -#define BLOOD_LEAK_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the blood leak data is published on the CAN bus. -#define BLOOD_LEAK_TIMEOUT_MS 500 ///< Blood leak detector timeout for zeroing and self-test (15 ms extended edge detection) +#define BLOOD_LEAK_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the blood leak data is published on the CAN bus. +#define BLOOD_LEAK_TIMEOUT_MS 500 ///< Blood leak detector timeout for zeroing and self-test (15 ms extended edge detection) +#define BLOOD_LEAK_PERSISTENCE ( 10 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Persistence for blood leak detected alarm. +#define BLOOD_LEAK_RESET_TX_FIFO 2 ///< Blood leak reset transmit FIFO command. +#define BLOOD_LEAK_START_COMM_CTRL_U_ASCII 21 ///< Blood leak start communication command, ^U (Ctrl-U) in ascii. +#define BLOOD_LEAK_UART_COMM_ACTIVE_LOW 0 ///< Blood leak UART communication active low command. +#define BLOOD_LEAK_UART_COMM_ACTIVE_HIGH 1 ///< Blood leak UART communication active high command. +#define BLOOD_LEAK_STARTUP_SEQ_LENGTH 6 ///< Blood leak start up sequence array length. +#define BLOOD_LEAK_START_FIFO_CTRL_U_INDEX 2 ///< Blood leak start communication sequence ^U index. +#define BLOOD_LEAK_START_FIFO_STOP_INDEX 3 ///< Blood leak start communication sequence stop write to FIFO index. + +#define BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH 11 ///< Blood leak set point maximum character length. +#define BLOOD_LEAK_SET_POINT_START_CHAR_ASCII 83 ///< Blood leak set point sequence start character in ASCII (letter S). +#define BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND 0 ///< Blood leak set point stop writing to FIFO command. +#define BLOOD_LEAK_SET_POINT_START_CHAR_INDEX 0 ///< Blood leak set point sequence start character index number. +#define BLOOD_LEAK_CARRIAGE_RETURN_ASCII 13 ///< Blood leak set point sequence carriage return character in ASCII. +#define BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH 15 ///< Blood leak set point sequence maximum length. + +#define BLOOD_LEAK_WAIT_2_READ_SET_POINT ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Blood leak wait to read set point in counts. +#define BLOOD_LEAK_MAX_SET_POINT_WRITE_TRIALS 3 ///< Blood leak maximum number of trials to write the set point. + +#define BLOOD_LEAK_MIN_WAIT_TIME_2_GET_CAL_MS ( 2 * MS_PER_SECOND ) ///< Blood leak minimum wait time to get calibration in milliseconds. + /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { - BLOOD_LEAK_INIT_STATE = 0, ///< Initial state - BLOOD_LEAK_ZERO_STATE, ///< Zero state - BLOOD_LEAK_SELF_TEST_STATE, ///< Self-test state - BLOOD_LEAK_NORMAL_STATE, ///< Normal state - NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states + BLOOD_LEAK_START_UP_STATE = 0, ///< Start up state. + BLOOD_LEAK_CHECK_SET_POINT_STATE, ///< Check set point state. + BLOOD_LEAK_SET_SET_POINT_STATE, ///< Set set point state. + BLOOD_LEAK_INIT_STATE, ///< Init state. + BLOOD_LEAK_ZERO_STATE, ///< Zero state. + BLOOD_LEAK_SELF_TEST_STATE, ///< Self-test state. + BLOOD_LEAK_NORMAL_STATE, ///< Normal state. + NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states. } BLOOD_LEAK_STATES_T; // ********** private data ********** -static BLOOD_LEAK_STATES_T bloodLeakState; ///< Current state of blood leak state machine. -static OVERRIDE_U32_T bloodLeakStatus; ///< Detected blood leak status for blood leak detector. -static SELF_TEST_STATUS_T bloodLeakSelfTestStatus; ///< Current status of blood leak self-test. +static BLOOD_LEAK_STATES_T bloodLeakState; ///< Current state of blood leak state machine. +static OVERRIDE_U32_T bloodLeakStatus; ///< Detected blood leak status for blood leak detector. +static SELF_TEST_STATUS_T bloodLeakSelfTestStatus; ///< Current status of blood leak self-test. -static BOOL bloodLeakZeroRequested = FALSE; ///< Blood leak zero requested flag -static U32 bloodLeakZeroStartTime = 0; ///< Blood leak zeroing start time. -static U32 bloodLeakSelfTestStartTime = 0; ///< Blood leak self-test start time. +static BOOL bloodLeakZeroRequested = FALSE; ///< Blood leak zero requested flag +static U32 bloodLeakZeroStartTime = 0; ///< Blood leak zeroing start time. +static U32 bloodLeakSelfTestStartTime = 0; ///< Blood leak self-test start time. -/// Interval (in ms) at which to publish blood leak data to CAN bus. -static OVERRIDE_U32_T bloodLeakDataPublishInterval = { BLOOD_LEAK_PUB_INTERVAL, BLOOD_LEAK_PUB_INTERVAL, 0, 0 }; -static U32 bloodLeakDataPublicationTimerCounter = 0; ///< Timer counter used to schedule blood leak data publication to CAN bus. +static U32 bloodLeakPersistenceCtr = 0; ///< Blood leak alarm persistence timer counter. +static OVERRIDE_U32_T bloodLeakDataPublishInterval = { BLOOD_LEAK_PUB_INTERVAL, + BLOOD_LEAK_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish blood leak data to CAN bus. +static U32 bloodLeakDataPublicationTimerCounter = 0; ///< Timer counter used to schedule blood leak data publication to CAN bus. +static U32 bloodLeakUARTCmdIndex; ///< Blood leak UART command index. +static U32 bloodLeakSetPointSeqLength = 0; ///< Blood leak set point sequence actual length. +static U08 bloodLeakSetPointSequence[ BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ]; ///< Blood leak set point sequence array. +static U32 bloodLeakWait2ReadSetPointCounter = 0; ///< Blood leak wait to read delay counter. +static U32 bloodLeakCurrentSetPointWriteTry = 0; ///< Blood leak current set point write try number. +static HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T bloodLeakCalRecord; ///< Blood leak calibration record structure. +static U32 bloodLeakGetCalStartTime = 0; ///< Blood leak get calibration start time. + +/// Blood leak start up sequence array. +static const U08 BLOOD_LEAK_START_UP_SEQUENCE[ BLOOD_LEAK_STARTUP_SEQ_LENGTH ] = { BLOOD_LEAK_RESET_TX_FIFO, + BLOOD_LEAK_UART_COMM_ACTIVE_LOW, + BLOOD_LEAK_START_COMM_CTRL_U_ASCII, + BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND, + BLOOD_LEAK_UART_COMM_ACTIVE_HIGH, + BLOOD_LEAK_UART_COMM_ACTIVE_LOW }; + // ********** private function prototypes ********** +static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ); +static BLOOD_LEAK_STATES_T handleBloodLeakCheckSetPointState( void ); +static BLOOD_LEAK_STATES_T handleBloodLeakSetSetPointState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakInitState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakZeroState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakSelfTestState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakNormalState( void ); +static void prepareSetPointSeq( void ); static void publishBloodLeakData( void ); /*********************************************************************//** * @brief * The initBloodLeak function initializes the Blood Leak module. * @details Inputs: none - * @details Outputs: Blood Leak module initialized. + * @details Outputs: bloodLeakState, bloodLeakStatus, bloodLeakSelfTestStatus, + * bloodLeakZeroRequested, bloodLeakZeroRequested, bloodLeakSelfTestStartTime, + * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence, + * bloodLeakWait2ReadSetPointCounter, bloodLeakDataPublicationTimerCounter, + * bloodLeakCurrentSetPointWriteTry, bloodLeakGetCalStartTime * @return none *************************************************************************/ void initBloodLeak( void ) { - bloodLeakState = BLOOD_LEAK_INIT_STATE; - bloodLeakStatus.data = BLOOD_LEAK_NOT_DETECTED; - bloodLeakStatus.ovInitData = BLOOD_LEAK_NOT_DETECTED; - bloodLeakStatus.ovData = BLOOD_LEAK_NOT_DETECTED; - bloodLeakStatus.override = OVERRIDE_RESET; - bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; - bloodLeakZeroRequested = FALSE; - bloodLeakZeroStartTime = 0; - bloodLeakSelfTestStartTime = 0; + bloodLeakDataPublicationTimerCounter = 0; + bloodLeakState = BLOOD_LEAK_START_UP_STATE; + bloodLeakStatus.data = BLOOD_LEAK_NOT_DETECTED; + bloodLeakStatus.ovInitData = BLOOD_LEAK_NOT_DETECTED; + bloodLeakStatus.ovData = BLOOD_LEAK_NOT_DETECTED; + bloodLeakStatus.override = OVERRIDE_RESET; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; + bloodLeakZeroRequested = FALSE; + bloodLeakZeroStartTime = 0; + bloodLeakSelfTestStartTime = 0; + bloodLeakUARTCmdIndex = 0; + bloodLeakSetPointSeqLength = 0; + bloodLeakWait2ReadSetPointCounter = 0; + bloodLeakCurrentSetPointWriteTry = 0; + bloodLeakGetCalStartTime = getMSTimerCount(); + + // Set the blood leak set pint sequence to 0 to be initialized + memset( bloodLeakSetPointSequence, 0x0, BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ); } /*********************************************************************//** * @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 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 ); + + getNVRecord2Driver( GET_CAL_BLOOD_LEAK_SENSOR, (U08*)&bloodLeakCalRecord, length, 0, ALARM_ID_HD_BLOOD_LEAK_INVALID_CAL_RECORD ); + prepareSetPointSeq(); + + // Force the state machine to go back to set the set point that has been received from + // 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(); + } + if ( getCurrentOperationMode() != MODE_INIT ) { // Execute blood leak state machine switch( bloodLeakState ) { + case BLOOD_LEAK_START_UP_STATE: + bloodLeakState = handleBloodLeakStartupState(); + break; + + case BLOOD_LEAK_CHECK_SET_POINT_STATE: + bloodLeakState = handleBloodLeakCheckSetPointState(); + break; + + case BLOOD_LEAK_SET_SET_POINT_STATE: + bloodLeakState = handleBloodLeakSetSetPointState(); + break; + case BLOOD_LEAK_INIT_STATE: bloodLeakState = handleBloodLeakInitState(); break; @@ -142,10 +233,158 @@ /*********************************************************************//** * @brief + * The execBloodLeakSelfTest function executes the blood leak self-test. + * @details Inputs: none + * @details Outputs: none + * @return blood leak self test results (SELF_TEST_STATUS_T) + *************************************************************************/ +SELF_TEST_STATUS_T execBloodLeakSelfTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + U32 length = sizeof( HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ); + ALARM_ID_T alarm = ALARM_ID_HD_BLOOD_LEAK_INVALID_CAL_RECORD; + BOOL calStatus = getNVRecord2Driver( GET_CAL_BLOOD_LEAK_SENSOR, (U08*)&bloodLeakCalRecord, length, 0, alarm ); + + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleBloodLeakStartupState function handles the startup state of the + * of blood leak state machine. + * @details Inputs: bloodLeakUARTCmdIndex + * @details Outputs: bloodLeakUARTCmdIndex + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ) +{ + BLOOD_LEAK_STATES_T state = BLOOD_LEAK_START_UP_STATE; + + 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 ); + } + else + { + setFPGABloodLeakUARTControl( (U08)command ); + } + + // Done with writing all the commands, reset the index and transition + if ( bloodLeakUARTCmdIndex >= ( BLOOD_LEAK_STARTUP_SEQ_LENGTH - 1 ) ) + { + bloodLeakUARTCmdIndex = 0; + state = BLOOD_LEAK_CHECK_SET_POINT_STATE; + } + else + { + bloodLeakUARTCmdIndex++; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBloodLeakCheckSetPointState function handles the check set point + * state to ensure the set point is set correctly. + * @details Inputs: none + * @details Outputs: bloodLeakUARTCmdIndex + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATES_T handleBloodLeakCheckSetPointState( void ) +{ + BLOOD_LEAK_STATES_T state = BLOOD_LEAK_CHECK_SET_POINT_STATE; + + U16 bloodLeakSetPoint = getFPGABloodLeakDetectSetPoint(); + + if ( bloodLeakSetPoint != bloodLeakCalRecord.setPoint ) + { + if ( bloodLeakCurrentSetPointWriteTry < BLOOD_LEAK_MAX_SET_POINT_WRITE_TRIALS ) + { + prepareSetPointSeq(); + bloodLeakCurrentSetPointWriteTry++; + state = BLOOD_LEAK_SET_SET_POINT_STATE; + } + else + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SENSOR_SET_POINT_SET_FAILURE ); + } + + } + else + { + state = BLOOD_LEAK_INIT_STATE; + bloodLeakCurrentSetPointWriteTry = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBloodLeakSetSetPointState function handles the set set point state. + * @details Inputs: bloodLeakUARTCmdIndex + * @details Outputs: bloodLeakUARTCmdIndex, bloodLeakSetPointSeqLength + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATES_T handleBloodLeakSetSetPointState( void ) +{ + BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SET_SET_POINT_STATE; + + // Check if the current buffer index is less than the buffer length + if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) + { + U32 command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; + + // The active high index is the length - 2 they are the last two elements + U32 activeHighIndex = bloodLeakSetPointSeqLength - 2; + + // Check if the current index towards the end of the buffer which are FIFO set and FIFO reset + if( activeHighIndex > bloodLeakUARTCmdIndex ) + { + setFPGABloodLeakUARTTransmit( (U08)command ); + } + else + { + setFPGABloodLeakUARTControl( (U08)command ); + } + + bloodLeakUARTCmdIndex++; + } + else + { + if ( ++bloodLeakWait2ReadSetPointCounter > BLOOD_LEAK_WAIT_2_READ_SET_POINT ) + { + bloodLeakWait2ReadSetPointCounter = 0; + bloodLeakUARTCmdIndex = 0; + // Done with writing the set point + state = BLOOD_LEAK_CHECK_SET_POINT_STATE; + } + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleBloodLeakInitState function handles the Blood Leak module in init * state. * @details Inputs: none - * @details Outputs: Blood Leak module init. + * @details Outputs: none * @return next state *************************************************************************/ static BLOOD_LEAK_STATES_T handleBloodLeakInitState( void ) @@ -188,7 +427,9 @@ { if ( TRUE == didTimeout( bloodLeakZeroStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) { +#ifndef IGNORE_BLOOD_LEAK_ALARM activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_FAULT ); +#endif } } @@ -207,6 +448,7 @@ { BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SELF_TEST_STATE; +#ifndef IGNORE_BLOOD_LEAK_ALARM if ( SELF_TEST_STATUS_IN_PROGRESS == bloodLeakSelfTestStatus ) { if ( FALSE == noFPGABloodLeakDetected() ) // Faked blood leak caused by independent MCU board @@ -217,8 +459,9 @@ else if ( TRUE == didTimeout( bloodLeakSelfTestStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) { bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SELF_TEST_FAILURE ); - } + } } else { @@ -228,6 +471,9 @@ state = BLOOD_LEAK_NORMAL_STATE; } } +#else + state = BLOOD_LEAK_NORMAL_STATE; +#endif return state; } @@ -254,21 +500,29 @@ } // Check status reading and act upon - if ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) + if ( ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) && ( MODE_TREA == getCurrentOperationMode() ) ) { - if ( getCurrentOperationMode() == MODE_TREA ) + if ( ++bloodLeakPersistenceCtr > BLOOD_LEAK_PERSISTENCE ) { + bloodLeakPersistenceCtr = BLOOD_LEAK_PERSISTENCE; +#ifndef IGNORE_BLOOD_LEAK_ALARM activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); +#endif } + } + else // Blood leak not detected + { + if ( bloodLeakPersistenceCtr > 0 ) + { + bloodLeakPersistenceCtr--; + } else { - activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_FAULT ); +#ifndef IGNORE_BLOOD_LEAK_ALARM + clearAlarmCondition( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); +#endif } } - else // Blood leak not detected - { - clearAlarmCondition( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); - } if ( TRUE == bloodLeakZeroRequested ) { @@ -317,21 +571,90 @@ /*********************************************************************//** * @brief + * The prepareSetPointSeq function prepares the set point sequence to be + * written to the blood leak sensor. + * @details Inputs: none + * @details Outputs: bloodLeakSetPointSequence, bloodLeakSetPointSeqLength + * @return none + *************************************************************************/ +static void prepareSetPointSeq( void ) +{ + U08 i; + // Set the local variables. + U32 digitCount; + U32 setPoint = bloodLeakCalRecord.setPoint; + U32 bufferIndex = BLOOD_LEAK_SET_POINT_START_CHAR_INDEX; + char tempCharBuffer[ BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ]; + memset( tempCharBuffer, 0x0, BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ); + + // Convert the set point number to the equivalent ASCII number with the unsigned integer data type + sprintf( tempCharBuffer, "%u", setPoint ); + + // Calculate the length of the character buffer. strlen does not count the null character. + digitCount = strlen( tempCharBuffer ); + + // Set the first item to the ASCII character of S. The format to set the set point is + // SXXXCR10. It starts with S followed by the characters up to 3 digits, carriage return and a 1 and a 0 to write to the buffer. + bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_SET_POINT_START_CHAR_ASCII; + + // Increment the buffer index + bufferIndex++; + + // Loop through the number of digits and get each ASCII value + for ( i = 0; i < digitCount; i++ ) + { + // Write the characters + bloodLeakSetPointSequence[ bufferIndex ] = tempCharBuffer[ i ]; + bufferIndex++; + } + + // After the characters, insert the carriage return into the buffer + bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_CARRIAGE_RETURN_ASCII; + bufferIndex++; + + // After the characters, insert the stop write to FIFO character which is number 0 + bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bufferIndex++; + + // Set active high and active low into the buffer + bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_UART_COMM_ACTIVE_HIGH; + bufferIndex++; + + bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_UART_COMM_ACTIVE_LOW; + + // Update the sequence length for writing to the sensor + bloodLeakSetPointSeqLength = bufferIndex + 1; + + // Get ready for the next write to the sensor + bloodLeakUARTCmdIndex = 0; +} + +/*********************************************************************//** + * @brief * The publishBloodLeakData function publishes blood leak data at the set interval. - * @details Inputs: bloodLeakStatus, bloodLeakState - * @details Outputs: if broadcast is due, send blood leak data + * @details Inputs: bloodLeakDataPublicationTimerCounter + * @details Outputs: bloodLeakDataPublicationTimerCounter * @return none *************************************************************************/ static void publishBloodLeakData( void ) { // Publish blood leak data on interval if ( ++bloodLeakDataPublicationTimerCounter >= getU32OverrideValue( &bloodLeakDataPublishInterval ) ) { - BLOOD_LEAK_DATA_T bloodLeakData; + BLOOD_LEAK_DATA_T data; - bloodLeakData.bloodLeakStatus = (U32)getBloodLeakStatus(); - bloodLeakData.bloodLeakState = (U32)bloodLeakState; - broadcastData( MSG_ID_HD_BLOOD_LEAK_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&bloodLeakData, sizeof( BLOOD_LEAK_DATA_T ) ); + data.bloodLeakStatus = (U32)getBloodLeakStatus(); + data.bloodLeakState = (U32)bloodLeakState; + data.bloodLeakZeroStatusCounter = (U32)getFPGABloodLeakZeroStatusCounter(); + data.bloodLeakCounter = (U32)getFPGABloodLeakCounter(); + data.bloodLeakZeroedStatus = (U32)getFPGABloodLeakZeroedStatus(); + data.bloodLeakDetectSetPoint = (U32)getFPGABloodLeakDetectSetPoint(); + data.bloodLeakDetectLevel = (U32)getFPGABloodLeakDetectLevel(); + data.bloodLeakStCount = (U32)getFPGABloodLeakStCount(); + data.bloodLeakLEDIntesity = (U32)getFPGABloodLeakLEDIntensity(); + data.bloodLeakRegisterCounter = (U32)getFPGABloodLeakRegisterCounter(); + + broadcastData( MSG_ID_HD_BLOOD_LEAK_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( BLOOD_LEAK_DATA_T ) ); bloodLeakDataPublicationTimerCounter = 0; } } @@ -360,7 +683,7 @@ U32 intvl = value / TASK_PRIORITY_INTERVAL; result = TRUE; - bloodLeakDataPublishInterval.ovData = intvl; + bloodLeakDataPublishInterval.ovData = intvl; bloodLeakDataPublishInterval.override = OVERRIDE_KEY; } @@ -383,7 +706,7 @@ { result = TRUE; bloodLeakDataPublishInterval.override = OVERRIDE_RESET; - bloodLeakDataPublishInterval.ovData = bloodLeakDataPublishInterval.ovInitData; + bloodLeakDataPublishInterval.ovData = bloodLeakDataPublishInterval.ovInitData; } return result; @@ -408,7 +731,7 @@ if ( TRUE == isTestingActivated() ) { result = TRUE; - bloodLeakStatus.ovData = (U32)status; + bloodLeakStatus.ovData = (U32)status; bloodLeakStatus.override = OVERRIDE_KEY; } } @@ -433,7 +756,7 @@ { result = TRUE; bloodLeakStatus.override = OVERRIDE_RESET; - bloodLeakStatus.ovData = bloodLeakStatus.ovInitData; + bloodLeakStatus.ovData = bloodLeakStatus.ovInitData; } return result;