Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r0ddfb88172db9b6c0b41b1dc5c0cc3e0296068be -r2c9bbece8057254f8389c26a818081002fb69a77 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 0ddfb88172db9b6c0b41b1dc5c0cc3e0296068be) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 2c9bbece8057254f8389c26a818081002fb69a77) @@ -40,12 +40,14 @@ #define BLOOD_LEAK_UART_COMM_ACTIVE_HIGH 1 ///< Blood leak UART communication active high command. #define BLOOD_LEAK_STARTUP_SEQ_LENGTH 5 ///< Blood leak start up sequence array length. -#define BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH 4 -#define BLOOD_LEAK_SET_POINT_START_CHAR_ASCII 83 -#define BLOOD_LEAK_SET_POINT_START_CHAR_INDEX 0 -#define BLOOD_LEAK_CARRIAGE_RETURN_ASCII 13 -#define BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH 7 +#define BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH 4 ///< 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_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 7 ///< Blood leak set point sequence maximum length. +#define BLOOD_LEAK_WAIT_2_READ_SET_POINT ( 0.5 * 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. /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates @@ -75,13 +77,13 @@ 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 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, @@ -111,22 +113,27 @@ * @details Inputs: none * @details Outputs: bloodLeakState, bloodLeakStatus, bloodLeakSelfTestStatus, * bloodLeakZeroRequested, bloodLeakZeroRequested, bloodLeakSelfTestStartTime, - * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence + * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence, + * bloodLeakWait2ReadSetPointCounter, bloodLeakDataPublicationTimerCounter, + * bloodLeakCurrentSetPointWriteTry * @return none *************************************************************************/ void initBloodLeak( void ) { - 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; + 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; // Set the blood leak set pint sequence to 0 to be initialized memset( bloodLeakSetPointSequence, 0x0, BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ); @@ -248,12 +255,20 @@ U32 bloodLeakSetPoint = (U32)getFPGABloodLeakDetectSetPoint(); - if ( REMOVE_LATER_SET_POINT != bloodLeakSetPoint ) + if ( bloodLeakSetPoint != REMOVE_LATER_SET_POINT ) { - prepareSetPointSeq(); + if ( bloodLeakCurrentSetPointWriteTry < BLOOD_LEAK_MAX_SET_POINT_WRITE_TRIALS ) + { + prepareSetPointSeq(); - bloodLeakUARTCmdIndex = 0; - state = BLOOD_LEAK_SET_SET_POINT_STATE; + bloodLeakUARTCmdIndex = 0; + state = BLOOD_LEAK_SET_SET_POINT_STATE; + } + else + { + // TODO fault alarm that we cannot write to blood leak? + } + } else { @@ -274,16 +289,16 @@ { BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SET_SET_POINT_STATE; - U32 command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; - // Check if the current buffer index is less than the buffer length if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) { - // The active high index is the length - 2 they are the last two elements - 1 since the - // index starts from 0 + 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 1 and 0 - if( activeHighIndex == bloodLeakUARTCmdIndex ) + if( activeHighIndex > bloodLeakUARTCmdIndex ) { setFPGABloodLeakUARTTransmit( (U08)command ); } @@ -296,8 +311,14 @@ } else { - // Done with writing the set point - state = BLOOD_LEAK_INIT_STATE; + 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;