foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
diag.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 diag.h
44  * @author foxBMS Team
45  * @date 2019-11-28 (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 header
52  *
53  */
54 
55 #ifndef FOXBMS__DIAG_H_
56 #define FOXBMS__DIAG_H_
57 
58 /*========== Includes =======================================================*/
59 #include "diag_cfg.h"
60 
61 #include "fstd_types.h"
62 
63 #include <stdint.h>
64 
65 /*========== Macros and Definitions =========================================*/
66 
67 /** diagnosis handler return types */
68 typedef enum {
69  DIAG_HANDLER_RETURN_OK, /*!< error not occurred or occurred but threshold not reached */
70  DIAG_HANDLER_RETURN_ERR_OCCURRED, /*!< error occurred and enabled */
71  DIAG_HANDLER_RETURN_WARNING_OCCURRED, /*!< warning occurred (error occurred but not enabled) */
72  DIAG_HANDLER_RETURN_WRONG_ID, /*!< wrong diagnosis id */
73  DIAG_HANDLER_RETURN_UNKNOWN, /*!< unknown return type */
74  DIAG_HANDLER_INVALID_TYPE, /*!< invalid diagnosis type, error in configuration */
75  DIAG_HANDLER_INVALID_DATA, /*!< invalid data, dependent of the diagHandler */
76  DIAG_HANDLER_INVALID_ERR_IMPACT, /*!< event neither string nor system level related */
77  DIAG_HANDLER_RETURN_NOT_READY, /*!< diagnosis handler not ready */
79 
80 /** possible states of the diagnosis module */
81 typedef enum {
82  DIAG_STATE_UNINITIALIZED, /*!< diagnosis module not initialized */
83  DIAG_STATE_INITIALIZED, /*!< diagnosis module initialized (ready for use) */
85 
86 /** central state struct of the diag module */
87 typedef struct {
88  DIAG_MODULE_STATE_e state; /*!< actual state of diagnosis module */
89  uint16_t errcnttotal; /*!< total counts of diagnosis entry records*/
90  uint16_t errcntreported; /*!< reported error counts to external tool*/
91  uint32_t entry_event[DIAG_ID_MAX]; /*!< last detected entry event*/
92  uint8_t entry_cnt[DIAG_ID_MAX]; /*!< reported event counter used for limitation */
93  uint16_t occurrenceCounter[BS_NR_OF_STRINGS][DIAG_ID_MAX]; /*!< counter for the occurrence of diag events */
94  uint8_t id2ch[DIAG_ID_MAX]; /*!< diagnosis-id to configuration channel selector*/
95  uint8_t nrOfConfiguredDiagnosisEntries; /*!< number of configured diagnosis entries */
96  uint32_t errflag[(DIAG_ID_MAX + 31) / 32]; /*!< detected error flags (bit_nr = diag_id) */
97  uint32_t warnflag[(DIAG_ID_MAX + 31) / 32]; /*!< detected warning flags (bit_nr = diag_id) */
98  uint32_t err_enableflag[(DIAG_ID_MAX + 31) / 32]; /*!< enabled error flags (bit_nr = diag_id) */
100 
101 /*========== Extern Constant and Variable Declarations ======================*/
102 
103 /*========== Extern Function Prototypes =====================================*/
104 
105 /**
106  * @brief DIAG_Handler provides generic error handling, based on diagnosis
107  * group.
108  * @details This function calls the handler functions depending on the
109  * diagnosis group of call. It needs to get called in every function
110  * which wants to apply some kind of diagnosis handling. According to
111  * its return value further treatment is either left to the calling
112  * module itself, or can be done in the callback function defined in
113  * diag_cfg.c
114  * @param diagId #DIAG_ID_e of the event that has occurred
115  * @param event event that occurred (OK, NOK, RESET)
116  * @param impact #DIAG_IMPACT_LEVEL_e of #DIAG_ID_e
117  * @param data individual information for #DIAG_ID_e e.g. string number,..
118  * @return #DIAG_HANDLER_RETURN_UNKNOWN if invalid #DIAG_EVENT_e, otherwise
119  * return value of #DIAG_RETURNTYPE_e
120  */
121 extern DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data);
122 
123 /**
124  * @brief DIAG_CheckEvent provides a simple interface to check an event for
125  * #STD_OK
126  * @details DIAG_CheckEvent is a wrapper function for #DIAG_Handler(). In simple
127  * cases where a return value that is not #STD_OK (or a 0 casted to
128  * #STD_OK) should increase the error counter in a diagnosis channel,
129  * this function should be used instead of directly calling the
130  * #DIAG_Handler().
131  * @param cond condition
132  * @param diagId event ID of the event that has occurred
133  * @param impact #DIAG_IMPACT_LEVEL_e of #DIAG_ID_e
134  * @param data individual information for #DIAG_ID_e e.g. string number,..
135  * @return STD_OK if ok, STD_NOT_OK if not ok
136  */
138  STD_RETURN_TYPE_e cond,
139  DIAG_ID_e diagId,
140  DIAG_IMPACT_LEVEL_e impact,
141  uint32_t data);
142 
143 /**
144  * @brief DIAG_Init initializes all needed structures/buffers.
145  * @details This function provides initialization of the diagnose module. In
146  * case of miss behaviour it calls Reset and adds an entry into
147  * database to ensure data validity/report back malfunction
148  * @param diag_dev_pointer
149  * @return #STD_OK if ok, #STD_NOT_OK if not ok
150  */
151 extern STD_RETURN_TYPE_e DIAG_Initialize(DIAG_DEV_s *diag_dev_pointer);
152 
153 /**
154  * @brief Checks if passed diagnosis entry has been triggered or not
155  * @param diagnosisEntry event ID of diagnosis entry
156  * @return #STD_OK if diagnosis entry has not surpassed error threshold, otherwise #STD_NOT_OK
157  */
159 
160 /**
161  * @brief Prints contents of the error buffer on user request.
162  */
163 extern void DIAG_PrintErrors(void);
164 
165 /**
166  * @brief Get configured delay of passed diagnosis entry
167  * @param diagnosisEntry event ID of diagnosis entry
168  * @return configured delay in ms
169  */
170 extern uint32_t DIAG_GetDelay(DIAG_ID_e diagnosisEntry);
171 
172 /**
173  * @brief Check if any fatal error is set
174  * @return true, if a diagnosis entry with severity #DIAG_FATAL_ERROR is set,
175  * otherwise false
176  */
177 extern bool DIAG_IsAnyFatalErrorSet(void);
178 
179 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
180 #ifdef UNITY_UNIT_TEST
181 #endif
182 
183 #endif /* FOXBMS__DIAG_H_ */
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
DIAG_MODULE_STATE_e
Definition: diag.h:81
@ DIAG_STATE_UNINITIALIZED
Definition: diag.h:82
@ DIAG_STATE_INITIALIZED
Definition: diag.h:83
STD_RETURN_TYPE_e DIAG_CheckEvent(STD_RETURN_TYPE_e cond, DIAG_ID_e diagId, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_CheckEvent provides a simple interface to check an event for STD_OK.
Definition: diag.c:374
DIAG_RETURNTYPE_e
Definition: diag.h:68
@ DIAG_HANDLER_RETURN_NOT_READY
Definition: diag.h:77
@ DIAG_HANDLER_INVALID_DATA
Definition: diag.h:75
@ DIAG_HANDLER_RETURN_WRONG_ID
Definition: diag.h:72
@ DIAG_HANDLER_INVALID_TYPE
Definition: diag.h:74
@ DIAG_HANDLER_RETURN_WARNING_OCCURRED
Definition: diag.h:71
@ DIAG_HANDLER_RETURN_ERR_OCCURRED
Definition: diag.h:70
@ DIAG_HANDLER_INVALID_ERR_IMPACT
Definition: diag.h:76
@ DIAG_HANDLER_RETURN_OK
Definition: diag.h:69
@ DIAG_HANDLER_RETURN_UNKNOWN
Definition: diag.h:73
uint32_t DIAG_GetDelay(DIAG_ID_e diagnosisEntry)
Get configured delay of passed diagnosis entry.
Definition: diag.c:386
void DIAG_PrintErrors(void)
Prints contents of the error buffer on user request.
Definition: diag.c:208
STD_RETURN_TYPE_e DIAG_GetDiagnosisEntryState(DIAG_ID_e diagnosisEntry)
Checks if passed diagnosis entry has been triggered or not.
Definition: diag.c:192
bool DIAG_IsAnyFatalErrorSet(void)
Check if any fatal error is set.
Definition: diag.c:391
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:246
STD_RETURN_TYPE_e DIAG_Initialize(DIAG_DEV_s *diag_dev_pointer)
DIAG_Init initializes all needed structures/buffers.
Definition: diag.c:116
Diagnostic module configuration header.
DIAG_EVENT_e
Definition: diag_cfg.h:264
DIAG_IMPACT_LEVEL_e
Definition: diag_cfg.h:277
DIAG_ID_e
Definition: diag_cfg.h:176
@ DIAG_ID_MAX
Definition: diag_cfg.h:260
Definition of foxBMS standard types.
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
uint16_t errcnttotal
Definition: diag.h:89
uint16_t errcntreported
Definition: diag.h:90
uint8_t nrOfConfiguredDiagnosisEntries
Definition: diag.h:95
DIAG_MODULE_STATE_e state
Definition: diag.h:88