foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
plausibility.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 plausibility.c
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2022-10-27 (date of last update)
47  * @version v1.4.1
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 /*========== Macros and Definitions =========================================*/
64 
65 /*========== Static Constant and Variable Definitions =======================*/
66 
67 /*========== Extern Constant and Variable Definitions =======================*/
68 
69 /*========== Static Function Prototypes =====================================*/
70 
71 /*========== Static Function Implementations ================================*/
72 
73 /*========== Extern Function Implementations ================================*/
74 extern STD_RETURN_TYPE_e PL_CheckStringVoltage(int32_t voltageAfe_mV, int32_t voltageCurrentSensor_mV) {
76 
77  /* Get deviation between these two measurements */
78  int32_t diff_mV = voltageAfe_mV - voltageCurrentSensor_mV;
79 
80  if (abs(diff_mV) < PL_STRING_VOLTAGE_TOLERANCE_mV) {
81  result = STD_OK;
82  }
83  return result;
84 }
85 
87  int16_t baseCellVoltage,
88  int16_t redundancy0CellVoltage,
89  int16_t *pCellVoltage) {
90  /* AXIVION Routine Generic-MissingParameterAssert: baseCellVoltage: parameter accepts whole range */
91  /* AXIVION Routine Generic-MissingParameterAssert: redundancy0CellVoltage: parameter accepts whole range */
92  /* Pointer validity check */
93  FAS_ASSERT(pCellVoltage != NULL_PTR);
94  STD_RETURN_TYPE_e retval = STD_OK;
95 
96  if (abs(baseCellVoltage - redundancy0CellVoltage) > PL_CELL_VOLTAGE_TOLERANCE_mV) {
97  retval = STD_NOT_OK;
98  }
99  /* Take the average value of base and redundant measurement value */
100  *pCellVoltage = (baseCellVoltage + redundancy0CellVoltage) / 2;
101  return retval;
102 }
103 
105  int16_t baseCelltemperature,
106  int16_t redundancy0Celltemperature,
107  int16_t *pCelltemperature) {
108  /* AXIVION Routine Generic-MissingParameterAssert: baseCelltemperature: parameter accepts whole range */
109  /* AXIVION Routine Generic-MissingParameterAssert: redundancy0Celltemperature: parameter accepts whole range */
110  /* Pointer validity check */
111  FAS_ASSERT(pCelltemperature != NULL_PTR);
112 
113  STD_RETURN_TYPE_e retval = STD_OK;
114 
115  if (abs(baseCelltemperature - redundancy0Celltemperature) > PL_CELL_TEMPERATURE_TOLERANCE_dK) {
116  retval = STD_NOT_OK;
117  }
118  /* Take the average value of base and redundant measurement value */
119  *pCelltemperature = (baseCelltemperature + redundancy0Celltemperature) / 2;
120  return retval;
121 }
122 
124  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltages,
125  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
126  /* Pointer validity check */
127  FAS_ASSERT(pCellVoltages != NULL_PTR);
128  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
129 
130  STD_RETURN_TYPE_e retval = STD_OK;
131 
132  /* Iterate over all cells */
133  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
134  STD_RETURN_TYPE_e plausibilityIssueDetected = STD_OK;
135  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
136  for (uint8_t c = 0u; c < BS_NR_OF_CELL_BLOCKS_PER_MODULE; c++) {
137  /* Only do check for valid voltages */
138  if ((pCellVoltages->invalidCellVoltage[s][m] & (0x01u << c)) == 0) {
139  if (abs(pCellVoltages->cellVoltage_mV[s][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c] -
140  pMinMaxAverageValues->averageCellVoltage_mV[s]) > PL_CELL_VOLTAGE_SPREAD_TOLERANCE_mV) {
141  /* Voltage difference too large */
142  plausibilityIssueDetected = STD_NOT_OK;
143  retval = STD_NOT_OK;
144  /* Set this cell voltage invalid */
145  pCellVoltages->invalidCellVoltage[s][m] |= (0x01u << c);
146  }
147  }
148  }
149  }
151  }
152  return retval;
153 }
154 
156  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatures,
157  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues) {
158  /* Pointer validity check */
159  FAS_ASSERT(pCellTemperatures != NULL_PTR);
160  FAS_ASSERT(pMinMaxAverageValues != NULL_PTR);
161 
162  STD_RETURN_TYPE_e retval = STD_OK;
163 
164  /* Iterate over all cells */
165  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
166  STD_RETURN_TYPE_e plausibilityIssueDetected = STD_OK;
167  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
168  for (uint8_t c = 0u; c < BS_NR_OF_TEMP_SENSORS_PER_MODULE; c++) {
169  /* Only do check for valid temperatures */
170  if ((pCellTemperatures->invalidCellTemperature[s][m] & (0x01u << c)) == 0) {
171  if (abs(pCellTemperatures->cellTemperature_ddegC[s][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c] -
172  (int16_t)pMinMaxAverageValues->averageTemperature_ddegC[s]) >
174  /* temperature difference too large */
175  plausibilityIssueDetected = STD_NOT_OK;
176  retval = STD_NOT_OK;
177  /* Set this cell temperature invalid */
178  pCellTemperatures->invalidCellTemperature[s][m] |= (0x01u << c);
179  } else {
180  pCellTemperatures->nrValidTemperatures[s]++;
181  }
182  }
183  }
184  }
186  }
187  return retval;
188 }
189 
190 /*========== Externalized Static Function Implementations (Unit Test) =======*/
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:371
Diagnosis driver header.
@ DIAG_STRING
Definition: diag_cfg.h:271
@ DIAG_ID_PLAUSIBILITY_CELL_TEMPERATURE_SPREAD
Definition: diag_cfg.h:192
@ DIAG_ID_PLAUSIBILITY_CELL_VOLTAGE_SPREAD
Definition: diag_cfg.h:191
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:248
math library for often used math functions
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
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
#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: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
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:135
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:132
int16_t averageCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:161
float averageTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:171