Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rab14e70c7bac24b0c3ebd02c6763285cdd3951ce -r4853f9f01e6a406783201902937d9ace760b0b38 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ab14e70c7bac24b0c3ebd02c6763285cdd3951ce) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 4853f9f01e6a406783201902937d9ace760b0b38) @@ -120,15 +120,16 @@ U32 readCount; ///< Read counts from FPGA OVERRIDE_F32_T temperatureValues; ///< Temperature values with override F32 maxAllowedTemperature; ///< Maximum allowed temperature of the sensor + U32 alarmStartTime; ///< Alarm start time } TEMP_SENSOR_T; // ********** private data ********** static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state. static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure. -static U32 fpgaRawADCReadInterval = 0; ///< FPGA raw ADC read interval count. -static U32 elapsedTime = 0; ///< Elapsed time variable. -static U32 internalHeatersConversionTimer = 0; ///< Conversion timer variable to calculate the heaters internal temperature. +static U32 fpgaRawADCReadInterval; ///< FPGA raw ADC read interval count. +static U32 elapsedTime; ///< Elapsed time variable. +static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature. static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, @@ -172,6 +173,7 @@ static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); static void monitorTemperatureSnsrs( U32 sensorIndex ); +static void checkAlarmStatus( U32 sensorIndex, ALARM_ID_T alarm, BOOL alarmOccurred, U32 alarmTimeout ); /*********************************************************************//** * @brief @@ -294,7 +296,7 @@ // Persistent alarm for the temperature sensors error bit fault check initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS, - TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS ); + TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS ); // TODO remove? // Persistent alarm for temperature sensors ADC error // When the FPGA read count does not increment for a period of time, it is considered as an internal error of the temperature sensors @@ -596,10 +598,23 @@ // is shifted 31 bits to the first bit of the U32 variable. // If that bit is a 1, there is either CRC error or Status error // that are ored on top of each other - U32 errorBit = adc >> 31; - isTemperatureNotValid = errorBit > 0; - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, sensorIndex, - TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); + U32 errorBit = adc >> 31; + isTemperatureNotValid = ( errorBit > 0 ? TRUE : FALSE ); + + // TODO for debugging only remove + if ( TRUE == isTemperatureNotValid ) + { + BOOL test = FALSE; + } + // TODO remove + + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, sensorIndex ); + + //checkAlarmStatus( sensorIndex, ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); + + // TODO remove this + //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, sensorIndex, + // TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); } break; @@ -658,28 +673,27 @@ static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) { BOOL isADCValid = FALSE; -#ifndef _VECTORCAST_ - isADCValid = TRUE; // TODO remove this line. Temporary set to true until FPGA error count is fixed - //THIS ISSUE HAS BEEN FIXED. TRY IT. -#endif // Check the status of FPGA error and FPGA count - BOOL isFPGAErrorZero = ( fpgaError == 0 ? TRUE : FALSE ); + BOOL isFPGAErrorZero = ( fpgaError == 0 ? TRUE : FALSE ); BOOL isFPGACountChanging = ( tempSensors[ sensorIndex ].readCount != fpgaCount ? TRUE : FALSE ); if ( TRUE == isFPGAErrorZero ) { if ( TRUE == isFPGACountChanging ) { tempSensors[ sensorIndex ].readCount = fpgaCount; - isADCValid = TRUE; + isADCValid = TRUE; } } BOOL isThereAnError = ( ( FALSE == isFPGACountChanging ) || ( FALSE == isFPGAErrorZero ) ? TRUE : FALSE ); - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + //checkAlarmStatus( sensorIndex, ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + // TODO remove + //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + return isADCValid; } @@ -698,15 +712,15 @@ { F32 temperature; - U32 const index = tempSensors[ sensorIndex ].adcNextIndex; - S32 const indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; + U32 index = tempSensors[ sensorIndex ].adcNextIndex; + S32 indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; tempSensors[ sensorIndex ].rawADCReads[ index ] = adc; tempSensors[ sensorIndex ].adcNextIndex = INC_WRAP( index, 0, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); tempSensors[ sensorIndex ].adcRunningSum = tempSensors[ sensorIndex ].adcRunningSum - indexValue + adc; // Calculate the average - F32 const avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; + F32 avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; // Check if the ADC value of the sensor is not out of range if ( ( (U32)avgADCReads < TEMP_SESNORS_MIN_ALLOWED_ADC_COUNT ) || ( (U32)avgADCReads > TEMP_SENSORS_MAX_ALLOWED_ADC_COUNT ) ) @@ -805,9 +819,9 @@ *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues( void ) { - U32 rawADC = 0; + U32 rawADC = 0; U32 errorCount = 0; - U32 readCount = 0; + U32 readCount = 0; // Look at the error counter and the specific error flag to make sure the error is a temperature sensor // Add a byte array to have bits for each sensor to find out exactly what sensor failed @@ -950,7 +964,41 @@ } } +/*********************************************************************//** + * @brief + * The checkAlarmStatus function checks the status of an alarm and check whether + * it has timed out. + * @details Inputs: tempSensors + * @details Outputs: tempSensors + * @param sensorIndex the index of the temperature sensor + * @param alarm the alarm ID + * @param alarmOccures the boolean signal that indicates whether the error has + * occurred. + * @param alarmTimeout the timeout of the provided timeout + * @return none + *************************************************************************/ +static void checkAlarmStatus( U32 sensorIndex, ALARM_ID_T alarm, BOOL alarmOccurred, U32 alarmTimeout ) +{ + U32 startTime = tempSensors[ sensorIndex ].alarmStartTime; + if ( TRUE == alarmOccurred ) + { + if ( 0 == startTime ) + { + tempSensors[ sensorIndex ].alarmStartTime = getMSTimerCount(); + } + else if ( TRUE == didTimeout( startTime, alarmTimeout ) ) + { + SET_ALARM_WITH_2_U32_DATA( alarm, sensorIndex, alarmTimeout ); + } + } + else if ( ( FALSE == alarmOccurred ) && ( startTime != 0 ) ) + { + tempSensors[ sensorIndex ].alarmStartTime = 0; + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rab14e70c7bac24b0c3ebd02c6763285cdd3951ce -r4853f9f01e6a406783201902937d9ace760b0b38 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision ab14e70c7bac24b0c3ebd02c6763285cdd3951ce) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 4853f9f01e6a406783201902937d9ace760b0b38) @@ -321,8 +321,8 @@ { DG_CMD_RESPONSE_T cmdResponse; - cmdResponse.commandID = DG_CMD_SAMPLE_WATER; - cmdResponse.rejected = TRUE; + cmdResponse.commandID = DG_CMD_SAMPLE_WATER; + cmdResponse.rejected = TRUE; cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_INVALID_MODE; switch ( sampleWaterCmd ) @@ -331,7 +331,7 @@ if ( ( DG_MODE_STAN == getCurrentOperationMode() ) && ( DG_STANDBY_MODE_STATE_SAMPLE_WATER == standbyState ) ) { stopSampleWaterRequest = TRUE; - cmdResponse.rejected = FALSE; + cmdResponse.rejected = FALSE; cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; } break; @@ -340,25 +340,25 @@ if ( ( DG_MODE_STAN == getCurrentOperationMode() ) && ( DG_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE == standbyState ) ) { startSampleWaterRequest = TRUE; - cmdResponse.rejected = FALSE; - cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; + cmdResponse.rejected = FALSE; + cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; } break; case SAMPLE_WATER_CMD_FLUSH: if ( ( DG_MODE_STAN == getCurrentOperationMode() ) && ( DG_STANDBY_MODE_STATE_IDLE == standbyState ) ) { - flushFilterRequest = TRUE; - cmdResponse.rejected = FALSE; + flushFilterRequest = TRUE; + cmdResponse.rejected = FALSE; cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; } break; case SAMPLE_WATER_CMD_END: if ( DG_MODE_STAN == getCurrentOperationMode() ) { - endSampleWaterRequest = TRUE; - cmdResponse.rejected = FALSE; + endSampleWaterRequest = TRUE; + cmdResponse.rejected = FALSE; cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; } break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r1e22b6ff6f42ddc57ad6c17e56057ab8a3765680 -r4853f9f01e6a406783201902937d9ace760b0b38 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1e22b6ff6f42ddc57ad6c17e56057ab8a3765680) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 4853f9f01e6a406783201902937d9ace760b0b38) @@ -450,21 +450,24 @@ DG_VERSIONS_T payload; U08 *payloadPtr = msg.payload; - // populate payload - payload.major = (U08)DG_VERSION_MAJOR; - payload.minor = (U08)DG_VERSION_MINOR; - payload.micro = (U08)DG_VERSION_MICRO; - payload.build = (U16)DG_VERSION_BUILD; - payload.compatibilityRev = (U32)SW_COMPATIBILITY_REV; - getFPGAVersions( &payload.fpgaId, &payload.fpgaMajor, &payload.fpgaMinor, &payload.fpgaLab ); + if ( message->hdr.payloadLen == sizeof( U08 ) + sizeof( U08 ) + sizeof( U08 ) + sizeof( U16 ) + sizeof( U32 ) ) + { + // populate payload + payload.major = (U08)DG_VERSION_MAJOR; + payload.minor = (U08)DG_VERSION_MINOR; + payload.micro = (U08)DG_VERSION_MICRO; + payload.build = (U16)DG_VERSION_BUILD; + payload.compatibilityRev = (U32)SW_COMPATIBILITY_REV; + getFPGAVersions( &payload.fpgaId, &payload.fpgaMajor, &payload.fpgaMinor, &payload.fpgaLab ); - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_VERSION; - msg.hdr.payloadLen = sizeof( DG_VERSIONS_T ); + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_VERSION; + msg.hdr.payloadLen = sizeof( DG_VERSIONS_T ); - // fill message payload - memcpy( payloadPtr, &payload, sizeof( DG_VERSIONS_T ) ); + // fill message payload + memcpy( payloadPtr, &payload, sizeof( DG_VERSIONS_T ) ); + } // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); @@ -497,7 +500,7 @@ msg.hdr.payloadLen = MAX_TOP_LEVEL_SN_CHARS + 1; // Fill message payload - memcpy( payloadPtr, &system.topLevelSN, MAX_TOP_LEVEL_SN_CHARS ); + memcpy( payloadPtr, &system.topLevelSN, sizeof( U08 ) * MAX_TOP_LEVEL_SN_CHARS ); payloadPtr += MAX_TOP_LEVEL_SN_CHARS; *payloadPtr = 0;