foxBMS-UnitTests  1.0.0
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
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
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-02-17 (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) =======*/
DATA_BLOCK_MSL_FLAG::packDischargeOvercurrent
uint8_t packDischargeOvercurrent
Definition: database_cfg.h:429
DATA_BLOCK_MSL_FLAG::stringDischargeOvercurrent
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:439
DIAG_ErrorOvercurrentDischarge
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
Definition: diag_cbs_current.c:150
DIAG_ErrorOvercurrentCharge
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
Definition: diag_cbs_current.c:68
DIAG_ID_PACK_OVERCURRENT_CHARGE_MSL
@ DIAG_ID_PACK_OVERCURRENT_CHARGE_MSL
Definition: diag_cfg.h:172
DIAG_DATABASE_SHIM
Definition: diag_cfg.h:113
DIAG_ID_STRING_OVERCURRENT_CHARGE_MOL
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_MOL
Definition: diag_cfg.h:168
DATA_BLOCK_ERRORSTATE::currentMeasurementError
uint8_t currentMeasurementError[BS_NR_OF_STRINGS]
Definition: database_cfg.h:340
DIAG_ID_OVERCURRENT_CHARGE_CELL_MSL
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_MSL
Definition: diag_cfg.h:160
DATA_BLOCK_RSL_FLAG::stringChargeOvercurrent
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:457
DIAG_ID_OVERCURRENT_CHARGE_CELL_RSL
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_RSL
Definition: diag_cfg.h:161
DATA_BLOCK_ERRORSTATE::currentMeasurementTimeout
uint8_t currentMeasurementTimeout[BS_NR_OF_STRINGS]
Definition: database_cfg.h:339
DATA_BLOCK_MOL_FLAG::cellChargeOvercurrent
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:476
DATA_BLOCK_MSL_FLAG::stringChargeOvercurrent
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:437
DATA_BLOCK_ERRORSTATE::currentOnOpenString
uint8_t currentOnOpenString[BS_NR_OF_STRINGS]
Definition: database_cfg.h:360
DIAG_ID_STRING_OVERCURRENT_CHARGE_RSL
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_RSL
Definition: diag_cfg.h:167
DIAG_EVENT_OK
@ DIAG_EVENT_OK
Definition: diag_cfg.h:201
DIAG_EVENT_RESET
@ DIAG_EVENT_RESET
Definition: diag_cfg.h:203
DIAG_ErrorCurrentMeasurement
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
Definition: diag_cbs_current.c:231
DIAG_ID_STRING_OVERCURRENT_DISCHARGE_RSL
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_RSL
Definition: diag_cfg.h:170
DATA_BLOCK_MOL_FLAG::cellDischargeOvercurrent
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:478
FAS_ASSERT
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:233
DATA_BLOCK_RSL_FLAG::cellChargeOvercurrent
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:456
DIAG_ID_e
enum DIAG_ID DIAG_ID_e
DIAG_ID_STRING_OVERCURRENT_CHARGE_MSL
@ DIAG_ID_STRING_OVERCURRENT_CHARGE_MSL
Definition: diag_cfg.h:166
DIAG_ErrorCurrentOnOpenString
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
Definition: diag_cbs_current.c:268
DATA_BLOCK_MSL_FLAG::packChargeOvercurrent
uint8_t packChargeOvercurrent
Definition: database_cfg.h:428
diag_cbs.h
Diagnosis driver header.
DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MSL
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MSL
Definition: diag_cfg.h:163
DATA_BLOCK_MOL_FLAG::stringDischargeOvercurrent
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:479
DIAG_ID_OVERCURRENT_CHARGE_CELL_MOL
@ DIAG_ID_OVERCURRENT_CHARGE_CELL_MOL
Definition: diag_cfg.h:162
DIAG_ID_CURRENT_MEASUREMENT_TIMEOUT
@ DIAG_ID_CURRENT_MEASUREMENT_TIMEOUT
Definition: diag_cfg.h:187
DATA_BLOCK_RSL_FLAG::stringDischargeOvercurrent
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:459
DIAG_DATABASE_SHIM::pTableRsl
DATA_BLOCK_RSL_FLAG_s * pTableRsl
Definition: diag_cfg.h:116
DIAG_EVENT_NOT_OK
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:202
DIAG_EVENT_e
enum DIAG_EVENT DIAG_EVENT_e
DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MSL
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MSL
Definition: diag_cfg.h:169
DIAG_ID_PACK_OVERCURRENT_DISCHARGE_MSL
@ DIAG_ID_PACK_OVERCURRENT_DISCHARGE_MSL
Definition: diag_cfg.h:173
NULL_PTR
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
DATA_BLOCK_RSL_FLAG::cellDischargeOvercurrent
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:458
DATA_BLOCK_MOL_FLAG::stringChargeOvercurrent
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:477
DIAG_DATABASE_SHIM::pTableMsl
DATA_BLOCK_MSL_FLAG_s * pTableMsl
Definition: diag_cfg.h:117
DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MOL
@ DIAG_ID_STRING_OVERCURRENT_DISCHARGE_MOL
Definition: diag_cfg.h:171
DIAG_DATABASE_SHIM::pTableMol
DATA_BLOCK_MOL_FLAG_s * pTableMol
Definition: diag_cfg.h:115
DATA_BLOCK_MSL_FLAG::cellChargeOvercurrent
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:436
DIAG_ID_OVERCURRENT_DISCHARGE_CELL_RSL
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_RSL
Definition: diag_cfg.h:164
DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MOL
@ DIAG_ID_OVERCURRENT_DISCHARGE_CELL_MOL
Definition: diag_cfg.h:165
DIAG_DATABASE_SHIM::pTableError
DATA_BLOCK_ERRORSTATE_s * pTableError
Definition: diag_cfg.h:114
FAS_TRAP
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:108
DIAG_ID_CURRENT_MEASUREMENT_ERROR
@ DIAG_ID_CURRENT_MEASUREMENT_ERROR
Definition: diag_cfg.h:188
DATA_BLOCK_MSL_FLAG::cellDischargeOvercurrent
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:438
BS_NR_OF_STRINGS
#define BS_NR_OF_STRINGS
Definition: battery_system_cfg.h:89
DIAG_ID_MAX
@ DIAG_ID_MAX
Definition: diag_cfg.h:196