foxBMS - Unit Tests  1.1.2
The foxBMS Unit Tests API Documentation
diag_cbs_current.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, 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 2021-05-19 (date of last update)
47  * @ingroup ENGINE
48  * @prefix DIAG
49  *
50  * @brief Diagnosis driver implementation
51  * @details TODO
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "diag_cbs.h"
56 
57 /*========== Macros and Definitions =========================================*/
58 
59 /*========== Static Constant and Variable Definitions =======================*/
60 
61 /*========== Extern Constant and Variable Definitions =======================*/
62 
63 /*========== Static Function Prototypes =====================================*/
64 
65 /*========== Static Function Implementations ================================*/
66 
67 /*========== Extern Function Implementations ================================*/
69  DIAG_ID_e ch_id,
70  DIAG_EVENT_e event,
71  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
72  uint32_t stringNumber) {
73  FAS_ASSERT(ch_id < DIAG_ID_MAX);
74  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
75  FAS_ASSERT(kpkDiagShim != NULL_PTR);
76  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
77 
78  switch (ch_id) {
80  if (event == DIAG_EVENT_RESET) {
81  kpkDiagShim->pTableMsl->cellChargeOvercurrent[stringNumber] = 0;
82  } else if (event == DIAG_EVENT_NOT_OK) {
83  kpkDiagShim->pTableMsl->cellChargeOvercurrent[stringNumber] = 1;
84  } else {
85  /* no relevant event, do nothing */
86  }
87  break;
89  if (event == DIAG_EVENT_RESET) {
90  kpkDiagShim->pTableRsl->cellChargeOvercurrent[stringNumber] = 0;
91  } else if (event == DIAG_EVENT_NOT_OK) {
92  kpkDiagShim->pTableRsl->cellChargeOvercurrent[stringNumber] = 1;
93  } else {
94  /* no relevant event, do nothing */
95  }
96  break;
98  if (event == DIAG_EVENT_RESET) {
99  kpkDiagShim->pTableMol->cellChargeOvercurrent[stringNumber] = 0;
100  } else if (event == DIAG_EVENT_NOT_OK) {
101  kpkDiagShim->pTableMol->cellChargeOvercurrent[stringNumber] = 1;
102  } else {
103  /* no relevant event, do nothing */
104  }
105  break;
107  if (event == DIAG_EVENT_RESET) {
108  kpkDiagShim->pTableMsl->stringChargeOvercurrent[stringNumber] = 0;
109  } else if (event == DIAG_EVENT_NOT_OK) {
110  kpkDiagShim->pTableMsl->stringChargeOvercurrent[stringNumber] = 1;
111  } else {
112  /* no relevant event, do nothing */
113  }
114  break;
116  if (event == DIAG_EVENT_RESET) {
117  kpkDiagShim->pTableRsl->stringChargeOvercurrent[stringNumber] = 0;
118  } else if (event == DIAG_EVENT_NOT_OK) {
119  kpkDiagShim->pTableRsl->stringChargeOvercurrent[stringNumber] = 1;
120  } else {
121  /* no relevant event, do nothing */
122  }
123  break;
125  if (event == DIAG_EVENT_RESET) {
126  kpkDiagShim->pTableMol->stringChargeOvercurrent[stringNumber] = 0;
127  } else if (event == DIAG_EVENT_NOT_OK) {
128  kpkDiagShim->pTableMol->stringChargeOvercurrent[stringNumber] = 1;
129  } else {
130  /* no relevant event, do nothing */
131  }
132  break;
133 
135  if (event == DIAG_EVENT_RESET) {
136  kpkDiagShim->pTableMsl->packChargeOvercurrent = 0;
137  } else if (event == DIAG_EVENT_NOT_OK) {
138  kpkDiagShim->pTableMsl->packChargeOvercurrent = 1;
139  } else {
140  /* no relevant event, do nothing */
141  }
142  break;
143 
144  default:
146  break;
147  }
148 }
149 
151  DIAG_ID_e ch_id,
152  DIAG_EVENT_e event,
153  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
154  uint32_t stringNumber) {
155  FAS_ASSERT(ch_id < DIAG_ID_MAX);
156  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
157  FAS_ASSERT(kpkDiagShim != NULL_PTR);
158  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
159 
160  switch (ch_id) {
162  if (event == DIAG_EVENT_RESET) {
163  kpkDiagShim->pTableMsl->cellDischargeOvercurrent[stringNumber] = 0;
164  } else if (event == DIAG_EVENT_NOT_OK) {
165  kpkDiagShim->pTableMsl->cellDischargeOvercurrent[stringNumber] = 1;
166  } else {
167  /* no relevant event, do nothing */
168  }
169  break;
171  if (event == DIAG_EVENT_RESET) {
172  kpkDiagShim->pTableRsl->cellDischargeOvercurrent[stringNumber] = 0;
173  } else if (event == DIAG_EVENT_NOT_OK) {
174  kpkDiagShim->pTableRsl->cellDischargeOvercurrent[stringNumber] = 1;
175  } else {
176  /* no relevant event, do nothing */
177  }
178  break;
180  if (event == DIAG_EVENT_RESET) {
181  kpkDiagShim->pTableMol->cellDischargeOvercurrent[stringNumber] = 0;
182  } else if (event == DIAG_EVENT_NOT_OK) {
183  kpkDiagShim->pTableMol->cellDischargeOvercurrent[stringNumber] = 1;
184  } else {
185  /* no relevant event, do nothing */
186  }
187  break;
189  if (event == DIAG_EVENT_RESET) {
190  kpkDiagShim->pTableMsl->stringDischargeOvercurrent[stringNumber] = 0;
191  } else if (event == DIAG_EVENT_NOT_OK) {
192  kpkDiagShim->pTableMsl->stringDischargeOvercurrent[stringNumber] = 1;
193  } else {
194  /* no relevant event, do nothing */
195  }
196  break;
198  if (event == DIAG_EVENT_RESET) {
199  kpkDiagShim->pTableRsl->stringDischargeOvercurrent[stringNumber] = 0;
200  } else if (event == DIAG_EVENT_NOT_OK) {
201  kpkDiagShim->pTableRsl->stringDischargeOvercurrent[stringNumber] = 1;
202  } else {
203  /* no relevant event, do nothing */
204  }
205  break;
207  if (event == DIAG_EVENT_RESET) {
208  kpkDiagShim->pTableMol->stringDischargeOvercurrent[stringNumber] = 0;
209  } else if (event == DIAG_EVENT_NOT_OK) {
210  kpkDiagShim->pTableMol->stringDischargeOvercurrent[stringNumber] = 1;
211  } else {
212  /* no relevant event, do nothing */
213  }
214  break;
216  if (event == DIAG_EVENT_RESET) {
217  kpkDiagShim->pTableMsl->packDischargeOvercurrent = 0;
218  } else if (event == DIAG_EVENT_NOT_OK) {
219  kpkDiagShim->pTableMsl->packDischargeOvercurrent = 1;
220  } else {
221  /* no relevant event, do nothing */
222  }
223  break;
224 
225  default:
227  break;
228  }
229 }
230 
232  DIAG_ID_e ch_id,
233  DIAG_EVENT_e event,
234  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
235  uint32_t stringNumber) {
236  FAS_ASSERT(ch_id < DIAG_ID_MAX);
237  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
238  FAS_ASSERT(kpkDiagShim != NULL_PTR);
239  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
240 
241  switch (ch_id) {
243  if (event == DIAG_EVENT_RESET) {
244  kpkDiagShim->pTableError->currentMeasurementTimeout[stringNumber] = 0u;
245  } else if (event == DIAG_EVENT_NOT_OK) {
246  kpkDiagShim->pTableError->currentMeasurementTimeout[stringNumber] = 1u;
247  } else {
248  /* no relevant event, do nothing */
249  }
250  break;
251 
253  if (event == DIAG_EVENT_RESET) {
254  kpkDiagShim->pTableError->currentMeasurementError[stringNumber] = 0u;
255  } else if (event == DIAG_EVENT_NOT_OK) {
256  kpkDiagShim->pTableError->currentMeasurementError[stringNumber] = 1u;
257  } else {
258  /* no relevant event, do nothing */
259  }
260  break;
261 
262  default:
264  break;
265  }
266 }
267 
269  DIAG_ID_e ch_id,
270  DIAG_EVENT_e event,
271  const DIAG_DATABASE_SHIM_s *const kpkDiagShim,
272  uint32_t stringNumber) {
273  FAS_ASSERT(ch_id < DIAG_ID_MAX);
274  FAS_ASSERT((event == DIAG_EVENT_OK) || (event == DIAG_EVENT_NOT_OK) || (event == DIAG_EVENT_RESET));
275  FAS_ASSERT(kpkDiagShim != NULL_PTR);
276  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
277 
278  switch (ch_id) {
280  if (event == DIAG_EVENT_RESET) {
281  kpkDiagShim->pTableError->currentOnOpenString[stringNumber] = 0u;
282  } else if (event == DIAG_EVENT_NOT_OK) {
283  kpkDiagShim->pTableError->currentOnOpenString[stringNumber] = 1u;
284  } else {
285  /* no relevant event, do nothing */
286  }
287  break;
288 
289  default:
291  break;
292  }
293 }
294 
295 /*========== Externalized Static Function Implementations (Unit Test) =======*/
#define BS_NR_OF_STRINGS
Diagnosis driver header.
void DIAG_ErrorCurrentOnOpenString(DIAG_ID_e ch_id, 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 ch_id, 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 ch_id, 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 ch_id, DIAG_EVENT_e event, const DIAG_DATABASE_SHIM_s *const kpkDiagShim, uint32_t stringNumber)
diagnosis callback function for overcurrent discharge events
enum DIAG_EVENT DIAG_EVENT_e
@ DIAG_EVENT_RESET
Definition: diag_cfg.h:236
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:235
@ DIAG_EVENT_OK
Definition: diag_cfg.h:234
enum DIAG_ID DIAG_ID_e
@ DIAG_ID_PACK_OVERCURRENT_CHARGE_MSL
Definition: diag_cfg.h:205
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_RSL
Definition: diag_cfg.h:194
@ DIAG_ID_CURRENT_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:220
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MOL
Definition: diag_cfg.h:204
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_RSL
Definition: diag_cfg.h:203
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_RSL
Definition: diag_cfg.h:200
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MSL
Definition: diag_cfg.h:196
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_MSL
Definition: diag_cfg.h:199
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_MOL
Definition: diag_cfg.h:201
@ DIAG_ID_MAX
Definition: diag_cfg.h:229
@ DIAG_ID_PACK_OVERCURRENT_DISCHARGE_MSL
Definition: diag_cfg.h:206
@ DIAG_ID_CURRENT_ON_OPEN_STRING
Definition: diag_cfg.h:207
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MSL
Definition: diag_cfg.h:202
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_MSL
Definition: diag_cfg.h:193
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MOL
Definition: diag_cfg.h:198
@ DIAG_ID_CURRENT_MEASUREMENT_ERROR
Definition: diag_cfg.h:221
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_MOL
Definition: diag_cfg.h:195
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_RSL
Definition: diag_cfg.h:197
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:233
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:108
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
uint8_t currentMeasurementTimeout[BS_NR_OF_STRINGS]
Definition: database_cfg.h:342
uint8_t currentMeasurementError[BS_NR_OF_STRINGS]
Definition: database_cfg.h:343
uint8_t currentOnOpenString[BS_NR_OF_STRINGS]
Definition: database_cfg.h:364
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:483
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:482
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:481
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:480
uint8_t packDischargeOvercurrent
Definition: database_cfg.h:433
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:440
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:443
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:441
uint8_t packChargeOvercurrent
Definition: database_cfg.h:432
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:442
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:462
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:461
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:463
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:460
DATA_BLOCK_MSL_FLAG_s * pTableMsl
Definition: diag_cfg.h:149
DATA_BLOCK_RSL_FLAG_s * pTableRsl
Definition: diag_cfg.h:148
DATA_BLOCK_ERRORSTATE_s * pTableError
Definition: diag_cfg.h:146
DATA_BLOCK_MOL_FLAG_s * pTableMol
Definition: diag_cfg.h:147