foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
bms_cfg.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 bms_cfg.h
44  * @author foxBMS Team
45  * @date 2020-02-24 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.0
48  * @ingroup ENGINE_CONFIGURATION
49  * @prefix BMS
50  *
51  * @brief bms driver configuration header
52  */
53 
54 #ifndef FOXBMS__BMS_CFG_H_
55 #define FOXBMS__BMS_CFG_H_
56 
57 /*========== Includes =======================================================*/
58 
59 #include "ftask_cfg.h"
60 
61 #include <stdint.h>
62 
63 /*========== Macros and Definitions =========================================*/
64 
65 /** ID to send a message without request */
66 #define BMS_REQ_ID_NOREQ (0u)
67 
68 /** ID to request the STANDBY state via CAN */
69 #define BMS_REQ_ID_STANDBY (3u)
70 
71 /** ID to request the NORMAL state via CAN */
72 #define BMS_REQ_ID_NORMAL (1u)
73 
74 /** ID to request the CHARGE state via CAN */
75 #define BMS_REQ_ID_CHARGE (2u)
76 
77 /**
78  * @brief Functions searching for next string return this value if no further
79  * string is available */
80 #define BMS_NO_STRING_AVAILABLE (255u)
81 
82 /**
83  * @brief TODO
84  * @details This define MUST represent the cycle time of the task in which
85  * context the functions run, e.g., if the #BMS_Trigger() is running
86  * in the 10 ms task then the define must be set to 10.
87  * This sets the minimum time between two subsequent executed
88  * states/substates.
89  * Define is only used for compile-time assertion, it has no
90  * programatic influence on the actual code.
91  */
92 #define BMS_STATEMACHINE_TASK_CYCLE_CONTEXT_MS (10u)
93 
94 #if BMS_STATEMACHINE_TASK_CYCLE_CONTEXT_MS != FTSK_TASK_CYCLIC_10MS_CYCLE_TIME
95 #error "Invalid BMS configuration. Make sure that BMS timing is configured correctly!"
96 #endif
97 
98 /**
99  * @brief BMS state machine short time definition in #BMS_Trigger() calls
100  * until next state/substate is processed
101  */
102 #define BMS_STATEMACH_SHORTTIME (1u)
103 
104 /**
105  * @brief BMS state machine medium time definition in #BMS_Trigger() calls
106  * until next state/substate is processed
107  */
108 #define BMS_STATEMACH_MEDIUMTIME (5u)
109 
110 /**
111  * @brief BMS state machine long time definition in #BMS_Trigger() calls until
112  * next state/substate is processed
113  */
114 #define BMS_STATEMACH_LONGTIME (10u)
115 
116 /** Time in #BMS_Trigger() calls to wait after closing any string minus or string plus contactor */
117 #define BMS_WAIT_TIME_AFTER_CLOSING_STRING_CONTACTOR (20u)
118 
119 /** Time in #BMS_Trigger() calls to wait after opening any string minus or string plus contactor */
120 #define BMS_WAIT_TIME_AFTER_OPENING_STRING_CONTACTOR (10u)
121 
122 /** Time in #BMS_Trigger() calls to wait between closing complete strings */
123 #define BMS_WAIT_TIME_BETWEEN_CLOSING_STRINGS (10u)
124 
125 /**
126  * @brief Timeout in #BMS_Trigger() calls when closing a string after which
127  * the state machines goes to error if the string still has not closed
128  */
129 #define BMS_STRING_CLOSE_TIMEOUT (500u)
130 
131 /**
132  * @brief Timeout in #BMS_Trigger() calls when opening a string after which
133  * the state machines goes to error if the string still has not opened
134  */
135 #define BMS_STRING_OPEN_TIMEOUT (1000u)
136 
137 /**
138  * @brief Max voltage difference in mV between two strings to allow
139  * closing the next string
140  */
141 #define BMS_NEXT_STRING_VOLTAGE_LIMIT_MV (3000)
142 
143 /** Max average string current to allow closing next string */
144 #define BMS_AVERAGE_STRING_CURRENT_LIMIT_MA (20000)
145 
146 /** Delay after closing precharge in #BMS_Trigger() calls */
147 #define BMS_TIME_WAIT_AFTER_CLOSING_PRECHARGE (100u)
148 
149 /** Delay after opening precharge in #BMS_Trigger() calls */
150 #define BMS_TIME_WAIT_AFTER_OPENING_PRECHARGE (50u)
151 
152 /**
153  * @brief Time to wait in #BMS_Trigger() calls after precharge opened because
154  * precharge failed
155  */
156 #define BMS_TIME_WAIT_AFTERPRECHARGEFAIL (300u)
157 
158 /**
159  * @brief Timeout in 1*10ms to wait before re-entering to precharge
160  * @details Prevents mechanical close/open timer cycle in case the control
161  * units sends incorrect state requests.
162  */
163 #define BMS_OSCILLATION_TIMEOUT (1000u)
164 
165 /** Number of allowed tries to close contactors */
166 #define BMS_PRECHARGE_TRIES (3u)
167 
168 /** Precharge threshold limit on voltage (in mV) */
169 #define BMS_PRECHARGE_VOLTAGE_THRESHOLD_mV (1000LL) /* mV */
170 
171 /** Precharge threshold limit on current (in mA) */
172 #define BMS_PRECHARGE_CURRENT_THRESHOLD_mA (50) /* mA */
173 
174 /**
175  * @details Time to wait after contactors opened because precharge failed in
176  * #BMS_Trigger() calls
177  */
178 #define BMS_STATEMACH_TIMEAFTERPRECHARGEFAIL (100u)
179 
180 /**
181  * @details Timeout in #BMS_Trigger() calls when closing precharge after which
182  * the state machines goes to error if precharge still has not closed
183  */
184 #define BMS_PRECHARGE_CLOSE_TIMEOUT (500u)
185 
186 /**
187  * @details Timeout in #BMS_Trigger() calls when opening precharge after which
188  * the state machines goes to error if precharge still has not opened
189  */
190 #define BMS_PRECHARGE_OPEN_TIMEOUT (500u)
191 
192 /*========== Extern Constant and Variable Declarations ======================*/
193 
194 /*========== Extern Function Prototypes =====================================*/
195 
196 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
197 #ifdef UNITY_UNIT_TEST
198 #endif
199 
200 #endif /* FOXBMS__BMS_CFG_H_ */
Task configuration header.