foxBMS - Unit Tests  1.4.0
The foxBMS Unit Tests API Documentation
redundancy.h
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.h
44  * @author foxBMS Team
45  * @date 2020-07-31 (date of creation)
46  * @updated 2022-07-28 (date of last update)
47  * @version v1.4.0
48  * @ingroup APPLICATION
49  * @prefix MRC
50  *
51  * @brief Header fileS for handling redundancy between redundant cell voltage
52  * and cell temperature measurements
53  *
54  */
55 
56 #ifndef FOXBMS__REDUNDANCY_H_
57 #define FOXBMS__REDUNDANCY_H_
58 
59 /*========== Includes =======================================================*/
60 #include "general.h"
61 
62 #include "database.h"
63 
64 /*========== Macros and Definitions =========================================*/
65 /**
66  * Maximum time between measurements before the
67  * redundancy module raises an error because a
68  * measurement is not updated anymore.
69  *
70  * The redundancy module will wait a maximum of this time for new current
71  * values. If no new values are updated within this timeframe it
72  * will invalidate the measurement values.
73  */
74 #define MRC_CURRENT_MEASUREMENT_PERIOD_TIMEOUT_ms (250u)
75 
76 /**
77  * Maximum time between AFE measurements before the
78  * redundancy module raises an error because a
79  * measurement is not updated anymore.
80  *
81  * The redundancy module will wait a maximum of this
82  * time for new values from the base AFE measurement and
83  * AFE redundant measurements. If no new values are updated
84  * from both measurement sources within this timeframe
85  * it will validate the measurement values it has up to
86  * this point if possible.
87  */
88 #define MRC_AFE_MEASUREMENT_PERIOD_TIMEOUT_ms (250u)
89 
90 /**
91  * Maximum time between current sensor high voltage, current
92  * and power measurements before the redundancy module raises
93  * an error because a measurement is not updated anymore.
94  *
95  * The redundancy module will wait a maximum of this
96  * time for new values from the current sensor. If no
97  * new values are updated within this timeframe it will
98  * validate the measurement values it has up to this point
99  * if possible.
100  */
101 #define MRC_CURRENT_SENSOR_MEASUREMENT_TIMEOUT_ms (300u)
102 
103 /**
104  * If both, the current sensor and the AFE measurement have no valid values
105  * we try to construct the string voltage by replacing invalid cell voltage
106  * measurements with the average cell voltage in this string. The result of
107  * this estimation will be flagged as invalid if more than the number of
108  * allowed invalid cell voltages are detected. The result will be markes as
109  * valid if less then this number of cells are detected as invalid.
110  */
111 #define MRC_ALLOWED_NUMBER_OF_INVALID_CELL_VOLTAGES (5u)
112 
113 /*========== Extern Constant and Variable Declarations ======================*/
114 /**
115  * This structure contains all the variables relevant for the redundancy state machine.
116  */
117 typedef struct {
122  uint32_t lastStringCurrentTimestamp[BS_NR_OF_STRINGS];
123  uint32_t lastStringPowerTimestamp[BS_NR_OF_STRINGS];
124 } MRC_STATE_s;
125 
126 /*========== Extern Function Prototypes =====================================*/
127 /**
128  * @brief Function to initalize redundancy module
129  *
130  * @return #STD_OK if module has been initialized successfully, otherwise #STD_NOT_OK
131  */
132 extern STD_RETURN_TYPE_e MRC_Initialize(void);
133 
134 /**
135  * @brief Function to validate the measurement between redundant measurement
136  * values for cell voltage and cell temperature
137  *
138  * @return #STD_OK if measurement has been validated successfully, otherwise i.e.
139  * if no new values have been measured since the last call #STD_NOT_OK
140  */
142 
143 /**
144  * @brief Function to validate the measurements of pack values (string values,
145  * pack values)
146  *
147  * @return #STD_OK if measurement has been validated successfully, otherwise i.e.
148  * if no new values have been measured since the last call #STD_NOT_OK
149  */
151 
152 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
153 #ifdef UNITY_UNIT_TEST
154 extern bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp);
156  uint32_t timestamp,
157  uint32_t previousTimestamp,
158  uint32_t timeInterval);
160  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
161  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0);
163  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase,
164  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0);
165 extern void TEST_MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor);
166 extern void TEST_MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor);
168  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor,
169  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage);
173  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages,
174  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues);
176  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures,
177  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues);
179  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
180  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0,
181  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages);
183  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage,
184  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages);
186  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase,
187  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0,
188  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures);
190  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature,
191  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature);
192 #endif
193 
194 #endif /* FOXBMS__REDUNDANCY_H_ */
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
Database module header.
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
General macros and definitions for the whole platform.
bool TEST_MRC_ValidateCellVoltageMeasurement(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0)
Definition: redundancy.c:1180
STD_RETURN_TYPE_e TEST_MRC_CalculateCellTemperatureMinMaxAverage(DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Definition: redundancy.c:1214
STD_RETURN_TYPE_e MRC_Initialize(void)
Function to initalize redundancy module.
Definition: redundancy.c:1086
bool TEST_MRC_ValidateCellTemperatureMeasurement(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0)
Definition: redundancy.c:1185
STD_RETURN_TYPE_e TEST_MRC_CalculateCellVoltageMinMaxAverage(DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Definition: redundancy.c:1209
void TEST_MRC_ValidateBatteryVoltageMeasurement(void)
Definition: redundancy.c:1203
void TEST_MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1195
STD_RETURN_TYPE_e TEST_MRC_UpdateCellTemperatureValidation(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature)
Definition: redundancy.c:1236
bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp)
Definition: redundancy.c:1171
void TEST_MRC_ValidateStringVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor, DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage)
Definition: redundancy.c:1198
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:1111
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:1230
void TEST_MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1191
STD_RETURN_TYPE_e MRC_ValidatePackMeasurement(void)
Function to validate the measurements of pack values (string values, pack values)
Definition: redundancy.c:1152
STD_RETURN_TYPE_e TEST_MRC_UpdateCellVoltageValidation(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
Definition: redundancy.c:1225
STD_RETURN_TYPE_e TEST_MRC_MeasurementUpdatedRecently(uint32_t timestamp, uint32_t previousTimestamp, uint32_t timeInterval)
Definition: redundancy.c:1174
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:1219
void TEST_MRC_ValidateHighVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1206
uint32_t lastBaseCelltemperatureTimestamp
Definition: redundancy.h:120
uint32_t lastRedundancy0CelltemperatureTimestamp
Definition: redundancy.h:121
uint32_t lastRedundancy0CellVoltageTimestamp
Definition: redundancy.h:119
uint32_t lastBaseCellVoltageTimestamp
Definition: redundancy.h:118