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