foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
redundancy.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file redundancy.c
44  * @author foxBMS Team
45  * @date 2020-07-31 (date of creation)
46  * @updated 2022-10-27 (date of last update)
47  * @version v1.4.1
48  * @ingroup APPLICATION
49  * @prefix MRC
50  *
51  * @brief Source file for handling redundancy between redundant cell voltage
52  * and cell temperature measurements
53  *
54  */
55 
56 /*========== Includes =======================================================*/
57 #include "redundancy.h"
58 
59 #include "bms.h"
60 #include "database.h"
61 #include "diag.h"
62 #include "foxmath.h"
63 #include "os.h"
64 #include "plausibility.h"
65 
66 /*========== Macros and Definitions =========================================*/
67 
68 /*========== Static Constant and Variable Definitions =======================*/
69 /** local copies of database tables */
70 /**@{*/
75 /**@}*/
76 
77 /** state of the redundancy module */
80  .lastRedundancy0CellVoltageTimestamp = 0u,
81  .lastBaseCelltemperatureTimestamp = 0u,
82  .lastRedundancy0CelltemperatureTimestamp = 0u,
83  .lastStringCurrentTimestamp = {0u},
84 };
85 
86 /*========== Extern Constant and Variable Definitions =======================*/
87 
88 /*========== Static Function Prototypes =====================================*/
89 /**
90  * @brief Check timestamp if measurement has been updated at least once.
91  * @param[in] timestamp timestamp of last measurement update
92  * @param[in] previousTimestamp timestamp of previously updated measurement
93  * @return true if measurement has been updated at least once, otherwise false
94  */
95 static bool MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp);
96 
97 /**
98  * @brief Check timestamp if measurement has been updated recently.
99  * @param[in] timestamp timestamp of last measurement update
100  * @param[in] previousTimestamp timestamp of previously updated measurement
101  * @param[in] timeInterval in systicks (type: uint32_t)
102  * @return true if measurement has recently been updated, otherwise false
103  */
105  uint32_t timestamp,
106  uint32_t previousTimestamp,
107  uint32_t timeInterval);
108 
109 /**
110  * @brief Function to validate results of cell voltage measurement
111  * @param[in] pCellVoltageBase base cell voltage measurement
112  * @param[in] pCellVoltageRedundancy0 redundant cell voltage measurement
113  * @return bool true, if measurement has been validated successfully and
114  * database entry needs to be updated, otherwise false.
115  */
117  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
118  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0);
119 
120 /**
121  * @brief Function to validate results of cell temperature measurement
122  * @param[in] pCellTemperatureBase base cell temperature measurement
123  * @param[in] pCellTemperatureRedundancy0 redundant cell temperature measurement
124  * @return bool true, if measurement has been validated successfully and
125  * database entry needs to be updated, otherwise false.
126  */
128  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase,
129  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0);
130 
131 /**
132  * @brief Function to validate results of current measurement
133  * @param[in] pTableCurrentSensor pointer to current measurements
134  */
135 static void MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor);
136 
137 /**
138  * @brief Function to validate results of string voltage measurement
139  * @param[in] pTableCurrentSensor pointer current sensor high voltage measurements
140  * @param[in] pTableCellVoltage pointer to cell voltage measurements
141  */
143  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor,
144  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage);
145 
146 /**
147  * @brief Function to validate HV battery voltage measurement
148  */
149 static void MRC_ValidateBatteryVoltageMeasurement(void);
150 
151 /**
152  * @brief Function to validate results of high voltage measurement and calculate
153  * battery voltage and high voltage bus voltage.
154  * @param[in] pTableCurrentSensor pointer current sensor high voltage measurements
155  */
157 
158 /**
159  * @brief Function to validate results of power measurement
160  * @param[in] pTableCurrentSensor pointer to power/current measurements
161  */
162 static void MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor);
163 
164 /**
165  * @brief Function calculates minimum, maximum and average cell voltages.
166  * @param[in] pValidatedVoltages validated voltages from base and/or redundant measurements
167  * @param[out] pMinMaxAverageValues calculated cell voltage min/max/average values
168  * @return #STD_NOT_OK if all cell voltage are invalid and no minimum, maximum
169  * and average cell voltage values could be calculated, otherwise #STD_OK
170  */
172  const DATA_BLOCK_CELL_VOLTAGE_s *const pValidatedVoltages,
173  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues);
174 
175 /**
176  * @brief Function calculates minimum, maximum and average cell temperatures.
177  * @param[in] pValidatedTemperatures validated temperatures from base and/or redundant measurements
178  * @param[out] pMinMaxAverageValues calculated cell temperature min/max/average values
179  * @return #STD_NOT_OK if all cell temperatures are invalid and no minimum, maximum
180  * and average cell temperature values could be calculated, otherwise #STD_OK
181  */
183  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures,
184  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues);
185 
186 /**
187  * @brief Function compares cell voltage measurements from base measurement with
188  * one redundant measurement and writes result in pValidatedVoltages.
189  * @param[in] pCellVoltageBase base cell voltage measurement
190  * @param[in] pCellVoltageRedundancy0 redundant cell voltage measurement
191  * @param[out] pValidatedVoltages validated voltages from redundant measurement values
192  * @return #STD_NOT_OK if not all cell voltages could be validated, otherwise
193  * #STD_OK
194  */
196  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
197  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0,
198  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages);
199 
200 /**
201  * @brief Function updates validated cell voltage measurement with data from a
202  * single measurement source. This can be the case if no redundancy is
203  * used at all or if one or more of the redundant measurements are not
204  * working properly.
205  * @param[in] pCellVoltage cell voltage measurement
206  * @param[out] pValidatedVoltages validated voltage values
207  * @return #STD_NOT_OK if not all cell voltages could be validated, otherwise
208  * #STD_OK
209  */
211  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage,
212  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages);
213 
214 /**
215  * @brief Function compares cell temperature measurements from base measurement
216  * with one redundant measurement and writes result in pValidatedTemperatures.
217  * @param[in] pCelltemperatureBase base cell temperature measurement
218  * @param[in] pCelltemperatureRedundancy0 redundant cell temperature measurement
219  * @param[out] pValidatedTemperatures validated temperatures from redundant measurement values
220  * @return #STD_NOT_OK if not all cell voltages could be validated, otherwise
221  * #STD_OK
222  */
224  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase,
225  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0,
226  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures);
227 
228 /**
229  * @brief Function updates validated cell temperature measurement with data from a
230  * single measurement source. This can be the case if no redundancy is
231  * used at all or if one or more of the redundant measurements are not
232  * working properly.
233  * @param[in] pCellTemperature cell temperature measurement
234  * @param[out] pValidatedTemperature validated temperature values
235  * @return #STD_NOT_OK if not all cell voltages could be validated, otherwise
236  * #STD_OK
237  */
239  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature,
240  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature);
241 
242 /*========== Static Function Implementations ================================*/
243 static bool MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp) {
244  bool retval = false;
245  if (!((timestamp == 0u) && (previousTimestamp == 0u))) {
246  /* Only possibility for timestamp AND previous timestamp to be 0 is, if
247  the measurement has never been updated. Thus, if this is not the case
248  the measurement must have been updated */
249  retval = true;
250  }
251  return retval;
252 }
253 
255  uint32_t timestamp,
256  uint32_t previousTimestamp,
257  uint32_t timeInterval) {
258  STD_RETURN_TYPE_e retval = STD_NOT_OK;
259  uint32_t currentTimestamp = OS_GetTickCount();
260 
261  /* Unsigned integer arithmetic also works correctly if currentTimestamp is
262  larger than pHeader->timestamp (timer overflow), thus no need to use abs() */
263  if (((currentTimestamp - timestamp) <= timeInterval) &&
264  (MRC_MeasurementUpdatedAtLeastOnce(timestamp, previousTimestamp) == true)) {
265  /* Difference between current timestamp and last update timestamp is
266  smaller than passed time interval */
267  retval = STD_OK;
268  }
269  return retval;
270 }
271 
273  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
274  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0) {
275  FAS_ASSERT(pCellVoltageBase != NULL_PTR);
276  FAS_ASSERT(pCellVoltageRedundancy0 != NULL_PTR);
277 
278  bool updatedValidatedVoltageDatbaseEntry = false;
279 
280  bool baseCellVoltageUpdated = false;
281 
282  bool useCellVoltageRedundancy = false;
283  bool baseCellVoltageMeasurementTimeoutReached = true;
284  bool redundancy0CellVoltageMeasurementTimeoutReached = true;
285 
286  /* Following decision will be undertaken:
287  *
288  * - Use redundancy only if timestamp of redundant database entry != 0
289  * - Perform redundant check if both timestamps have been updated
290  * - Add timeout and trigger error if timestamps have not been updated in the last XXXXms
291  * - If timeout reached and only one of the two redundant measurements has been updated use this measurement value
292  * but throw an error that one measurement has not been updated recently.
293  */
294 
295  /* -------------- Check if cell voltage redundant measurement is used -- */
296  /* Use redundant cell voltage measurements if measurement values have been acquired once */
297  useCellVoltageRedundancy = DATA_DatabaseEntryUpdatedAtLeastOnce(pCellVoltageRedundancy0->header);
298 
299  /* ----------------- Check timestamp of base measurements--------------- */
301  baseCellVoltageMeasurementTimeoutReached = false;
303  } else {
304  baseCellVoltageMeasurementTimeoutReached = true;
305  /* Set error flag */
307  }
308 
309  /* Check if base measurement values have been updated since last MRC */
310  if (mrc_state.lastBaseCellVoltageTimestamp != pCellVoltageBase->header.timestamp) {
311  baseCellVoltageUpdated = true;
312  } else {
313  baseCellVoltageUpdated = false;
314  }
315 
316  /* ----------------- Check timestamp of redundant measurements --------- */
318  false) &&
319  (useCellVoltageRedundancy == true)) {
320  redundancy0CellVoltageMeasurementTimeoutReached = true;
321  /* Set error flag */
323  } else {
324  redundancy0CellVoltageMeasurementTimeoutReached = false;
326  }
327 
328  /* ----------------- Validate cell voltages ---------------------------- */
329  if (useCellVoltageRedundancy == true) {
330  bool redundany0CellVoltageUpdated = false;
331  /* Check if redundant measurement values have been updated since last MRC */
332  if (mrc_state.lastRedundancy0CellVoltageTimestamp != pCellVoltageRedundancy0->header.timestamp) {
333  redundany0CellVoltageUpdated = true;
334  } else {
335  redundany0CellVoltageUpdated = false;
336  }
337  /* Make sure cell voltage timestamps have been updated since last call */
338  if ((baseCellVoltageUpdated == true) && (redundany0CellVoltageUpdated == true)) {
339  /* Update timestamp */
342 
343  /* Validate cell voltages */
344  MRC_ValidateCellVoltage(pCellVoltageBase, pCellVoltageRedundancy0, &mrc_tableCellVoltages);
345  /* Set to true for following minimum, maximum and average calculation */
346  updatedValidatedVoltageDatbaseEntry = true;
347  } else if ((baseCellVoltageUpdated == true) || (redundany0CellVoltageUpdated == true)) {
348  /* At least one measurement has been updated */
349  if (baseCellVoltageUpdated == true) {
350  /* Has redundant measurement timeout been reached? If yes, update. */
351  if (redundancy0CellVoltageMeasurementTimeoutReached == true) {
352  /* Copy cell voltage base measurement values into validated database struct */
354  /* Set to true for following minimum, maximum and average calculation */
355  updatedValidatedVoltageDatbaseEntry = true;
356  }
357  } else if (redundany0CellVoltageUpdated == true) {
358  /* Has base measurement timeout been reached? If yes, update. */
359  if (baseCellVoltageMeasurementTimeoutReached == true) {
360  /* Copy cell voltage base measurement values into validated database struct */
361  MRC_UpdateCellVoltageValidation(pCellVoltageRedundancy0, &mrc_tableCellVoltages);
362  /* Set to true for following minimum, maximum and average calculation */
363  updatedValidatedVoltageDatbaseEntry = true;
364  }
365  } else {
367  }
368  } else {
369  /* No cell voltage measurement has been updated -> do nothing */
370  }
371  } else {
372  if (baseCellVoltageUpdated == true) {
373  /* Only update database entries if new raw data has been acquired */
374  /* Update timestamp */
376 
377  /* Copy cell voltage base measurement values into validated database struct */
379 
380  /* Set to true for following minimum, maximum and average calculation */
381  updatedValidatedVoltageDatbaseEntry = true;
382  }
383  }
384 
385  if (updatedValidatedVoltageDatbaseEntry == true) {
386  /* Calculate min/max/average cell voltages */
388 
389  /* Individual cell voltages validated and min/max/average calculated -> check voltage spread */
391  /* Recalculate min/max/average cell voltages as at least one cell voltage has been detected as invalid */
393  }
394  }
395 
396  return updatedValidatedVoltageDatbaseEntry;
397 }
398 
400  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase,
401  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0) {
402  FAS_ASSERT(pCellTemperatureBase != NULL_PTR);
403  FAS_ASSERT(pCellTemperatureRedundancy0 != NULL_PTR);
404 
405  bool baseCelltemperatureUpdated = false;
406  bool useCelltemperatureRedundancy = false;
407  bool updatedValidatedTemperatureDatbaseEntry = false;
408 
409  bool baseCellTemperatureMeasurementTimeoutReached = true;
410  bool redundancy0CellTemperatureMeasurementTimeoutReached = true;
411 
412  /* Following decision will be undertaken:
413  *
414  * - Use redundancy only if timestamp of redundant database entry != 0
415  * - Perform redundant check if both timestamps have been updated
416  * - Add timeout and trigger error if timestamps have not been updated in the last XXXXms
417  * - If timeout reached and only one of the two redundant measurements has been updated use this measurement value
418  * but throw an error that one measurement has not been updated recently.
419  */
420 
421  /* -------------- Check if cell cell temperature redundant measurement is used ---------- */
422  /* Use redundant cell voltage measurements if measurement values have been acquired once */
423  useCelltemperatureRedundancy = DATA_DatabaseEntryUpdatedAtLeastOnce(pCellTemperatureRedundancy0->header);
424 
425  /* ----------------- Check timestamp of base measurements--------------- */
427  baseCellTemperatureMeasurementTimeoutReached = false;
429  } else {
430  baseCellTemperatureMeasurementTimeoutReached = true;
431  /* Set error flag */
433  }
434  /* Check if base measurement values have been updated since last MRC */
435  if (mrc_state.lastBaseCelltemperatureTimestamp != pCellTemperatureBase->header.timestamp) {
436  baseCelltemperatureUpdated = true;
437  } else {
438  baseCelltemperatureUpdated = false;
439  }
440 
441  /* ----------------- Check timestamp of redundant measurements --------- */
443  false) &&
444  (useCelltemperatureRedundancy == true)) {
445  redundancy0CellTemperatureMeasurementTimeoutReached = true;
446  /* Set error flag */
447  (void)DIAG_Handler(
449  } else {
450  redundancy0CellTemperatureMeasurementTimeoutReached = false;
452  }
453 
454  /* ----------------- Validate cell temperatures ------------------------ */
455  if (useCelltemperatureRedundancy == true) {
456  bool redundancy0CelltemperatureUpdated = false;
457  /* Check if redundant measurement values have been updated since last MRC */
458  if (mrc_state.lastRedundancy0CelltemperatureTimestamp != pCellTemperatureRedundancy0->header.timestamp) {
459  redundancy0CelltemperatureUpdated = true;
460  } else {
461  redundancy0CelltemperatureUpdated = false;
462  }
463  /* Make sure cell voltage timestamps have been updated since last call */
464  if ((baseCelltemperatureUpdated == true) && (redundancy0CelltemperatureUpdated == true)) {
465  /* Update timestamp */
467  mrc_state.lastRedundancy0CelltemperatureTimestamp = pCellTemperatureRedundancy0->header.timestamp;
468 
469  /* Validate cell temperatures */
470  MRC_ValidateCellTemperature(pCellTemperatureBase, pCellTemperatureRedundancy0, &mrc_tableCellTemperatures);
471  /* Set to true for following minimum, maximum and average calculation */
472  updatedValidatedTemperatureDatbaseEntry = true;
473  } else if ((baseCelltemperatureUpdated == true) || (redundancy0CelltemperatureUpdated == true)) {
474  /* At least one measurement has been updated */
475  if (baseCelltemperatureUpdated == true) {
476  /* Has redundant measurement timeout been reached? If yes, update. */
477  if (redundancy0CellTemperatureMeasurementTimeoutReached == true) {
478  /* Copy cell temperature base measurement values into validated database struct */
480  /* Set to true for following minimum, maximum and average calculation */
481  updatedValidatedTemperatureDatbaseEntry = true;
482  }
483  } else if (redundancy0CelltemperatureUpdated == true) {
484  /* Has base measurement timeout been reached? If yes, update. */
485  if (baseCellTemperatureMeasurementTimeoutReached == true) {
486  /* Copy cell temperature redundant measurement values into validated database struct */
487  MRC_UpdateCellTemperatureValidation(pCellTemperatureRedundancy0, &mrc_tableCellTemperatures);
488  /* Set to true for following minimum, maximum and average calculation */
489  updatedValidatedTemperatureDatbaseEntry = true;
490  }
491  } else {
493  }
494  } else {
495  /* No cell temperature measurement has been updated -> do nothing */
496  }
497  } else { /* useCelltemperatureRedundancy == true */
498  if (baseCelltemperatureUpdated == true) {
499  /* Only update database entries if new raw data has been acquired */
500  /* Update timestamp */
502 
503  /* Copy cell temperature base measurement values into validated database struct */
505 
506  /* Set to true for following minimum, maximum and average calculation */
507  updatedValidatedTemperatureDatbaseEntry = true;
508  }
509  }
510 
511  if (updatedValidatedTemperatureDatbaseEntry == true) {
512  /* Calculate min/max/average cell temperatures */
514 
515  /* Individual cell temperatures validated and min/max/average calculated -> check temperature spread */
517  /* Recalculate min/max/average temperatures as at least one temperature has been detected as invalid */
519  }
520  }
521 
522  return updatedValidatedTemperatureDatbaseEntry;
523 }
524 
526  FAS_ASSERT(pTableCurrentSensor != NULL_PTR);
527  int32_t packCurrent_mA = 0;
528 
529  /* Validate pack current. Will be invalidated if not all current measurement values are valid */
531 
532  /* Iterate over all strings to calculate pack current */
533  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
534  /* Check timestamp of measurement */
536  pTableCurrentSensor->timestampCurrent[s],
537  pTableCurrentSensor->previousTimestampCurrent[s],
540 
541  if (noTimeout == STD_OK) {
542  /* Check if current entry has been updated since last call */
543  if (mrc_state.lastStringCurrentTimestamp[s] != pTableCurrentSensor->timestampCurrent[s]) {
544  mrc_state.lastStringCurrentTimestamp[s] = pTableCurrentSensor->timestampCurrent[s];
545  mrc_tablePackValues.stringCurrent_mA[s] = pTableCurrentSensor->current_mA[s];
546  if (pTableCurrentSensor->invalidCurrentMeasurement[s] == 0u) {
547  /* String current measurement valid -> set valid flag */
550  } else {
551  /* String current measurement invalid -> set invalid flag */
554  }
555  } else {
556  /* Nothing to do. Measurement has not been updated but still within timeout */
557  }
558  } else {
559  /* Measurement timeout reached -> set string current invalid */
561  }
562 
564  packCurrent_mA += mrc_tablePackValues.stringCurrent_mA[s];
565  } else {
566  /* One string current is invalid -> pack current cannot be correct.
567  * Set pack current invalid */
569  }
570  }
571  mrc_tablePackValues.packCurrent_mA = packCurrent_mA;
572 }
573 
575  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor,
576  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage) {
577  /* Pointer validity check */
578  FAS_ASSERT(pTableCurrentSensor != NULL_PTR);
579  FAS_ASSERT(pTableCellVoltage != NULL_PTR);
580 
581  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
582  /* Check timeout of current sensor measurement */
584  pTableCurrentSensor->timestampHighVoltage[s][0u],
585  pTableCurrentSensor->previousTimestampHighVoltage[s][0u],
588 
589  /* Perform plausibility check if AFE and new current sensor measurement is valid */
590  if ((updatedMeasurement == STD_OK) && (pTableCurrentSensor->invalidHighVoltageMeasurement[s][0u] == 0u) &&
591  (pTableCellVoltage->nrValidCellVoltages[s] == BS_NR_OF_CELL_BLOCKS_PER_STRING)) {
592  STD_RETURN_TYPE_e voltagePlausible =
593  PL_CheckStringVoltage(pTableCellVoltage->packVoltage_mV[s], pTableCurrentSensor->highVoltage_mV[s][0u]);
595 
596  /* Use current sensor measurement */ /* TODO: use really current sensor? Average of both? AFE measurement? */
597  mrc_tablePackValues.stringVoltage_mV[s] = pTableCurrentSensor->highVoltage_mV[s][0u];
598 
599  if (voltagePlausible == STD_OK) {
601  } else {
603  }
604  } else {
605  /* Plausibility check cannot be performed if we do not have valid
606  * values from AFE and current sensor measurement */
608 
609  if ((updatedMeasurement == STD_OK) && (pTableCurrentSensor->invalidHighVoltageMeasurement[s][0u] == 0u)) {
610  /* Current sensor measurement valid -> use this measurement */
611  mrc_tablePackValues.stringVoltage_mV[s] = pTableCurrentSensor->highVoltage_mV[s][0u];
613  } else if (pTableCellVoltage->nrValidCellVoltages[s] == BS_NR_OF_CELL_BLOCKS_PER_STRING) {
614  /* AFE measurement valid -> use this measurement */
615  mrc_tablePackValues.stringVoltage_mV[s] = pTableCellVoltage->packVoltage_mV[s];
617  } else {
618  /* AFE and current sensor measurement invalid -> try to construct
619  * a valid from the number of valid cell voltages and substitute
620  * invalid cell voltages with the average cell voltage. */
621  uint16_t numberInvalidCellVoltages =
622  (BS_NR_OF_CELL_BLOCKS_PER_STRING - pTableCellVoltage->nrValidCellVoltages[s]);
623 
625  pTableCellVoltage->packVoltage_mV[s] +
626  (mrc_tableMinimumMaximumValues.averageCellVoltage_mV[s] * (int16_t)numberInvalidCellVoltages);
627 
628  /* Only use this as valid value if not more than five cell voltages are invalid */
629  if (numberInvalidCellVoltages > MRC_ALLOWED_NUMBER_OF_INVALID_CELL_VOLTAGES) {
631  } else {
633  }
634  }
635  }
636  }
637 }
638 
640  int64_t sumOfStringValues_mV = 0;
641  int8_t numberOfValidStringVoltages = 0;
642  uint8_t numberOfConnectedStrings = BMS_GetNumberOfConnectedStrings();
643 
644  if (0u != numberOfConnectedStrings) {
645  /* Iterate over all strings to see which strings are connected */
646  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
647  bool isStringConnected = BMS_IsStringClosed(s);
648  if ((mrc_tablePackValues.invalidStringVoltage[s] == 0u) && (isStringConnected == true)) {
649  /* AXIVION Disable Style MisraC2012Directive-4.1: Values start with 0, iteration is less than UINT8_MAX; overflow impossible */
650  sumOfStringValues_mV += mrc_tablePackValues.stringVoltage_mV[s];
651  numberOfValidStringVoltages++;
652  /* AXIVION Enable Style MisraC2012Directive-4.1: */
653  }
654  }
655  } else {
656  /* Take average of all strings if no strings are connected */
657  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
659  /* AXIVION Disable Style MisraC2012Directive-4.1: Values start with 0, iteration is less than UINT8_MAX; overflow impossible */
660  sumOfStringValues_mV += mrc_tablePackValues.stringVoltage_mV[s];
661  numberOfValidStringVoltages++;
662  /* AXIVION Enable Style MisraC2012Directive-4.1: */
663  }
664  }
665  }
666 
667  /* Only calculate average if at least one string voltage is valid */
668  if (0 != numberOfValidStringVoltages) {
669  /* AXIVION Next Codeline Style MisraC2012Directive-4.1: truncation impossible;
670  we sum INT32 values x times and divide by x, resulting in INT32 */
671  mrc_tablePackValues.batteryVoltage_mV = (int32_t)(sumOfStringValues_mV / numberOfValidStringVoltages);
673  } else {
676  }
677 }
678 
680  FAS_ASSERT(pTableCurrentSensor != NULL_PTR);
681 
682  int32_t sum_mV = 0;
683  uint8_t validVoltages = 0u;
684  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
685  /* Check timeout of current sensor measurement */
687  pTableCurrentSensor->timestampHighVoltage[s][2u],
688  pTableCurrentSensor->previousTimestampHighVoltage[s][2u],
691 
692  const bool stringClosed = BMS_IsStringClosed(s);
693  const bool stringPrecharging = BMS_IsStringPrecharging(s);
694  if (((stringPrecharging == true) || (stringClosed == true)) && (updatedMeasurement == STD_OK)) {
695  /* Only voltages of connected strings can be used */
696  if (pTableCurrentSensor->invalidHighVoltageMeasurement[s][2] == 0u) {
697  /* Measured high voltage is valid */
698  validVoltages++;
699  sum_mV += pTableCurrentSensor->highVoltage_mV[s][2];
700  }
701  }
702  }
703 
704  if (validVoltages > 0u) {
705  mrc_tablePackValues.highVoltageBusVoltage_mV = (sum_mV / (int32_t)validVoltages);
707  } else {
708  /* TODO: do we want to write special data if no valid values can be read? */
710  }
711 }
712 
714  FAS_ASSERT(pTableCurrentSensor != NULL_PTR);
715  bool calculatePower = false;
716  int32_t packPower_W = 0;
717 
718  /* Validate pack power. Will be invalidated if not all power measurement values are valid */
720 
721  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
722  /* Check timeout of current sensor measurement */
724  pTableCurrentSensor->timestampPower[s],
725  pTableCurrentSensor->previousTimestampPower[s],
728 
729  if (noTimeout == STD_OK) {
730  /* Check if current sensor measurement has been updated */
731  if (pTableCurrentSensor->timestampPower[s] != mrc_state.lastStringPowerTimestamp[s]) {
732  mrc_state.lastStringPowerTimestamp[s] = pTableCurrentSensor->timestampPower[s];
733  /* Check if measurement is valid */
734  if (pTableCurrentSensor->invalidPowerMeasurement[s] == 0u) {
735  mrc_tablePackValues.stringPower_W[s] = pTableCurrentSensor->power_W[s];
737  } else {
738  /* Measurement has been updated but value is invalid -> calculate from current and string voltage */
739  calculatePower = true;
740  /* TODO: do we want to calculate values by hand if we are within time limit but value is invalid? */
741  }
742  } else {
743  /* Nothing to do. Measurement has not been updated but still within timeout */
744  }
745  } else {
746  /* Timeout reached. Set invalid flag */
747  calculatePower = true;
749  }
750  if ((calculatePower == true) && (mrc_tablePackValues.invalidStringCurrent[s] == 0u) &&
752  /* Power measurement is invalid, but current and string voltage measurement are valid */
753  int64_t stringPower_W =
755  (UNIT_CONVERSION_FACTOR_1000_INTEGER * /* convert: mV -> V */
756  UNIT_CONVERSION_FACTOR_1000_INTEGER)); /* convert: mA -> A */
757  mrc_tablePackValues.stringPower_W[s] = (int32_t)stringPower_W;
759  }
761  packPower_W += mrc_tablePackValues.stringPower_W[s];
763  } else {
764  /* One string power is invalid -> pack power cannot be correct.
765  * Set pack power invalid */
768  }
769  }
770  mrc_tablePackValues.packPower_W = packPower_W;
771 }
772 
774  const DATA_BLOCK_CELL_VOLTAGE_s *const pValidatedVoltages,
775  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
776  /* Pointer validity check */
777  FAS_ASSERT(pValidatedVoltages != NULL_PTR);
778  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
779 
780  STD_RETURN_TYPE_e retval = STD_OK;
781 
782  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
783  uint16_t nrValidCellVoltages = 0u;
784  int16_t min = INT16_MAX;
785  int16_t max = INT16_MIN;
786  int32_t sum = 0;
787  uint16_t moduleNumberMinimum = 0u;
788  uint16_t cellNumberMinimum = 0u;
789  uint16_t moduleNumberMaximum = 0u;
790  uint16_t cellNumberMaximum = 0u;
791  /* Iterate over all cells in each string */
792  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
793  for (uint8_t c = 0u; c < BS_NR_OF_CELL_BLOCKS_PER_MODULE; c++) {
794  if ((pValidatedVoltages->invalidCellVoltage[s][m] & (0x01u << c)) == 0u) {
795  /* Cell voltage is valid -> use this voltage for subsequent calculations */
796  nrValidCellVoltages++;
797  sum += pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
798 
799  if (pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] < min) {
800  min = pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
801  moduleNumberMinimum = m;
802  cellNumberMinimum = c;
803  }
804  if (pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] > max) {
805  max = pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
806  moduleNumberMaximum = m;
807  cellNumberMaximum = c;
808  }
809  }
810  }
811  }
812  pMinMaxAverageValues->minimumCellVoltage_mV[s] = min;
813  pMinMaxAverageValues->nrCellMinimumCellVoltage[s] = cellNumberMinimum;
814  pMinMaxAverageValues->nrModuleMinimumCellVoltage[s] = moduleNumberMinimum;
815  pMinMaxAverageValues->maximumCellVoltage_mV[s] = max;
816  pMinMaxAverageValues->nrCellMaximumCellVoltage[s] = cellNumberMaximum;
817  pMinMaxAverageValues->nrModuleMaximumCellVoltage[s] = moduleNumberMaximum;
818  pMinMaxAverageValues->validMeasuredCellVoltages[s] = nrValidCellVoltages;
819 
820  /* Prevent division by 0, if all cell voltages are invalid */
821  if (nrValidCellVoltages > 0u) {
822  pMinMaxAverageValues->averageCellVoltage_mV[s] = (int16_t)(sum / (int32_t)nrValidCellVoltages);
823  } else {
824  pMinMaxAverageValues->averageCellVoltage_mV[s] = 0;
825  retval = STD_NOT_OK;
826  }
827  }
828  return retval;
829 }
830 
832  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures,
833  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
834  /* Pointer validity check */
835  FAS_ASSERT(pValidatedTemperatures != NULL_PTR);
836  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
837 
838  STD_RETURN_TYPE_e retval = STD_OK;
839 
840  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
841  uint16_t moduleNumberMinimum = 0u;
842  uint16_t sensorNumberMinimum = 0u;
843  uint16_t moduleNumberMaximum = 0u;
844  uint16_t sensorNumberMaximum = 0u;
845  uint16_t nrValidCelltemperatures = 0u;
846  int16_t min = INT16_MAX;
847  int16_t max = INT16_MIN;
848  float sum_ddegC = 0.0f;
849 
850  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
851  for (uint8_t c = 0u; c < BS_NR_OF_TEMP_SENSORS_PER_MODULE; c++) {
852  if ((pValidatedTemperatures->invalidCellTemperature[s][m] & (0x01u << c)) == 0u) {
853  /* Cell temperature is valid -> use this voltage for subsequent calculations */
854  nrValidCelltemperatures++;
855  sum_ddegC += (float)pValidatedTemperatures
856  ->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c];
857 
858  if (pValidatedTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] <
859  min) {
860  min = pValidatedTemperatures
862  moduleNumberMinimum = m;
863  sensorNumberMinimum = c;
864  }
865  if (pValidatedTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] >
866  max) {
867  max = pValidatedTemperatures
869  moduleNumberMaximum = m;
870  sensorNumberMaximum = c;
871  }
872  }
873  }
874  }
875  pMinMaxAverageValues->minimumTemperature_ddegC[s] = min;
876  pMinMaxAverageValues->nrSensorMinimumTemperature[s] = sensorNumberMinimum;
877  pMinMaxAverageValues->nrModuleMinimumTemperature[s] = moduleNumberMinimum;
878  pMinMaxAverageValues->maximumTemperature_ddegC[s] = max;
879  pMinMaxAverageValues->nrSensorMaximumTemperature[s] = sensorNumberMaximum;
880  pMinMaxAverageValues->nrModuleMaximumTemperature[s] = moduleNumberMaximum;
881  pMinMaxAverageValues->validMeasuredCellTemperatures[s] = nrValidCelltemperatures;
882 
883  /* Prevent division by 0, if all cell voltages are invalid */
884  if (nrValidCelltemperatures > 0u) {
885  pMinMaxAverageValues->averageTemperature_ddegC[s] = (sum_ddegC / (float)nrValidCelltemperatures);
886  } else {
887  pMinMaxAverageValues->averageTemperature_ddegC[s] = 0.0f;
888  retval = STD_NOT_OK;
889  }
890  }
891  return retval;
892 }
893 
895  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
896  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0,
897  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages) {
898  /* Pointer validity check */
899  FAS_ASSERT(pCellVoltageBase != NULL_PTR);
900  FAS_ASSERT(pCellVoltageRedundancy0 != NULL_PTR);
901  FAS_ASSERT(pValidatedVoltages != NULL_PTR);
902 
903  uint16_t numberValidMeasurements = 0u;
904  STD_RETURN_TYPE_e noPlausibilityIssueDetected = STD_OK; /* Flag if implausible value detected */
905  STD_RETURN_TYPE_e retval = STD_OK;
906 
907  /* Iterate over all cell measurements */
908  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
909  int32_t sum = 0;
910  for (uint8_t m = 0; m < BS_NR_OF_MODULES_PER_STRING; m++) {
911  for (uint8_t c = 0; c < BS_NR_OF_CELL_BLOCKS_PER_MODULE; c++) {
912  if (((pCellVoltageBase->invalidCellVoltage[s][m] & (1u << c)) == 0u) &&
913  ((pCellVoltageRedundancy0->invalidCellVoltage[s][m] & (1u << c)) == 0u)) {
914  /* Check if cell voltage of base AND redundant measurement is valid -> do plausibility check */
915  if (STD_OK ==
917  pCellVoltageBase->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c],
918  pCellVoltageRedundancy0->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c],
919  &pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c])) {
920  /* Clear valid flag */
921  pValidatedVoltages->invalidCellVoltage[s][m] = pValidatedVoltages->invalidCellVoltage[s][m] &
922  (~(1u << c));
923  numberValidMeasurements++;
924  sum += pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
925  } else {
926  /* Set invalid flag */
927  noPlausibilityIssueDetected = STD_NOT_OK;
928  pValidatedVoltages->invalidCellVoltage[s][m] |= (1u << c);
929  /* Set return value to #STD_NOT_OK as not all cell voltages have a valid measurement value */
930  retval = STD_NOT_OK;
931  }
932  } else if ((pCellVoltageBase->invalidCellVoltage[s][m] & (1u << c)) == 0u) {
933  /* Only base measurement value is valid -> use this voltage without further plausibility checks */
934  pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] =
935  pCellVoltageBase->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
936  /* Reset valid flag */
937  pValidatedVoltages->invalidCellVoltage[s][m] = pValidatedVoltages->invalidCellVoltage[s][m] &
938  (~(1u << c));
939  numberValidMeasurements++;
940  sum += pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
941  } else if ((pCellVoltageRedundancy0->invalidCellVoltage[s][m] & (1u << c)) == 0u) {
942  /* Only redundant measurement value is valid -> use this voltage without further plausibility checks */
943  pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] =
944  pCellVoltageRedundancy0->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
945  /* Reset valid flag */
946  pValidatedVoltages->invalidCellVoltage[s][m] = pValidatedVoltages->invalidCellVoltage[s][m] &
947  (~(1u << c));
948  numberValidMeasurements++;
949  sum += pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
950  } else {
951  /* Both, base and redundant measurement value are invalid */
952  /* Save average cell voltage value of base and redundant */
953  pValidatedVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] =
954  (pCellVoltageBase->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] +
955  pCellVoltageRedundancy0->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c]) /
956  2u;
957  /* Set invalid flag */
958  pValidatedVoltages->invalidCellVoltage[s][m] |= (1u << c);
959  /* Set return value to #STD_NOT_OK as not all cell voltages have a valid measurement value */
960  retval = STD_NOT_OK;
961  }
962  }
963  }
964  pValidatedVoltages->nrValidCellVoltages[s] = numberValidMeasurements;
965  pValidatedVoltages->packVoltage_mV[s] = sum;
966  numberValidMeasurements = 0u; /* Reset counter for next string */
967 
968  (void)DIAG_CheckEvent(noPlausibilityIssueDetected, DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE, DIAG_STRING, s);
969  noPlausibilityIssueDetected = STD_OK; /* Reset flag for next string */
970  }
971  return retval;
972 }
973 
975  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage,
976  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages) {
977  /* Pointer validity check */
978  FAS_ASSERT(pCellVoltage != NULL_PTR);
979  FAS_ASSERT(pValidatedVoltages != NULL_PTR);
980 
981  /* Save header struct to copy to correct database entry */
982  DATA_BLOCK_HEADER_s tmpHeader = pValidatedVoltages->header;
983  /* Copy whole database entry */
984  *pValidatedVoltages = *pCellVoltage;
985  /* Restore previous header */
986  pValidatedVoltages->header = tmpHeader;
987 
988  return STD_OK;
989 }
990 
992  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase,
993  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0,
994  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures) {
995  /* Pointer validity check */
996  FAS_ASSERT(pCelltemperatureBase != NULL_PTR);
997  FAS_ASSERT(pCelltemperatureRedundancy0 != NULL_PTR);
998  FAS_ASSERT(pValidatedTemperatures != NULL_PTR);
999 
1000  uint16_t numberValidMeasurements = 0u;
1001  STD_RETURN_TYPE_e noPlausibilityIssueDetected = STD_OK; /* Flag if implausible value detected */
1002  STD_RETURN_TYPE_e retval = STD_OK;
1003 
1004  /* Iterate over all cell measurements */
1005  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
1006  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
1007  for (uint8_t c = 0u; c < BS_NR_OF_TEMP_SENSORS_PER_MODULE; c++) {
1008  if (((pCelltemperatureBase->invalidCellTemperature[s][m] & (1u << c)) == 0u) &&
1009  ((pCelltemperatureRedundancy0->invalidCellTemperature[s][m] & (1u << c)) == 0u)) {
1010  /* Check if cell voltage of base AND redundant measurement is valid -> do plausibility check */
1011  if (STD_OK ==
1013  pCelltemperatureBase->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c],
1014  pCelltemperatureRedundancy0
1016  &pValidatedTemperatures
1018  /* Clear valid flag */
1019  pValidatedTemperatures->invalidCellTemperature[s][m] =
1020  pValidatedTemperatures->invalidCellTemperature[s][m] & (~(1u << c));
1021  numberValidMeasurements++;
1022  } else {
1023  /* Set invalid flag */
1024  noPlausibilityIssueDetected = STD_NOT_OK;
1025  pValidatedTemperatures->invalidCellTemperature[s][m] |= (1u << c);
1026  /* Set return value to #STD_NOT_OK as not all cell temperatures have a valid measurement value */
1027  retval = STD_NOT_OK;
1028  }
1029  } else if ((pCelltemperatureBase->invalidCellTemperature[s][m] & (1u << c)) == 0u) {
1030  /* Only base measurement value is valid -> use this temperature without further plausibility checks */
1031  pValidatedTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] =
1032  pCelltemperatureBase->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c];
1033  /* Reset valid flag */
1034  pValidatedTemperatures->invalidCellTemperature[s][m] =
1035  pValidatedTemperatures->invalidCellTemperature[s][m] & (~(1u << c));
1036  numberValidMeasurements++;
1037  } else if ((pCelltemperatureRedundancy0->invalidCellTemperature[s][m] & (1u << c)) == 0u) {
1038  /* Only redundant measurement value is valid -> use this temperature without further plausibility checks */
1039  pValidatedTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] =
1040  pCelltemperatureRedundancy0
1041  ->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c];
1042  /* Reset valid flag */
1043  pValidatedTemperatures->invalidCellTemperature[s][m] =
1044  pValidatedTemperatures->invalidCellTemperature[s][m] & (~(1u << c));
1045  numberValidMeasurements++;
1046  } else {
1047  /* Both, base and redundant measurement value are invalid */
1048  /* Save average cell voltage value of base and redundant */
1049  pValidatedTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] =
1050  (pCelltemperatureBase->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] +
1051  pCelltemperatureRedundancy0
1053  2u;
1054  /* Set invalid flag */
1055  pValidatedTemperatures->invalidCellTemperature[s][m] |= (1u << c);
1056  /* Set return value to #STD_NOT_OK as not all cell temperatures have a valid measurement value */
1057  retval = STD_NOT_OK;
1058  }
1059  }
1060  }
1061  pValidatedTemperatures->nrValidTemperatures[s] = numberValidMeasurements;
1062  numberValidMeasurements = 0u; /* Reset counter for next string */
1063 
1064  (void)DIAG_CheckEvent(noPlausibilityIssueDetected, DIAG_ID_PLAUSIBILITY_CELL_TEMP, DIAG_STRING, s);
1065  noPlausibilityIssueDetected = STD_OK; /* Reset flag for next string */
1066  }
1067 
1068  return retval;
1069 }
1070 
1072  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature,
1073  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature) {
1074  /* Pointer validity check */
1075  FAS_ASSERT(pCellTemperature != NULL_PTR);
1076  FAS_ASSERT(pValidatedTemperature != NULL_PTR);
1077 
1078  /* Save header struct to copy to correct database entry */
1079  DATA_BLOCK_HEADER_s tmpHeader = pValidatedTemperature->header;
1080  /* Copy whole database entry */
1081  *pValidatedTemperature = *pCellTemperature;
1082  /* Restore previous header */
1083  pValidatedTemperature->header = tmpHeader;
1084  return STD_OK;
1085 }
1086 
1087 /*========== Extern Function Implementations ================================*/
1089  STD_RETURN_TYPE_e retval = STD_NOT_OK;
1090  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
1091  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
1092  /* Invalidate cell voltage values */
1093  mrc_tableCellVoltages.invalidCellVoltage[s][m] = 0xFFFFFFFFFFFFFFFFULL;
1095  /* Invalidate cell temperature values */
1097  }
1098  /* Invalidate string values */
1102  }
1103  /* Invalidate pack values */
1104  mrc_tablePackValues.invalidPackCurrent = 0x01; /*!< bitmask if current is valid. 0->valid, 1->invalid */
1105  mrc_tablePackValues.invalidBatteryVoltage = 0x01; /*!< bitmask if voltage is valid. 0->valid, 1->invalid */
1106  mrc_tablePackValues.invalidHvBusVoltage = 0x01; /*!< bitmask if voltage is valid. 0->valid, 1->invalid */
1107  mrc_tablePackValues.invalidPackPower = 0x01; /*!< bitmask if power is valid. 0->valid, 1->invalid */
1108 
1110  return retval;
1111 }
1112 
1114  STD_RETURN_TYPE_e retval = STD_OK;
1115 
1116  /* Database entries are declared static, so that they are placed in the data segment and not on the stack */
1117  static DATA_BLOCK_CELL_VOLTAGE_s mrc_tableCellVoltageBase = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE_BASE};
1118  static DATA_BLOCK_CELL_VOLTAGE_s mrc_tableCellVoltageRedundancy0 = {
1120 
1121  static DATA_BLOCK_CELL_TEMPERATURE_s mrc_tableCelltemperatureBase = {
1123  static DATA_BLOCK_CELL_TEMPERATURE_s mrc_tableCelltemperatureRedundancy0 = {
1125 
1126  /* Get measurement values */
1128  &mrc_tableCellVoltageBase,
1129  &mrc_tableCellVoltageRedundancy0,
1130  &mrc_tableCelltemperatureBase,
1131  &mrc_tableCelltemperatureRedundancy0);
1132 
1133  /* Perform validation of cell voltage measurement */
1134  bool updateCellVoltages =
1135  MRC_ValidateCellVoltageMeasurement(&mrc_tableCellVoltageBase, &mrc_tableCellVoltageRedundancy0);
1136 
1137  /* Perform validation of cell temperature measurement */
1138  bool updateCellTemperatures =
1139  MRC_ValidateCellTemperatureMeasurement(&mrc_tableCelltemperatureBase, &mrc_tableCelltemperatureRedundancy0);
1140 
1141  /* Update database entries if necessary */
1142  if ((updateCellVoltages == true) && (updateCellTemperatures == true)) {
1144  } else if (updateCellVoltages == true) {
1146  } else if (updateCellTemperatures == true) {
1148  } else {
1149  retval = STD_NOT_OK;
1150  }
1151  return retval;
1152 }
1153 
1155  STD_RETURN_TYPE_e retval = STD_OK;
1157 
1158  DATA_READ_DATA(&tableCurrentSensor);
1159 
1160  MRC_ValidateCurrentMeasurement(&tableCurrentSensor);
1163  MRC_ValidateHighVoltageBusMeasurement(&tableCurrentSensor);
1164  MRC_ValidatePowerMeasurement(&tableCurrentSensor);
1165 
1167 
1168  return retval;
1169 }
1170 
1171 /*========== Externalized Static Function Implementations (Unit Test) =======*/
1172 #ifdef UNITY_UNIT_TEST
1173 extern bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp) {
1174  return MRC_MeasurementUpdatedAtLeastOnce(timestamp, previousTimestamp);
1175 }
1177  uint32_t timestamp,
1178  uint32_t previousTimestamp,
1179  uint32_t timeInterval) {
1180  return MRC_MeasurementUpdatedRecently(timestamp, previousTimestamp, timeInterval);
1181 }
1183  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
1184  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0) {
1185  return MRC_ValidateCellVoltageMeasurement(pCellVoltageBase, pCellVoltageRedundancy0);
1186 }
1188  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase,
1189  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0) {
1190  return MRC_ValidateCellTemperatureMeasurement(pCellTemperatureBase, pCellTemperatureRedundancy0);
1191 }
1192 
1194  MRC_ValidateCurrentMeasurement(pTableCurrentSensor);
1195 }
1196 
1198  MRC_ValidatePowerMeasurement(pTableCurrentSensor);
1199 }
1201  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor,
1202  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage) {
1203  MRC_ValidateStringVoltageMeasurement(pTableCurrentSensor, pTableCellVoltage);
1204 }
1207 }
1209  MRC_ValidateHighVoltageBusMeasurement(pTableCurrentSensor);
1210 }
1212  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages,
1213  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
1214  return MRC_CalculateCellVoltageMinMaxAverage(pValidatedVoltages, pMinMaxAverageValues);
1215 }
1217  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures,
1218  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
1219  return MRC_CalculateCellTemperatureMinMaxAverage(pValidatedTemperatures, pMinMaxAverageValues);
1220 }
1222  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
1223  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0,
1224  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages) {
1225  return MRC_ValidateCellVoltage(pCellVoltageBase, pCellVoltageRedundancy0, pValidatedVoltages);
1226 }
1228  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage,
1229  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages) {
1230  return MRC_UpdateCellVoltageValidation(pCellVoltage, pValidatedVoltages);
1231 }
1233  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase,
1234  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0,
1235  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures) {
1236  return MRC_ValidateCellTemperature(pCelltemperatureBase, pCelltemperatureRedundancy0, pValidatedTemperatures);
1237 }
1239  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature,
1240  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature) {
1241  return MRC_UpdateCellTemperatureValidation(pCellTemperature, pValidatedTemperature);
1242 }
1243 #endif
#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.
Definition: bms.c:1606
uint8_t BMS_GetNumberOfConnectedStrings(void)
Returns number of connected strings.
Definition: bms.c:1615
bool BMS_IsStringClosed(uint8_t stringNumber)
Returns string state (closed or open)
Definition: bms.c:1597
bms driver header
Database module header.
#define DATA_READ_DATA(...)
Definition: database.h:83
#define DATA_WRITE_DATA(...)
Definition: database.h:93
@ DATA_BLOCK_ID_CELL_VOLTAGE_REDUNDANCY0
Definition: database_cfg.h:99
@ DATA_BLOCK_ID_MIN_MAX
Definition: database_cfg.h:78
@ DATA_BLOCK_ID_CELL_VOLTAGE
Definition: database_cfg.h:76
@ DATA_BLOCK_ID_CELL_TEMPERATURE_REDUNDANCY0
Definition: database_cfg.h:100
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
Definition: database_cfg.h:98
@ DATA_BLOCK_ID_CURRENT_SENSOR
Definition: database_cfg.h:79
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
Definition: database_cfg.h:97
@ DATA_BLOCK_ID_PACK_VALUES
Definition: database_cfg.h:105
@ DATA_BLOCK_ID_CELL_TEMPERATURE
Definition: database_cfg.h:77
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.
STD_RETURN_TYPE_e DIAG_CheckEvent(STD_RETURN_TYPE_e cond, DIAG_ID_e diagId, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_CheckEvent provides a simple interface to check an event for STD_OK.
Definition: diag.c:371
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:243
Diagnosis driver header.
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:258
@ DIAG_EVENT_OK
Definition: diag_cfg.h:257
@ DIAG_SYSTEM
Definition: diag_cfg.h:270
@ DIAG_STRING
Definition: diag_cfg.h:271
@ DIAG_ID_POWER_MEASUREMENT_ERROR
Definition: diag_cfg.h:244
@ DIAG_ID_CURRENT_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:239
@ DIAG_ID_BASE_CELL_TEMPERATURE_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:237
@ DIAG_ID_PLAUSIBILITY_PACK_VOLTAGE
Definition: diag_cfg.h:228
@ DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE
Definition: diag_cfg.h:187
@ DIAG_ID_PLAUSIBILITY_CELL_TEMP
Definition: diag_cfg.h:190
@ DIAG_ID_CURRENT_SENSOR_POWER_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:243
@ DIAG_ID_BASE_CELL_VOLTAGE_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:235
@ DIAG_ID_CURRENT_SENSOR_V1_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:241
@ DIAG_ID_CURRENT_SENSOR_V3_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:242
@ DIAG_ID_REDUNDANCY0_CELL_VOLTAGE_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:236
@ DIAG_ID_CURRENT_MEASUREMENT_ERROR
Definition: diag_cfg.h:240
@ DIAG_ID_REDUNDANCY0_CELL_TEMPERATURE_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:238
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:248
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:126
math library for often used math functions
#define UNIT_CONVERSION_FACTOR_1000_INTEGER
Definition: foxmath.h:75
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
@ STD_NOT_OK
Definition: fstd_types.h:83
@ STD_OK
Definition: fstd_types.h:82
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:76
Declaration of the OS wrapper interface.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:139
STD_RETURN_TYPE_e PL_CheckTemperatureSpread(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Cell temperature spread plausibility check.
Definition: plausibility.c:155
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.
Definition: plausibility.c:104
STD_RETURN_TYPE_e PL_CheckStringVoltage(int32_t voltageAfe_mV, int32_t voltageCurrentSensor_mV)
Pack voltage plausibility check between LTC and current sensor values.
Definition: plausibility.c:74
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.
Definition: plausibility.c:86
STD_RETURN_TYPE_e PL_CheckVoltageSpread(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Cell voltage spread plausibility check.
Definition: plausibility.c:123
plausibility checks for cell voltage and cell temperatures
static DATA_BLOCK_CELL_TEMPERATURE_s mrc_tableCellTemperatures
Definition: redundancy.c:73
static DATA_BLOCK_CELL_VOLTAGE_s mrc_tableCellVoltages
Definition: redundancy.c:72
bool TEST_MRC_ValidateCellVoltageMeasurement(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0)
Definition: redundancy.c:1182
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....
Definition: redundancy.c:974
static DATA_BLOCK_MIN_MAX_s mrc_tableMinimumMaximumValues
Definition: redundancy.c:71
static void MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Function to validate results of power measurement.
Definition: redundancy.c:713
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 ...
Definition: redundancy.c:894
static void MRC_ValidateStringVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor, DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage)
Function to validate results of string voltage measurement.
Definition: redundancy.c:574
STD_RETURN_TYPE_e TEST_MRC_CalculateCellTemperatureMinMaxAverage(DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Definition: redundancy.c:1216
STD_RETURN_TYPE_e MRC_Initialize(void)
Function to initalize redundancy module.
Definition: redundancy.c:1088
bool TEST_MRC_ValidateCellTemperatureMeasurement(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0)
Definition: redundancy.c:1187
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...
Definition: redundancy.c:679
STD_RETURN_TYPE_e TEST_MRC_CalculateCellVoltageMinMaxAverage(DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Definition: redundancy.c:1211
void TEST_MRC_ValidateBatteryVoltageMeasurement(void)
Definition: redundancy.c:1205
static DATA_BLOCK_PACK_VALUES_s mrc_tablePackValues
Definition: redundancy.c:74
void TEST_MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1197
STD_RETURN_TYPE_e TEST_MRC_UpdateCellTemperatureValidation(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature)
Definition: redundancy.c:1238
static bool MRC_ValidateCellTemperatureMeasurement(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0)
Function to validate results of cell temperature measurement.
Definition: redundancy.c:399
bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp)
Definition: redundancy.c:1173
static void MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Function to validate results of current measurement.
Definition: redundancy.c:525
void TEST_MRC_ValidateStringVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor, DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage)
Definition: redundancy.c:1200
static bool MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp)
Check timestamp if measurement has been updated at least once.
Definition: redundancy.c:243
STD_RETURN_TYPE_e MRC_ValidateAfeMeasurement(void)
Function to validate the measurement between redundant measurement values for cell voltage and cell t...
Definition: redundancy.c:1113
STD_RETURN_TYPE_e TEST_MRC_ValidateCellTemperature(DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures)
Definition: redundancy.c:1232
void TEST_MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1193
STD_RETURN_TYPE_e MRC_ValidatePackMeasurement(void)
Function to validate the measurements of pack values (string values, pack values)
Definition: redundancy.c:1154
STD_RETURN_TYPE_e TEST_MRC_UpdateCellVoltageValidation(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
Definition: redundancy.c:1227
STD_RETURN_TYPE_e TEST_MRC_MeasurementUpdatedRecently(uint32_t timestamp, uint32_t previousTimestamp, uint32_t timeInterval)
Definition: redundancy.c:1176
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.
Definition: redundancy.c:773
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....
Definition: redundancy.c:1071
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 ...
Definition: redundancy.c:991
STD_RETURN_TYPE_e TEST_MRC_ValidateCellVoltage(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
Definition: redundancy.c:1221
static MRC_STATE_s mrc_state
Definition: redundancy.c:78
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.
Definition: redundancy.c:831
static void MRC_ValidateBatteryVoltageMeasurement(void)
Function to validate HV battery voltage measurement.
Definition: redundancy.c:639
static bool MRC_ValidateCellVoltageMeasurement(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0)
Function to validate results of cell voltage measurement.
Definition: redundancy.c:272
static STD_RETURN_TYPE_e MRC_MeasurementUpdatedRecently(uint32_t timestamp, uint32_t previousTimestamp, uint32_t timeInterval)
Check timestamp if measurement has been updated recently.
Definition: redundancy.c:254
void TEST_MRC_ValidateHighVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1208
Header fileS for handling redundancy between redundant cell voltage and cell temperature measurements...
#define MRC_ALLOWED_NUMBER_OF_INVALID_CELL_VOLTAGES
Definition: redundancy.h:111
#define MRC_CURRENT_MEASUREMENT_PERIOD_TIMEOUT_ms
Definition: redundancy.h:74
#define MRC_CURRENT_SENSOR_MEASUREMENT_TIMEOUT_ms
Definition: redundancy.h:101
#define MRC_AFE_MEASUREMENT_PERIOD_TIMEOUT_ms
Definition: redundancy.h:88
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:146
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
Definition: database_cfg.h:148
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
Definition: database_cfg.h:151
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:150
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:131
bool validModuleVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:138
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:129
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:135
uint16_t nrValidCellVoltages[BS_NR_OF_STRINGS]
Definition: database_cfg.h:136
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:132
uint32_t previousTimestampCurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:215
uint32_t timestampCurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:216
uint32_t previousTimestampHighVoltage[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
Definition: database_cfg.h:237
int32_t current_mA[BS_NR_OF_STRINGS]
Definition: database_cfg.h:212
uint32_t timestampHighVoltage[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
Definition: database_cfg.h:239
uint32_t previousTimestampPower[BS_NR_OF_STRINGS]
Definition: database_cfg.h:222
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:211
uint32_t timestampPower[BS_NR_OF_STRINGS]
Definition: database_cfg.h:223
int32_t highVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
Definition: database_cfg.h:234
uint8_t invalidCurrentMeasurement[BS_NR_OF_STRINGS]
Definition: database_cfg.h:213
uint8_t invalidHighVoltageMeasurement[BS_NR_OF_STRINGS][BS_NR_OF_VOLTAGES_FROM_CURRENT_SENSOR]
Definition: database_cfg.h:233
int32_t power_W[BS_NR_OF_STRINGS]
Definition: database_cfg.h:219
uint8_t invalidPowerMeasurement[BS_NR_OF_STRINGS]
Definition: database_cfg.h:220
DATA_BLOCK_ID_e uniqueId
Definition: database_cfg.h:119
int16_t minimumTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:172
uint16_t nrSensorMinimumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:174
uint16_t nrModuleMinimumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:173
uint16_t nrModuleMaximumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:176
int16_t maximumTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:175
int16_t averageCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:161
uint16_t nrSensorMaximumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:177
uint16_t validMeasuredCellVoltages[BS_NR_OF_STRINGS]
Definition: database_cfg.h:170
float averageTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:171
uint16_t validMeasuredCellTemperatures[BS_NR_OF_STRINGS]
Definition: database_cfg.h:178
uint16_t nrCellMaximumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:169
uint16_t nrCellMinimumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:167
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:159
uint16_t nrModuleMinimumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:166
uint16_t nrModuleMaximumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:168
int16_t maximumCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:164
int16_t minimumCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:162
int32_t stringVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:198
int32_t stringPower_W[BS_NR_OF_STRINGS]
Definition: database_cfg.h:202
uint8_t invalidStringPower[BS_NR_OF_STRINGS]
Definition: database_cfg.h:203
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:187
int32_t stringCurrent_mA[BS_NR_OF_STRINGS]
Definition: database_cfg.h:200
uint8_t invalidStringCurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:201
uint8_t invalidStringVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:199
uint32_t lastBaseCelltemperatureTimestamp
Definition: redundancy.h:120
uint32_t lastStringCurrentTimestamp[BS_NR_OF_STRINGS]
Definition: redundancy.h:122
uint32_t lastRedundancy0CelltemperatureTimestamp
Definition: redundancy.h:121
uint32_t lastRedundancy0CellVoltageTimestamp
Definition: redundancy.h:119
uint32_t lastStringPowerTimestamp[BS_NR_OF_STRINGS]
Definition: redundancy.h:123
uint32_t lastBaseCellVoltageTimestamp
Definition: redundancy.h:118