Index: firmware/App/Controllers/ConductivitySensors.c =================================================================== diff -u -r56429f955d5da2c3e571908b5a383125ea078197 -rc20562aef9d0b7487f16aeaa0568f1d92ca844ed --- firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 56429f955d5da2c3e571908b5a383125ea078197) +++ firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision c20562aef9d0b7487f16aeaa0568f1d92ca844ed) @@ -74,6 +74,8 @@ #define EMSTAT_CPI_OR_CD1_INDEX 0 ///< Emstat board CPi index number. #define EMSTAT_CPO_OR_CD2_INDEX 1 ///< Emstat board CPo index number. +#define EMSTAT_PACKAGE_BUFFER_SIZE 50 ///< EmStat package buffer size + #define DATA_PUBLISH_COUNTER_START_COUNT 40 ///< Data publish counter start count. #define COND_SENSOR_BAD_STATUS_PERSISTENCE_PERIOD ( 1 * MS_PER_SECOND ) ///< Conductivity sensor bad status persistence period. #define COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Conductivity sensors FPGA error timeout in milliseconds. @@ -104,7 +106,7 @@ { BOOL packageStarted; ///< Emstat package started flag. U08 packageIndex; ///< Emstat package index number. - U08 package[ 50 ]; ///< Emstat read buffer package. + U08 package[ EMSTAT_PACKAGE_BUFFER_SIZE ]; ///< Emstat read buffer package. EMSTAT_COND_SENSORS_T sensors[ EMSTAT_NUM_OF_SENSORS_PER_BOARD ]; ///< Emstat conductivity and corresponding temperature sensors. } EMSTAT_READ_T; @@ -149,6 +151,9 @@ static void processEmstatMeasurementDataPackets( U08 boardSensorIndex, EMSTAT_READ_T* readPackage, EMSTAT_VARIABLE_T* receivedPackets ); static F32 getCalibrationAppliedConductivityValue( U32 sensorId, F32 compensatedValue ); +//#define PICO_STATUS_CHECK //wjb +//#define CONDUCTIVITY_BAD_CHAR //wjb + /*********************************************************************//** * @brief * The initConductivitySensors function initializes the ConductivitySensors module. @@ -526,12 +531,18 @@ checkFPGAPersistentAlarms( FPGA_PERS_ERROR_CPI_CPO_COND_SENSORS, rxFifoCount ); // Only process the sensor read if there is a new byte +#ifdef PICO_STATUS_CHECK + rxFifoCount = 10; +#endif if ( 0 != rxFifoCount ) { emstatByte = getFPGAEmstatCPiCPoByteOut(); // fpgaErrorCount = getFPGAEmstatCPiCPoRxErrCount(); // checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_CPI_CPO_COND_SENSORS, fpgaErrorCount ); +#ifdef PICO_STATUS_CHECK + emstatByte = ';'; +#endif processEmstatSensorRead( &emstatBoardRead[ EMSTAT_CPI_CPO_BOARD ], emstatByte ); } break; @@ -542,12 +553,19 @@ checkFPGAPersistentAlarms( FPGA_PERS_ERROR_CD1_CD2_COND_SENSORS, rxFifoCount ); // Only process the sensor read if there is a new byte +#ifdef PICO_STATUS_CHECK + rxFifoCount = 10; +#endif if ( 0 != rxFifoCount) { emstatByte = getFPGAEmstatCD1CD2OutByte(); // fpgaErrorCount = getFPGAEmstatCD1CD2RxErrCount(); // checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_CD1_CD2_COND_SENSORS, fpgaErrorCount ); +#ifdef PICO_STATUS_CHECK + emstatByte = ';'; +#endif + processEmstatSensorRead( &emstatBoardRead[ EMSTAT_CD1_CD2_BOARD ], emstatByte ); } break; @@ -578,15 +596,19 @@ break; case ';': +#ifndef PICO_STATUS_CHECK if ( TRUE == readPackage->packageStarted ) +#endif { processEmstatMeasurementDataPackets( EMSTAT_CPI_OR_CD1_INDEX, readPackage, (EMSTAT_VARIABLE_T*)readPackage->package ); readPackage->packageIndex = 0; } break; case '\n': +#ifndef PICO_STATUS_CHECK if ( TRUE == readPackage->packageStarted ) +#endif { processEmstatMeasurementDataPackets( EMSTAT_CPO_OR_CD2_INDEX, readPackage, (EMSTAT_VARIABLE_T*)readPackage->package ); readPackage->packageStarted = FALSE; @@ -615,12 +637,27 @@ *************************************************************************/ static void processEmstatMeasurementDataPackets( U08 boardSensorIndex, EMSTAT_READ_T* readPackage, EMSTAT_VARIABLE_T* receivedPackets ) { + +#ifdef PICO_STATUS_CHECK + static int picoCounter = 0; + int picoSensorId = 0; + int picoCounterMax = 10000; +#endif CONDUCTIVITY_SENSORS_T sensorId = readPackage->sensors[ boardSensorIndex ].condSnsr; BOOL convStatus = hexStrToDec( (U08*)&receivedPackets->status, &condSensorStatus[ sensorId ].sensorStatus, sizeof( receivedPackets->status ) ); BOOL isSensorStatusBad = ( EMSTAT_PICO_STATUS_TIMING_NOT_MET == condSensorStatus[ sensorId ].sensorStatus ? TRUE : FALSE ); ALARM_ID_T badHexAlarm = readPackage->sensors[ boardSensorIndex ].condSnsrHex2StrAlarm; BOOL isConvNotValid = FALSE; +#ifdef PICO_STATUS_CHECK + if (picoCounter++ >= picoCounterMax) + { + // simulate error + condSensorStatus[ picoSensorId ].sensorStatus = EMSTAT_PICO_STATUS_TIMING_NOT_MET; + isSensorStatusBad = TRUE; + } +#endif + if ( FALSE == isSensorStatusBad ) { U32 prefix = prefixStrToSIFactor( receivedPackets->prefix ); @@ -635,6 +672,9 @@ condSensorStatus[ sensorId ].rawCondValue = conductivity; } +#ifdef CONDUCTIVITY_BAD_CHAR + convStatus = FALSE; +#endif isConvNotValid = ( TRUE == convStatus ? FALSE : TRUE ); // Check the conductivity sensors bad status alarm checkPersistentAlarm( badHexAlarm, isConvNotValid, isConvNotValid, COND_SENSORS_BAD_CHAR_TIME_OUT_MS ); Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r9e5ee62245eb2a73b167eabd6c274a71a76a7b0e -rc20562aef9d0b7487f16aeaa0568f1d92ca844ed --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 9e5ee62245eb2a73b167eabd6c274a71a76a7b0e) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision c20562aef9d0b7487f16aeaa0568f1d92ca844ed) @@ -107,6 +107,9 @@ #define PROCESSOR_FPGA_CLOCK_DIFF_TOLERANCE 1 ///< Tolerance for processor clock speed check against FPGA clock. +#define MAX_FPGA_COMM_FAILURES_WINDOW_MS (1 * SEC_PER_MIN * MS_PER_SECOND) ///< ///< FPGA comm failures window +#define MAX_FPGA_COMM_FAILURES 3 ///< FPGA maximum comm failures per MAX_FPGA_COMM_FAILURES_WINDOW_MS + // FPGA header struct. #pragma pack(push,1) typedef struct @@ -328,7 +331,6 @@ // ********** private data ********** static FPGA_STATE_T fpgaState = FPGA_STATE_START; ///< FPGA current state. -static U32 fpgaCommRetryCount = 0; ///< FPGA communication retry count. static U32 fpgaReceiptCounter = 0; ///< FPGA receipt completed counter. static U32 fpgaTransmitCounter = 0; ///< FPGA transmit completed counter. static BOOL fpgaWriteCommandInProgress = FALSE; ///< Flag indicates whether a FPGA write command is in progress. @@ -379,6 +381,8 @@ static void consumeUnexpectedData( void ); static void monitorFPGAPowerStatus( void ); +static BOOL checkFPGACommFailure( void ); + /*********************************************************************//** * @brief * The initFPGA function initializes the FPGA module. @@ -497,6 +501,10 @@ // Initialize the persistent alarm for FPGA power out initPersistentAlarm( ALARM_ID_DG_FPGA_POWER_OUT_TIMEOUT, FPGA_POWER_OUT_TIMEOUT_MS, FPGA_POWER_OUT_TIMEOUT_MS ); + + // initialize FPGA clock speed error time windowed count + initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES_WINDOW_MS); + } /*********************************************************************//** @@ -607,15 +615,12 @@ } // if retries for commands exceeds limit or FPGA reports comm error, fault - if ( ( fpgaCommRetryCount > MAX_COMM_ERROR_RETRIES ) #ifdef _RELEASE_ - || ( fpgaSensorReadings.fpgaIOErrorCntProcessor > MAX_COMM_ERROR_RETRIES ) ) -#else - ) -#endif + if ( fpgaSensorReadings.fpgaIOErrorCntProcessor > MAX_COMM_ERROR_RETRIES ) { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FPGA_COMM_TIMEOUT, fpgaCommRetryCount, (U32)fpgaSensorReadings.fpgaIOErrorCntProcessor ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FPGA_COMM_TIMEOUT, MAX_FPGA_COMM_FAILURES, (U32)fpgaSensorReadings.fpgaIOErrorCntProcessor ) } +#endif // reset comm flags after processing incoming responses resetFPGACommFlags(); @@ -719,24 +724,23 @@ // does the FPGA response CRC check out? if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) { - fpgaCommRetryCount = 0; // capture the read values memcpy( &fpgaHeader, &fpgaReadResponseBuffer[ FPGA_READ_RSP_HDR_LEN ], sizeof( FPGA_HEADER_T ) ); result = FPGA_STATE_WRITE_ALL_ACTUATORS; } else { - fpgaCommRetryCount++; + checkFPGACommFailure(); } } else // header read was NAK'd { - fpgaCommRetryCount++; + checkFPGACommFailure(); } } else // no response to read command { - fpgaCommRetryCount++; + checkFPGACommFailure(); } // There should not be any data received at this time @@ -811,12 +815,15 @@ *************************************************************************/ static FPGA_STATE_T handleFPGAReceiveAllSensorsState( void ) { + static int CRCCounter = 0; + static int NAKCounter = 0; + FPGA_STATE_T result = FPGA_STATE_WRITE_ALL_ACTUATORS; // check bulk write command success if ( ( FALSE == fpgaWriteCommandResponseReceived ) || ( fpgaWriteResponseBuffer[ 0 ] != FPGA_WRITE_CMD_ACK ) ) { - fpgaCommRetryCount++; + checkFPGACommFailure(); } // if bulk read command is ACK'd, collect the readings @@ -828,28 +835,36 @@ U32 rspSize = FPGA_READ_RSP_HDR_LEN + fpgaReadByteSize; U32 crcPos = rspSize; U16 crc = MAKE_WORD_OF_BYTES( fpgaReadResponseBuffer[ crcPos ], fpgaReadResponseBuffer[ crcPos + 1 ] ); + U08 address1 = fpgaReadResponseBuffer[1]; //wjb + U08 address2 = fpgaReadResponseBuffer[2]; //wjb + U32 loadCell = getFPGALoadCellA1(); + if (fpgaReadResponseBuffer[1] != 0) + CRCCounter++; + + if (fpgaReadResponseBuffer[1] != 0xaa) + NAKCounter++; + // does the FPGA response CRC check out? if ( crc == crc16( fpgaReadResponseBuffer, rspSize ) ) { - fpgaCommRetryCount = 0; // capture the read values memcpy( &fpgaSensorReadings, &fpgaReadResponseBuffer[ FPGA_READ_RSP_HDR_LEN ], fpgaReadByteSize ); result = FPGA_STATE_WRITE_ALL_ACTUATORS; } else // bad CRC { - fpgaCommRetryCount++; - } + checkFPGACommFailure(); + } } else // read command was NAK'd { - fpgaCommRetryCount++; + checkFPGACommFailure(); } } else // no response to read command { - fpgaCommRetryCount++; + checkFPGACommFailure(); } // There should not be any data received at this time @@ -902,7 +917,11 @@ *************************************************************************/ void execFPGAClockSpeedTest( void ) { + #ifndef DEBUG_ENABLED + static U16 currentFPGATimerCount_ms = 0; + static U32 currentTimerCount_ms = 0; + U16 const newFPGATimerCount_ms = getFPGATimerCount(); U32 const newTimerCount_ms = getMSTimerCount(); U32 const diffFPGATimerCount = (U32)u16DiffWithWrap( currentFPGATimerCount_ms, newFPGATimerCount_ms ); @@ -2686,4 +2705,26 @@ return fpgaSensorReadings.fpgaPowerSupply2; } +/*********************************************************************//** + * @brief + * The checkFPGACommFailure function increments the FPGA comm failure + * windowed timer and returns whether or not the number of failures in + * the window have been reached. + * @details Inputs: none + * @details Outputs: none + * @return TRUE if windowed count exceeded, else false. + *************************************************************************/ +BOOL checkFPGACommFailure( void ) +{ + BOOL status = false; + + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FPGA_COMM_TIMEOUT, MAX_FPGA_COMM_FAILURES, (U32)fpgaSensorReadings.fpgaIOErrorCntProcessor ) + status = TRUE; + } + + return status; + +} /**@}*/