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