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