foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
plausibility.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, 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 plausibility.c
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.0
48  * @ingroup APPLICATION
49  * @prefix PL
50  *
51  * @brief plausibility checks for cell voltage and cell temperatures
52  *
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "plausibility.h"
57 
58 #include "battery_system_cfg.h"
59 
60 #include "diag.h"
61 #include "foxmath.h"
62 
63 #include <stdint.h>
64 
65 /*========== Macros and Definitions =========================================*/
66 
67 /*========== Static Constant and Variable Definitions =======================*/
68 
69 /*========== Extern Constant and Variable Definitions =======================*/
70 
71 /*========== Static Function Prototypes =====================================*/
72 
73 /*========== Static Function Implementations ================================*/
74 
75 /*========== Extern Function Implementations ================================*/
76 extern STD_RETURN_TYPE_e PL_CheckStringVoltage(int32_t voltageAfe_mV, int32_t voltageCurrentSensor_mV) {
78 
79  /* Get deviation between these two measurements */
80  int32_t diff_mV = voltageAfe_mV - voltageCurrentSensor_mV;
81 
82  if (abs(diff_mV) < PL_STRING_VOLTAGE_TOLERANCE_mV) {
83  result = STD_OK;
84  }
85  return result;
86 }
87 
89  int16_t baseCellVoltage,
90  int16_t redundancy0CellVoltage,
91  int16_t *pCellVoltage) {
92  /* AXIVION Routine Generic-MissingParameterAssert: baseCellVoltage: parameter accepts whole range */
93  /* AXIVION Routine Generic-MissingParameterAssert: redundancy0CellVoltage: parameter accepts whole range */
94  /* Pointer validity check */
95  FAS_ASSERT(pCellVoltage != NULL_PTR);
96  STD_RETURN_TYPE_e retval = STD_OK;
97 
98  if (abs(baseCellVoltage - redundancy0CellVoltage) > PL_CELL_VOLTAGE_TOLERANCE_mV) {
99  retval = STD_NOT_OK;
100  }
101  /* Take the average value of base and redundant measurement value */
102  *pCellVoltage = (baseCellVoltage + redundancy0CellVoltage) / 2;
103  return retval;
104 }
105 
107  int16_t baseCelltemperature,
108  int16_t redundancy0Celltemperature,
109  int16_t *pCelltemperature) {
110  /* AXIVION Routine Generic-MissingParameterAssert: baseCelltemperature: parameter accepts whole range */
111  /* AXIVION Routine Generic-MissingParameterAssert: redundancy0Celltemperature: parameter accepts whole range */
112  /* Pointer validity check */
113  FAS_ASSERT(pCelltemperature != NULL_PTR);
114 
115  STD_RETURN_TYPE_e retval = STD_OK;
116 
117  if (abs(baseCelltemperature - redundancy0Celltemperature) > PL_CELL_TEMPERATURE_TOLERANCE_dK) {
118  retval = STD_NOT_OK;
119  }
120  /* Take the average value of base and redundant measurement value */
121  *pCelltemperature = (baseCelltemperature + redundancy0Celltemperature) / 2;
122  return retval;
123 }
124 
126  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltages,
127  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
128  /* Pointer validity check */
129  FAS_ASSERT(pCellVoltages != NULL_PTR);
130  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
131 
132  STD_RETURN_TYPE_e retval = STD_OK;
133 
134  /* Iterate over all cells */
135  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
136  STD_RETURN_TYPE_e plausibilityIssueDetected = STD_OK;
137  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
138  for (uint8_t c = 0u; c < BS_NR_OF_CELL_BLOCKS_PER_MODULE; c++) {
139  /* Only do check for valid voltages */
140  if ((pCellVoltages->invalidCellVoltage[s][m] & (0x01u << c)) == 0) {
141  if (abs(pCellVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] -
142  pMinMaxAverageValues->averageCellVoltage_mV[s]) > PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV) {
143  /* Voltage difference too large */
144  plausibilityIssueDetected = STD_NOT_OK;
145  retval = STD_NOT_OK;
146  /* Set this cell voltage invalid */
147  pCellVoltages->invalidCellVoltage[s][m] |= (0x01u << c);
148  }
149  }
150  }
151  }
153  }
154  return retval;
155 }
156 
158  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatures,
159  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
160  /* Pointer validity check */
161  FAS_ASSERT(pCellTemperatures != NULL_PTR);
162  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
163 
164  STD_RETURN_TYPE_e retval = STD_OK;
165 
166  /* Iterate over all cells */
167  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
168  STD_RETURN_TYPE_e plausibilityIssueDetected = STD_OK;
169  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
170  for (uint8_t c = 0u; c < BS_NR_OF_TEMP_SENSORS_PER_MODULE; c++) {
171  /* Only do check for valid temperatures */
172  if ((pCellTemperatures->invalidCellTemperature[s][m] & (0x01u << c)) == 0) {
173  if (abs(pCellTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] -
174  (int16_t)pMinMaxAverageValues->averageTemperature_ddegC[s]) >
176  /* temperature difference too large */
177  plausibilityIssueDetected = STD_NOT_OK;
178  retval = STD_NOT_OK;
179  /* Set this cell temperature invalid */
180  pCellTemperatures->invalidCellTemperature[s][m] |= (0x01u << c);
181  } else {
182  pCellTemperatures->nrValidTemperatures[s]++;
183  }
184  }
185  }
186  }
188  }
189  return retval;
190 }
191 
192 /*========== Externalized Static Function Implementations (Unit Test) =======*/
193 #ifdef UNITY_UNIT_TEST
194 #endif
Configuration of the battery system (e.g., number of battery modules, battery cells,...
#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_MODULES_PER_STRING
number of modules in a string
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:374
Diagnosis driver header.
@ DIAG_STRING
Definition: diag_cfg.h:279
@ DIAG_ID_PLAUSIBILITY_CELL_TEMPERATURE_SPREAD
Definition: diag_cfg.h:194
@ DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE_SPREAD
Definition: diag_cfg.h:193
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:250
math library for often used math functions
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
@ STD_NOT_OK
Definition: fstd_types.h:84
@ STD_OK
Definition: fstd_types.h:83
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
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:157
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:106
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:76
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:88
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:125
plausibility checks for cell voltage and cell temperatures
#define PL_CELL_TEMPERATURE_TOLERANCE_dK
Maximum difference between redundant cell temperature measurements in deci kelvin.
#define PL_CELL_VOLTAGE_TOLERANCE_mV
Maximum difference between redundant cell voltage measurement.
#define PL_STRING_VOLTAGE_TOLERANCE_mV
Maximum difference between pack voltage measurement from AFE and current sensor.
#define PL_CELL_TEMPERATURE_SPREAD_TOLERANCE_dK
Maximum deviation between a single cell temperature measurement and the average cell temperature in d...
#define PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV
Maximum deviation between a single cell voltage measurement and the average cell voltage.
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
Definition: database_cfg.h:151
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
Definition: database_cfg.h:154
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:153
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:138
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:135
int16_t averageCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:164
float_t averageTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:174