80 .lastRedundancy0CellvoltageTimestamp = 0u,
81 .lastBaseCelltemperatureTimestamp = 0u,
82 .lastRedundancy0CelltemperatureTimestamp = 0u,
83 .lastStringCurrentTimestamp = {0u},
106 uint32_t previousTimestamp,
107 uint32_t timeInterval);
245 if (!((timestamp == 0u) && (previousTimestamp == 0u))) {
256 uint32_t previousTimestamp,
257 uint32_t timeInterval) {
263 if (((currentTimestamp - timestamp) <= timeInterval) &&
278 bool updatedValidatedVoltageDatbaseEntry =
false;
280 bool baseCellvoltageUpdated =
false;
282 bool useCellvoltageRedundancy =
false;
283 bool baseCellvoltageMeasurementTimeoutReached =
true;
284 bool redundancy0CellvoltageMeasurementTimeoutReached =
true;
301 baseCellvoltageMeasurementTimeoutReached =
false;
304 baseCellvoltageMeasurementTimeoutReached =
true;
311 baseCellvoltageUpdated =
true;
313 baseCellvoltageUpdated =
false;
319 (useCellvoltageRedundancy ==
true)) {
320 redundancy0CellvoltageMeasurementTimeoutReached =
true;
324 redundancy0CellvoltageMeasurementTimeoutReached =
false;
329 if (useCellvoltageRedundancy ==
true) {
330 bool redundany0CellvoltageUpdated =
false;
333 redundany0CellvoltageUpdated =
true;
335 redundany0CellvoltageUpdated =
false;
338 if ((baseCellvoltageUpdated ==
true) && (redundany0CellvoltageUpdated ==
true)) {
346 updatedValidatedVoltageDatbaseEntry =
true;
348 }
else if ((baseCellvoltageUpdated ==
true) || (redundany0CellvoltageUpdated ==
true)) {
350 if (baseCellvoltageUpdated ==
true) {
352 if (redundancy0CellvoltageMeasurementTimeoutReached ==
true) {
356 updatedValidatedVoltageDatbaseEntry =
true;
358 }
else if (redundany0CellvoltageUpdated ==
true) {
360 if (baseCellvoltageMeasurementTimeoutReached ==
true) {
364 updatedValidatedVoltageDatbaseEntry =
true;
373 if (baseCellvoltageUpdated ==
true) {
382 updatedValidatedVoltageDatbaseEntry =
true;
386 if (updatedValidatedVoltageDatbaseEntry ==
true) {
397 return updatedValidatedVoltageDatbaseEntry;
406 bool baseCelltemperatureUpdated =
false;
407 bool useCelltemperatureRedundancy =
false;
408 bool updatedValidatedTemperatureDatbaseEntry =
false;
410 bool baseCellTemperatureMeasurementTimeoutReached =
true;
411 bool redundancy0CellTemperatureMeasurementTimeoutReached =
true;
428 baseCellTemperatureMeasurementTimeoutReached =
false;
431 baseCellTemperatureMeasurementTimeoutReached =
true;
437 baseCelltemperatureUpdated =
true;
439 baseCelltemperatureUpdated =
false;
445 (useCelltemperatureRedundancy ==
true)) {
446 redundancy0CellTemperatureMeasurementTimeoutReached =
true;
450 redundancy0CellTemperatureMeasurementTimeoutReached =
false;
455 if (useCelltemperatureRedundancy ==
true) {
456 bool redundancy0CelltemperatureUpdated =
false;
459 redundancy0CelltemperatureUpdated =
true;
461 redundancy0CelltemperatureUpdated =
false;
464 if ((baseCelltemperatureUpdated ==
true) && (redundancy0CelltemperatureUpdated ==
true)) {
472 updatedValidatedTemperatureDatbaseEntry =
true;
474 }
else if ((baseCelltemperatureUpdated ==
true) || (redundancy0CelltemperatureUpdated ==
true)) {
476 if (baseCelltemperatureUpdated ==
true) {
478 if (redundancy0CellTemperatureMeasurementTimeoutReached ==
true) {
482 updatedValidatedTemperatureDatbaseEntry =
true;
484 }
else if (redundancy0CelltemperatureUpdated ==
true) {
486 if (baseCellTemperatureMeasurementTimeoutReached ==
true) {
490 updatedValidatedTemperatureDatbaseEntry =
true;
499 if (baseCelltemperatureUpdated ==
true) {
508 updatedValidatedTemperatureDatbaseEntry =
true;
512 if (updatedValidatedTemperatureDatbaseEntry ==
true) {
523 return updatedValidatedTemperatureDatbaseEntry;
528 int32_t packCurrent_mA = 0;
542 if (noTimeout ==
STD_OK) {
600 if (voltagePlausible ==
STD_OK) {
622 uint16_t numberInvalidCellVoltages =
641 int64_t sumOfStringValues_mV = 0;
642 int8_t numberOfValidStringVoltages = 0;
645 if (0u != numberOfConnectedStrings) {
652 numberOfValidStringVoltages++;
662 numberOfValidStringVoltages++;
669 if (0 != numberOfValidStringVoltages) {
682 uint8_t validVoltages = 0u;
693 if (((stringPrecharging ==
true) || (stringClosed ==
true)) && (updatedMeasurement ==
STD_OK)) {
703 if (validVoltages > 0u) {
714 bool calculatePower =
false;
715 int32_t packPower_W = 0;
728 if (noTimeout ==
STD_OK) {
738 calculatePower =
true;
746 calculatePower =
true;
752 int64_t stringPower_W =
782 uint16_t nrValidCellvoltages = 0u;
783 int16_t min = INT16_MAX;
784 int16_t max = INT16_MIN;
786 uint16_t moduleNumberMinimum = 0u;
787 uint16_t cellNumberMinimum = 0u;
788 uint16_t moduleNumberMaximum = 0u;
789 uint16_t cellNumberMaximum = 0u;
795 nrValidCellvoltages++;
800 moduleNumberMinimum = m;
801 cellNumberMinimum = c;
805 moduleNumberMaximum = m;
806 cellNumberMaximum = c;
820 if (nrValidCellvoltages > 0u) {
840 uint16_t moduleNumberMinimum = 0u;
841 uint16_t sensorNumberMinimum = 0u;
842 uint16_t moduleNumberMaximum = 0u;
843 uint16_t sensorNumberMaximum = 0u;
844 uint16_t nrValidCelltemperatures = 0u;
845 int16_t min = INT16_MAX;
846 int16_t max = INT16_MIN;
847 float sum_ddegC = 0.0f;
853 nrValidCelltemperatures++;
854 sum_ddegC += (float)pValidatedTemperatures
859 min = pValidatedTemperatures
861 moduleNumberMinimum = m;
862 sensorNumberMinimum = c;
866 max = pValidatedTemperatures
868 moduleNumberMaximum = m;
869 sensorNumberMaximum = c;
883 if (nrValidCelltemperatures > 0u) {
902 uint16_t numberValidMeasurements = 0u;
922 numberValidMeasurements++;
938 numberValidMeasurements++;
947 numberValidMeasurements++;
965 numberValidMeasurements = 0u;
968 noPlausibilityIssueDetected =
STD_OK;
983 *pValidatedVoltages = *pCellvoltage;
985 pValidatedVoltages->
header = tmpHeader;
999 uint16_t numberValidMeasurements = 0u;
1013 pCelltemperatureRedundancy0
1015 &pValidatedTemperatures
1020 numberValidMeasurements++;
1035 numberValidMeasurements++;
1039 pCelltemperatureRedundancy0
1044 numberValidMeasurements++;
1050 pCelltemperatureRedundancy0
1061 numberValidMeasurements = 0u;
1064 noPlausibilityIssueDetected =
STD_OK;
1080 *pValidatedTemperature = *pCellTemperature;
1082 pValidatedTemperature->
header = tmpHeader;
1127 &mrc_tableCellvoltageBase,
1128 &mrc_tableCellvoltageRedundancy0,
1129 &mrc_tableCelltemperatureBase,
1130 &mrc_tableCelltemperatureRedundancy0);
1133 bool updateCellVoltages =
1137 bool updateCellTemperatures =
1141 if ((updateCellVoltages ==
true) && (updateCellTemperatures ==
true)) {
1143 }
else if (updateCellVoltages ==
true) {
1145 }
else if (updateCellTemperatures ==
true) {
1171 #ifdef UNITY_UNIT_TEST
1172 extern bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp) {
1177 uint32_t previousTimestamp,
1178 uint32_t timeInterval) {
1181 extern bool TEST_MRC_ValidateCellVoltageMeasurement(
1186 extern bool TEST_MRC_ValidateCellTemperatureMeasurement(
1199 extern void TEST_MRC_ValidateStringVoltageMeasurement(
1204 extern void TEST_MRC_ValidateBatteryVoltageMeasurement(
void) {
#define BS_NR_OF_CELL_BLOCKS_PER_MODULE
number of cells per module
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
#define BS_NR_OF_CELL_BLOCKS_PER_STRING
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
bool BMS_IsStringPrecharging(uint8_t stringNumber)
Returns if string is currently precharging or not.
uint8_t BMS_GetNumberOfConnectedStrings(void)
Returns number of connected strings.
bool BMS_IsStringClosed(uint8_t stringNumber)
Returns string state (closed or open)
#define DATA_READ_DATA(...)
#define DATA_WRITE_DATA(...)
@ DATA_BLOCK_ID_CELL_VOLTAGE_REDUNDANCY0
@ DATA_BLOCK_ID_CELL_VOLTAGE
@ DATA_BLOCK_ID_CELL_TEMPERATURE_REDUNDANCY0
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
@ DATA_BLOCK_ID_CURRENT_SENSOR
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
@ DATA_BLOCK_ID_PACK_VALUES
@ DATA_BLOCK_ID_CELL_TEMPERATURE
bool DATA_DatabaseEntryUpdatedAtLeastOnce(DATA_BLOCK_HEADER_s dataBlockHeader)
Checks if passed database entry has been updated at least once.
bool DATA_EntryUpdatedWithinInterval(DATA_BLOCK_HEADER_s dataBlockHeader, uint32_t timeInterval)
Checks if passed database entry has been updated within the last time interval.
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diag_id, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
STD_RETURN_TYPE_e DIAG_CheckEvent(STD_RETURN_TYPE_e cond, DIAG_ID_e diag_id, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_CheckEvent provides a simple interface to check an event for STD_OK.
@ DIAG_ID_POWER_MEASUREMENT_ERROR
@ DIAG_ID_CURRENT_MEASUREMENT_TIMEOUT
@ DIAG_ID_BASE_CELL_TEMPERATURE_MESUREMENT_TIMEOUT
@ DIAG_ID_PLAUSIBILITY_PACK_VOLTAGE
@ DIAG_ID_REDUNDANCY0_CELL_TEMPERATURE_MESUREMENT_TIMEOUT
@ DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE
@ DIAG_ID_PLAUSIBILITY_CELL_TEMP
@ DIAG_ID_CURRENT_SENSOR_POWER_MEASUREMENT_TIMEOUT
@ DIAG_ID_REDUNDANCY0_CELL_VOLTAGE_MESUREMENT_TIMEOUT
@ DIAG_ID_CURRENT_SENSOR_V1_MEASUREMENT_TIMEOUT
@ DIAG_ID_CURRENT_SENSOR_V3_MEASUREMENT_TIMEOUT
@ DIAG_ID_BASE_CELL_VOLTAGE_MESUREMENT_TIMEOUT
@ DIAG_ID_CURRENT_MEASUREMENT_ERROR
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
math library for often used math functions
#define UNIT_CONVERSION_FACTOR_1000_INTEGER
#define NULL_PTR
Null pointer.
Declaration of the OS wrapper interface.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
STD_RETURN_TYPE_e PL_CheckTemperatureSpread(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Cell temperature spread plausibility check.
STD_RETURN_TYPE_e PL_CheckCellvoltage(int16_t baseCellVoltage, int16_t redundancy0CellVoltage, int16_t *pCellVoltage)
Cell voltage plausibility check between two redundant cell voltage measurement values.
STD_RETURN_TYPE_e PL_CheckCelltemperature(int16_t baseCelltemperature, int16_t redundancy0Celltemperature, int16_t *pCelltemperature)
Cell temperature plausibility check between two redundant cell temperature measurement values.
STD_RETURN_TYPE_e PL_CheckVoltageSpread(DATA_BLOCK_CELL_VOLTAGE_s *pCellvoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Cell voltage spread plausibility check.
STD_RETURN_TYPE_e PL_CheckStringVoltage(int32_t voltageAfe_mV, int32_t voltageCurrentSensor_mV)
Pack voltage plausibility check between LTC and current sensor values.
plausibility checks for cell voltage and cell temperatures
static DATA_BLOCK_CELL_TEMPERATURE_s mrc_tableCellTemperatures
static DATA_BLOCK_CELL_VOLTAGE_s mrc_tableCellVoltages
static DATA_BLOCK_MIN_MAX_s mrc_tableMinimumMaximumValues
static void MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Function to validate results of power measurement.
static void MRC_ValidateStringVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor, DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage)
Function to validate results of string voltage measurement.
STD_RETURN_TYPE_e MRC_Initialize(void)
Function to initalize redundancy module.
static void MRC_ValidateHighVoltageBusMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Function to validate results of high voltage measurement and calculate battery voltage and high volta...
static STD_RETURN_TYPE_e MRC_ValidateCellVoltage(DATA_BLOCK_CELL_VOLTAGE_s *pCellvoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellvoltageRedundancy0, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
Function compares cell voltage measurements from base measurement with one redundant measurement and ...
static STD_RETURN_TYPE_e MRC_UpdateCellVoltageValidation(DATA_BLOCK_CELL_VOLTAGE_s *pCellvoltage, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
Function updates validated cell voltage measurement with data from a single measurement source....
static DATA_BLOCK_PACK_VALUES_s mrc_tablePackValues
static bool MRC_ValidateCellTemperatureMeasurement(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0)
Function to validate results of cell temperature measurement.
static void MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Function to validate results of current measurement.
static bool MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp)
Check timestamp if measurement has been updated at least once.
STD_RETURN_TYPE_e MRC_ValidateAfeMeasurement(void)
Function to validate the measurement between redundant measurement values for cell voltage and cell t...
STD_RETURN_TYPE_e MRC_ValidatePackMeasurement(void)
Function to validate the measurements of pack values (string values, pack values)
static STD_RETURN_TYPE_e MRC_CalculateCellVoltageMinMaxAverage(const DATA_BLOCK_CELL_VOLTAGE_s *const pValidatedVoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Function calculates minimum, maximum and average cell voltages.
static STD_RETURN_TYPE_e MRC_UpdateCellTemperatureValidation(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature)
Function updates validated cell temperature measurement with data from a single measurement source....
static STD_RETURN_TYPE_e MRC_ValidateCellTemperature(DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures)
Function compares cell temperature measurements from base measurement with one redundant measurement ...
static MRC_STATE_s mrc_state
static STD_RETURN_TYPE_e MRC_CalculateCellTemperatureMinMaxAverage(DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Function calculates minimum, maximum and average cell temperatures.
static void MRC_ValidateBatteryVoltageMeasurement(void)
Function to validate HV battery voltage measurement.
static bool MRC_ValidateCellVoltageMeasurement(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0)
Function to validate results of cell voltage measurement.
static STD_RETURN_TYPE_e MRC_MeasurementUpdatedRecently(uint32_t timestamp, uint32_t previousTimestamp, uint32_t timeInterval)
Check timestamp if measurement has been updated recently.
Header fileS for handling redundancy between redundant cell voltage and cell temperature measurements...
#define MRC_ALLOWED_NUMBER_OF_INVALID_CELL_VOLTAGES
#define MRC_CURRENT_MEASUREMENT_PERIOD_TIMEOUT_ms
#define MRC_CURRENT_SENSOR_MEASUREMENT_TIMEOUT_ms
#define MRC_AFE_MEASUREMENT_PERIOD_TIMEOUT_ms
DATA_BLOCK_HEADER_s header
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
bool validModuleVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
DATA_BLOCK_HEADER_s header
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
uint16_t nrValidCellVoltages[BS_NR_OF_STRINGS]
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
uint32_t previousTimestampCurrent[BS_NR_OF_STRINGS]
uint32_t timestampCurrent[BS_NR_OF_STRINGS]
uint32_t previousTimestampHighVoltage[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
int32_t current_mA[BS_NR_OF_STRINGS]
uint32_t timestampHighVoltage[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
uint32_t previousTimestampPower[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
uint32_t timestampPower[BS_NR_OF_STRINGS]
int32_t highVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
uint8_t invalidCurrentMeasurement[BS_NR_OF_STRINGS]
uint8_t invalidHighVoltageMeasurement[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
int32_t power_W[BS_NR_OF_STRINGS]
uint8_t invalidPowerMeasurement[BS_NR_OF_STRINGS]
int16_t minimumTemperature_ddegC[BS_NR_OF_STRINGS]
uint16_t nrSensorMinimumTemperature[BS_NR_OF_STRINGS]
uint16_t nrModuleMinimumTemperature[BS_NR_OF_STRINGS]
uint16_t nrModuleMaximumTemperature[BS_NR_OF_STRINGS]
int16_t maximumTemperature_ddegC[BS_NR_OF_STRINGS]
int16_t averageCellVoltage_mV[BS_NR_OF_STRINGS]
uint16_t nrSensorMaximumTemperature[BS_NR_OF_STRINGS]
uint16_t validMeasuredCellVoltages[BS_NR_OF_STRINGS]
float averageTemperature_ddegC[BS_NR_OF_STRINGS]
uint16_t validMeasuredCellTemperatures[BS_NR_OF_STRINGS]
uint16_t nrCellMaximumCellVoltage[BS_NR_OF_STRINGS]
uint16_t nrCellMinimumCellVoltage[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
uint16_t nrModuleMinimumCellVoltage[BS_NR_OF_STRINGS]
uint16_t nrModuleMaximumCellVoltage[BS_NR_OF_STRINGS]
int16_t maximumCellVoltage_mV[BS_NR_OF_STRINGS]
int16_t minimumCellVoltage_mV[BS_NR_OF_STRINGS]
int32_t stringVoltage_mV[BS_NR_OF_STRINGS]
int32_t highVoltageBusVoltage_mV
uint8_t invalidBatteryVoltage
int32_t stringPower_W[BS_NR_OF_STRINGS]
uint8_t invalidStringPower[BS_NR_OF_STRINGS]
uint8_t invalidPackCurrent
int32_t batteryVoltage_mV
DATA_BLOCK_HEADER_s header
int32_t stringCurrent_mA[BS_NR_OF_STRINGS]
uint8_t invalidHvBusVoltage
uint8_t invalidStringCurrent[BS_NR_OF_STRINGS]
uint8_t invalidStringVoltage[BS_NR_OF_STRINGS]
uint32_t lastBaseCellvoltageTimestamp
uint32_t lastBaseCelltemperatureTimestamp
uint32_t lastStringCurrentTimestamp[BS_NR_OF_STRINGS]
uint32_t lastRedundancy0CelltemperatureTimestamp
uint32_t lastStringPowerTimestamp[BS_NR_OF_STRINGS]
uint32_t lastRedundancy0CellvoltageTimestamp