foxBMS  1.4.1
The foxBMS Battery Management System API Documentation
ltc_6806.c
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_6806.c
44  * @author foxBMS Team
45  * @date 2019-09-01 (date of creation)
46  * @updated 2022-10-27 (date of last update)
47  * @version v1.4.1
48  * @ingroup DRIVERS
49  * @prefix LTC
50  *
51  * @brief Driver for the LTC monitoring chip.
52  *
53  */
54 
55 /*========== Includes =======================================================*/
56 /* clang-format off */
57 #include "ltc.h"
58 #include "ltc_6806_cfg.h"
59 /* clang-format on */
60 
61 #include "HL_spi.h"
62 #include "HL_system.h"
63 
64 #include "afe_plausibility.h"
65 #include "database.h"
66 #include "diag.h"
67 #include "io.h"
68 #include "ltc_pec.h"
69 #include "os.h"
70 #include "pex.h"
71 
72 /*========== Macros and Definitions =========================================*/
73 
74 /**
75  * TI port expander register addresses
76  * @{
77  */
78 #define LTC_PORT_EXPANDER_TI_INPUT_REG_ADR (0x00u)
79 #define LTC_PORT_EXPANDER_TI_OUTPUT_REG_ADR (0x01u)
80 #define LTC_PORT_EXPANDER_TI_CONFIG_REG_ADR (0x03u)
81 /**@}*/
82 
83 /**
84  * Value of the LSB in mV
85  */
86 #if LTC_HIRNG == 0u
87 #define LTC_FUEL_CELL_LSB_RESOLUTION_mV (1.5f)
88 #else
89 #define LTC_FUEL_CELL_LSB_RESOLUTION_mV (3.0f)
90 #endif
91 
92 /**
93  * Value for positive full scale measurement for fuel cell
94  */
95 #define LTC_FUELCELL_POSITIVE_FULLSCALE_RANGE_mV ((int16_t)((0x7FF * LTC_FUEL_CELL_LSB_RESOLUTION_mV)))
96 
97 /**
98  * Value for negative full scale measurement for fuel cell
99  */
100 #define LTC_FUELCELL_NEGATIVE_FULLSCALE_RANGE_mV \
101  ((int16_t)((((~0x001) + 1) & 0x7FF) * (-LTC_FUEL_CELL_LSB_RESOLUTION_mV)))
102 
103 /*========== Static Constant and Variable Definitions =======================*/
104 /**
105  * PEC buffer for RX and TX
106  * @{
107  */
108 /* AXIVION Disable Style MisraC2012-1.2: The Pec buffer must be put in the shared RAM section for performance reasons */
109 #pragma SET_DATA_SECTION(".sharedRAM")
112 #pragma SET_DATA_SECTION()
113 /* AXIVION Enable Style MisraC2012-1.2: only Pec buffer needed to be in the shared RAM setcion */
114 /**@}*/
115 
116 /** index of used cells */
117 static uint16_t ltc_used_cells_index[BS_NR_OF_STRINGS] = {0};
118 /** local copies of database tables */
119 /**@{*/
124 /**@}*/
125 /** stores information on the detected open wires locally */
127 static LTC_ERRORTABLE_s ltc_errorTable = {0}; /*!< init in LTC_ResetErrorTable-function */
128 
129 /** local definition of plausible cell voltage values for the LTC 6806 */
132  .minimumPlausibleVoltage_mV = -5000,
133 };
134 
135 /*========== Extern Constant and Variable Definitions =======================*/
136 
138  .timer = 0,
139  .statereq = {.request = LTC_STATE_NO_REQUEST, .string = 0xFFu},
141  .substate = 0,
142  .laststate = LTC_STATEMACH_UNINITIALIZED,
143  .lastsubstate = 0,
144  .adcModereq = LTC_ADCMODE_FAST_DCP0,
145  .adcMode = LTC_ADCMODE_FAST_DCP0,
146  .adcMeasChreq = LTC_ADCMEAS_UNDEFINED,
147  .adcMeasCh = LTC_ADCMEAS_UNDEFINED,
148  .numberOfMeasuredMux = 32,
149  .triggerentry = 0,
150  .ErrRetryCounter = 0,
151  .ErrRequestCounter = 0,
152  .VoltageSampleTime = 0,
153  .muxSampleTime = 0,
154  .commandDataTransferTime = 3,
155  .commandTransferTime = 3,
156  .gpioClocksTransferTime = 3,
157  .muxmeas_seqptr = NULL_PTR,
158  .muxmeas_seqendptr = NULL_PTR,
159  .muxmeas_nr_end = 0,
160  .first_measurement_made = false,
161  .ltc_muxcycle_finished = STD_NOT_OK,
162  .check_spi_flag = STD_NOT_OK,
163  .balance_control_done = STD_NOT_OK,
164  .transmit_ongoing = false,
165  .dummyByte_ongoing = STD_NOT_OK,
166  .ltcData.pSpiInterface = spi_ltcInterface,
167  .ltcData.txBuffer = ltc_TxPecBuffer,
168  .ltcData.rxBuffer = ltc_RxPecBuffer,
169  .ltcData.frameLength = LTC_N_BYTES_FOR_DATA_TRANSMISSION,
170  .ltcData.cellVoltage = &ltc_cellVoltage,
171  .ltcData.cellTemperature = &ltc_celltemperature,
172  .ltcData.balancingFeedback = NULL_PTR,
173  .ltcData.balancingControl = NULL_PTR,
174  .ltcData.slaveControl = NULL_PTR,
175  .ltcData.openWireDetection = &ltc_openWireDetection,
176  .ltcData.errorTable = &ltc_errorTable,
177  .ltcData.allGpioVoltages = &ltc_allgpiovoltage,
178  .ltcData.openWire = &ltc_openwire,
179  .ltcData.usedCellIndex = ltc_used_cells_index,
180  .currentString = 0u,
181  .requestedString = 0u,
182 };
183 
184 static uint16_t ltc_cmdWRCFG[4] = {0x00, 0x01, 0x3D, 0x6E};
185 static uint16_t ltc_cmdRDCFG[4] = {0x00, 0x02, 0x2B, 0x0A};
186 
187 /* static uint16_t ltc_cmdRDAUXA[4] = {0x00, 0x0C, 0xEF, 0xCC};
188 static uint16_t ltc_cmdRDAUXB[4] = {0x00, 0x0E, 0x72, 0x9A};
189 static uint16_t ltc_cmdRDAUXC[4] = {0x00, 0x0D, 0x64, 0xFE};
190 static uint16_t ltc_cmdRDAUXD[4] = {0x00, 0x0F, 0xF9, 0xA8}; */
191 
192 static uint16_t ltc_cmdRDCVA_Fuelcell[4] = {0x00, 0x04, 0x07, 0xC2};
193 static uint16_t ltc_cmdRDCVB_Fuelcell[4] = {0x00, 0x05, 0x8C, 0xF0};
194 static uint16_t ltc_cmdRDCVC_Fuelcell[4] = {0x00, 0x06, 0x9A, 0x94};
195 static uint16_t ltc_cmdRDCVD_Fuelcell[4] = {0x00, 0x07, 0x11, 0xA6};
196 static uint16_t ltc_cmdRDCVE_Fuelcell[4] = {0x00, 0x08, 0x5E, 0x52};
197 static uint16_t ltc_cmdRDCVF_Fuelcell[4] = {0x00, 0x09, 0xD5, 0x60};
198 static uint16_t ltc_cmdRDCVG_Fuelcell[4] = {0x00, 0x0A, 0xC3, 0x04};
199 static uint16_t ltc_cmdRDCVH_Fuelcell[4] = {0x00, 0x0B, 0x48, 0x36};
200 static uint16_t ltc_cmdRDCVI_Fuelcell[4] = {0x00, 0x0C, 0xEF, 0xCC};
201 
202 /* static uint16_t ltc_cmdMUTE[4] = {0x00, 0x28, 0xE8, 0x0E}; !< MUTE discharging via S pins */
203 /* static uint16_t ltc_cmdUNMUTE[4] = {0x00, 0x29, 0x63, 0x3C}; !< UN-MUTE discharging via S pins */
204 
205 static uint16_t ltc_cmdADCV_normal_Fuelcell[4] = {0x04, 0x40, 0xED, 0xB0}; /*!< All cells, normal mode */
206 
207 /* GPIOs */
208 /* static uint16_t ltc_cmdADAX_normal_GPIO1[4] = {0x05, 0x61, 0x58, 0x92}; !< Single channel, GPIO 1, normal mode */
209 /* static uint16_t ltc_cmdADAX_filtered_GPIO1[4] = {0x05, 0xE1, 0x1C, 0xB4}; !< Single channel, GPIO 1, filtered mode */
210 /* static uint16_t ltc_cmdADAX_fast_GPIO1[4] = {0x04, 0xE1, 0x94, 0xF8}; !< Single channel, GPIO 1, fast mode */
211 /* static uint16_t ltc_cmdADAX_normal_GPIO2[4] = {0x05, 0x62, 0x4E, 0xF6}; !< Single channel, GPIO 2, normal mode */
212 /* static uint16_t ltc_cmdADAX_filtered_GPIO2[4] = {0x05, 0xE2, 0x0A, 0xD0}; !< Single channel, GPIO 2, filtered mode */
213 /* static uint16_t ltc_cmdADAX_fast_GPIO2[4] = {0x04, 0xE2, 0x82, 0x9C}; !< Single channel, GPIO 2, fast mode */
214 /* static uint16_t ltc_cmdADAX_normal_GPIO3[4] = {0x05, 0x63, 0xC5, 0xC4}; !< Single channel, GPIO 3, normal mode */
215 /* static uint16_t ltc_cmdADAX_filtered_GPIO3[4] = {0x05, 0xE3, 0x81, 0xE2}; !< Single channel, GPIO 3, filtered mode */
216 /* static uint16_t ltc_cmdADAX_fast_GPIO3[4] = {0x04, 0xE3, 0x09, 0xAE}; !< Single channel, GPIO 3, fast mode */
217 /* static uint16_t ltc_cmdADAX_normal_GPIO4[4] = {0x05, 0x64, 0x62, 0x3E}; !< Single channel, GPIO 4, normal mode */
218 /* static uint16_t ltc_cmdADAX_filtered_GPIO4[4] = {0x05, 0xE4, 0x26, 0x18}; !< Single channel, GPIO 4, filtered mode */
219 /* static uint16_t ltc_cmdADAX_fast_GPIO4[4] = {0x04, 0xE4, 0xAE, 0x54}; !< Single channel, GPIO 4, fast mode */
220 /* static uint16_t ltc_cmdADAX_normal_GPIO5[4] = {0x05, 0x65, 0xE9, 0x0C}; !< Single channel, GPIO 5, normal mode */
221 /* static uint16_t ltc_cmdADAX_filtered_GPIO5[4] = {0x05, 0xE5, 0xAD, 0x2A}; !< Single channel, GPIO 5, filtered mode */
222 /* static uint16_t ltc_cmdADAX_fast_GPIO5[4] = {0x04, 0xE5, 0x25, 0x66}; !< Single channel, GPIO 5, fast mode */
223 /* static uint16_t ltc_cmdADAX_normal_ALLGPIOS[4] = {0x05, 0x60, 0xD3, 0xA0}; !< All channels, normal mode */
224 /* static uint16_t ltc_cmdADAX_filtered_ALLGPIOS[4] =
225  {0x05, 0xE0, 0x97, 0x86}; !< All channels, filtered mode */
226 /* static uint16_t ltc_cmdADAX_fast_ALLGPIOS[4] = {0x04, 0xE0, 0x1F, 0xCA}; !< All channels, fast mode */
227 
228 /* Open-wire */
230  {0x07, 0xC0, 0xBA, 0x70}; /*!< Broadcast, Pull-up current, All cells, normal mode, 100ms */
232  {0x06, 0xC0, 0x32, 0x3C}; /*!< Broadcast, Pull-down current, All cells, normal mode, 100ms */
233 
234 /*========== Static Function Prototypes =====================================*/
235 static void LTC_SetFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state);
236 static void LTC_InitializeDatabase(LTC_STATE_s *ltc_state);
237 static void LTC_SaveLastStates(LTC_STATE_s *ltc_state);
238 static void LTC_StateTransition(LTC_STATE_s *ltc_state, LTC_STATEMACH_e state, uint8_t substate, uint16_t timer_ms);
239 static void LTC_CondBasedStateTransition(
240  LTC_STATE_s *ltc_state,
241  STD_RETURN_TYPE_e retVal,
242  DIAG_ID_e diagCode,
243  LTC_STATEMACH_e state_ok,
244  uint8_t substate_ok,
245  uint16_t timer_ms_ok,
246  LTC_STATEMACH_e state_nok,
247  uint8_t substate_nok,
248  uint16_t timer_ms_nok);
249 
250 static void LTC_ResetErrorTable(LTC_STATE_s *ltc_state);
252  SPI_INTERFACE_CONFIG_s *pSpiInterface,
253  uint16_t *pTxBuff,
254  uint16_t *pRxBuff,
255  uint32_t frameLength);
256 
258  SPI_INTERFACE_CONFIG_s *pSpiInterface,
259  LTC_ADCMODE_e adcMode,
260  LTC_ADCMEAS_CHAN_e adcMeasCh);
262  SPI_INTERFACE_CONFIG_s *pSpiInterface,
263  LTC_ADCMODE_e adcMode,
264  uint8_t PUP);
265 
267  LTC_STATE_s *ltc_state,
268  uint16_t *pRxBuff,
269  uint8_t registerSet,
270  uint8_t stringNumber);
271 
273  LTC_STATE_s *ltc_state,
274  uint16_t *DataBufferSPI_RX_with_PEC,
275  uint8_t stringNumber);
277  uint16_t *Command,
278  SPI_INTERFACE_CONFIG_s *pSpiInterface,
279  uint16_t *pTxBuff,
280  uint16_t *pRxBuff,
281  uint32_t frameLength);
282 
283 static uint32_t LTC_GetSpiClock(SPI_INTERFACE_CONFIG_s *pSpiInterface);
284 static void LTC_SetTransferTimes(LTC_STATE_s *ltc_state);
285 
287 
288 /*========== Static Function Implementations ================================*/
289 /**
290  * @brief in the database, initializes the fields related to the LTC drivers.
291  *
292  * This function loops through all the LTC-related data fields in the database
293  * and sets them to 0. It should be called in the initialization or re-initialization
294  * routine of the LTC driver.
295  *
296  * @param ltc_state: state of the ltc state machine
297  *
298  */
299 static void LTC_InitializeDatabase(LTC_STATE_s *ltc_state) {
300  uint16_t i = 0;
301 
302  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
303  ltc_state->ltcData.cellVoltage->state = 0;
304  for (i = 0; i < BS_NR_OF_CELL_BLOCKS_PER_STRING; i++) {
305  ltc_state->ltcData.cellVoltage->cellVoltage_mV[s][i] = 0;
306  ltc_state->ltcData.openWireDetection->openWirePup[s][i] = 0;
307  ltc_state->ltcData.openWireDetection->openWirePdown[s][i] = 0;
308  ltc_state->ltcData.openWireDetection->openWireDelta[s][i] = 0;
309  }
310 
311  ltc_state->ltcData.cellTemperature->state = 0;
312  for (i = 0; i < BS_NR_OF_TEMP_SENSORS_PER_STRING; i++) {
313  ltc_state->ltcData.cellTemperature->cellTemperature_ddegC[s][i] = 0;
314  }
315 
316  ltc_state->ltcData.allGpioVoltages->state = 0;
317  for (i = 0; i < (BS_NR_OF_MODULES_PER_STRING * BS_NR_OF_GPIOS_PER_MODULE); i++) {
318  ltc_state->ltcData.allGpioVoltages->gpioVoltages_mV[s][i] = 0;
319  }
320 
321  for (i = 0; i < (BS_NR_OF_MODULES_PER_STRING * (BS_NR_OF_CELL_BLOCKS_PER_MODULE + 1)); i++) {
322  ltc_state->ltcData.openWire->openwire[s][i] = 0;
323  }
324  ltc_state->ltcData.openWire->state = 0;
325  }
326 
327  DATA_WRITE_DATA(ltc_state->ltcData.cellVoltage, ltc_state->ltcData.cellTemperature, ltc_state->ltcData.openWire);
328 }
329 
330 /**
331  * @brief Saves the last state and the last substate
332  *
333  * @param ltc_state: state of the ltc state machine
334  */
335 static void LTC_SaveLastStates(LTC_STATE_s *ltc_state) {
336  ltc_state->laststate = ltc_state->state;
337  ltc_state->lastsubstate = ltc_state->substate;
338 }
339 
340 /**
341  * @brief function for setting LTC_Trigger state transitions
342  *
343  * @param ltc_state: state of the ltc state machine
344  * @param state: state to transition into
345  * @param substate: substate to transition into
346  * @param timer_ms: transition into state, substate after timer elapsed
347  */
348 static void LTC_StateTransition(LTC_STATE_s *ltc_state, LTC_STATEMACH_e state, uint8_t substate, uint16_t timer_ms) {
349  ltc_state->state = state;
350  ltc_state->substate = substate;
351  ltc_state->timer = timer_ms;
352 }
353 
354 /**
355  * @brief condition-based state transition depending on retVal
356  *
357  * If retVal is #STD_OK, after timer_ms_ok is elapsed the LTC statemachine will
358  * transition into state_ok and substate_ok, otherwise after timer_ms_nok the
359  * statemachine will transition to state_nok and substate_nok. Depending on
360  * value of retVal the corresponding diagnosis entry will be called.
361  *
362  * @param ltc_state state of the ltc state machine
363  * @param retVal condition to determine if state machine will transition
364  * into ok or nok states
365  * @param diagCode symbolic IDs for diagnosis entry, called with
366  * #DIAG_EVENT_OK if retVal is #STD_OK, #DIAG_EVENT_NOT_OK
367  * otherwise
368  * @param state_ok state to transition into if retVal is #STD_OK
369  * @param substate_ok substate to transition into if retVal is #STD_OK
370  * @param timer_ms_ok transition into state_ok, substate_ok after timer_ms_ok
371  * elapsed
372  * @param state_nok state to transition into if retVal is #STD_NOT_OK
373  * @param substate_nok substate to transition into if retVal is #STD_NOT_OK
374  * @param timer_ms_nok transition into state_nok, substate_nok after
375  * timer_ms_nok elapsed
376  */
378  LTC_STATE_s *ltc_state,
379  STD_RETURN_TYPE_e retVal,
380  DIAG_ID_e diagCode,
381  LTC_STATEMACH_e state_ok,
382  uint8_t substate_ok,
383  uint16_t timer_ms_ok,
384  LTC_STATEMACH_e state_nok,
385  uint8_t substate_nok,
386  uint16_t timer_ms_nok) {
387  if ((retVal != STD_OK)) {
389  LTC_StateTransition(ltc_state, state_nok, substate_nok, timer_ms_nok);
390  } else {
391  DIAG_Handler(diagCode, DIAG_EVENT_OK, DIAG_STRING, ltc_state->currentString);
392  LTC_StateTransition(ltc_state, state_ok, substate_ok, timer_ms_ok);
393  }
394 }
395 
396 /*========== Extern Function Implementations ================================*/
397 extern void LTC_SaveVoltages(LTC_STATE_s *ltc_state, uint8_t stringNumber) {
398  /* Pointer validity check */
399  FAS_ASSERT(ltc_state != NULL_PTR);
400 
401  /* Iterate over all cell to:
402  *
403  * 1. Check open-wires and set respective cell measurements to invalid
404  * 2. Perform minimum/maximum measurement value plausibility check
405  * 3. Calculate string values
406  */
407  STD_RETURN_TYPE_e cellVoltageMeasurementValid = STD_OK;
408  int32_t stringVoltage_mV = 0;
409  uint16_t numberValidMeasurements = 0;
410  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
411  for (uint8_t c = 0u; c < BS_NR_OF_CELL_BLOCKS_PER_MODULE; c++) {
412  /* ------- 1. Check open-wires -----------------
413  * Is cell N input not open wire &&
414  * Is cell N+1 input not open wire &&
415  * Is cell voltage valid because of previous PEC error
416  * If so, everything okay, else set cell voltage measurement to invalid.
417  */
418  if ((ltc_state->ltcData.openWire
419  ->openwire[stringNumber][(m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE + 1u)) + c] == 0u) &&
420  (ltc_state->ltcData.openWire
421  ->openwire[stringNumber][(m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE + 1u)) + c + 1u] == 0u) &&
422  ((ltc_state->ltcData.cellVoltage->invalidCellVoltage[stringNumber][m] & (0x01u << c)) == 0u)) {
423  /* Cell voltage is valid -> perform minimum/maximum plausibility check */
424 
425  /* ------- 2. Perform minimum/maximum measurement range check ---------- */
427  ltc_state->ltcData.cellVoltage
428  ->cellVoltage_mV[stringNumber][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c],
430  /* Cell voltage is valid -> calculate string voltage */
431  /* -------- 3. Calculate string values ------------- */
432  stringVoltage_mV += ltc_state->ltcData.cellVoltage
433  ->cellVoltage_mV[stringNumber][(m * BS_NR_OF_CELL_BLOCKS_PER_MODULE) + c];
434  numberValidMeasurements++;
435  } else {
436  /* Invalidate cell voltage measurement */
437  ltc_state->ltcData.cellVoltage->invalidCellVoltage[stringNumber][m] |= (0x01u << c);
438  cellVoltageMeasurementValid = STD_NOT_OK;
439  }
440  } else {
441  /* Set cell voltage measurement value invalid, if not already invalid because of PEC Error */
442  ltc_state->ltcData.cellVoltage->invalidCellVoltage[stringNumber][m] |= (0x01u << c);
443  cellVoltageMeasurementValid = STD_NOT_OK;
444  }
445  }
446  }
447  DIAG_CheckEvent(cellVoltageMeasurementValid, DIAG_ID_AFE_CELL_VOLTAGE_MEAS_ERROR, DIAG_STRING, stringNumber);
448  ltc_state->ltcData.cellVoltage->packVoltage_mV[stringNumber] = stringVoltage_mV;
449  ltc_state->ltcData.cellVoltage->nrValidCellVoltages[stringNumber] = numberValidMeasurements;
450 
451  /* Increment state variable each time new values are written into database */
452  ltc_state->ltcData.cellVoltage->state++;
453 
454  DATA_WRITE_DATA(ltc_state->ltcData.cellVoltage);
455 }
456 
457 extern void LTC_SaveTemperatures(LTC_STATE_s *ltc_state, uint8_t stringNumber) {
458  STD_RETURN_TYPE_e cellTemperatureMeasurementValid = STD_OK;
459  uint16_t numberValidMeasurements = 0;
460  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
461  for (uint8_t c = 0u; c < BS_NR_OF_TEMP_SENSORS_PER_MODULE; c++) {
462  /* ------- 1. Check valid flag -----------------
463  * Is cell temperature valid because of previous PEC error
464  * If so, everything okay, else set cell temperature measurement to invalid.
465  */
466  if ((ltc_state->ltcData.cellTemperature->invalidCellTemperature[stringNumber][m] & (0x01u << c)) == 0u) {
467  /* Cell temperature is valid -> perform minimum/maximum plausibility check */
468 
469  /* ------- 2. Perform minimum/maximum measurement range check ---------- */
470  if (STD_OK ==
472  ltc_state->ltcData.cellTemperature
473  ->cellTemperature_ddegC[stringNumber][(m * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + c])) {
474  numberValidMeasurements++;
475  } else {
476  /* Invalidate cell temperature measurement */
477  ltc_state->ltcData.cellTemperature->invalidCellTemperature[stringNumber][m] |= (0x01u << c);
478  cellTemperatureMeasurementValid = STD_NOT_OK;
479  }
480  } else {
481  /* Already invalid because of PEC Error */
482  cellTemperatureMeasurementValid = STD_NOT_OK;
483  }
484  }
485  }
487  cellTemperatureMeasurementValid, DIAG_ID_AFE_CELL_TEMPERATURE_MEAS_ERROR, DIAG_STRING, stringNumber);
488 
489  ltc_state->ltcData.cellTemperature->nrValidTemperatures[stringNumber] = numberValidMeasurements;
490  ltc_state->ltcData.cellTemperature->state++;
492 }
493 
494 /**
495  * @brief stores the measured GPIOs in the database.
496  *
497  * This function loops through the data of all modules in the LTC daisy-chain that are
498  * stored in the ltc_allgpiovoltage buffer and writes them in the database.
499  * At each write iteration, the variable named "state" and related to voltages in the
500  * database is incremented.
501  *
502  * @param ltc_state: state of the ltc state machine
503  *
504  */
505 extern void LTC_SaveAllGpioMeasurement(LTC_STATE_s *ltc_state) {
506  ltc_state->ltcData.allGpioVoltages->state++;
508 }
509 
510 /**
511  * @brief re-entrance check of LTC state machine trigger function
512  *
513  * This function is not re-entrant and should only be called time- or event-triggered.
514  * It increments the triggerentry counter from the state variable ltc_state.
515  * It should never be called by two different processes, so if it is the case, triggerentry
516  * should never be higher than 0 when this function is called.
517  *
518  * @param ltc_state: state of the ltc state machine
519  *
520  * @return retval 0 if no further instance of the function is active, 0xff else
521  *
522  */
523 uint8_t LTC_CheckReEntrance(LTC_STATE_s *ltc_state) {
524  uint8_t retval = 0;
525 
527  if (!ltc_state->triggerentry) {
528  ltc_state->triggerentry++;
529  } else {
530  retval = 0xFF; /* multiple calls of function */
531  }
533 
534  return (retval);
535 }
536 
537 /**
538  * @brief gets the current state request.
539  *
540  * This function is used in the functioning of the LTC state machine.
541  *
542  * @param ltc_state: state of the ltc state machine
543  *
544  * @return retval current state request, taken from LTC_STATE_REQUEST_e
545  */
547  LTC_REQUEST_s retval = {.request = LTC_STATE_NO_REQUEST, .string = 0x0u};
548 
550  retval.request = ltc_state->statereq.request;
551  retval.string = ltc_state->statereq.string;
553 
554  return (retval);
555 }
556 
557 /**
558  * @brief gets the current state.
559  *
560  * This function is used in the functioning of the LTC state machine.
561  *
562  * @param ltc_state: state of the ltc state machine
563  *
564  * @return current state, taken from LTC_STATEMACH_e
565  */
567  return ltc_state->state;
568 }
569 
570 /**
571  * @brief transfers the current state request to the state machine.
572  *
573  * This function takes the current state request from ltc_state and transfers it to the state machine.
574  * It resets the value from ltc_state to LTC_STATE_NO_REQUEST
575  *
576  * @param ltc_state state of the ltc state machine
577  * @param pBusIDptr bus ID, main or backup (deprecated)
578  * @param pAdcModeptr LTC ADCmeasurement mode (fast, normal or filtered)
579  * @param pAdcMeasChptr number of channels measured for GPIOS (one at a time for multiplexers or all five GPIOs)
580  *
581  * @return retVal current state request, taken from LTC_STATE_REQUEST_e
582  *
583  */
585  LTC_STATE_s *ltc_state,
586  uint8_t *pBusIDptr,
587  LTC_ADCMODE_e *pAdcModeptr,
588  LTC_ADCMEAS_CHAN_e *pAdcMeasChptr) {
589  LTC_REQUEST_s retval = {.request = LTC_STATE_NO_REQUEST, .string = 0x0u};
590 
592  retval.request = ltc_state->statereq.request;
593  retval.string = ltc_state->statereq.string;
594  ltc_state->requestedString = ltc_state->statereq.string;
595  *pAdcModeptr = ltc_state->adcModereq;
596  *pAdcMeasChptr = ltc_state->adcMeasChreq;
598  ltc_state->statereq.string = 0x0u;
600 
601  return (retval);
602 }
603 
605  LTC_RETURN_TYPE_e retVal = LTC_ERROR;
606 
608  retVal = LTC_CheckStateRequest(ltc_state, statereq);
609 
610  if ((retVal == LTC_OK) || (retVal == LTC_BUSY_OK) || (retVal == LTC_OK_FROM_ERROR)) {
611  ltc_state->statereq.request = statereq.request;
612  ltc_state->statereq.string = statereq.string;
613  }
615 
616  return (retVal);
617 }
618 
619 void LTC_Trigger(LTC_STATE_s *ltc_state) {
620  STD_RETURN_TYPE_e retVal = STD_OK;
621  LTC_REQUEST_s statereq = {.request = LTC_STATE_NO_REQUEST, .string = 0x0u};
622  uint8_t tmpbusID = 0;
625  STD_RETURN_TYPE_e continueFunction = STD_OK;
626 
627  FAS_ASSERT(ltc_state != NULL_PTR);
628 
629  /* Check re-entrance of function */
630  if (LTC_CheckReEntrance(ltc_state) > 0u) {
631  continueFunction = STD_NOT_OK;
632  }
633 
634  if (ltc_state->check_spi_flag == STD_NOT_OK) {
635  if (ltc_state->timer > 0u) {
636  if ((--ltc_state->timer) > 0u) {
637  ltc_state->triggerentry--;
638  continueFunction = STD_NOT_OK; /* handle state machine only if timer has elapsed */
639  }
640  }
641  } else {
642  if (AFE_IsTransmitOngoing(ltc_state) == true) {
643  if (ltc_state->timer > 0u) {
644  if ((--ltc_state->timer) > 0u) {
645  ltc_state->triggerentry--;
646  continueFunction = STD_NOT_OK; /* handle state machine only if timer has elapsed */
647  }
648  }
649  }
650  }
651 
652  if (continueFunction == STD_OK) {
653  switch (ltc_state->state) {
654  /****************************UNINITIALIZED***********************************/
656  /* waiting for Initialization Request */
657  statereq = LTC_TransferStateRequest(ltc_state, &tmpbusID, &tmpadcMode, &tmpadcMeasCh);
658  if (statereq.request == LTC_STATE_INIT_REQUEST) {
659  LTC_SaveLastStates(ltc_state);
660  LTC_InitializeDatabase(ltc_state);
661  LTC_ResetErrorTable(ltc_state);
664  ltc_state->adcMode = tmpadcMode;
665  ltc_state->adcMeasCh = tmpadcMeasCh;
666  } else if (statereq.request == LTC_STATE_NO_REQUEST) {
667  /* no actual request pending */
668  } else {
669  ltc_state->ErrRequestCounter++; /* illegal request pending */
670  }
671  break;
672 
673  /****************************INITIALIZATION**********************************/
675 
676  LTC_SetTransferTimes(ltc_state);
677  if (ltc_state->substate == LTC_INIT_STRING) {
678  LTC_SaveLastStates(ltc_state);
679  ltc_state->spiSeqPtr = ltc_state->ltcData.pSpiInterface;
681  ltc_state->spiSeqEndPtr = ltc_state->ltcData.pSpiInterface + BS_NR_OF_STRINGS;
684  } else if (ltc_state->substate == LTC_ENTRY_INITIALIZATION) {
685  LTC_SaveLastStates(ltc_state);
686  retVal =
687  LTC_TRANSMIT_WAKE_UP(ltc_state->spiSeqPtr); /* Send dummy byte to wake up the daisy chain */
689  ltc_state,
690  retVal,
698  } else if (ltc_state->substate == LTC_RE_ENTRY_INITIALIZATION) {
699  LTC_SaveLastStates(ltc_state);
700  retVal = LTC_TRANSMIT_WAKE_UP(
701  ltc_state->spiSeqPtr); /* Send dummy byte again to wake up the daisy chain */
703  ltc_state,
704  retVal,
712  } else if (ltc_state->substate == LTC_START_INIT_INITIALIZATION) {
713  LTC_SaveLastStates(ltc_state);
714  ltc_state->check_spi_flag = STD_OK;
715  AFE_SetTransmitOngoing(ltc_state);
716  retVal = LTC_Init(
717  ltc_state->spiSeqPtr,
718  ltc_state->ltcData.txBuffer,
719  ltc_state->ltcData.rxBuffer,
720  ltc_state->ltcData.frameLength); /* Initialize main LTC loop */
721  ltc_state->lastsubstate = ltc_state->substate;
724  ltc_state,
728  } else if (ltc_state->substate == LTC_CHECK_INITIALIZATION) {
729  /* Read values written in config register, currently unused */
730  LTC_SaveLastStates(ltc_state);
731  AFE_SetTransmitOngoing(ltc_state);
732  retVal = LTC_ReadRegister(
733  ltc_cmdRDCFG,
734  ltc_state->spiSeqPtr,
735  ltc_state->ltcData.txBuffer,
736  ltc_state->ltcData.rxBuffer,
737  ltc_state->ltcData.frameLength); /* Read config register */
739  ltc_state,
743  } else if (ltc_state->substate == LTC_EXIT_INITIALIZATION) {
744  LTC_SaveLastStates(ltc_state);
745  ++ltc_state->spiSeqPtr;
746  ++ltc_state->currentString;
747  if (ltc_state->spiSeqPtr >= ltc_state->spiSeqEndPtr) {
750  } else {
753  }
754  }
755  break;
756 
757  /****************************INITIALIZED*************************************/
759  LTC_SaveLastStates(ltc_state);
761  break;
762 
763  /****************************START MEASUREMENT*******************************/
765 
768 
769  ltc_state->spiSeqPtr = ltc_state->ltcData.pSpiInterface;
771  ltc_state->spiSeqEndPtr = ltc_state->ltcData.pSpiInterface + BS_NR_OF_STRINGS;
772  ltc_state->currentString = 0u;
773 
774  ltc_state->check_spi_flag = STD_NOT_OK;
775  retVal = LTC_StartVoltageMeasurement(ltc_state->spiSeqPtr, ltc_state->adcMode, ltc_state->adcMeasCh);
776 
778  ltc_state,
779  retVal,
787 
788  break;
789 
790  /****************************START MEASUREMENT CONTINUE*******************************/
791  /* Do not reset SPI interface pointer */
793 
796 
797  ltc_state->check_spi_flag = STD_NOT_OK;
798  retVal = LTC_StartVoltageMeasurement(ltc_state->spiSeqPtr, ltc_state->adcMode, ltc_state->adcMeasCh);
799 
801  ltc_state,
802  retVal,
810 
811  break;
812 
813  /****************************READ VOLTAGE************************************/
815 
817  ltc_state->check_spi_flag = STD_OK;
818  AFE_SetTransmitOngoing(ltc_state);
819  retVal = LTC_ReadRegister(
821  ltc_state->spiSeqPtr,
822  ltc_state->ltcData.txBuffer,
823  ltc_state->ltcData.rxBuffer,
824  ltc_state->ltcData.frameLength);
826  ltc_state,
827  retVal,
835  break;
836  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_B_RDCVB_READVOLTAGE) {
837  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
840  ltc_state, ltc_state->ltcData.rxBuffer, 0u, ltc_state->currentString);
841 
842  AFE_SetTransmitOngoing(ltc_state);
843  retVal = LTC_ReadRegister(
845  ltc_state->spiSeqPtr,
846  ltc_state->ltcData.txBuffer,
847  ltc_state->ltcData.rxBuffer,
848  ltc_state->ltcData.frameLength);
850  ltc_state,
851  retVal,
859  break;
860  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_C_RDCVC_READVOLTAGE) {
861  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
864  ltc_state, ltc_state->ltcData.rxBuffer, 1u, ltc_state->currentString);
865 
866  AFE_SetTransmitOngoing(ltc_state);
867  retVal = LTC_ReadRegister(
869  ltc_state->spiSeqPtr,
870  ltc_state->ltcData.txBuffer,
871  ltc_state->ltcData.rxBuffer,
872  ltc_state->ltcData.frameLength);
874  ltc_state,
875  retVal,
883  break;
884  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_D_RDCVD_READVOLTAGE) {
885  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
888  ltc_state, ltc_state->ltcData.rxBuffer, 2u, ltc_state->currentString);
889 
890  AFE_SetTransmitOngoing(ltc_state);
891  retVal = LTC_ReadRegister(
893  ltc_state->spiSeqPtr,
894  ltc_state->ltcData.txBuffer,
895  ltc_state->ltcData.rxBuffer,
896  ltc_state->ltcData.frameLength);
898  ltc_state,
899  retVal,
907  break;
908  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_E_RDCVE_READVOLTAGE) {
909  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
912  ltc_state, ltc_state->ltcData.rxBuffer, 3u, ltc_state->currentString);
913 
914  AFE_SetTransmitOngoing(ltc_state);
915  retVal = LTC_ReadRegister(
917  ltc_state->spiSeqPtr,
918  ltc_state->ltcData.txBuffer,
919  ltc_state->ltcData.rxBuffer,
920  ltc_state->ltcData.frameLength);
922  ltc_state,
923  retVal,
931  break;
932  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_F_RDCVF_READVOLTAGE) {
933  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
936  ltc_state, ltc_state->ltcData.rxBuffer, 4u, ltc_state->currentString);
937 
938  AFE_SetTransmitOngoing(ltc_state);
939  retVal = LTC_ReadRegister(
941  ltc_state->spiSeqPtr,
942  ltc_state->ltcData.txBuffer,
943  ltc_state->ltcData.rxBuffer,
944  ltc_state->ltcData.frameLength);
946  ltc_state,
947  retVal,
955  break;
956  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_G_RDCVG_READVOLTAGE) {
957  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
960  ltc_state, ltc_state->ltcData.rxBuffer, 5u, ltc_state->currentString);
961 
962  AFE_SetTransmitOngoing(ltc_state);
963  retVal = LTC_ReadRegister(
965  ltc_state->spiSeqPtr,
966  ltc_state->ltcData.txBuffer,
967  ltc_state->ltcData.rxBuffer,
968  ltc_state->ltcData.frameLength);
970  ltc_state,
971  retVal,
979  break;
980  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_H_RDCVH_READVOLTAGE) {
981  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
984  ltc_state, ltc_state->ltcData.rxBuffer, 6u, ltc_state->currentString);
985 
986  AFE_SetTransmitOngoing(ltc_state);
987  retVal = LTC_ReadRegister(
989  ltc_state->spiSeqPtr,
990  ltc_state->ltcData.txBuffer,
991  ltc_state->ltcData.rxBuffer,
992  ltc_state->ltcData.frameLength);
994  ltc_state,
995  retVal,
1003  break;
1004  } else if (ltc_state->substate == LTC_READ_VOLTAGE_REGISTER_I_RDCVI_READVOLTAGE) {
1005  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
1008  ltc_state, ltc_state->ltcData.rxBuffer, 7u, ltc_state->currentString);
1009 
1010  AFE_SetTransmitOngoing(ltc_state);
1011  retVal = LTC_ReadRegister(
1013  ltc_state->spiSeqPtr,
1014  ltc_state->ltcData.txBuffer,
1015  ltc_state->ltcData.rxBuffer,
1016  ltc_state->ltcData.frameLength);
1018  ltc_state,
1019  retVal,
1027  break;
1028  } else if (ltc_state->substate == LTC_EXIT_READVOLTAGE) {
1029  retVal = LTC_CheckPec(ltc_state, ltc_state->ltcData.rxBuffer, ltc_state->currentString);
1032  ltc_state, ltc_state->ltcData.rxBuffer, 8u, ltc_state->currentString);
1033 
1034  /* Switch to different state if read voltage state is reused
1035  * e.g. open-wire check... */
1036  if (ltc_state->reusageMeasurementMode == LTC_NOT_REUSED) {
1037  LTC_SaveVoltages(ltc_state, ltc_state->currentString);
1038 
1039  ++ltc_state->spiSeqPtr;
1040  ++ltc_state->currentString;
1041  if (ltc_state->spiSeqPtr >= ltc_state->spiSeqEndPtr) {
1042  if (LTC_IsFirstMeasurementCycleFinished(ltc_state) == false) {
1044  }
1045  statereq = LTC_TransferStateRequest(ltc_state, &tmpbusID, &tmpadcMode, &tmpadcMeasCh);
1046  if (statereq.request == LTC_STATE_OPENWIRE_CHECK_REQUEST) {
1047  if (statereq.string < BS_NR_OF_STRINGS) {
1048  ltc_state->spiSeqPtr = ltc_state->ltcData.pSpiInterface + statereq.string;
1049  ltc_state->requestedString = statereq.string;
1050  /* This is necessary because the state machine will go through read voltage measurement registers */
1051  ltc_state->currentString = statereq.string;
1054  ltc_state,
1058  }
1059  } else {
1062  ltc_state->check_spi_flag = STD_NOT_OK;
1063  }
1064  } else {
1067  ltc_state->check_spi_flag = STD_NOT_OK;
1068  }
1069  } else if (ltc_state->reusageMeasurementMode == LTC_REUSE_READVOLT_FOR_ADOW_PUP) {
1071  ltc_state,
1075  } else if (ltc_state->reusageMeasurementMode == LTC_REUSE_READVOLT_FOR_ADOW_PDOWN) {
1077  ltc_state,
1081  }
1082  }
1083  break;
1084 
1085  /**************************OPEN-WIRE CHECK*******************************/
1088  /* Run ADOW command with PUP = 1 */
1089  ltc_state->adcMode = LTC_OW_MEASUREMENT_MODE;
1090  ltc_state->check_spi_flag = STD_NOT_OK;
1091 
1092  retVal = LTC_StartOpenWireMeasurement(ltc_state->spiSeqPtr, ltc_state->adcMode, 1);
1093  if (retVal == STD_OK) {
1095 
1097  ltc_state,
1101 
1102  ltc_state->resendCommandCounter--;
1103 
1104  /* Check how many retries are left */
1105  if (ltc_state->resendCommandCounter == 0) {
1106  /* Switch to read voltage state to read cell voltages */
1107 
1109  ltc_state,
1113 
1114  /* Reuse read voltage register */
1116  }
1117  } else {
1121  }
1122  } else if (ltc_state->substate == LTC_READ_VOLTAGES_PULLUP_OPENWIRE_CHECK) {
1123  /* Previous state: Read voltage -> information stored in voltage buffer */
1125 
1126  /* Copy data from voltage struct into open-wire struct */
1127  for (uint16_t i = 0u; i < BS_NR_OF_CELL_BLOCKS_PER_STRING; i++) {
1128  ltc_state->ltcData.openWireDetection->openWirePup[ltc_state->requestedString][i] =
1129  ltc_state->ltcData.cellVoltage->cellVoltage_mV[ltc_state->requestedString][i];
1130  }
1131 
1132  /* Set number of ADOW retries - send ADOW command with pull-down two times */
1135  ltc_state,
1139  } else if (ltc_state->substate == LTC_REQUEST_PULLDOWN_CURRENT_OPENWIRE_CHECK) {
1140  /* Run ADOW command with PUP = 0 */
1141  ltc_state->adcMode = LTC_OW_MEASUREMENT_MODE;
1142  ltc_state->check_spi_flag = STD_NOT_OK;
1143 
1144  retVal = LTC_StartOpenWireMeasurement(ltc_state->spiSeqPtr, ltc_state->adcMode, 0);
1145  if (retVal == STD_OK) {
1147 
1149  ltc_state,
1153 
1154  ltc_state->resendCommandCounter--;
1155 
1156  /* Check how many retries are left */
1157  if (ltc_state->resendCommandCounter == 0) {
1158  /* Switch to read voltage state to read cell voltages */
1159 
1161  ltc_state,
1165 
1166  /* Reuse read voltage register */
1168  }
1169  } else {
1173  }
1174  } else if (ltc_state->substate == LTC_READ_VOLTAGES_PULLDOWN_OPENWIRE_CHECK) {
1175  /* Previous state: Read voltage -> information stored in voltage buffer */
1177 
1178  /* Copy data from voltage struct into open-wire struct */
1179  for (uint16_t i = 0u; i < BS_NR_OF_CELL_BLOCKS_PER_STRING; i++) {
1180  ltc_state->ltcData.openWireDetection->openWirePdown[ltc_state->requestedString][i] =
1181  ltc_state->ltcData.cellVoltage->cellVoltage_mV[ltc_state->requestedString][i];
1182  }
1183 
1186  } else if (ltc_state->substate == LTC_PERFORM_OPENWIRE_CHECK) {
1187  /* Perform actual open-wire check */
1188 
1189  /* Take difference between pull-up and pull-down measurement */
1190  for (uint16_t i = 1u; i < BS_NR_OF_CELL_BLOCKS_PER_STRING; i++) {
1191  ltc_state->ltcData.openWireDetection->openWireDelta[ltc_state->requestedString][i] = (int32_t)(
1192  ltc_state->ltcData.openWireDetection->openWirePup[ltc_state->requestedString][i] -
1193  ltc_state->ltcData.openWireDetection->openWirePdown[ltc_state->requestedString][i]);
1194  }
1195 
1196  /* PDOWN or PUP positive or negative full scale value: C(N) or C(N-1) open*/
1197  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
1198  /* PUP */
1199  for (uint8_t p = 0u; p < BS_NR_OF_CELL_BLOCKS_PER_MODULE; p++) {
1200  if ((ltc_state->ltcData.openWireDetection
1201  ->openWirePup[ltc_state->requestedString]
1202  [p + (m * BS_NR_OF_CELL_BLOCKS_PER_MODULE)] ==
1204  (ltc_state->ltcData.openWireDetection
1205  ->openWirePup[ltc_state->requestedString]
1206  [p + (m * BS_NR_OF_CELL_BLOCKS_PER_MODULE)] ==
1208  ltc_state->ltcData.openWire->openwire[ltc_state->requestedString]
1209  [p + (m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE))] = 1;
1210  ltc_state->ltcData.openWire
1211  ->openwire[ltc_state->requestedString]
1212  [(p + 1u) + (m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE))] = 1;
1213  }
1214  if ((ltc_state->ltcData.openWireDetection
1215  ->openWirePdown[ltc_state->requestedString]
1216  [p + (m * BS_NR_OF_CELL_BLOCKS_PER_MODULE)] ==
1218  (ltc_state->ltcData.openWireDetection
1219  ->openWirePdown[ltc_state->requestedString]
1220  [p + (m * BS_NR_OF_CELL_BLOCKS_PER_MODULE)] ==
1222  ltc_state->ltcData.openWire->openwire[ltc_state->requestedString]
1223  [p + (m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE))] = 1;
1224  ltc_state->ltcData.openWire
1225  ->openwire[ltc_state->requestedString]
1226  [(p + 1u) + (m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE))] = 1;
1227  }
1228  }
1229  }
1230 
1231  /* data sheet page 28: "for all values of n from 1 to 36: If CELL Delta(n+1) < -200mV then C(n) is open" */
1232  for (uint8_t m = 0u; m < BS_NR_OF_MODULES_PER_STRING; m++) {
1233  /* ltc_state->ltcData.openWireDelta parsed from 1 to (BS_NR_OF_CELL_BLOCKS_PER_MODULE-1) */
1234  for (uint8_t c = 1u; c < BS_NR_OF_CELL_BLOCKS_PER_MODULE; c++) {
1235  /* If delta cell(n+1) < -200mV: open-wire at C(n) */
1236  if (ltc_state->ltcData.openWireDetection
1237  ->openWireDelta[ltc_state->requestedString]
1239  ltc_state->ltcData.openWire->openwire[ltc_state->requestedString]
1240  [c + (m * BS_NR_OF_CELL_BLOCKS_PER_MODULE)] = 1;
1241  }
1242  }
1243  }
1244 
1245  ltc_state->ltcData.openWire->nrOpenWires[ltc_state->requestedString] = 0;
1246  for (uint16_t c = 0u; c < (BS_NR_OF_MODULES_PER_STRING * (BS_NR_OF_CELL_BLOCKS_PER_MODULE + 1));
1247  c++) {
1248  if (ltc_state->ltcData.openWire->openwire[ltc_state->requestedString][c] == 1) {
1249  ltc_state->ltcData.openWire->nrOpenWires[ltc_state->requestedString]++;
1250  }
1251  }
1252 
1253  /* Write database entry */
1254  DATA_WRITE_DATA(ltc_state->ltcData.openWire);
1255  /* Start new measurement cycle */
1257  }
1258  break;
1259 
1260  /****************************DEFAULT**************************/
1261  default:
1262  /* invalid state */
1264  break;
1265  }
1266 
1267  ltc_state->triggerentry--; /* reentrance counter */
1268  } /* continueFunction */
1269 }
1270 
1271 /**
1272  * @brief saves the voltage values read from the LTC daisy-chain.
1273  *
1274  * After a voltage measurement was initiated to measure the voltages of the cells,
1275  * the result is read via SPI from the daisy-chain.
1276  * There are 6 register to read _(A,B,C,D,E,F,G,H,I) to get all cell voltages.
1277  * Only one register can be read at a time.
1278  * This function is called to store the result from the transmission in a buffer.
1279  *
1280  * @param ltc_state state of the ltc state machine
1281  * @param pRxBuff receive buffer
1282  * @param registerSet voltage register that was read (voltage register A,B,C,D,E,F,G,H or I)
1283  * @param stringNumber string addressed
1284  *
1285  */
1287  LTC_STATE_s *ltc_state,
1288  uint16_t *pRxBuff,
1289  uint8_t registerSet,
1290  uint8_t stringNumber) {
1291  uint16_t cellOffset = 0;
1292  uint16_t val_ui = 0;
1293  int16_t voltage = 0;
1294  uint64_t bitmask = 0;
1295  uint16_t buffer_LSB = 0;
1296  uint16_t buffer_MSB = 0;
1297 
1298  cellOffset = registerSet * 4u;
1299 
1300  /* Calculate bitmask for valid flags */
1301  bitmask |= 0x0Full << cellOffset; /* 0x0F: four voltages in each register */
1302 
1303  /* reinitialize index counter at begin of cycle */
1304  if (cellOffset == 0u) {
1305  (ltc_state->ltcData.usedCellIndex[stringNumber]) = 0u;
1306  }
1307 
1308  /* Retrieve data without command and CRC*/
1309  for (uint8_t m = 0u; m < LTC_N_LTC; m++) {
1310  uint8_t incrementations = 0u;
1311 
1312  /* parse all four voltages (4 * 12bits) contained in one register */
1313  for (uint8_t c = 0u; c < 4u; c++) {
1314  switch (c) {
1315  case 0u:
1316  buffer_MSB = pRxBuff[4u + (m * 8u)];
1317  buffer_LSB = (pRxBuff[4u + 1u + (m * 8u)]) >> 4u;
1318  val_ui = (uint16_t)(buffer_LSB | (buffer_MSB << 4u));
1319  break;
1320  case 1u:
1321  buffer_MSB = pRxBuff[4u + 1u + (m * 8u)] & 0x0Fu;
1322  buffer_LSB = (pRxBuff[4u + 2u + (m * 8u)]);
1323  val_ui = (uint16_t)(buffer_LSB | (buffer_MSB << 8u));
1324  break;
1325  case 2u:
1326  buffer_MSB = pRxBuff[4u + 3u + (m * 8u)];
1327  buffer_LSB = (pRxBuff[4u + 4u + (m * 8u)]) >> 4u;
1328  val_ui = (uint16_t)(buffer_LSB | (buffer_MSB << 4u));
1329  break;
1330  case 3u:
1331  buffer_MSB = pRxBuff[4u + 4u + (m * 8u)] & 0x0Fu;
1332  buffer_LSB = (pRxBuff[4u + 5u + (m * 8u)]);
1333  val_ui = (uint16_t)(buffer_LSB | (buffer_MSB << 8u));
1334  break;
1335  default:
1336  break;
1337  }
1338 
1339  /* Check signed bit if measured value is negative or not */
1340  if ((val_ui & (1u << (12u - 1u))) == 0u) {
1341  voltage = (int16_t)(((val_ui & 0x7FFu)) * LTC_FUEL_CELL_LSB_RESOLUTION_mV); /* Unit mV */
1342  } else {
1343  voltage = (int16_t)(((((~val_ui) + 1) & 0x7FF)) * (-LTC_FUEL_CELL_LSB_RESOLUTION_mV)); /* Unit mV */
1344  }
1345 
1346  if (ltc_state->ltcData.errorTable->PEC_valid[stringNumber][m] == true) {
1347  ltc_state->ltcData.cellVoltage->cellVoltage_mV[stringNumber]
1348  [(ltc_state->ltcData.usedCellIndex[stringNumber]) +
1349  (m * BS_NR_OF_CELL_BLOCKS_PER_MODULE)] = voltage;
1350  bitmask = ~bitmask; /* negate bitmask to only validate flags of this voltage register */
1351  ltc_state->ltcData.cellVoltage->invalidCellVoltage[stringNumber][(m / LTC_NUMBER_OF_LTC_PER_MODULE)] &=
1352  bitmask;
1353  } else {
1354  /* PEC_valid == false: Invalidate only flags of this voltage register */
1355  ltc_state->ltcData.cellVoltage->invalidCellVoltage[stringNumber][(m / LTC_NUMBER_OF_LTC_PER_MODULE)] |=
1356  bitmask;
1357  }
1358 
1359  (ltc_state->ltcData.usedCellIndex[stringNumber])++;
1360  incrementations++;
1361 
1362  if ((ltc_state->ltcData.usedCellIndex[stringNumber]) > BS_NR_OF_CELL_BLOCKS_PER_MODULE) {
1363  break;
1364  }
1365  }
1366 
1367  /* Restore start value for next module in the daisy-chain. Only
1368  * decrement used cell index if current module is not the last
1369  * module in the daisy-chain. */
1370  if ((m + 1u) < LTC_N_LTC) {
1371  (ltc_state->ltcData.usedCellIndex[stringNumber]) -= incrementations;
1372  }
1373  }
1374 }
1375 
1376 /**
1377  * @brief initialize the daisy-chain.
1378  *
1379  * To initialize the LTC6804 daisy-chain, a dummy byte (0x00) is sent.
1380  *
1381  * @param pSpiInterface pointer to SPI configuration
1382  * @param pTxBuff transmit buffer
1383  * @param pRxBuff receive buffer
1384  * @param frameLength number of words to transmit
1385  *
1386  * @return retVal #STD_OK if dummy byte was sent correctly by SPI, #STD_NOT_OK otherwise
1387  *
1388  */
1390  SPI_INTERFACE_CONFIG_s *pSpiInterface,
1391  uint16_t *pTxBuff,
1392  uint16_t *pRxBuff,
1393  uint32_t frameLength) {
1394  STD_RETURN_TYPE_e retVal = STD_NOT_OK;
1395 
1396  uint8_t PEC_Check[6];
1397  uint16_t PEC_result = 0;
1398 
1399  /* now construct the message to be sent: it contains the wanted data, PLUS the needed PECs */
1400  pTxBuff[0] = ltc_cmdWRCFG[0];
1401  pTxBuff[1] = ltc_cmdWRCFG[1];
1402  pTxBuff[2] = ltc_cmdWRCFG[2];
1403  pTxBuff[3] = ltc_cmdWRCFG[3];
1404 
1405  /* set REFON bit to 1 */
1406  /* data for the configuration */
1407  for (uint16_t i = 0u; i < LTC_N_LTC; i++) {
1408  /* 3F = disable all pull-downs, 40: REFON = 1 */
1409  pTxBuff[4u + (i * 8u)] = 0x3F;
1410  pTxBuff[5u + (i * 8u)] = (LTC_HIRNG << 7u) | 0x40u;
1411  pTxBuff[6u + (i * 8u)] = 0x00;
1412  pTxBuff[7u + (i * 8u)] = 0x00;
1413  pTxBuff[8u + (i * 8u)] = 0x00;
1414  pTxBuff[9u + (i * 8u)] = 0x00;
1415 
1416  PEC_Check[0] = pTxBuff[4u + (i * 8u)];
1417  PEC_Check[1] = pTxBuff[5u + (i * 8u)];
1418  PEC_Check[2] = pTxBuff[6u + (i * 8u)];
1419  PEC_Check[3] = pTxBuff[7u + (i * 8u)];
1420  PEC_Check[4] = pTxBuff[8u + (i * 8u)];
1421  PEC_Check[5] = pTxBuff[9u + (i * 8u)];
1422 
1423  PEC_result = LTC_pec15_calc(6, PEC_Check);
1424  pTxBuff[10u + (i * 8u)] = (PEC_result >> 8u) & 0xFFu;
1425  pTxBuff[11u + (i * 8u)] = PEC_result & 0xFFu;
1426  } /* end for */
1427 
1428  retVal = LTC_TRANSMIT_RECEIVE_DATA(pSpiInterface, pTxBuff, pRxBuff, frameLength);
1429 
1430  return retVal;
1431 }
1432 
1433 /**
1434  * @brief resets the error table.
1435  *
1436  * This function should be called during initialization or before starting a new measurement cycle
1437  *
1438  * @param ltc_state: state of the ltc state machine
1439  *
1440  */
1441 static void LTC_ResetErrorTable(LTC_STATE_s *ltc_state) {
1442  uint16_t i = 0;
1443 
1444  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
1445  for (i = 0; i < LTC_N_LTC; i++) {
1446  ltc_state->ltcData.errorTable->PEC_valid[s][i] = false;
1447  ltc_state->ltcData.errorTable->mux0[s][i] = 0;
1448  ltc_state->ltcData.errorTable->mux1[s][i] = 0;
1449  ltc_state->ltcData.errorTable->mux2[s][i] = 0;
1450  ltc_state->ltcData.errorTable->mux3[s][i] = 0;
1451  }
1452  }
1453 }
1454 
1455 /**
1456  * @brief tells the LTC daisy-chain to start measuring the voltage on all cells.
1457  *
1458  * This function sends an instruction to the daisy-chain via SPI, in order to start voltage measurement for all cells.
1459  *
1460  * @param pSpiInterface pointer to SPI configuration
1461  * @param adcMode LTC ADCmeasurement mode (fast, normal or filtered)
1462  * @param adcMeasCh number of cell voltage measured (2 cells or all cells)
1463  *
1464  * @return retVal #STD_OK if dummy byte was sent correctly by SPI, #STD_NOT_OK otherwise
1465  *
1466  */
1468  SPI_INTERFACE_CONFIG_s *pSpiInterface,
1469  LTC_ADCMODE_e adcMode,
1470  LTC_ADCMEAS_CHAN_e adcMeasCh) {
1471  STD_RETURN_TYPE_e retVal = STD_OK;
1472 
1473  retVal = LTC_TRANSMIT_COMMAND(pSpiInterface, ltc_cmdADCV_normal_Fuelcell);
1474 
1475  return retVal;
1476 }
1477 
1478 /**
1479  * @brief tells LTC daisy-chain to start measuring the voltage on GPIOS.
1480  *
1481  * This function sends an instruction to the daisy-chain via SPI to start the measurement.
1482  *
1483  * @param pSpiInterface pointer to SPI configuration
1484  * @param adcMode LTC ADCmeasurement mode (fast, normal or filtered)
1485  * @param PUP pull-up bit for pull-up or pull-down current (0: pull-down, 1: pull-up)
1486  *
1487  * @return retVal #STD_OK if command was sent correctly by SPI, #STD_NOT_OK otherwise
1488  *
1489  */
1491  SPI_INTERFACE_CONFIG_s *pSpiInterface,
1492  LTC_ADCMODE_e adcMode,
1493  uint8_t PUP) {
1494  STD_RETURN_TYPE_e retval = STD_NOT_OK;
1495 
1496  if (PUP == 0u) {
1497  /* pull-down current */
1499  } else if (PUP == 1u) {
1500  /* pull-up current */
1502  }
1503 
1504  return retval;
1505 }
1506 
1507 /**
1508  * @brief checks if the data received from the daisy-chain is not corrupt.
1509  *
1510  * This function computes the PEC (CRC) from the data received by the daisy-chain.
1511  * It compares it with the PEC sent by the LTCs.
1512  * If there are errors, the array the error table is updated to locate the LTCs in daisy-chain
1513  * that transmitted corrupt data.
1514  *
1515  * @param ltc_state state of the ltc state machine
1516  * @param DataBufferSPI_RX_with_PEC data obtained from the SPI transmission
1517  * @param stringNumber string addressed
1518  *
1519  * @return retVal STD_OK if PEC check is OK, STD_NOT_OK otherwise
1520  *
1521  */
1523  LTC_STATE_s *ltc_state,
1524  uint16_t *DataBufferSPI_RX_with_PEC,
1525  uint8_t stringNumber) {
1526  uint16_t i = 0;
1527  STD_RETURN_TYPE_e retVal = STD_OK;
1528  uint8_t PEC_TX[2];
1529  uint16_t PEC_result = 0;
1530  uint8_t PEC_Check[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1531 
1532  /* check all PECs and put data without command and PEC in DataBufferSPI_RX (easier to use) */
1533  for (i = 0; i < LTC_N_LTC; i++) {
1534  PEC_Check[0] = DataBufferSPI_RX_with_PEC[4u + (i * 8u)];
1535  PEC_Check[1] = DataBufferSPI_RX_with_PEC[5u + (i * 8u)];
1536  PEC_Check[2] = DataBufferSPI_RX_with_PEC[6u + (i * 8u)];
1537  PEC_Check[3] = DataBufferSPI_RX_with_PEC[7u + (i * 8u)];
1538  PEC_Check[4] = DataBufferSPI_RX_with_PEC[8u + (i * 8u)];
1539  PEC_Check[5] = DataBufferSPI_RX_with_PEC[9u + (i * 8u)];
1540 
1541  PEC_result = LTC_pec15_calc(6, PEC_Check);
1542  PEC_TX[0] = (uint8_t)((PEC_result >> 8u) & 0xFFu);
1543  PEC_TX[1] = (uint8_t)(PEC_result & 0xFFu);
1544 
1545  /* if calculated PEC not equal to received PEC */
1546  if ((PEC_TX[0] != DataBufferSPI_RX_with_PEC[10u + (i * 8u)]) ||
1547  (PEC_TX[1] != DataBufferSPI_RX_with_PEC[11u + (i * 8u)])) {
1548  /* update error table of the corresponding LTC only if PEC check is activated */
1549  if (LTC_DISCARD_PEC == false) {
1550  ltc_state->ltcData.errorTable->PEC_valid[stringNumber][i] = false;
1551  retVal = STD_NOT_OK;
1552  } else {
1553  ltc_state->ltcData.errorTable->PEC_valid[stringNumber][i] = true;
1554  }
1555  } else {
1556  /* update error table of the corresponding LTC */
1557  ltc_state->ltcData.errorTable->PEC_valid[stringNumber][i] = true;
1558  }
1559  }
1560  return retVal;
1561 }
1562 
1563 /**
1564  * @brief send command to the LTC daisy-chain and receives data from the LTC
1565  * daisy-chain.
1566  * @details This is the core function to receive data from the LTC6806
1567  * daisy-chain.
1568  * A 2 byte command is sent with the corresponding PEC.
1569  * *Example*: read configuration register (RDCFG).
1570  * Only command has to be set, the function calculates the PEC
1571  * automatically.
1572  * - The data sent is:
1573  * - 2 bytes (COMMAND) 2 bytes (PEC)
1574  * - The data received is:
1575  * - 6 bytes (LTC1) 2 bytes (PEC) +
1576  * - 6 bytes (LTC2) 2 bytes (PEC) +
1577  * - 6 bytes (LTC3) 2 bytes (PEC) +
1578  * - ... +
1579  * - 6 bytes (LTC{LTC_N_LTC}) 2 bytes (PEC)
1580  *
1581  * The function does not check the PECs. This has to be done
1582  * elsewhere.
1583  *
1584  * @param Command command sent to the daisy-chain
1585  * @param pSpiInterface pointer to SPI configuration
1586  * @param pTxBuff transmit buffer
1587  * @param pRxBuff receive buffer
1588  * @param frameLength number of words to transmit
1589  *
1590  * @return #STD_OK if SPI transmission is OK, #STD_NOT_OK otherwise
1591  */
1593  uint16_t *Command,
1594  SPI_INTERFACE_CONFIG_s *pSpiInterface,
1595  uint16_t *pTxBuff,
1596  uint16_t *pRxBuff,
1597  uint32_t frameLength) {
1598  STD_RETURN_TYPE_e statusSPI = STD_OK;
1599  uint16_t i = 0;
1600 
1601  /* DataBufferSPI_RX_with_PEC contains the data to receive.
1602  The transmission function checks the PECs.
1603  It constructs DataBufferSPI_RX, which contains the received data without PEC (easier to use). */
1604 
1605  for (i = 0; i < LTC_N_BYTES_FOR_DATA_TRANSMISSION; i++) {
1606  pTxBuff[i] = 0x00;
1607  }
1608 
1609  pTxBuff[0] = Command[0];
1610  pTxBuff[1] = Command[1];
1611  pTxBuff[2] = Command[2];
1612  pTxBuff[3] = Command[3];
1613 
1614  statusSPI = LTC_TRANSMIT_RECEIVE_DATA(pSpiInterface, pTxBuff, pRxBuff, frameLength);
1615 
1616  return statusSPI;
1617 }
1618 
1619 /**
1620  * @brief gets the frequency of the SPI clock.
1621  *
1622  * This function reads the configuration from the SPI handle directly.
1623  *
1624  * @param pSpiInterface pointer to SPI configuration
1625  *
1626  * @return frequency of the SPI clock
1627  */
1628 static uint32_t LTC_GetSpiClock(SPI_INTERFACE_CONFIG_s *pSpiInterface) {
1629  uint32_t SPI_Clock = 0;
1630  uint32_t prescaler = 0;
1631 
1632  /* if (LTC_SPI_INSTANCE == SPI2 || LTC_SPI_INSTANCE == SPI3) { */
1633  /* SPI2 and SPI3 are connected to APB1 (PCLK1) */
1634  /* The prescaler setup bits LTC_SPI_PRESCALER corresponds to the bits 5:3 in the SPI_CR1 register */
1635  /* Reference manual p.909 */
1636  /* The shift by 3 puts the bits 5:3 to the first position */
1637  /* Division are made by powers of 2 which corresponds to shifting to the right */
1638  /* Then 0 corresponds to divide by 2, 1 corresponds to divide by 4... so 1 has to be added to the value of the configuration bits */
1639 
1640  /* SPI_Clock = HAL_RCC_GetPCLK1Freq()>>((LTC_SPI_PRESCALER>>3)+1);
1641  } */
1642 
1643  /* if (LTC_SPI_INSTANCE == SPI1 || LTC_SPI_INSTANCE == SPI4 || LTC_SPI_INSTANCE == SPI5 || LTC_SPI_INSTANCE == SPI6) { */
1644  /* SPI1, SPI4, SPI5 and SPI6 are connected to APB2 (PCLK2) */
1645  /* The prescaler setup bits LTC_SPI_PRESCALER corresponds to the bits 5:3 in the SPI_CR1 register */
1646  /* Reference manual p.909 */
1647  /* The shift by 3 puts the bits 5:3 to the first position */
1648  /* Division are made by powers of 2 which corresponds to shifting to the right */
1649  /* Then 0 corresponds to divide by 2, 1 corresponds to divide by 4... so 1 has to be added to the value of the configuration bits */
1650 
1651  /* SPI_Clock = HAL_RCC_GetPCLK2Freq()>>((LTC_SPI_PRESCALER>>3)+1);
1652  } */
1653 
1654  /* Get SPI prescaler */
1655  prescaler = ((pSpiInterface->pNode->FMT0) >> 8u) & 0xFFu;
1656  SPI_Clock = (uint32_t)(AVCLK1_FREQ * 1000000u) / (prescaler + 1u);
1657 
1658  return SPI_Clock;
1659 }
1660 
1661 /**
1662  * @brief sets the transfer time needed to receive/send data with the LTC daisy-chain.
1663  *
1664  * This function gets the clock frequency and uses the number of LTCs in the daisy-chain.
1665  *
1666  * @param ltc_state: state of the ltc state machine
1667  *
1668  */
1669 static void LTC_SetTransferTimes(LTC_STATE_s *ltc_state) {
1670  uint32_t transferTime_us = 0;
1671  uint32_t SPI_Clock = 0;
1672 
1673  SPI_Clock = LTC_GetSpiClock(ltc_state->ltcData.pSpiInterface);
1674 
1675  /* Transmission of a command and data */
1676  /* Multiplication by 1000*1000 to get us */
1677  transferTime_us = (8u * 1000u * 1000u) / (SPI_Clock);
1678  transferTime_us *= LTC_N_BYTES_FOR_DATA_TRANSMISSION;
1679  transferTime_us = transferTime_us + LTC_SPI_WAKEUP_WAIT_TIME_US;
1680  ltc_state->commandDataTransferTime = (transferTime_us / 1000u) + 1u;
1681 
1682  /* Transmission of a command */
1683  /* Multiplication by 1000*1000 to get us */
1684  transferTime_us = ((4u) * 8u * 1000u * 1000u) / (SPI_Clock);
1685  transferTime_us = transferTime_us + LTC_SPI_WAKEUP_WAIT_TIME_US;
1686  ltc_state->commandTransferTime = (transferTime_us / 1000u) + 1u;
1687 
1688  /* Transmission of a command + 9 clocks */
1689  /* Multiplication by 1000*1000 to get us */
1690  transferTime_us = ((4u + 9u) * 8u * 1000u * 1000u) / (SPI_Clock);
1691  transferTime_us = transferTime_us + LTC_SPI_WAKEUP_WAIT_TIME_US;
1692  ltc_state->gpioClocksTransferTime = (transferTime_us / 1000u) + 1u;
1693 }
1694 
1695 /**
1696  * @brief checks the state requests that are made.
1697  *
1698  * This function checks the validity of the state requests.
1699  * The results of the checked is returned immediately.
1700  *
1701  * @param ltc_state: state of the ltc state machine
1702  * @param statereq state request to be checked
1703  *
1704  * @return result of the state request that was made, taken from #LTC_RETURN_TYPE_e
1705  */
1707  LTC_RETURN_TYPE_e retVal = LTC_OK;
1708  if (statereq.string >= BS_NR_OF_STRINGS) {
1709  retVal = LTC_ILLEGAL_REQUEST;
1710  } else if (ltc_state->statereq.request == LTC_STATE_NO_REQUEST) {
1711  /* init only allowed from the uninitialized state */
1712  if (statereq.request == LTC_STATE_INIT_REQUEST) {
1713  if (ltc_state->state == LTC_STATEMACH_UNINITIALIZED) {
1714  retVal = LTC_OK;
1715  } else {
1716  retVal = LTC_ALREADY_INITIALIZED;
1717  }
1718  } else {
1719  retVal = LTC_OK;
1720  }
1721  } else {
1722  retVal = LTC_REQUEST_PENDING;
1723  }
1724  return retVal;
1725 }
1726 
1728  bool retval = false;
1729 
1731  retval = ltc_state->first_measurement_made;
1733 
1734  return retval;
1735 }
1736 
1737 /**
1738  * @brief sets the measurement initialization status.
1739  */
1742  ltc_state->first_measurement_made = true;
1744 }
1745 
1746 extern void LTC_InitializeMonitoringPin(void) {
1747  /* Set 3rd PE pins to enable daisy chains */
1764 }
1765 
1766 /*========== Externalized Static Function Implementations (Unit Test) =======*/
1767 #ifdef UNITY_UNIT_TEST
1768 uint8_t TEST_LTC_CheckReEntrance(LTC_STATE_s *ltc_state) {
1769  return LTC_CheckReEntrance(ltc_state);
1770 }
1771 
1772 extern void TEST_LTC_SetFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state) {
1774 }
1775 
1776 /** this define is used for creating the declaration of a function for variable extraction */
1777 #define TEST_LTC_DEFINE_GET(VARIABLE) \
1778  extern void TEST_LTC_Get_##VARIABLE(uint8_t data[4]) { \
1779  for (uint8_t i = 0u; i < 4u; i++) { \
1780  data[i] = (uint8_t)(VARIABLE)[i]; \
1781  } \
1782  }
1783 
1784 TEST_LTC_DEFINE_GET(ltc_cmdWRCFG);
1785 TEST_LTC_DEFINE_GET(ltc_cmdRDCFG);
1786 TEST_LTC_DEFINE_GET(ltc_cmdRDCVA_Fuelcell);
1787 TEST_LTC_DEFINE_GET(ltc_cmdRDCVB_Fuelcell);
1788 TEST_LTC_DEFINE_GET(ltc_cmdRDCVC_Fuelcell);
1789 TEST_LTC_DEFINE_GET(ltc_cmdRDCVD_Fuelcell);
1790 TEST_LTC_DEFINE_GET(ltc_cmdRDCVE_Fuelcell);
1791 TEST_LTC_DEFINE_GET(ltc_cmdRDCVF_Fuelcell);
1792 TEST_LTC_DEFINE_GET(ltc_cmdRDCVG_Fuelcell);
1793 TEST_LTC_DEFINE_GET(ltc_cmdRDCVH_Fuelcell);
1794 TEST_LTC_DEFINE_GET(ltc_cmdRDCVI_Fuelcell);
1795 TEST_LTC_DEFINE_GET(ltc_cmdADCV_normal_Fuelcell);
1796 TEST_LTC_DEFINE_GET(ltc_BC_cmdADOW_PUP_100ms_fuelcell);
1797 TEST_LTC_DEFINE_GET(ltc_BC_cmdADOW_PDOWN_100ms_fuelcell);
1798 #endif
STD_RETURN_TYPE_e AFE_PlausibilityCheckTempMinMax(const int16_t celltemperature_ddegC)
Cell temperature plausibility check.
STD_RETURN_TYPE_e AFE_PlausibilityCheckVoltageMeasurementRange(const int16_t cellVoltage_mV, const AFE_PLAUSIBILITY_VALUES_s plausibleValues)
Cell voltage measurement range plausibility check.
plausibility checks for cell voltage and cell temperatures
#define BS_NR_OF_CELL_BLOCKS_PER_MODULE
number of cells per module
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
#define BS_NR_OF_GPIOS_PER_MODULE
Number of GPIOs on the LTC IC.
#define BS_NR_OF_CELL_BLOCKS_PER_STRING
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
#define BS_NR_OF_TEMP_SENSORS_PER_STRING
Database module header.
#define DATA_WRITE_DATA(...)
Definition: database.h:93
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
Definition: database_cfg.h:98
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
Definition: database_cfg.h:84
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
Definition: database_cfg.h:97
@ DATA_BLOCK_ID_ALL_GPIO_VOLTAGES_BASE
Definition: database_cfg.h:85
STD_RETURN_TYPE_e DIAG_CheckEvent(STD_RETURN_TYPE_e cond, DIAG_ID_e diagId, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_CheckEvent provides a simple interface to check an event for STD_OK.
Definition: diag.c:371
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:243
Diagnosis driver header.
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:258
@ DIAG_EVENT_OK
Definition: diag_cfg.h:257
@ DIAG_STRING
Definition: diag_cfg.h:271
DIAG_ID_e
Definition: diag_cfg.h:174
@ DIAG_ID_AFE_CELL_VOLTAGE_MEAS_ERROR
Definition: diag_cfg.h:188
@ DIAG_ID_AFE_CELL_TEMPERATURE_MEAS_ERROR
Definition: diag_cfg.h:189
@ DIAG_ID_AFE_COM_INTEGRITY
Definition: diag_cfg.h:179
@ DIAG_ID_AFE_SPI
Definition: diag_cfg.h:178
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:252
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:126
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
@ STD_NOT_OK
Definition: fstd_types.h:83
@ STD_OK
Definition: fstd_types.h:82
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:76
Header for the driver for the IO module.
Headers for the driver for the LTC monitoring chip.
static uint16_t ltc_cmdRDCVI_Fuelcell[4]
Definition: ltc_6806.c:200
uint16_t ltc_TxPecBuffer[LTC_N_BYTES_FOR_DATA_TRANSMISSION]
Definition: ltc_6806.c:111
static STD_RETURN_TYPE_e LTC_StartVoltageMeasurement(SPI_INTERFACE_CONFIG_s *pSpiInterface, LTC_ADCMODE_e adcMode, LTC_ADCMEAS_CHAN_e adcMeasCh)
tells the LTC daisy-chain to start measuring the voltage on all cells.
Definition: ltc_6806.c:1467
static DATA_BLOCK_ALL_GPIO_VOLTAGES_s ltc_allgpiovoltage
Definition: ltc_6806.c:122
static STD_RETURN_TYPE_e LTC_StartOpenWireMeasurement(SPI_INTERFACE_CONFIG_s *pSpiInterface, LTC_ADCMODE_e adcMode, uint8_t PUP)
tells LTC daisy-chain to start measuring the voltage on GPIOS.
Definition: ltc_6806.c:1490
static uint16_t ltc_cmdRDCVA_Fuelcell[4]
Definition: ltc_6806.c:192
LTC_STATEMACH_e LTC_GetState(LTC_STATE_s *ltc_state)
gets the current state.
Definition: ltc_6806.c:566
static STD_RETURN_TYPE_e LTC_ReadRegister(uint16_t *Command, SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength)
send command to the LTC daisy-chain and receives data from the LTC daisy-chain.
Definition: ltc_6806.c:1592
bool LTC_IsFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state)
gets the measurement initialization status.
Definition: ltc_6806.c:1727
static const AFE_PLAUSIBILITY_VALUES_s ltc_plausibleCellVoltages6806
Definition: ltc_6806.c:130
static void LTC_StateTransition(LTC_STATE_s *ltc_state, LTC_STATEMACH_e state, uint8_t substate, uint16_t timer_ms)
function for setting LTC_Trigger state transitions
Definition: ltc_6806.c:348
static void LTC_SetFirstMeasurementCycleFinished(LTC_STATE_s *ltc_state)
sets the measurement initialization status.
Definition: ltc_6806.c:1740
static LTC_RETURN_TYPE_e LTC_CheckStateRequest(LTC_STATE_s *ltc_state, LTC_REQUEST_s statereq)
checks the state requests that are made.
Definition: ltc_6806.c:1706
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
static uint16_t ltc_cmdRDCVD_Fuelcell[4]
Definition: ltc_6806.c:195
static void LTC_SetTransferTimes(LTC_STATE_s *ltc_state)
sets the transfer time needed to receive/send data with the LTC daisy-chain.
Definition: ltc_6806.c:1669
static uint32_t LTC_GetSpiClock(SPI_INTERFACE_CONFIG_s *pSpiInterface)
gets the frequency of the SPI clock.
Definition: ltc_6806.c:1628
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 STD_RETURN_TYPE_e LTC_CheckPec(LTC_STATE_s *ltc_state, uint16_t *DataBufferSPI_RX_with_PEC, uint8_t stringNumber)
checks if the data received from the daisy-chain is not corrupt.
Definition: ltc_6806.c:1522
static uint16_t ltc_cmdRDCVE_Fuelcell[4]
Definition: ltc_6806.c:196
static uint16_t ltc_cmdRDCFG[4]
Definition: ltc_6806.c:185
static void LTC_SaveLastStates(LTC_STATE_s *ltc_state)
Saves the last state and the last substate.
Definition: ltc_6806.c:335
LTC_REQUEST_s LTC_TransferStateRequest(LTC_STATE_s *ltc_state, uint8_t *pBusIDptr, LTC_ADCMODE_e *pAdcModeptr, LTC_ADCMEAS_CHAN_e *pAdcMeasChptr)
transfers the current state request to the state machine.
Definition: ltc_6806.c:584
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
static uint16_t ltc_used_cells_index[BS_NR_OF_STRINGS]
Definition: ltc_6806.c:117
#define LTC_FUEL_CELL_LSB_RESOLUTION_mV
Definition: ltc_6806.c:87
void LTC_InitializeMonitoringPin(void)
Sets the transceiver pins to enable LTC6820 IC.
Definition: ltc_6806.c:1746
static DATA_BLOCK_CELL_VOLTAGE_s ltc_cellVoltage
Definition: ltc_6806.c:120
static void LTC_SaveRXtoVoltagebuffer_Fuelcell(LTC_STATE_s *ltc_state, uint16_t *pRxBuff, uint8_t registerSet, uint8_t stringNumber)
saves the voltage values read from the LTC daisy-chain.
Definition: ltc_6806.c:1286
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
#define LTC_FUELCELL_NEGATIVE_FULLSCALE_RANGE_mV
Definition: ltc_6806.c:100
static STD_RETURN_TYPE_e LTC_Init(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength)
initialize the daisy-chain.
Definition: ltc_6806.c:1389
static void LTC_ResetErrorTable(LTC_STATE_s *ltc_state)
resets the error table.
Definition: ltc_6806.c:1441
LTC_STATE_s ltc_stateBase
Definition: ltc_6806.c:137
static uint16_t ltc_cmdRDCVF_Fuelcell[4]
Definition: ltc_6806.c:197
static uint16_t ltc_cmdRDCVB_Fuelcell[4]
Definition: ltc_6806.c:193
void LTC_SaveAllGpioMeasurement(LTC_STATE_s *ltc_state)
stores the measured GPIOs in the database.
Definition: ltc_6806.c:505
static LTC_ERRORTABLE_s ltc_errorTable
Definition: ltc_6806.c:127
void LTC_Trigger(LTC_STATE_s *ltc_state)
trigger function for the LTC driver state machine.
Definition: ltc_6806.c:619
uint8_t LTC_CheckReEntrance(LTC_STATE_s *ltc_state)
re-entrance check of LTC state machine trigger function
Definition: ltc_6806.c:523
#define LTC_FUELCELL_POSITIVE_FULLSCALE_RANGE_mV
Definition: ltc_6806.c:95
static DATA_BLOCK_OPEN_WIRE_s ltc_openwire
Definition: ltc_6806.c:123
static void LTC_InitializeDatabase(LTC_STATE_s *ltc_state)
in the database, initializes the fields related to the LTC drivers.
Definition: ltc_6806.c:299
uint16_t ltc_RxPecBuffer[LTC_N_BYTES_FOR_DATA_TRANSMISSION]
Definition: ltc_6806.c:110
static LTC_OPENWIRE_DETECTION_s ltc_openWireDetection
Definition: ltc_6806.c:126
static void LTC_CondBasedStateTransition(LTC_STATE_s *ltc_state, STD_RETURN_TYPE_e retVal, DIAG_ID_e diagCode, LTC_STATEMACH_e state_ok, uint8_t substate_ok, uint16_t timer_ms_ok, LTC_STATEMACH_e state_nok, uint8_t substate_nok, uint16_t timer_ms_nok)
condition-based state transition depending on retVal
Definition: ltc_6806.c:377
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 DATA_BLOCK_CELL_TEMPERATURE_s ltc_celltemperature
Definition: ltc_6806.c:121
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
Header for the configuration for the LTC 6806 monitoring IC.
#define LTC_STATEMACH_DAISY_CHAIN_FIRST_INITIALIZATION_TIME
Definition: ltc_6806_cfg.h:177
#define LTC_TRANSMISSION_TIMEOUT
Definition: ltc_6806_cfg.h:146
#define LTC_FUELCELL_NORMAL_ALL_CELLS_MS
Definition: ltc_6806_cfg.h:168
#define LTC_TRANSMIT_COMMAND(spi_ltcInterface, command)
Definition: ltc_6806_cfg.h:272
#define LTC_STATEMACH_SHORTTIME
Definition: ltc_6806_cfg.h:171
#define LTC_DISCARD_PEC
Definition: ltc_6806_cfg.h:89
#define LTC_NUMBER_OF_LTC_PER_MODULE
Definition: ltc_6806_cfg.h:104
#define LTC_HIRNG
Definition: ltc_6806_cfg.h:111
#define LTC_VOLTAGE_MEASUREMENT_MODE
Definition: ltc_6806_cfg.h:125
#define LTC_ADOW_THRESHOLD
Definition: ltc_6806_cfg.h:117
#define LTC_FUEL_CELL_ADOW_TIME_MS
Definition: ltc_6806_cfg.h:114
#define LTC_SPI_WAKEUP_WAIT_TIME_US
Definition: ltc_6806_cfg.h:165
#define LTC_TRANSMIT_WAKE_UP(spi_ltcInterface)
Definition: ltc_6806_cfg.h:268
#define LTC_NMBR_REQ_ADOW_COMMANDS
Definition: ltc_6806_cfg.h:262
#define LTC_OW_MEASUREMENT_MODE
Definition: ltc_6806_cfg.h:140
#define LTC_TRANSMIT_RECEIVE_DATA(spi_ltcInterface, txbuf, rxbuf, length)
Definition: ltc_6806_cfg.h:275
#define LTC_STATEMACH_DAISY_CHAIN_SECOND_INITIALIZATION_TIME
Definition: ltc_6806_cfg.h:182
bool AFE_IsTransmitOngoing(LTC_STATE_s *pLtcState)
gets the SPI transmit status.
Definition: ltc_afe_dma.c:74
void AFE_SetTransmitOngoing(LTC_STATE_s *pLtcState)
sets the SPI transmit status.
Definition: ltc_afe_dma.c:79
#define LTC_N_BYTES_FOR_DATA_TRANSMISSION
Definition: ltc_cfg.h:78
#define LTC_N_LTC
Definition: ltc_cfg.h:67
@ LTC_RE_ENTRY_INITIALIZATION
Definition: ltc_defs.h:177
@ LTC_ENTRY_INITIALIZATION
Definition: ltc_defs.h:175
@ LTC_START_INIT_INITIALIZATION
Definition: ltc_defs.h:176
@ LTC_EXIT_INITIALIZATION
Definition: ltc_defs.h:180
@ LTC_CHECK_INITIALIZATION
Definition: ltc_defs.h:179
@ LTC_INIT_STRING
Definition: ltc_defs.h:174
@ LTC_STATE_INIT_REQUEST
Definition: ltc_defs.h:365
@ LTC_STATE_OPENWIRE_CHECK_REQUEST
Definition: ltc_defs.h:387
@ LTC_STATE_NO_REQUEST
Definition: ltc_defs.h:391
LTC_STATEMACH_e
Definition: ltc_defs.h:118
@ LTC_STATEMACH_INITIALIZATION
Definition: ltc_defs.h:121
@ LTC_STATEMACH_UNINITIALIZED
Definition: ltc_defs.h:120
@ LTC_STATEMACH_STARTMEAS_CONTINUE
Definition: ltc_defs.h:149
@ LTC_STATEMACH_OPENWIRE_CHECK
Definition: ltc_defs.h:141
@ LTC_STATEMACH_READVOLTAGE
Definition: ltc_defs.h:127
@ LTC_STATEMACH_INITIALIZED
Definition: ltc_defs.h:123
@ LTC_STATEMACH_STARTMEAS
Definition: ltc_defs.h:126
@ LTC_REQUEST_PULLDOWN_CURRENT_OPENWIRE_CHECK
Definition: ltc_defs.h:236
@ LTC_READ_VOLTAGES_PULLDOWN_OPENWIRE_CHECK
Definition: ltc_defs.h:237
@ LTC_READ_VOLTAGES_PULLUP_OPENWIRE_CHECK
Definition: ltc_defs.h:235
@ LTC_REQUEST_PULLUP_CURRENT_OPENWIRE_CHECK
Definition: ltc_defs.h:234
@ LTC_PERFORM_OPENWIRE_CHECK
Definition: ltc_defs.h:238
LTC_ADCMEAS_CHAN_e
Definition: ltc_defs.h:104
@ LTC_ADCMEAS_UNDEFINED
Definition: ltc_defs.h:105
@ LTC_ADCMEAS_ALLCHANNEL_CELLS
Definition: ltc_defs.h:106
LTC_RETURN_TYPE_e
Definition: ltc_defs.h:397
@ LTC_BUSY_OK
Definition: ltc_defs.h:399
@ LTC_ILLEGAL_REQUEST
Definition: ltc_defs.h:401
@ LTC_ALREADY_INITIALIZED
Definition: ltc_defs.h:408
@ LTC_ERROR
Definition: ltc_defs.h:407
@ LTC_OK_FROM_ERROR
Definition: ltc_defs.h:406
@ LTC_REQUEST_PENDING
Definition: ltc_defs.h:400
@ LTC_OK
Definition: ltc_defs.h:398
@ LTC_READ_VOLTAGE_REGISTER_F_RDCVF_READVOLTAGE
Definition: ltc_defs.h:196
@ LTC_READ_VOLTAGE_REGISTER_A_RDCVA_READVOLTAGE
Definition: ltc_defs.h:191
@ LTC_READ_VOLTAGE_REGISTER_D_RDCVD_READVOLTAGE
Definition: ltc_defs.h:194
@ LTC_READ_VOLTAGE_REGISTER_G_RDCVG_READVOLTAGE
Definition: ltc_defs.h:197
@ LTC_READ_VOLTAGE_REGISTER_I_RDCVI_READVOLTAGE
Definition: ltc_defs.h:199
@ LTC_READ_VOLTAGE_REGISTER_B_RDCVB_READVOLTAGE
Definition: ltc_defs.h:192
@ LTC_EXIT_READVOLTAGE
Definition: ltc_defs.h:200
@ LTC_READ_VOLTAGE_REGISTER_H_RDCVH_READVOLTAGE
Definition: ltc_defs.h:198
@ LTC_READ_VOLTAGE_REGISTER_E_RDCVE_READVOLTAGE
Definition: ltc_defs.h:195
@ LTC_READ_VOLTAGE_REGISTER_C_RDCVC_READVOLTAGE
Definition: ltc_defs.h:193
@ LTC_REUSE_READVOLT_FOR_ADOW_PUP
Definition: ltc_defs.h:495
@ LTC_REUSE_READVOLT_FOR_ADOW_PDOWN
Definition: ltc_defs.h:496
@ LTC_NOT_REUSED
Definition: ltc_defs.h:494
LTC_ADCMODE_e
Definition: ltc_defs.h:93
@ LTC_ADCMODE_UNDEFINED
Definition: ltc_defs.h:94
@ LTC_ADCMODE_FAST_DCP0
Definition: ltc_defs.h:95
@ LTC_ENTRY
Definition: ltc_defs.h:161
Declaration of the OS wrapper interface.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:135
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:131
void PEX_SetPin(uint8_t portExpander, uint8_t pin)
sets pin to high.
Definition: pex.c:321
void PEX_SetPinDirectionOutput(uint8_t portExpander, uint8_t pin)
sets pin to input.
Definition: pex.c:394
Header for the driver for the NXP PCA9539 port expander module.
#define PEX_PIN16
Definition: pex_cfg.h:95
#define PEX_PIN13
Definition: pex_cfg.h:92
#define PEX_PIN10
Definition: pex_cfg.h:89
#define PEX_PORT_EXPANDER3
Definition: pex_cfg.h:76
#define PEX_PIN17
Definition: pex_cfg.h:96
#define PEX_PIN12
Definition: pex_cfg.h:91
#define PEX_PIN15
Definition: pex_cfg.h:94
#define PEX_PIN11
Definition: pex_cfg.h:90
#define PEX_PIN14
Definition: pex_cfg.h:93
SPI_INTERFACE_CONFIG_s spi_ltcInterface[BS_NR_OF_STRINGS]
Definition: spi_cfg.c:173
struct definition for plausibility values of an AFE
const int16_t maximumPlausibleVoltage_mV
uint16_t gpioVoltages_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING *BS_NR_OF_GPIOS_PER_MODULE]
Definition: database_cfg.h:318
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:315
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:146
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
Definition: database_cfg.h:148
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
Definition: database_cfg.h:151
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:150
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:131
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:129
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
Definition: database_cfg.h:135
uint16_t nrValidCellVoltages[BS_NR_OF_STRINGS]
Definition: database_cfg.h:136
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:132
DATA_BLOCK_ID_e uniqueId
Definition: database_cfg.h:119
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:302
uint16_t nrOpenWires[BS_NR_OF_STRINGS]
Definition: database_cfg.h:304
uint8_t openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING *(BS_NR_OF_CELL_BLOCKS_PER_MODULE+1u)]
Definition: database_cfg.h:307
LTC_OPENWIRE_DETECTION_s * openWireDetection
Definition: ltc_defs.h:447
DATA_BLOCK_ALL_GPIO_VOLTAGES_s * allGpioVoltages
Definition: ltc_defs.h:444
DATA_BLOCK_CELL_VOLTAGE_s * cellVoltage
Definition: ltc_defs.h:439
DATA_BLOCK_CELL_TEMPERATURE_s * cellTemperature
Definition: ltc_defs.h:440
uint16_t * txBuffer
Definition: ltc_defs.h:436
LTC_ERRORTABLE_s * errorTable
Definition: ltc_defs.h:448
SPI_INTERFACE_CONFIG_s * pSpiInterface
Definition: ltc_defs.h:435
uint16_t * rxBuffer
Definition: ltc_defs.h:437
uint16_t * usedCellIndex
Definition: ltc_defs.h:446
uint32_t frameLength
Definition: ltc_defs.h:438
DATA_BLOCK_OPEN_WIRE_s * openWire
Definition: ltc_defs.h:445
uint8_t PEC_valid[BS_NR_OF_STRINGS][LTC_N_LTC]
Definition: ltc_defs.h:71
uint8_t mux3[BS_NR_OF_STRINGS][LTC_N_LTC]
Definition: ltc_defs.h:75
uint8_t mux2[BS_NR_OF_STRINGS][LTC_N_LTC]
Definition: ltc_defs.h:74
uint8_t mux0[BS_NR_OF_STRINGS][LTC_N_LTC]
Definition: ltc_defs.h:72
uint8_t mux1[BS_NR_OF_STRINGS][LTC_N_LTC]
Definition: ltc_defs.h:73
int32_t openWireDelta[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: ltc_defs.h:82
int16_t openWirePdown[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: ltc_defs.h:81
int16_t openWirePup[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: ltc_defs.h:80
LTC_STATE_REQUEST_e request
Definition: ltc_defs.h:511
uint8_t string
Definition: ltc_defs.h:512
uint32_t commandDataTransferTime
Definition: ltc_defs.h:543
LTC_DATAPTR_s ltcData
Definition: ltc_defs.h:578
LTC_ADCMODE_e adcModereq
Definition: ltc_defs.h:530
LTC_REQUEST_s statereq
Definition: ltc_defs.h:522
uint8_t triggerentry
Definition: ltc_defs.h:541
SPI_INTERFACE_CONFIG_s * spiSeqPtr
Definition: ltc_defs.h:568
uint32_t commandTransferTime
Definition: ltc_defs.h:544
SPI_INTERFACE_CONFIG_s * spiSeqEndPtr
Definition: ltc_defs.h:569
uint8_t substate
Definition: ltc_defs.h:524
LTC_STATEMACH_e laststate
Definition: ltc_defs.h:525
uint8_t lastsubstate
Definition: ltc_defs.h:526
LTC_ADCMEAS_CHAN_e adcMeasCh
Definition: ltc_defs.h:532
LTC_REUSE_MODE_e reusageMeasurementMode
Definition: ltc_defs.h:558
uint32_t gpioClocksTransferTime
Definition: ltc_defs.h:546
uint16_t timer
Definition: ltc_defs.h:520
uint8_t resendCommandCounter
Definition: ltc_defs.h:565
LTC_STATEMACH_e state
Definition: ltc_defs.h:523
uint8_t spiNumberInterfaces
Definition: ltc_defs.h:570
LTC_ADCMODE_e adcMode
Definition: ltc_defs.h:527
uint8_t currentString
Definition: ltc_defs.h:571
uint32_t ErrRequestCounter
Definition: ltc_defs.h:540
STD_RETURN_TYPE_e check_spi_flag
Definition: ltc_defs.h:563
bool first_measurement_made
Definition: ltc_defs.h:560
uint8_t requestedString
Definition: ltc_defs.h:572
LTC_ADCMEAS_CHAN_e adcMeasChreq
Definition: ltc_defs.h:534
spiBASE_t * pNode
Definition: spi_cfg.h:125