foxBMS  1.4.0
The foxBMS Battery Management System API Documentation
ltc.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, 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 ltc.h
44  * @author foxBMS Team
45  * @date 2015-09-01 (date of creation)
46  * @updated 2022-07-28 (date of last update)
47  * @version v1.4.0
48  * @ingroup DRIVERS
49  * @prefix LTC
50  *
51  * @brief Headers for the driver for the LTC monitoring chip.
52  *
53  */
54 
55 #ifndef FOXBMS__LTC_H_
56 #define FOXBMS__LTC_H_
57 
58 /*========== Includes =======================================================*/
59 #include "ltc_defs.h"
60 
61 /*========== Macros and Definitions =========================================*/
62 
63 /*========== Extern Constant and Variable Declarations ======================*/
64 
65 /**
66  * This variable contains the internal state of the LTC state machine.
67  */
69 
70 /*========== Extern Function Prototypes =====================================*/
71 
72 /**
73  * @brief trigger function for the LTC driver state machine.
74  *
75  * This function contains the sequence of events in the LTC state machine.
76  * It must be called time-triggered, every 1ms.
77  */
78 extern void LTC_Trigger(LTC_STATE_s *ltc_state);
79 
80 /**
81  * @brief sets the current state request of the state variable ltc_state.
82  *
83  * This function is used to make a state request to the state machine,e.g, start voltage measurement,
84  * read result of voltage measurement, re-initialization
85  * It calls LTC_CheckStateRequest() to check if the request is valid.
86  * The state request is rejected if is not valid.
87  * The result of the check is returned immediately, so that the requester can act in case
88  * it made a non-valid state request.
89  *
90  * @param ltc_state state of the ltc state machine
91  * @param statereq state request to set
92  *
93  * @return current state request, taken from LTC_STATE_REQUEST_e
94  */
96 
97 /**
98  * @brief gets the measurement initialization status.
99  *
100  * @param ltc_state state of the ltc state machine
101  *
102  * @return true if a first measurement cycle was made, false otherwise
103  *
104  */
105 extern bool LTC_IsFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state);
106 
107 /**
108  * @brief stores the measured voltages in the database.
109  *
110  * This function loops through the data of all modules in the LTC daisy-chain that are
111  * stored in the LTC_CellVoltages buffer and writes them in the database.
112  * At each write iteration, the variable named "state" and related to voltages in the
113  * database is incremented.
114  *
115  * @param ltc_state state of the ltc state machine
116  *
117  * @param stringNumber string addressed
118  *
119  */
120 extern void LTC_SaveVoltages(LTC_STATE_s *ltc_state, uint8_t stringNumber);
121 
122 /**
123  * @brief stores the measured temperatures and the measured multiplexer feedbacks in the database.
124  *
125  * This function loops through the temperature and multiplexer feedback data of all modules
126  * in the LTC daisy-chain that are stored in the LTC_MultiplexerVoltages buffer and writes
127  * them in the database.
128  * At each write iteration, the variables named "state" and related to temperatures and multiplexer feedbacks
129  * in the database are incremented.
130  *
131  * @param ltc_state state of the ltc state machine
132  * @param stringNumber string addressed
133  *
134  */
135 extern void LTC_SaveTemperatures(LTC_STATE_s *ltc_state, uint8_t stringNumber);
136 
137 /**
138  * @brief stores the measured GPIOs in the database.
139  *
140  * This function loops through the data of all modules in the LTC daisy-chain that are
141  * stored in the ltc_allgpiovoltage buffer and writes them in the database.
142  * At each write iteration, the variable named "state" and related to voltages in the
143  * database is incremented.
144  *
145  * @param ltc_state: state of the ltc state machine
146  *
147  */
148 extern void LTC_SaveAllGpioMeasurement(LTC_STATE_s *ltc_state);
149 
150 /**
151  * @brief gets the current state request.
152  *
153  * This function is used in the functioning of the LTC state machine.
154  *
155  * @param ltc_state: state of the ltc state machine
156  *
157  * @return retval current state request, taken from LTC_STATE_REQUEST_e
158  */
160 
161 /**
162  * @brief gets the current state.
163  *
164  * This function is used in the functioning of the LTC state machine.
165  *
166  * @param ltc_state: state of the ltc state machine
167  *
168  * @return current state, taken from LTC_STATEMACH_e
169  */
170 extern LTC_STATEMACH_e LTC_GetState(LTC_STATE_s *ltc_state);
171 
172 /**
173  * @brief Sets the transceiver pins to enable LTC6820 IC.
174  *
175  */
176 extern void LTC_InitializeMonitoringPin(void);
177 
178 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
179 #ifdef UNITY_UNIT_TEST
180 extern uint8_t TEST_LTC_CheckReEntrance();
181 extern void TEST_LTC_SetFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state);
182 
183 /** this define is used for creating the declaration of a function for variable extraction
184  * deviate from style guide in order to make the variable name better recognizable
185  */
186 #define TEST_LTC_DECLARE_GET(VARIABLE) extern void TEST_LTC_Get_##VARIABLE(uint8_t data[4])
187 TEST_LTC_DECLARE_GET(ltc_cmdWRCFG);
188 TEST_LTC_DECLARE_GET(ltc_cmdWRCFG2);
189 TEST_LTC_DECLARE_GET(ltc_cmdRDCFG);
190 TEST_LTC_DECLARE_GET(ltc_cmdRDCVA);
191 TEST_LTC_DECLARE_GET(ltc_cmdRDCVB);
192 TEST_LTC_DECLARE_GET(ltc_cmdRDCVC);
193 TEST_LTC_DECLARE_GET(ltc_cmdRDCVD);
194 TEST_LTC_DECLARE_GET(ltc_cmdRDCVE);
195 TEST_LTC_DECLARE_GET(ltc_cmdRDCVF);
196 TEST_LTC_DECLARE_GET(ltc_cmdWRCOMM);
197 TEST_LTC_DECLARE_GET(ltc_cmdSTCOMM);
198 TEST_LTC_DECLARE_GET(ltc_cmdRDCOMM);
199 TEST_LTC_DECLARE_GET(ltc_cmdRDAUXA);
200 TEST_LTC_DECLARE_GET(ltc_cmdRDAUXB);
201 TEST_LTC_DECLARE_GET(ltc_cmdRDAUXC);
202 TEST_LTC_DECLARE_GET(ltc_cmdRDAUXD);
203 TEST_LTC_DECLARE_GET(ltc_cmdADCV_normal_DCP0);
204 TEST_LTC_DECLARE_GET(ltc_cmdADCV_normal_DCP1);
205 TEST_LTC_DECLARE_GET(ltc_cmdADCV_filtered_DCP0);
206 TEST_LTC_DECLARE_GET(ltc_cmdADCV_filtered_DCP1);
207 TEST_LTC_DECLARE_GET(ltc_cmdADCV_fast_DCP0);
208 TEST_LTC_DECLARE_GET(ltc_cmdADCV_fast_DCP1);
209 TEST_LTC_DECLARE_GET(ltc_cmdADCV_fast_DCP0_twocells);
210 TEST_LTC_DECLARE_GET(ltc_cmdADAX_normal_GPIO1);
211 TEST_LTC_DECLARE_GET(ltc_cmdADAX_filtered_GPIO1);
212 TEST_LTC_DECLARE_GET(ltc_cmdADAX_fast_GPIO1);
213 TEST_LTC_DECLARE_GET(ltc_cmdADAX_normal_GPIO2);
214 TEST_LTC_DECLARE_GET(ltc_cmdADAX_filtered_GPIO2);
215 TEST_LTC_DECLARE_GET(ltc_cmdADAX_fast_GPIO2);
216 TEST_LTC_DECLARE_GET(ltc_cmdADAX_normal_GPIO3);
217 TEST_LTC_DECLARE_GET(ltc_cmdADAX_filtered_GPIO3);
218 TEST_LTC_DECLARE_GET(ltc_cmdADAX_fast_GPIO3);
219 TEST_LTC_DECLARE_GET(ltc_cmdADAX_normal_ALLGPIOS);
220 TEST_LTC_DECLARE_GET(ltc_cmdADAX_filtered_ALLGPIOS);
221 TEST_LTC_DECLARE_GET(ltc_cmdADAX_fast_ALLGPIOS);
222 TEST_LTC_DECLARE_GET(ltc_BC_cmdADOW_PUP_normal_DCP0);
223 TEST_LTC_DECLARE_GET(ltc_BC_cmdADOW_PDOWN_normal_DCP0);
224 TEST_LTC_DECLARE_GET(ltc_BC_cmdADOW_PUP_filtered_DCP0);
225 TEST_LTC_DECLARE_GET(ltc_BC_cmdADOW_PDOWN_filtered_DCP0);
226 TEST_LTC_DECLARE_GET(ltc_cmdRDCVA_Fuelcell);
227 TEST_LTC_DECLARE_GET(ltc_cmdRDCVB_Fuelcell);
228 TEST_LTC_DECLARE_GET(ltc_cmdRDCVC_Fuelcell);
229 TEST_LTC_DECLARE_GET(ltc_cmdRDCVD_Fuelcell);
230 TEST_LTC_DECLARE_GET(ltc_cmdRDCVE_Fuelcell);
231 TEST_LTC_DECLARE_GET(ltc_cmdRDCVF_Fuelcell);
232 TEST_LTC_DECLARE_GET(ltc_cmdRDCVG_Fuelcell);
233 TEST_LTC_DECLARE_GET(ltc_cmdRDCVH_Fuelcell);
234 TEST_LTC_DECLARE_GET(ltc_cmdRDCVI_Fuelcell);
235 TEST_LTC_DECLARE_GET(ltc_cmdADCV_normal_Fuelcell);
236 TEST_LTC_DECLARE_GET(ltc_BC_cmdADOW_PUP_100ms_fuelcell);
237 TEST_LTC_DECLARE_GET(ltc_BC_cmdADOW_PDOWN_100ms_fuelcell);
238 #endif
239 
240 #endif /* FOXBMS__LTC_H_ */
LTC_STATEMACH_e LTC_GetState(LTC_STATE_s *ltc_state)
gets the current state.
Definition: ltc_6806.c:566
bool LTC_IsFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state)
gets the measurement initialization status.
Definition: ltc_6806.c:1727
LTC_RETURN_TYPE_e LTC_SetStateRequest(LTC_STATE_s *ltc_state, LTC_REQUEST_s statereq)
sets the current state request of the state variable ltc_state.
Definition: ltc_6806.c:604
void LTC_SaveTemperatures(LTC_STATE_s *ltc_state, uint8_t stringNumber)
stores the measured temperatures and the measured multiplexer feedbacks in the database.
Definition: ltc_6806.c:457
void LTC_InitializeMonitoringPin(void)
Sets the transceiver pins to enable LTC6820 IC.
Definition: ltc_6806.c:1746
LTC_REQUEST_s LTC_GetStateRequest(LTC_STATE_s *ltc_state)
gets the current state request.
Definition: ltc_6806.c:546
void LTC_SaveVoltages(LTC_STATE_s *ltc_state, uint8_t stringNumber)
stores the measured voltages in the database.
Definition: ltc_6806.c:397
LTC_STATE_s ltc_stateBase
Definition: ltc_6806.c:137
void LTC_SaveAllGpioMeasurement(LTC_STATE_s *ltc_state)
stores the measured GPIOs in the database.
Definition: ltc_6806.c:505
void LTC_Trigger(LTC_STATE_s *ltc_state)
trigger function for the LTC driver state machine.
Definition: ltc_6806.c:619
static uint16_t ltc_cmdRDCVI_Fuelcell[4]
Definition: ltc_6806.c:200
static uint16_t ltc_cmdRDCVA_Fuelcell[4]
Definition: ltc_6806.c:192
static uint16_t ltc_cmdRDCVD_Fuelcell[4]
Definition: ltc_6806.c:195
static uint16_t ltc_cmdRDCVG_Fuelcell[4]
Definition: ltc_6806.c:198
static uint16_t ltc_cmdRDCVH_Fuelcell[4]
Definition: ltc_6806.c:199
static uint16_t ltc_cmdRDCVE_Fuelcell[4]
Definition: ltc_6806.c:196
static uint16_t ltc_cmdRDCFG[4]
Definition: ltc_6806.c:185
static uint16_t ltc_cmdRDCVF_Fuelcell[4]
Definition: ltc_6806.c:197
static uint16_t ltc_cmdRDCVB_Fuelcell[4]
Definition: ltc_6806.c:193
static uint16_t ltc_BC_cmdADOW_PDOWN_100ms_fuelcell[4]
Definition: ltc_6806.c:231
static uint16_t ltc_cmdWRCFG[4]
Definition: ltc_6806.c:184
static uint16_t ltc_BC_cmdADOW_PUP_100ms_fuelcell[4]
Definition: ltc_6806.c:229
static uint16_t ltc_cmdRDCVC_Fuelcell[4]
Definition: ltc_6806.c:194
static uint16_t ltc_cmdADCV_normal_Fuelcell[4]
Definition: ltc_6806.c:205
static uint16_t ltc_cmdADAX_fast_GPIO3[4]
Definition: ltc_6813-1.c:251
static uint16_t ltc_cmdRDCVC[4]
Definition: ltc_6813-1.c:195
static uint16_t ltc_cmdRDAUXB[4]
Definition: ltc_6813-1.c:203
static uint16_t ltc_cmdRDCVA[4]
Definition: ltc_6813-1.c:193
static uint16_t ltc_cmdWRCOMM[4]
Definition: ltc_6813-1.c:199
static uint16_t ltc_cmdADAX_normal_GPIO1[4]
Definition: ltc_6813-1.c:243
static uint16_t ltc_cmdRDAUXA[4]
Definition: ltc_6813-1.c:202
static uint16_t ltc_cmdRDCVB[4]
Definition: ltc_6813-1.c:194
static uint16_t ltc_cmdADCV_fast_DCP1[4]
Definition: ltc_6813-1.c:237
static uint16_t ltc_cmdWRCFG2[4]
Definition: ltc_6813-1.c:190
static uint16_t ltc_cmdRDAUXC[4]
Definition: ltc_6813-1.c:204
static uint16_t ltc_cmdADAX_fast_GPIO2[4]
Definition: ltc_6813-1.c:248
static uint16_t ltc_cmdADAX_normal_ALLGPIOS[4]
Definition: ltc_6813-1.c:258
static uint16_t ltc_cmdADAX_filtered_GPIO3[4]
Definition: ltc_6813-1.c:250
static uint16_t ltc_cmdADAX_filtered_GPIO2[4]
Definition: ltc_6813-1.c:247
static uint16_t ltc_cmdRDCVD[4]
Definition: ltc_6813-1.c:196
static uint16_t ltc_cmdADAX_fast_ALLGPIOS[4]
Definition: ltc_6813-1.c:261
static uint16_t ltc_cmdADAX_normal_GPIO2[4]
Definition: ltc_6813-1.c:246
static uint16_t ltc_BC_cmdADOW_PDOWN_filtered_DCP0[4]
Definition: ltc_6813-1.c:279
static uint16_t ltc_cmdADAX_filtered_ALLGPIOS[4]
Definition: ltc_6813-1.c:259
static uint16_t ltc_cmdADCV_fast_DCP0[4]
Definition: ltc_6813-1.c:235
static uint16_t ltc_cmdADCV_filtered_DCP0[4]
Definition: ltc_6813-1.c:231
static uint16_t ltc_cmdADAX_normal_GPIO3[4]
Definition: ltc_6813-1.c:249
static uint16_t ltc_cmdADCV_normal_DCP1[4]
Definition: ltc_6813-1.c:229
static uint16_t ltc_cmdRDCVE[4]
Definition: ltc_6813-1.c:197
static uint16_t ltc_cmdRDAUXD[4]
Definition: ltc_6813-1.c:205
static uint16_t ltc_cmdADCV_normal_DCP0[4]
Definition: ltc_6813-1.c:227
static uint16_t ltc_BC_cmdADOW_PDOWN_normal_DCP0[4]
Definition: ltc_6813-1.c:269
static uint16_t ltc_cmdADCV_fast_DCP0_twocells[4]
Definition: ltc_6813-1.c:239
static uint16_t ltc_cmdRDCVF[4]
Definition: ltc_6813-1.c:198
static uint16_t ltc_BC_cmdADOW_PUP_normal_DCP0[4]
Definition: ltc_6813-1.c:264
static uint16_t ltc_cmdRDCOMM[4]
Definition: ltc_6813-1.c:201
static uint16_t ltc_cmdSTCOMM[4]
Definition: ltc_6813-1.c:200
static uint16_t ltc_cmdADAX_filtered_GPIO1[4]
Definition: ltc_6813-1.c:244
static uint16_t ltc_BC_cmdADOW_PUP_filtered_DCP0[4]
Definition: ltc_6813-1.c:274
static uint16_t ltc_cmdADCV_filtered_DCP1[4]
Definition: ltc_6813-1.c:233
static uint16_t ltc_cmdADAX_fast_GPIO1[4]
Definition: ltc_6813-1.c:245
Headers for the driver for the LTC monitoring chip.
LTC_STATEMACH_e
Definition: ltc_defs.h:118
LTC_RETURN_TYPE_e
Definition: ltc_defs.h:397