foxBMS  1.2.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 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 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_STATEMACH_e LTC_GetState(LTC_STATE_s *ltc_state)
gets the current state.
Definition: ltc_6806.c:558
bool LTC_IsFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state)
gets the measurement initialization status.
Definition: ltc_6806.c:1719
void LTC_SaveAllGPIOMeasurement(LTC_STATE_s *ltc_state)
stores the measured GPIOs in the database.
Definition: ltc_6806.c:497
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:596
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:449
LTC_REQUEST_s LTC_GetStateRequest(LTC_STATE_s *ltc_state)
gets the current state request.
Definition: ltc_6806.c:538
void LTC_SaveVoltages(LTC_STATE_s *ltc_state, uint8_t stringNumber)
stores the measured voltages in the database.
Definition: ltc_6806.c:389
LTC_STATE_s ltc_stateBase
Definition: ltc_6806.c:134
void LTC_Trigger(LTC_STATE_s *ltc_state)
trigger function for the LTC driver state machine.
Definition: ltc_6806.c:611
void LTC_monitoringPinInit(void)
Sets the transceiver pins to enable LTC6820 IC.
Definition: ltc_6806.c:1738
static uint16_t ltc_cmdRDCVI_Fuelcell[4]
Definition: ltc_6806.c:197
static uint16_t ltc_cmdRDCVA_Fuelcell[4]
Definition: ltc_6806.c:189
static uint16_t ltc_cmdRDCVD_Fuelcell[4]
Definition: ltc_6806.c:192
static uint16_t ltc_cmdRDCVG_Fuelcell[4]
Definition: ltc_6806.c:195
static uint16_t ltc_cmdRDCVH_Fuelcell[4]
Definition: ltc_6806.c:196
static uint16_t ltc_cmdRDCVE_Fuelcell[4]
Definition: ltc_6806.c:193
static uint16_t ltc_cmdRDCFG[4]
Definition: ltc_6806.c:182
static uint16_t ltc_cmdRDCVF_Fuelcell[4]
Definition: ltc_6806.c:194
static uint16_t ltc_cmdRDCVB_Fuelcell[4]
Definition: ltc_6806.c:190
static uint16_t ltc_BC_cmdADOW_PDOWN_100ms_fuelcell[4]
Definition: ltc_6806.c:228
static uint16_t ltc_cmdWRCFG[4]
Definition: ltc_6806.c:181
static uint16_t ltc_BC_cmdADOW_PUP_100ms_fuelcell[4]
Definition: ltc_6806.c:226
static uint16_t ltc_cmdRDCVC_Fuelcell[4]
Definition: ltc_6806.c:191
static uint16_t ltc_cmdADCV_normal_Fuelcell[4]
Definition: ltc_6806.c:202
static uint16_t ltc_cmdADAX_fast_GPIO3[4]
Definition: ltc_6813-1.c:248
static uint16_t ltc_cmdRDCVC[4]
Definition: ltc_6813-1.c:192
static uint16_t ltc_cmdRDAUXB[4]
Definition: ltc_6813-1.c:200
static uint16_t ltc_cmdRDCVA[4]
Definition: ltc_6813-1.c:190
static uint16_t ltc_cmdWRCOMM[4]
Definition: ltc_6813-1.c:196
static uint16_t ltc_cmdADAX_normal_GPIO1[4]
Definition: ltc_6813-1.c:240
static uint16_t ltc_cmdRDAUXA[4]
Definition: ltc_6813-1.c:199
static uint16_t ltc_cmdRDCVB[4]
Definition: ltc_6813-1.c:191
static uint16_t ltc_cmdADCV_fast_DCP1[4]
Definition: ltc_6813-1.c:234
static uint16_t ltc_cmdWRCFG2[4]
Definition: ltc_6813-1.c:187
static uint16_t ltc_cmdRDAUXC[4]
Definition: ltc_6813-1.c:201
static uint16_t ltc_cmdADAX_fast_GPIO2[4]
Definition: ltc_6813-1.c:245
static uint16_t ltc_cmdADAX_normal_ALLGPIOS[4]
Definition: ltc_6813-1.c:255
static uint16_t ltc_cmdADAX_filtered_GPIO3[4]
Definition: ltc_6813-1.c:247
static uint16_t ltc_cmdADAX_filtered_GPIO2[4]
Definition: ltc_6813-1.c:244
static uint16_t ltc_cmdRDCVD[4]
Definition: ltc_6813-1.c:193
static uint16_t ltc_cmdADAX_fast_ALLGPIOS[4]
Definition: ltc_6813-1.c:258
static uint16_t ltc_cmdADAX_normal_GPIO2[4]
Definition: ltc_6813-1.c:243
static uint16_t ltc_BC_cmdADOW_PDOWN_filtered_DCP0[4]
Definition: ltc_6813-1.c:276
static uint16_t ltc_cmdADAX_filtered_ALLGPIOS[4]
Definition: ltc_6813-1.c:256
static uint16_t ltc_cmdADCV_fast_DCP0[4]
Definition: ltc_6813-1.c:232
static uint16_t ltc_cmdADCV_filtered_DCP0[4]
Definition: ltc_6813-1.c:228
static uint16_t ltc_cmdADAX_normal_GPIO3[4]
Definition: ltc_6813-1.c:246
static uint16_t ltc_cmdADCV_normal_DCP1[4]
Definition: ltc_6813-1.c:226
static uint16_t ltc_cmdRDCVE[4]
Definition: ltc_6813-1.c:194
static uint16_t ltc_cmdRDAUXD[4]
Definition: ltc_6813-1.c:202
static uint16_t ltc_cmdADCV_normal_DCP0[4]
Definition: ltc_6813-1.c:224
static uint16_t ltc_BC_cmdADOW_PDOWN_normal_DCP0[4]
Definition: ltc_6813-1.c:266
static uint16_t ltc_cmdADCV_fast_DCP0_twocells[4]
Definition: ltc_6813-1.c:236
static uint16_t ltc_cmdRDCVF[4]
Definition: ltc_6813-1.c:195
static uint16_t ltc_BC_cmdADOW_PUP_normal_DCP0[4]
Definition: ltc_6813-1.c:261
static uint16_t ltc_cmdRDCOMM[4]
Definition: ltc_6813-1.c:198
static uint16_t ltc_cmdSTCOMM[4]
Definition: ltc_6813-1.c:197
static uint16_t ltc_cmdADAX_filtered_GPIO1[4]
Definition: ltc_6813-1.c:241
static uint16_t ltc_BC_cmdADOW_PUP_filtered_DCP0[4]
Definition: ltc_6813-1.c:271
static uint16_t ltc_cmdADCV_filtered_DCP1[4]
Definition: ltc_6813-1.c:230
static uint16_t ltc_cmdADAX_fast_GPIO1[4]
Definition: ltc_6813-1.c:242
Headers for the driver for the LTC monitoring chip.
LTC_STATEMACH_e
Definition: ltc_defs.h:116
LTC_RETURN_TYPE_e
Definition: ltc_defs.h:395