foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
redundancy.h
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 redundancy.h
44  * @author foxBMS Team
45  * @date 2020-07-31 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.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 
61 #include "database.h"
62 
63 #include <stdint.h>
64 
65 /*========== Macros and Definitions =========================================*/
66 /**
67  * Maximum time between measurements before the
68  * redundancy module raises an error because a
69  * measurement is not updated anymore.
70  *
71  * The redundancy module will wait a maximum of this time for new current
72  * values. If no new values are updated within this timeframe it
73  * will invalidate the measurement values.
74  */
75 #define MRC_CURRENT_MEASUREMENT_PERIOD_TIMEOUT_ms (250u)
76 
77 /**
78  * Maximum time between AFE measurements before the
79  * redundancy module raises an error because a
80  * measurement is not updated anymore.
81  *
82  * The redundancy module will wait a maximum of this
83  * time for new values from the base AFE measurement and
84  * AFE redundant measurements. If no new values are updated
85  * from both measurement sources within this timeframe
86  * it will validate the measurement values it has up to
87  * this point if possible.
88  */
89 #define MRC_AFE_MEASUREMENT_PERIOD_TIMEOUT_ms (250u)
90 
91 /**
92  * Maximum time between current sensor high voltage, current
93  * and power measurements before the redundancy module raises
94  * an error because a measurement is not updated anymore.
95  *
96  * The redundancy module will wait a maximum of this
97  * time for new values from the current sensor. If no
98  * new values are updated within this timeframe it will
99  * validate the measurement values it has up to this point
100  * if possible.
101  */
102 #define MRC_CURRENT_SENSOR_MEASUREMENT_TIMEOUT_ms (300u)
103 
104 /**
105  * If both, the current sensor and the AFE measurement have no valid values
106  * we try to construct the string voltage by replacing invalid cell voltage
107  * measurements with the average cell voltage in this string. The result of
108  * this estimation will be flagged as invalid if more than the number of
109  * allowed invalid cell voltages are detected. The result will be markes as
110  * valid if less then this number of cells are detected as invalid.
111  */
112 #define MRC_ALLOWED_NUMBER_OF_INVALID_CELL_VOLTAGES (5u)
113 
114 /*========== Extern Constant and Variable Declarations ======================*/
115 /**
116  * This structure contains all the variables relevant for the redundancy state machine.
117  */
118 typedef struct {
123  uint32_t lastStringCurrentTimestamp[BS_NR_OF_STRINGS];
124  uint32_t lastStringPowerTimestamp[BS_NR_OF_STRINGS];
125 } MRC_STATE_s;
126 
127 /*========== Extern Function Prototypes =====================================*/
128 /**
129  * @brief Function to initalize redundancy module
130  *
131  * @return #STD_OK if module has been initialized successfully, otherwise #STD_NOT_OK
132  */
133 extern STD_RETURN_TYPE_e MRC_Initialize(void);
134 
135 /**
136  * @brief Function to validate the measurement between redundant measurement
137  * values for cell voltage and cell temperature
138  *
139  * @return #STD_OK if measurement has been validated successfully, otherwise i.e.
140  * if no new values have been measured since the last call #STD_NOT_OK
141  */
143 
144 /**
145  * @brief Function to validate the measurements of pack values (string values,
146  * pack values)
147  *
148  * @return #STD_OK if measurement has been validated successfully, otherwise i.e.
149  * if no new values have been measured since the last call #STD_NOT_OK
150  */
152 
153 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
154 #ifdef UNITY_UNIT_TEST
155 extern bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp);
157  uint32_t timestamp,
158  uint32_t previousTimestamp,
159  uint32_t timeInterval);
161  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
162  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0);
164  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase,
165  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0);
166 extern void TEST_MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor);
167 extern void TEST_MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor);
169  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor,
170  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage);
174  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages,
175  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues);
177  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures,
178  DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues);
180  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase,
181  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0,
182  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages);
184  DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage,
185  DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages);
187  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase,
188  DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0,
189  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures);
191  DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature,
192  DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature);
193 #endif
194 
195 #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:82
bool TEST_MRC_ValidateCellVoltageMeasurement(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0)
Definition: redundancy.c:1186
STD_RETURN_TYPE_e TEST_MRC_CalculateCellTemperatureMinMaxAverage(DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Definition: redundancy.c:1220
STD_RETURN_TYPE_e MRC_Initialize(void)
Function to initalize redundancy module.
Definition: redundancy.c:1092
bool TEST_MRC_ValidateCellTemperatureMeasurement(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0)
Definition: redundancy.c:1191
STD_RETURN_TYPE_e TEST_MRC_CalculateCellVoltageMinMaxAverage(DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
Definition: redundancy.c:1215
void TEST_MRC_ValidateBatteryVoltageMeasurement(void)
Definition: redundancy.c:1209
void TEST_MRC_ValidatePowerMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1201
STD_RETURN_TYPE_e TEST_MRC_UpdateCellTemperatureValidation(DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature)
Definition: redundancy.c:1242
bool TEST_MRC_MeasurementUpdatedAtLeastOnce(uint32_t timestamp, uint32_t previousTimestamp)
Definition: redundancy.c:1177
void TEST_MRC_ValidateStringVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor, DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage)
Definition: redundancy.c:1204
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:1117
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:1236
void TEST_MRC_ValidateCurrentMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1197
STD_RETURN_TYPE_e MRC_ValidatePackMeasurement(void)
Function to validate the measurements of pack values (string values, pack values)
Definition: redundancy.c:1158
STD_RETURN_TYPE_e TEST_MRC_UpdateCellVoltageValidation(DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
Definition: redundancy.c:1231
STD_RETURN_TYPE_e TEST_MRC_MeasurementUpdatedRecently(uint32_t timestamp, uint32_t previousTimestamp, uint32_t timeInterval)
Definition: redundancy.c:1180
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:1225
void TEST_MRC_ValidateHighVoltageMeasurement(DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
Definition: redundancy.c:1212
uint32_t lastBaseCelltemperatureTimestamp
Definition: redundancy.h:121
uint32_t lastRedundancy0CelltemperatureTimestamp
Definition: redundancy.h:122
uint32_t lastRedundancy0CellVoltageTimestamp
Definition: redundancy.h:120
uint32_t lastBaseCellVoltageTimestamp
Definition: redundancy.h:119