foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
diag_cbs_current.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 diag_cbs_current.c
44  * @author foxBMS Team
45  * @date 2021-02-17 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.0
48  * @ingroup ENGINE
49  * @prefix DIAG
50  *
51  * @brief Diagnosis driver implementation
52  * @details TODO
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "diag_cbs.h"
57 #include "fstd_types.h"
58 
59 #include <stdint.h>
60 
61 /*========== Macros and Definitions =========================================*/
62 
63 /*========== Static Constant and Variable Definitions =======================*/
64 
65 /*========== Extern Constant and Variable Definitions =======================*/
66 
67 /*========== Static Function Prototypes =====================================*/
68 
69 /*========== Static Function Implementations ================================*/
70 
71 /*========== Extern Function Implementations ================================*/
73  DIAG_ID_e diagId,
74  DIAG_EVENT_e event,
75  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
76  uint32_t stringNumber) {
77  FAS_ASSERT(diagId < DIAG_ID_MAX);
78  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
79  FAS_ASSERT(kpkDiagShim != NULL_PTR);
80  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
81 
82  switch (diagId) {
84  if (event == DIAG_EVENT_RESET) {
85  kpkDiagShim->pTableMsl->cellChargeOvercurrent[stringNumber] = 0;
86  } else if (event == DIAG_EVENT_NOT_OK) {
87  kpkDiagShim->pTableMsl->cellChargeOvercurrent[stringNumber] = 1;
88  } else {
89  /* no relevant event, do nothing */
90  }
91  break;
93  if (event == DIAG_EVENT_RESET) {
94  kpkDiagShim->pTableRsl->cellChargeOvercurrent[stringNumber] = 0;
95  } else if (event == DIAG_EVENT_NOT_OK) {
96  kpkDiagShim->pTableRsl->cellChargeOvercurrent[stringNumber] = 1;
97  } else {
98  /* no relevant event, do nothing */
99  }
100  break;
102  if (event == DIAG_EVENT_RESET) {
103  kpkDiagShim->pTableMol->cellChargeOvercurrent[stringNumber] = 0;
104  } else if (event == DIAG_EVENT_NOT_OK) {
105  kpkDiagShim->pTableMol->cellChargeOvercurrent[stringNumber] = 1;
106  } else {
107  /* no relevant event, do nothing */
108  }
109  break;
111  if (event == DIAG_EVENT_RESET) {
112  kpkDiagShim->pTableMsl->stringChargeOvercurrent[stringNumber] = 0;
113  } else if (event == DIAG_EVENT_NOT_OK) {
114  kpkDiagShim->pTableMsl->stringChargeOvercurrent[stringNumber] = 1;
115  } else {
116  /* no relevant event, do nothing */
117  }
118  break;
120  if (event == DIAG_EVENT_RESET) {
121  kpkDiagShim->pTableRsl->stringChargeOvercurrent[stringNumber] = 0;
122  } else if (event == DIAG_EVENT_NOT_OK) {
123  kpkDiagShim->pTableRsl->stringChargeOvercurrent[stringNumber] = 1;
124  } else {
125  /* no relevant event, do nothing */
126  }
127  break;
129  if (event == DIAG_EVENT_RESET) {
130  kpkDiagShim->pTableMol->stringChargeOvercurrent[stringNumber] = 0;
131  } else if (event == DIAG_EVENT_NOT_OK) {
132  kpkDiagShim->pTableMol->stringChargeOvercurrent[stringNumber] = 1;
133  } else {
134  /* no relevant event, do nothing */
135  }
136  break;
137 
139  if (event == DIAG_EVENT_RESET) {
140  kpkDiagShim->pTableMsl->packChargeOvercurrent = 0;
141  } else if (event == DIAG_EVENT_NOT_OK) {
142  kpkDiagShim->pTableMsl->packChargeOvercurrent = 1;
143  } else {
144  /* no relevant event, do nothing */
145  }
146  break;
147 
148  default:
150  break; /* LCOV_EXCL_LINE */
151  }
152 }
153 
155  DIAG_ID_e diagId,
156  DIAG_EVENT_e event,
157  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
158  uint32_t stringNumber) {
159  FAS_ASSERT(diagId < DIAG_ID_MAX);
160  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
161  FAS_ASSERT(kpkDiagShim != NULL_PTR);
162  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
163 
164  switch (diagId) {
166  if (event == DIAG_EVENT_RESET) {
167  kpkDiagShim->pTableMsl->cellDischargeOvercurrent[stringNumber] = 0;
168  } else if (event == DIAG_EVENT_NOT_OK) {
169  kpkDiagShim->pTableMsl->cellDischargeOvercurrent[stringNumber] = 1;
170  } else {
171  /* no relevant event, do nothing */
172  }
173  break;
175  if (event == DIAG_EVENT_RESET) {
176  kpkDiagShim->pTableRsl->cellDischargeOvercurrent[stringNumber] = 0;
177  } else if (event == DIAG_EVENT_NOT_OK) {
178  kpkDiagShim->pTableRsl->cellDischargeOvercurrent[stringNumber] = 1;
179  } else {
180  /* no relevant event, do nothing */
181  }
182  break;
184  if (event == DIAG_EVENT_RESET) {
185  kpkDiagShim->pTableMol->cellDischargeOvercurrent[stringNumber] = 0;
186  } else if (event == DIAG_EVENT_NOT_OK) {
187  kpkDiagShim->pTableMol->cellDischargeOvercurrent[stringNumber] = 1;
188  } else {
189  /* no relevant event, do nothing */
190  }
191  break;
193  if (event == DIAG_EVENT_RESET) {
194  kpkDiagShim->pTableMsl->stringDischargeOvercurrent[stringNumber] = 0;
195  } else if (event == DIAG_EVENT_NOT_OK) {
196  kpkDiagShim->pTableMsl->stringDischargeOvercurrent[stringNumber] = 1;
197  } else {
198  /* no relevant event, do nothing */
199  }
200  break;
202  if (event == DIAG_EVENT_RESET) {
203  kpkDiagShim->pTableRsl->stringDischargeOvercurrent[stringNumber] = 0;
204  } else if (event == DIAG_EVENT_NOT_OK) {
205  kpkDiagShim->pTableRsl->stringDischargeOvercurrent[stringNumber] = 1;
206  } else {
207  /* no relevant event, do nothing */
208  }
209  break;
211  if (event == DIAG_EVENT_RESET) {
212  kpkDiagShim->pTableMol->stringDischargeOvercurrent[stringNumber] = 0;
213  } else if (event == DIAG_EVENT_NOT_OK) {
214  kpkDiagShim->pTableMol->stringDischargeOvercurrent[stringNumber] = 1;
215  } else {
216  /* no relevant event, do nothing */
217  }
218  break;
220  if (event == DIAG_EVENT_RESET) {
221  kpkDiagShim->pTableMsl->packDischargeOvercurrent = 0;
222  } else if (event == DIAG_EVENT_NOT_OK) {
223  kpkDiagShim->pTableMsl->packDischargeOvercurrent = 1;
224  } else {
225  /* no relevant event, do nothing */
226  }
227  break;
228 
229  default:
231  break; /* LCOV_EXCL_LINE */
232  }
233 }
234 
236  DIAG_ID_e diagId,
237  DIAG_EVENT_e event,
238  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
239  uint32_t stringNumber) {
240  FAS_ASSERT(diagId < DIAG_ID_MAX);
241  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
242  FAS_ASSERT(kpkDiagShim != NULL_PTR);
243  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
244 
245  switch (diagId) {
247  if (event == DIAG_EVENT_RESET) {
248  kpkDiagShim->pTableError->currentMeasurementTimeoutError[stringNumber] = false;
249  } else if (event == DIAG_EVENT_NOT_OK) {
250  kpkDiagShim->pTableError->currentMeasurementTimeoutError[stringNumber] = true;
251  } else {
252  /* no relevant event, do nothing */
253  }
254  break;
255 
257  if (event == DIAG_EVENT_RESET) {
258  kpkDiagShim->pTableError->currentMeasurementInvalidError[stringNumber] = false;
259  } else if (event == DIAG_EVENT_NOT_OK) {
260  kpkDiagShim->pTableError->currentMeasurementInvalidError[stringNumber] = true;
261  } else {
262  /* no relevant event, do nothing */
263  }
264  break;
265 
266  default:
268  break; /* LCOV_EXCL_LINE */
269  }
270 }
271 
273  DIAG_ID_e diagId,
274  DIAG_EVENT_e event,
275  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
276  uint32_t stringNumber) {
277  FAS_ASSERT(diagId < DIAG_ID_MAX);
278  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
279  FAS_ASSERT(kpkDiagShim != NULL_PTR);
280  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
281 
282  switch (diagId) {
284  if (event == DIAG_EVENT_RESET) {
285  kpkDiagShim->pTableError->currentOnOpenStringDetectedError[stringNumber] = false;
286  } else if (event == DIAG_EVENT_NOT_OK) {
287  kpkDiagShim->pTableError->currentOnOpenStringDetectedError[stringNumber] = true;
288  } else {
289  /* no relevant event, do nothing */
290  }
291  break;
292 
293  default:
295  break; /* LCOV_EXCL_LINE */
296  }
297 }
298 
299 /*========== Externalized Static Function Implementations (Unit Test) =======*/
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
Diagnosis driver header.
void DIAG_ErrorCurrentOnOpenString(DIAG_ID_e diagId, DIAG_EVENT_e event, const DIAG_DATABASE_SHIM_s *const kpkDiagShim, uint32_t stringNumber)
diagnosis callback function for overcurrent charge events
void DIAG_ErrorCurrentMeasurement(DIAG_ID_e diagId, DIAG_EVENT_e event, const DIAG_DATABASE_SHIM_s *const kpkDiagShim, uint32_t stringNumber)
diagnosis callback function for current measurement related events
void DIAG_ErrorOvercurrentCharge(DIAG_ID_e diagId, DIAG_EVENT_e event, const DIAG_DATABASE_SHIM_s *const kpkDiagShim, uint32_t stringNumber)
diagnosis callback function for overcurrent charge events
void DIAG_ErrorOvercurrentDischarge(DIAG_ID_e diagId, DIAG_EVENT_e event, const DIAG_DATABASE_SHIM_s *const kpkDiagShim, uint32_t stringNumber)
diagnosis callback function for overcurrent discharge events
DIAG_EVENT_e
Definition: diag_cfg.h:264
@ DIAG_EVENT_RESET
Definition: diag_cfg.h:267
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:266
@ DIAG_EVENT_OK
Definition: diag_cfg.h:265
DIAG_ID_e
Definition: diag_cfg.h:176
@ DIAG_ID_PACK_OVERCURRENT_CHARGE_MSL
Definition: diag_cfg.h:225
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_RSL
Definition: diag_cfg.h:214
@ DIAG_ID_CURRENT_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:243
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MOL
Definition: diag_cfg.h:224
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_RSL
Definition: diag_cfg.h:223
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_RSL
Definition: diag_cfg.h:220
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MSL
Definition: diag_cfg.h:216
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_MSL
Definition: diag_cfg.h:219
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_MOL
Definition: diag_cfg.h:221
@ DIAG_ID_MAX
Definition: diag_cfg.h:260
@ DIAG_ID_PACK_OVERCURRENT_DISCHARGE_MSL
Definition: diag_cfg.h:226
@ DIAG_ID_CURRENT_ON_OPEN_STRING
Definition: diag_cfg.h:227
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MSL
Definition: diag_cfg.h:222
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_MSL
Definition: diag_cfg.h:213
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MOL
Definition: diag_cfg.h:218
@ DIAG_ID_CURRENT_MEASUREMENT_ERROR
Definition: diag_cfg.h:244
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_MOL
Definition: diag_cfg.h:215
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_RSL
Definition: diag_cfg.h:217
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:250
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:129
Definition of foxBMS standard types.
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
bool currentMeasurementInvalidError[BS_NR_OF_STRINGS]
Definition: database_cfg.h:344
bool currentMeasurementTimeoutError[BS_NR_OF_STRINGS]
Definition: database_cfg.h:343
bool currentOnOpenStringDetectedError[BS_NR_OF_STRINGS]
Definition: database_cfg.h:376
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:497
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:499
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:498
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:500
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:458
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:457
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:460
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:459
uint8_t packDischargeOvercurrent
Definition: database_cfg.h:450
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:479
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:478
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:477
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:480
DATA_BLOCK_MOL_FLAG_s * pTableMol
Definition: diag_cfg.h:167
DATA_BLOCK_RSL_FLAG_s * pTableRsl
Definition: diag_cfg.h:168
DATA_BLOCK_MSL_FLAG_s * pTableMsl
Definition: diag_cfg.h:169
DATA_BLOCK_ERROR_STATE_s * pTableError
Definition: diag_cfg.h:166