foxBMS-UnitTests  1.0.0
The foxBMS Unit Tests API Documentation
mxm_1785x.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
38  * ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file mxm_1785x.c
44  * @author foxBMS Team
45  * @date 2019-01-15 (date of creation)
46  * @updated 2020-09-10 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix MXM
49  *
50  * @brief Driver for the MAX17841B ASCI and MAX1785x monitoring chip
51  *
52  * @details This file contains the main-state-machine that drives the
53  * monitoring ICs of the MAX1785x family by Maxim Integrated.
54  *
55  */
56 
57 /*========== Includes =======================================================*/
58 #include "mxm_1785x.h"
59 
60 #include "database.h"
61 #include "diag.h"
62 #include "mxm_1785x_tools.h"
63 #include "mxm_battery_management.h"
64 #include "mxm_registry.h"
65 #include "os.h"
66 #include "tsi.h"
67 
68 /*========== Macros and Definitions =========================================*/
69 
70 /** length of voltage-read array */
71 #define MXM_VOLTAGE_READ_ARRAY_LENGTH (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE + 3u)
72 
73 /*========== Static Constant and Variable Definitions =======================*/
74 /**
75  * @brief Mapping of voltage registers
76  *
77  * This array maps registers of the monitoring IC onto cell-numbers. The
78  * register values are defined in the #MXM_REG_NAME_e enum.
79  * For now the length of this array is #MXM_VOLTAGE_READ_ARRAY_LENGTH
80  * as it is enabled for the measurement of all cells, two AUX-voltages and
81  * one block voltage. This has to be adapted once this driver is enabled for
82  * general operation.
83  */
100  MXM_REG_AUX2,
102 };
103 
104 /**
105  * @brief Local cell voltage data block
106  *
107  * This local instance stores the measured cell voltages. In contrast to
108  * #MXM_MONITORING_INSTANCE::localVoltages, the layout of this structure
109  * changes with the defined battery-system as it is described by the
110  * database_cfg.h. Mapping the values from
111  * #MXM_MONITORING_INSTANCE::localVoltages to #mxm_cellVoltages and copying
112  * these entries into the database is handled by #MXM_ParseVoltagesIntoDB().
113  */
115 
116 /**
117  * @brief Local cell temperature data block
118  * @details This local instance stores the measured cell temperatures.
119  */
121 
122 /** @brief Local data structure for openwire results. */
124 
125 /**
126  * @brief Balancing control
127  * @details This variable stores information about which cells need balancing
128  */
130 
131 /**
132  * @brief Module index in the daisy chain
133  * @details Used for balancing
134  */
135 static uint8_t mxm_moduleBalancingIndex = {0};
136 
137 /**
138  * @brief Even cells group needs to be balanced
139  * @details Even and odd cells can't be balanced at the same time
140  */
141 static uint8_t mxm_evenCellsNeedBalancing = {0};
142 
143 /**
144  * @brief Odd cells group needs to be balanced
145  * @details Even and odd cells can't be balanced at the same time
146  */
147 static uint8_t mxm_oddCellsNeedBalancing = {0};
148 
149 /**
150  * @brief Even cells group balancing done
151  * @details Odd cells can be balanced now
152  */
153 static uint8_t mxm_evenCellsBalancingProcessed = {0};
154 
155 /**
156  * @brief Odd cells group balancing done
157  * @details Even cells can be balanced now
158  */
159 static uint8_t mxm_oddCellsBalancingProcessed = {0};
160 
161 /**
162  * @brief Mask to control balacing
163  * @details Bitfield masked with register BALSWCTRL, 16 bits => up to 14 cells
164  */
165 uint16_t mxm_cellsToBalance = 0x00;
166 
167 /** @brief Timers used to guarantee that balancing is performed periodically @{*/
168 static uint32_t mxm_previousTime = {0};
169 static uint32_t mxm_currentTime = {0};
170 /**@}*/
171 
172 /** @brief Delay in milliseconds before the balancing status is updated */
173 #define MXM_DELAY_BALANCING 10000u
174 
175 /*========== Extern Constant and Variable Definitions =======================*/
176 
177 /*========== Static Function Prototypes =====================================*/
178 
179 /** @brief Retrieves data from lower statemachine and writes it to the rx buffer. */
181 
182 /**
183  * @brief Parse voltage values from a READALL receive buffer into an
184  * array.
185  * @details This function expects a preprocessed RX buffer with an answer
186  * to a READALL command. It will parse the data bytes from this
187  * message into an array structured like mxm_local_cellvoltages.
188  * The offset of the measured cell has to be defined. For example
189  * cell 1 has an offset of 0 and cell 4 has an offset of 3. The
190  * offset for the READALL command is always defined in reference
191  * to module 0.
192  *
193  * If is_temperature_measurement is set to true, the function
194  * expects an auxiliary measurement (e.g. temperatures).
195  * @param[in] volt_rx_buffer array-pointer to the RX buffer
196  * @param[in] volt_rx_buffer_len length of the RX buffer
197  * @param[in] meas_offset offset of the data in the cell voltage
198  * array (target)
199  * @param[in] conversionType type of conversion that has been used
200  * for the measured data
201  * @param[out] voltages_target array-pointer to the cell voltages
202  * array
203  * @param[in] meas_type whether the measurement is temperature
204  * or cell
205  * @param[in] full_scale_reference_mV reference voltage of full scale
206  */
207 static void MXM_ParseVoltageLineReadall(
208  uint8_t *volt_rx_buffer,
209  uint16_t volt_rx_buffer_len,
210  uint8_t meas_offset,
211  MXM_CONVERSION_TYPE_e conversionType,
212  uint16_t *voltages_target,
213  MXM_MEASURE_TYPE_e meas_type,
214  uint32_t full_scale_reference_mV);
215 
216 /**
217  * @brief Parse a RX buffer containing voltage values.
218  * @details This function parses a RX buffer containing the answer to a
219  * READALL command. It will check whether the message contains a
220  * READALL command and whether a supported register has been
221  * queried.
222  * Depending on the queried register, it will pass the proper
223  * parameters to #MXM_ParseVoltageLineReadall(). The contained
224  * data from this message will be parsed into a struct structured
225  * like #MXM_MONITORING_INSTANCE::localVoltages.
226  * @param[in] volt_rx_buffer array-pointer to the RX buffer
227  * @param[in] volt_rx_buffer_len length of the RX buffer
228  * @param[out] datastorage contains all measured voltages for local
229  * consumption in the module
230  * @param[in] conversionType type of conversion that has been used for
231  * the measured data
232  * @return #STD_NOT_OK in the case that the RX buffer does not contain a
233  * valid message or the conversion-type is unknown,
234  * otherwise #STD_OK
235  */
237  uint8_t *volt_rx_buffer,
238  uint16_t volt_rx_buffer_len,
239  MXM_DATA_STORAGE_s *datastorage,
240  MXM_CONVERSION_TYPE_e conversionType);
241 
242 /**
243  * @brief Test the #MXM_ParseVoltageReadall()-function
244  * @details Test the function #MXM_ParseVoltageReadall() by passing predefined
245  * RX buffer to it and checking the outcome. This function writes to
246  * the variable #MXM_MONITORING_INSTANCE::localVoltages and nulls it
247  * completely after execution. It is intended as a self-check that can
248  * be performed during startup of the driver.
249  * @return #STD_OK if the self-check has been performed successfully,
250  * otherwise #STD_NOT_OK
251  */
253 
254 /**
255  * @brief Encapsulation for reading voltages from a register
256  * @details This function encapsulates the request of state-changes and
257  * following conversion for the reading of an arbitrary
258  * measurement voltage of the daisy-chain. Its parameters are
259  * a variable for tracking the state of the underlying
260  * state-machines and the register address that has to be
261  * queried. It returns whether the action has been successful
262  * or not.
263  * In order to obtain all cell voltages this function has to
264  * be called for every relevant register address.
265  * @param[in,out] pState pointer to the state-machine struct
266  * @param[in] regAddress register address that shall be queried
267  * @return current state of the action:
268  * - MXM_MON_STATE_PASS upon completion
269  * - MXM_MON_STATE_PENDING as long as the action is
270  * ongoing
271  * - MXM_MON_STATE_FAIL if the function failed and could
272  * not recover on its own
273  */
276 
277 /**
278  * @brief Copies measured voltage data into the database.
279  * @details This function copies the acquired voltage data from
280  * #MXM_MONITORING_INSTANCE::localVoltages into the database-struct mxm_cellVoltages and
281  * copies this struct into the database. This action is required due
282  * to different data layouts. This driver always stores its
283  * cell-voltages in an array with 14*32 = 448 cells in order to reduce
284  * the amount of different configurations and variants.
285  *
286  * This function maps these values into the database-struct which
287  * scales with the number of connected cells and monitoring ICs.
288  * @return #STD_OK if the action was successful or #STD_NOT_OK otherwise
289  */
291 
292 /**
293  * @brief Execute all preinit selfchecks.
294  * @details Executes the following self-checks:
295  * - #MXM_CRC8SelfTest()
296  * - #MXM_ConvertTest()
297  * - #MXM_FirstSetBitTest()
298  * - #MXM_ExtractValueFromRegisterTest()
299  * - #MXM_ParseVoltageReadallTest()
300  * - #MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck()
301  *
302  * These self-checks do not need an initialized daisy-chain
303  * and can therefore be executed at startup of the
304  * state-machine.
305  *
306  * After execution of each test, the return value is stored in
307  * the supplied state-struct. The function returns whether the
308  * self-check has successfully passed.
309  * @param[in,out] pState pointer to the state-struct, will write status into
310  * @return #STD_OK on success, #STD_NOT_OK on failure,
311  * return value has to be used
312  */
314 
315 /**
316  * @brief State-Machine implementation for operation state
317  * @details This state-machine contains the "program" with which the
318  * connected monitoring satellites are controlled. It is
319  * entered by #MXM_StateMachine() once the daisy-chain has
320  * been initialized and is in operation state.
321  * @param[in,out] pState used as both input and output (stores
322  * state-information, requests and intermediate values)
323  */
325 
326 /**
327  * @brief Fill the balancing datastructure
328  * @details This function fills the data-structure that describes
329  * which balancing channels of the monitoring ICs should be
330  * activated.
331  * @return #STD_NOT_OK in case of invalid access
332  */
334 
335 /**
336  * @brief Handle the statemachine-transactions for a WRITEALL
337  * @details Before calling this function, update the command buffer of
338  * the state-variable. Then call this function and pass on the
339  * state-variable and the next state. The function will
340  * handle the communication with the lower state-machine and
341  * will transition into the next state, if the command has
342  * been sent successfully.
343  * @param[in,out] pInstance pointer to instance of the mxm
344  * monitoring state-machine
345  * @param[in] nextState state that should be entered upon successfull
346  * completion
347  */
348 static void MXM_HandleStateWriteall(
349  MXM_MONITORING_INSTANCE_s *pInstance,
351 
352 /**
353  * @brief Handle the statemachine-transactions for a READALL
354  * @details Call this function and pass on the state-variable, the
355  * register to be read and the next state. The function will
356  * handle the communication with the lower state-machine and
357  * will transition into the next state, if the command has
358  * been sent successfully. Moreover it will return true when
359  * transitioning. The return value has to be checked and used
360  * to execute additional code if necessary.
361  * @param[in,out] pInstance pointer to instance of the mxm
362  * monitoring state-machine
363  * @param[in] registerName register that should be read
364  * @param[in] nextState state that should be entered upon successfull
365  * completion
366  * @return true when the state has been handled, false otherwise, use
367  * this to execute additional code when the message has been
368  * read.
369  */
371  MXM_MONITORING_INSTANCE_s *pInstance,
372  MXM_REG_NAME_e registerName,
374 
375 /**
376  * @brief Processes the retrieved information on openwire
377  * @details Parses through a retrieved RX buffer and writes into the
378  * database.
379  * @param[in,out] pInstance pointer to instance of the Maxim monitoring
380  * state-machine
381  * @param[in,out] pDataOpenWire pointer to the local copy of the data-base
382  * entry
383  */
384 static void MXM_ProcessOpenWire(MXM_MONITORING_INSTANCE_s *pInstance, DATA_BLOCK_OPEN_WIRE_s *pDataOpenWire);
385 
386 /*========== Static Function Implementations ================================*/
389  pInstance->dcByte = MXM_5XGetLastDCByte(pInstance->pInstance5X);
390 }
391 
393  MXM_MONITORING_INSTANCE_s *pInstance,
395  FAS_ASSERT(pInstance != NULL_PTR);
396 
397  if (pInstance->requestStatus5x == MXM_5X_STATE_UNSENT) {
399  pInstance->pInstance5X,
401  pInstance->batteryCmdBuffer,
402  &pInstance->requestStatus5x);
403  } else if (pInstance->requestStatus5x == MXM_5X_STATE_UNPROCESSED) {
404  /* wait for processing */
405  } else if (pInstance->requestStatus5x == MXM_5X_STATE_PROCESSED) {
406  /* continue to the substate specified by the request */
407  pInstance->operationSubstate = nextState;
409  } else if (pInstance->requestStatus5x == MXM_5X_STATE_ERROR) {
410  /* default-behavior: retry */
412  } else {
413  /* invalid value, trap */
415  }
416 }
417 
419  MXM_MONITORING_INSTANCE_s *pInstance,
420  MXM_REG_NAME_e registerName,
422  FAS_ASSERT(pInstance != NULL_PTR);
423 
424  bool retval = false;
425  if (pInstance->requestStatus5x == MXM_5X_STATE_UNSENT) {
426  pInstance->batteryCmdBuffer.regAddress = registerName;
428  pInstance->pInstance5X, MXM_STATEMACH_5X_READALL, pInstance->batteryCmdBuffer, &pInstance->requestStatus5x);
429  } else if (pInstance->requestStatus5x == MXM_5X_STATE_PROCESSED) {
431  pInstance->operationSubstate = nextState;
433  retval = true;
434  } else if (pInstance->requestStatus5x == MXM_5X_STATE_UNPROCESSED) {
435  /* do nothing */
436  } else if (pInstance->requestStatus5x == MXM_5X_STATE_ERROR) {
437  /* try to reset state */
439  } else {
440  /* invalid state --> trap */
442  }
443 
444  return retval;
445 }
446 
448  FAS_ASSERT(pInstance != NULL_PTR);
449  FAS_ASSERT(pDataOpenWire != NULL_PTR);
450 
451  uint8_t numberOfSatellites = MXM_5XGetNumberOfSatellites(pInstance->pInstance5X);
452  uint8_t msg_len = BATTERY_MANAGEMENT_TX_LENGTH_READALL + (2u * numberOfSatellites);
453  /* step over every byte-tuple in the RX-buffer */
454  for (uint8_t i_po = 2u; i_po < (msg_len - 2u); i_po = i_po + 2u) {
455  /* calculate current module number (first in RX-buffer is last in line) */
456  uint8_t calculatedModuleNumberInDaisyChain = numberOfSatellites - ((uint16_t)(i_po / 2u) - 1u) - 1u;
457  uint8_t stringNumber = 0u;
458  uint16_t moduleNumber = 0u;
459  MXM_ConvertModuleToString(calculatedModuleNumberInDaisyChain, &stringNumber, &moduleNumber);
460  uint16_t calculated_module_position = moduleNumber * MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE;
461 
462  /* step over every cell in the module and update the openwire struct accordingly */
463  for (uint8_t c = 0u; c < MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE; c++) {
464  if (c < 8u) {
465  /* cell numbers under 8 can be found in the LSB */
466  uint8_t mask = 1u << c;
467  if ((uint8_t)(mask & pInstance->rxBuffer[i_po]) > 0u) {
468  pDataOpenWire->openwire[stringNumber][calculated_module_position + c] = 1;
469  } else {
470  pDataOpenWire->openwire[stringNumber][calculated_module_position + c] = 0;
471  }
472  } else {
473  /* cell numbers over or equal 8 can be found in the MSB */
474  uint8_t mask = 1u << (c - 8u);
475  if ((uint8_t)(mask & pInstance->rxBuffer[i_po + 1u]) > 0u) {
476  pDataOpenWire->openwire[stringNumber][calculated_module_position + c] = 1;
477  } else {
478  pDataOpenWire->openwire[stringNumber][calculated_module_position + c] = 0;
479  }
480  }
481  }
482  }
483 
484  /* write database block */
485  DATA_WRITE_DATA(pDataOpenWire);
486 }
487 
489  STD_RETURN_TYPE_e retval = STD_OK;
490 
491  /* Re-Initialize the cells to balance at each iteration */
492  mxm_cellsToBalance = 0u;
493 
494  /* /!\ WARNING
495  In this function, EVEN cells refer to the even cells IN THE REAL MODULE, and NOT in the database index.
496  --> EVEN cells in a module = ODD database index
497  --> ODD cells in a module = EVEN database index
498  e.g. : Cell 2 in the module corresponds to index 1 in the database
499  the cell index is even, but the database index is odd. */
500 
501  /* Iterate over all the cells of the module 'mxm_moduleBalancingIndex' in a daisy-chain */
503  for (uint8_t cell_index = 0; cell_index < BS_NR_OF_CELLS_PER_MODULE; cell_index++) {
504  if (cell_index < MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE) {
505  /* Determine the position of the cell 'cell_index' of module 'mxm_moduleBalancingIndex' in the DB */
506  uint8_t stringNumber = 0u;
507  uint16_t moduleNumber = 0u;
508  MXM_ConvertModuleToString(mxm_moduleBalancingIndex, &stringNumber, &moduleNumber);
509  uint16_t db_index = (moduleNumber * BS_NR_OF_CELLS_PER_MODULE) + cell_index;
510  if (mxm_balancingControl.balancingState[stringNumber][db_index] == 1) {
511  /* Cell 'cell_index' of module 'mxm_moduleBalancingIndex' needs to be balanced.
512  Need to determine the balancing order --> even or odd cells?
513  If the balancing order has not been determined before, need to do it. */
514  if ((mxm_evenCellsNeedBalancing == 0u) && (mxm_oddCellsNeedBalancing == 0u)) {
515  if (((cell_index % 2u) != 0u) && (mxm_evenCellsBalancingProcessed == 0u)) {
517  } else if (((cell_index % 2u) == 0u) && (mxm_oddCellsBalancingProcessed == 0u)) {
519  }
520  }
521  /* If the even cells need to be balanced */
522  if ((mxm_evenCellsNeedBalancing == 1u) && ((cell_index % 2u) != 0u) &&
524  mxm_cellsToBalance |= (0x01u << cell_index);
525  }
526  /* If the odd cells need to be balanced */
527  else if (
528  (mxm_oddCellsNeedBalancing == 1u) && ((cell_index % 2u) == 0u) &&
530  mxm_cellsToBalance |= (0x01u << cell_index);
531  }
532  }
533  } else {
534  retval = STD_NOT_OK;
535  }
536  }
537  } else {
538  retval = STD_NOT_OK;
539  }
540  return retval;
541 }
542 
544  uint8_t *volt_rx_buffer,
545  uint16_t volt_rx_buffer_len,
546  uint8_t meas_offset,
547  MXM_CONVERSION_TYPE_e conversionType,
548  uint16_t *voltages_target,
549  MXM_MEASURE_TYPE_e meas_type,
550  uint32_t full_scale_reference_mV) {
551  uint8_t number_of_connected_devices =
552  (volt_rx_buffer_len - 2u - 2u) /
553  2u; /*!< buffer-length - length of start - length of end divided by two (LSB and MSB) */
554  /* TODO impact of alive counter on rxBufferLength
555  * otherwise offset at the end of message is currently 2 (DATACHECKBYTE and CRC) */
556  for (uint8_t i = 2u; i < (volt_rx_buffer_len - 2u); i = i + 2u) {
557  uint8_t calculated_module_number = number_of_connected_devices - ((uint16_t)(i / 2u) - 1u) - 1u;
558  uint16_t calculated_module_position = 0u;
559  switch (meas_type) {
560  case MXM_MEASURE_TEMP:
561  calculated_module_position = calculated_module_number * MXM_MAXIMUM_NR_OF_AUX_PER_MODULE;
562  break;
564  calculated_module_position = calculated_module_number * MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE;
565  break;
567  calculated_module_position = calculated_module_number;
568  break;
569  default:
571  break;
572  }
573  uint16_t calculated_array_position = calculated_module_position + meas_offset;
574  MXM_Convert(
575  volt_rx_buffer[i],
576  volt_rx_buffer[i + 1u],
577  &voltages_target[calculated_array_position],
578  conversionType,
579  full_scale_reference_mV);
580  }
581  return;
582 }
583 
585  uint8_t *volt_rx_buffer,
586  uint16_t volt_rx_buffer_len,
587  MXM_DATA_STORAGE_s *datastorage,
588  MXM_CONVERSION_TYPE_e conversionType) {
589  STD_RETURN_TYPE_e retval = STD_OK;
590  FAS_ASSERT(volt_rx_buffer != NULL_PTR);
591  FAS_ASSERT(datastorage != NULL_PTR);
592 
593  uint8_t cell_offset = 0;
594  if (volt_rx_buffer[0] != BATTERY_MANAGEMENT_READALL) {
595  /* rxBuffer does not contain a READALL command */
596  retval = STD_NOT_OK;
597  } else if ((volt_rx_buffer_len % 2u) != 0u) {
598  /* without alive counter rx-buffer always should be of even length */
599  /* TODO impact of alive-counter-byte */
600  retval = STD_NOT_OK;
601  } else if (
602  (conversionType != MXM_CONVERSION_UNIPOLAR) && (conversionType != MXM_CONVERSION_BIPOLAR) &&
603  (conversionType != MXM_CONVERSION_BLOCK_VOLTAGE)) {
604  /* conversion type is not supported */
605  retval = STD_NOT_OK;
606  } else {
607  switch (volt_rx_buffer[1]) {
608  case MXM_REG_CELL1:
609  cell_offset = 0u;
611  volt_rx_buffer,
612  volt_rx_buffer_len,
613  cell_offset,
614  conversionType,
615  datastorage->cellVoltages,
617  5000u);
618  break;
619  case MXM_REG_CELL2:
620  cell_offset = 1u;
622  volt_rx_buffer,
623  volt_rx_buffer_len,
624  cell_offset,
625  conversionType,
626  datastorage->cellVoltages,
628  5000u);
629  break;
630  case MXM_REG_CELL3:
631  cell_offset = 2u;
633  volt_rx_buffer,
634  volt_rx_buffer_len,
635  cell_offset,
636  conversionType,
637  datastorage->cellVoltages,
639  5000u);
640  break;
641  case MXM_REG_CELL4:
642  cell_offset = 3u;
644  volt_rx_buffer,
645  volt_rx_buffer_len,
646  cell_offset,
647  conversionType,
648  datastorage->cellVoltages,
650  5000u);
651  break;
652  case MXM_REG_CELL5:
653  cell_offset = 4u;
655  volt_rx_buffer,
656  volt_rx_buffer_len,
657  cell_offset,
658  conversionType,
659  datastorage->cellVoltages,
661  5000u);
662  break;
663  case MXM_REG_CELL6:
664  cell_offset = 5u;
666  volt_rx_buffer,
667  volt_rx_buffer_len,
668  cell_offset,
669  conversionType,
670  datastorage->cellVoltages,
672  5000u);
673  break;
674  case MXM_REG_CELL7:
675  cell_offset = 6u;
677  volt_rx_buffer,
678  volt_rx_buffer_len,
679  cell_offset,
680  conversionType,
681  datastorage->cellVoltages,
683  5000u);
684  break;
685  case MXM_REG_CELL8:
686  cell_offset = 7u;
688  volt_rx_buffer,
689  volt_rx_buffer_len,
690  cell_offset,
691  conversionType,
692  datastorage->cellVoltages,
694  5000u);
695  break;
696  case MXM_REG_CELL9:
697  cell_offset = 8u;
699  volt_rx_buffer,
700  volt_rx_buffer_len,
701  cell_offset,
702  conversionType,
703  datastorage->cellVoltages,
705  5000u);
706  break;
707  case MXM_REG_CELL10:
708  cell_offset = 9u;
710  volt_rx_buffer,
711  volt_rx_buffer_len,
712  cell_offset,
713  conversionType,
714  datastorage->cellVoltages,
716  5000u);
717  break;
718  case MXM_REG_CELL11:
719  cell_offset = 10u;
721  volt_rx_buffer,
722  volt_rx_buffer_len,
723  cell_offset,
724  conversionType,
725  datastorage->cellVoltages,
727  5000u);
728  break;
729  case MXM_REG_CELL12:
730  cell_offset = 11u;
732  volt_rx_buffer,
733  volt_rx_buffer_len,
734  cell_offset,
735  conversionType,
736  datastorage->cellVoltages,
738  5000u);
739  break;
740  case MXM_REG_CELL13:
741  cell_offset = 12u;
743  volt_rx_buffer,
744  volt_rx_buffer_len,
745  cell_offset,
746  conversionType,
747  datastorage->cellVoltages,
749  5000u);
750  break;
751  case MXM_REG_CELL14:
752  cell_offset = 13u;
754  volt_rx_buffer,
755  volt_rx_buffer_len,
756  cell_offset,
757  conversionType,
758  datastorage->cellVoltages,
760  5000u);
761  break;
762  case MXM_REG_AUX0:
763  cell_offset = 0u;
765  volt_rx_buffer,
766  volt_rx_buffer_len,
767  cell_offset,
768  conversionType,
769  datastorage->auxVoltages,
771  3300u);
772  break;
773  case MXM_REG_AUX2:
774  cell_offset = 2u;
776  volt_rx_buffer,
777  volt_rx_buffer_len,
778  cell_offset,
779  conversionType,
780  datastorage->auxVoltages,
782  3300u);
783  break;
784  case MXM_REG_BLOCK:
785  cell_offset = 0u;
787  volt_rx_buffer,
788  volt_rx_buffer_len,
789  cell_offset,
790  conversionType,
791  datastorage->blockVoltages,
793  65000u);
794  /* TODO scaling and variable size (65000)*/
795  break;
796  default:
797  /* the read register is not a valid cell register */
798  retval = STD_NOT_OK;
799  break;
800  }
801  }
802  return retval;
803 }
804 
806  FAS_ASSERT(pInstance != NULL_PTR);
807  STD_RETURN_TYPE_e retval = STD_OK;
808 
809  uint8_t test_buffer[100];
810  uint16_t test_buffer_len = 100;
811 
812  /* not a readall buffer */
813  test_buffer[0] = BATTERY_MANAGEMENT_HELLOALL;
814  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
815  STD_NOT_OK) {
816  retval = STD_NOT_OK;
817  }
818 
819  /* not a cell voltage register */
820  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
821  test_buffer[1] = MXM_REG_VERSION;
822  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
823  STD_NOT_OK) {
824  retval = STD_NOT_OK;
825  }
826 
827  /* bogus conversion type */
828  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
829  test_buffer[1] = MXM_REG_CELL1;
830  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, (MXM_CONVERSION_TYPE_e)42) !=
831  STD_NOT_OK) {
832  retval = STD_NOT_OK;
833  }
834 
835  /* not an even length of rxBuffer */
836  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
837  test_buffer[1] = MXM_REG_CELL1;
838  test_buffer_len = 5;
839  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
840  STD_NOT_OK) {
841  retval = STD_NOT_OK;
842  }
843 
844  /* test data for CELL1REG */
845  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
846  test_buffer[1] = MXM_REG_CELL1;
847  test_buffer[2] = 0xFCu;
848  test_buffer[3] = 0xFFu;
849  test_buffer[4] = 0x00u;
850  test_buffer[5] = 0x00u;
851  test_buffer[6] = 0xFCu;
852  test_buffer[7] = 0xFFu;
853  test_buffer[8] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
854  test_buffer[9] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
855  test_buffer_len = 10u;
856  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
857  STD_OK) {
858  retval = STD_NOT_OK;
859  } else {
860  if ((pInstance->localVoltages.cellVoltages[0] != 5000u) || (pInstance->localVoltages.cellVoltages[14] != 0u) ||
861  (pInstance->localVoltages.cellVoltages[28] != 5000u)) {
862  retval = STD_NOT_OK;
863  }
864  }
865 
866  /* null mxm_local_cellvoltages */
867  for (uint16_t i_0 = 0; i_0 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_0++) {
868  pInstance->localVoltages.cellVoltages[i_0] = 0;
869  }
870 
871  /* test data for CELL2REG */
872  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
873  test_buffer[1] = MXM_REG_CELL2;
874  test_buffer[2] = 0xFCu;
875  test_buffer[3] = 0xFFu;
876  test_buffer[4] = 0x00u;
877  test_buffer[5] = 0x00u;
878  test_buffer[6] = 0xFCu;
879  test_buffer[7] = 0xFFu;
880  test_buffer[8] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
881  test_buffer[9] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
882  test_buffer_len = 10;
883  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
884  STD_OK) {
885  retval = STD_NOT_OK;
886  } else {
887  if ((pInstance->localVoltages.cellVoltages[1] != 5000u) || (pInstance->localVoltages.cellVoltages[15] != 0u) ||
888  (pInstance->localVoltages.cellVoltages[29] != 5000u)) {
889  retval = STD_NOT_OK;
890  }
891  }
892 
893  /* null mxm_local_cellvoltages */
894  for (uint16_t i_1 = 0; i_1 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_1++) {
895  pInstance->localVoltages.cellVoltages[i_1] = 0;
896  }
897 
898  /* test data for CELL3REG */
899  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
900  test_buffer[1] = MXM_REG_CELL3;
901  test_buffer[2] = 0xFCu;
902  test_buffer[3] = 0xFFu;
903  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
904  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
905  test_buffer_len = 6;
906  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
907  STD_OK) {
908  retval = STD_NOT_OK;
909  } else {
910  if (pInstance->localVoltages.cellVoltages[2] != 5000u) {
911  retval = STD_NOT_OK;
912  }
913  }
914 
915  /* null mxm_local_cellvoltages */
916  for (uint16_t i_2 = 0; i_2 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_2++) {
917  pInstance->localVoltages.cellVoltages[i_2] = 0;
918  }
919 
920  /* test data for CELL4REG */
921  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
922  test_buffer[1] = MXM_REG_CELL4;
923  test_buffer[2] = 0xFCu;
924  test_buffer[3] = 0xFFu;
925  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
926  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
927  test_buffer_len = 6;
928  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
929  STD_OK) {
930  retval = STD_NOT_OK;
931  } else {
932  if (pInstance->localVoltages.cellVoltages[3] != 5000u) {
933  retval = STD_NOT_OK;
934  }
935  }
936 
937  /* null mxm_local_cellvoltages */
938  for (uint16_t i_3 = 0; i_3 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_3++) {
939  pInstance->localVoltages.cellVoltages[i_3] = 0;
940  }
941 
942  /* test data for CELL5REG */
943  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
944  test_buffer[1] = MXM_REG_CELL5;
945  test_buffer[2] = 0xFCu;
946  test_buffer[3] = 0xFFu;
947  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
948  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
949  test_buffer_len = 6;
950  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
951  STD_OK) {
952  retval = STD_NOT_OK;
953  } else {
954  if (pInstance->localVoltages.cellVoltages[4] != 5000u) {
955  retval = STD_NOT_OK;
956  }
957  }
958 
959  /* null mxm_local_cellvoltages */
960  for (uint16_t i_4 = 0; i_4 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_4++) {
961  pInstance->localVoltages.cellVoltages[i_4] = 0;
962  }
963 
964  /* test data for CELL6REG */
965  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
966  test_buffer[1] = MXM_REG_CELL6;
967  test_buffer[2] = 0xFCu;
968  test_buffer[3] = 0xFFu;
969  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
970  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
971  test_buffer_len = 6;
972  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
973  STD_OK) {
974  retval = STD_NOT_OK;
975  } else {
976  if (pInstance->localVoltages.cellVoltages[5] != 5000u) {
977  retval = STD_NOT_OK;
978  }
979  }
980 
981  /* null mxm_local_cellvoltages */
982  for (uint16_t i_5 = 0; i_5 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_5++) {
983  pInstance->localVoltages.cellVoltages[i_5] = 0;
984  }
985 
986  /* test data for CELL7REG */
987  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
988  test_buffer[1] = MXM_REG_CELL7;
989  test_buffer[2] = 0xFCu;
990  test_buffer[3] = 0xFFu;
991  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
992  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
993  test_buffer_len = 6;
994  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
995  STD_OK) {
996  retval = STD_NOT_OK;
997  } else {
998  if (pInstance->localVoltages.cellVoltages[6] != 5000u) {
999  retval = STD_NOT_OK;
1000  }
1001  }
1002 
1003  /* null mxm_local_cellvoltages */
1004  for (uint16_t i_6 = 0; i_6 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_6++) {
1005  pInstance->localVoltages.cellVoltages[i_6] = 0;
1006  }
1007 
1008  /* test data for CELL8REG */
1009  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1010  test_buffer[1] = MXM_REG_CELL8;
1011  test_buffer[2] = 0xFCu;
1012  test_buffer[3] = 0xFFu;
1013  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1014  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1015  test_buffer_len = 6;
1016  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1017  STD_OK) {
1018  retval = STD_NOT_OK;
1019  } else {
1020  if (pInstance->localVoltages.cellVoltages[7] != 5000u) {
1021  retval = STD_NOT_OK;
1022  }
1023  }
1024 
1025  /* null mxm_local_cellvoltages */
1026  for (uint16_t i_7 = 0; i_7 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_7++) {
1027  pInstance->localVoltages.cellVoltages[i_7] = 0;
1028  }
1029 
1030  /* test data for CELL9REG */
1031  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1032  test_buffer[1] = MXM_REG_CELL9;
1033  test_buffer[2] = 0xFCu;
1034  test_buffer[3] = 0xFFu;
1035  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1036  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1037  test_buffer_len = 6;
1038  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1039  STD_OK) {
1040  retval = STD_NOT_OK;
1041  } else {
1042  if (pInstance->localVoltages.cellVoltages[8] != 5000u) {
1043  retval = STD_NOT_OK;
1044  }
1045  }
1046 
1047  /* null mxm_local_cellvoltages */
1048  for (uint16_t i_8 = 0; i_8 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_8++) {
1049  pInstance->localVoltages.cellVoltages[i_8] = 0;
1050  }
1051 
1052  /* test data for CELL10REG */
1053  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1054  test_buffer[1] = MXM_REG_CELL10;
1055  test_buffer[2] = 0xFCu;
1056  test_buffer[3] = 0xFFu;
1057  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1058  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1059  test_buffer_len = 6;
1060  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1061  STD_OK) {
1062  retval = STD_NOT_OK;
1063  } else {
1064  if (pInstance->localVoltages.cellVoltages[9] != 5000u) {
1065  retval = STD_NOT_OK;
1066  }
1067  }
1068 
1069  /* null mxm_local_cellvoltages */
1070  for (uint16_t i_9 = 0; i_9 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_9++) {
1071  pInstance->localVoltages.cellVoltages[i_9] = 0;
1072  }
1073 
1074  /* test data for CELL11REG */
1075  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1076  test_buffer[1] = MXM_REG_CELL11;
1077  test_buffer[2] = 0xFCu;
1078  test_buffer[3] = 0xFFu;
1079  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1080  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1081  test_buffer_len = 6;
1082  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1083  STD_OK) {
1084  retval = STD_NOT_OK;
1085  } else {
1086  if (pInstance->localVoltages.cellVoltages[10] != 5000u) {
1087  retval = STD_NOT_OK;
1088  }
1089  }
1090 
1091  /* null mxm_local_cellvoltages */
1092  for (uint16_t i_10 = 0; i_10 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_10++) {
1093  pInstance->localVoltages.cellVoltages[i_10] = 0;
1094  }
1095 
1096  /* test data for CELL12REG */
1097  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1098  test_buffer[1] = MXM_REG_CELL12;
1099  test_buffer[2] = 0xFCu;
1100  test_buffer[3] = 0xFFu;
1101  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1102  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1103  test_buffer_len = 6;
1104  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1105  STD_OK) {
1106  retval = STD_NOT_OK;
1107  } else {
1108  if (pInstance->localVoltages.cellVoltages[11] != 5000u) {
1109  retval = STD_NOT_OK;
1110  }
1111  }
1112 
1113  /* null mxm_local_cellvoltages */
1114  for (uint16_t i_11 = 0; i_11 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_11++) {
1115  pInstance->localVoltages.cellVoltages[i_11] = 0;
1116  }
1117 
1118  /* test data for CELL13REG */
1119  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1120  test_buffer[1] = MXM_REG_CELL13;
1121  test_buffer[2] = 0xFCu;
1122  test_buffer[3] = 0xFFu;
1123  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1124  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1125  test_buffer_len = 6;
1126  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1127  STD_OK) {
1128  retval = STD_NOT_OK;
1129  } else {
1130  if (pInstance->localVoltages.cellVoltages[12] != 5000u) {
1131  retval = STD_NOT_OK;
1132  }
1133  }
1134 
1135  /* null mxm_local_cellvoltages */
1136  for (uint16_t i_12 = 0; i_12 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_12++) {
1137  pInstance->localVoltages.cellVoltages[i_12] = 0;
1138  }
1139 
1140  /* test data for CELL14REG */
1141  test_buffer[0] = BATTERY_MANAGEMENT_READALL;
1142  test_buffer[1] = MXM_REG_CELL14;
1143  test_buffer[2] = 0xFCu;
1144  test_buffer[3] = 0xFFu;
1145  test_buffer[4] = 0x42u; /* DATACHECKBYTE, irrelevant for function, filled with dummy bytes */
1146  test_buffer[5] = 0x44u; /* CRCBYTE, irrelevant for function, filled with dummy bytes */
1147  test_buffer_len = 6;
1148  if (MXM_ParseVoltageReadall(test_buffer, test_buffer_len, &pInstance->localVoltages, MXM_CONVERSION_UNIPOLAR) !=
1149  STD_OK) {
1150  retval = STD_NOT_OK;
1151  } else {
1152  if (pInstance->localVoltages.cellVoltages[13] != 5000u) {
1153  retval = STD_NOT_OK;
1154  }
1155  }
1156 
1157  /* null mxm_local_cellvoltages */
1158  for (uint16_t i_13 = 0; i_13 < (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE * MXM_MAXIMUM_NR_OF_MODULES); i_13++) {
1159  pInstance->localVoltages.cellVoltages[i_13] = 0;
1160  }
1161 
1162  return retval;
1163 }
1164 
1167  FAS_ASSERT(pState != NULL_PTR);
1169  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1170  pState->batteryCmdBuffer.regAddress = regAddress;
1173  } else if (pState->requestStatus5x == MXM_5X_STATE_PROCESSED) {
1175  uint8_t temp_len = BATTERY_MANAGEMENT_TX_LENGTH_READALL +
1176  (2u * MXM_5XGetNumberOfSatellites(pState->pInstance5X));
1177  if (regAddress == MXM_REG_BLOCK) {
1179  } else {
1181  }
1183  retval = MXM_MONITORING_STATE_PASS;
1184  } else if (pState->requestStatus5x == MXM_5X_STATE_UNPROCESSED) {
1185  /* do nothing */
1186  } else if (pState->requestStatus5x == MXM_5X_STATE_ERROR) {
1187  /* try to reset state */
1189  } else {
1190  /* invalid state --> trap */
1192  }
1193  return retval;
1194 }
1195 
1197  FAS_ASSERT(pInstance != NULL_PTR);
1198  STD_RETURN_TYPE_e retval = STD_OK;
1199 
1200  /* voltages */
1201  for (uint8_t i_mod = 0; i_mod < (BS_NR_OF_MODULES * BS_NR_OF_STRINGS); i_mod++) {
1202  if (i_mod < MXM_MAXIMUM_NR_OF_MODULES) {
1203  uint8_t stringNumber = 0u;
1204  uint16_t moduleNumber = 0u;
1205  MXM_ConvertModuleToString(i_mod, &stringNumber, &moduleNumber);
1206  mxm_cellVoltages.moduleVoltage_mV[stringNumber][moduleNumber] =
1207  pInstance->localVoltages.blockVoltages[i_mod];
1208  /* every iteration that we hit a string first (module 0), we reset the packvoltage counter */
1209  if (moduleNumber == 0u) {
1210  mxm_cellVoltages.packVoltage_mV[stringNumber] = 0;
1211  }
1212  mxm_cellVoltages.packVoltage_mV[stringNumber] += pInstance->localVoltages.blockVoltages[i_mod];
1213  for (uint8_t i_bat = 0; i_bat < BS_NR_OF_CELLS_PER_MODULE; i_bat++) {
1214  if (i_bat < MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE) {
1215  uint16_t cell_counter_db = (moduleNumber * BS_NR_OF_CELLS_PER_MODULE) + i_bat;
1216  uint16_t cell_counter_max = (i_mod * MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE) + i_bat;
1217  mxm_cellVoltages.cellVoltage_mV[stringNumber][cell_counter_db] =
1218  pInstance->localVoltages.cellVoltages[cell_counter_max];
1219  }
1220  }
1221  } else {
1222  retval = STD_NOT_OK;
1223  }
1224  }
1225 
1226  /* temperatures */
1227  for (uint8_t i_mod = 0; i_mod < (BS_NR_OF_MODULES * BS_NR_OF_STRINGS); i_mod++) {
1228  if (i_mod < MXM_MAXIMUM_NR_OF_MODULES) {
1229  uint8_t stringNumber = 0u;
1230  uint16_t moduleNumber = 0u;
1231  MXM_ConvertModuleToString(i_mod, &stringNumber, &moduleNumber);
1232  /* TODO make configurable for all number of temperatures */
1233  for (uint8_t i_t = 0; i_t < BS_NR_OF_TEMP_SENSORS_PER_MODULE; i_t++) {
1235  uint16_t t_counter_db = (moduleNumber * BS_NR_OF_TEMP_SENSORS_PER_MODULE) + i_t;
1236  uint16_t t_counter_max = (i_mod * MXM_MAXIMUM_NR_OF_AUX_PER_MODULE) + i_t;
1237  /* TODO refactor into nice code */
1238  uint16_t volt_temp = (pInstance->localVoltages.auxVoltages[t_counter_max] /
1239  ((float)3300 - pInstance->localVoltages.auxVoltages[t_counter_max])) *
1240  1000;
1241 
1242  int16_t temperature_ddegC = TSI_GetTemperature(volt_temp);
1243  mxm_cellTemperatures.cellTemperature_ddegC[stringNumber][t_counter_db] = temperature_ddegC;
1244  }
1245  }
1246  } else {
1247  retval = STD_NOT_OK;
1248  }
1249  }
1250 
1252 
1253  return retval;
1254 }
1255 
1257  FAS_ASSERT(pState != NULL_PTR);
1258  STD_RETURN_TYPE_e retval = STD_OK;
1259  pState->selfCheck.crc = MXM_CRC8SelfTest();
1260  pState->selfCheck.conv = MXM_ConvertTest();
1265 
1266  if ((pState->selfCheck.crc == STD_OK) && (pState->selfCheck.addressSpaceChecker == STD_OK) &&
1267  (pState->selfCheck.conv == STD_OK) && (pState->selfCheck.firstSetBit == STD_OK) &&
1269  retval = STD_OK;
1270  } else {
1271  retval = STD_NOT_OK;
1272  }
1273 
1274  return retval;
1275 }
1276 
1278  pState->operationRequested = false;
1279  /* TODO handle transition to measurement states properly with dedicated state-machine */
1280  /* TODO parse DATACHECKBYTE where available */
1281 
1283 
1284  switch (pState->operationSubstate) {
1287  /* set SCANSTROBE, enable 4x OVERSAMPL */
1288  pState->batteryCmdBuffer.lsb = 0x09u;
1289  /* enable AUTOBALSWDIS */
1290  pState->batteryCmdBuffer.msb = 0x10u;
1292 
1293  break;
1296  /* no additional handling needed */
1297  }
1298  break;
1299  case MXM_OP_GET_VOLTAGES:
1300  temp_mon_state = MXM_MonGetVoltages(pState, mxm_voltageCellAddresses[pState->mxmVoltageCellCounter]);
1301 
1302  if (temp_mon_state == MXM_MONITORING_STATE_PASS) {
1303  pState->mxmVoltageCellCounter++;
1304  /* modified: read one additional aux entry */
1306  pState->mxmVoltageCellCounter = 0;
1308  }
1309  } else if (temp_mon_state == MXM_MONITORING_STATE_FAIL) {
1310  /* reinitialize */
1312  }
1313  break;
1314  case MXM_OP_GET_ALRTSUM:
1316  /* no additional handling needed */
1317  }
1318  break;
1320  if (MXM_ParseVoltagesIntoDB(pState) == STD_OK) {
1322  pState->firstMeasurementDone = true;
1323  }
1324  if (pState->stopRequested == true) {
1326  } else {
1327  /* do nothing */
1328  }
1329  break;
1330  case MXM_OP_PINOPEN_ENTRY:
1331  if (pState->openwireRequested == true) {
1333  pState->openwireRequested = false;
1334  } else {
1336  }
1337  break;
1338  case MXM_OP_PINOPEN_EXIT:
1340  break;
1342  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1344  pState->batteryCmdBuffer.lsb = 0xFFu;
1345  pState->batteryCmdBuffer.msb = 0xFFu; /* execute diagnostic on every cell */
1346  }
1348  break;
1350  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1352  pState->batteryCmdBuffer.lsb = 0x81u;
1353  pState->batteryCmdBuffer.msb = 0x00u; /* request comp scan */
1354  }
1356  break;
1359  /* no additional handling needed */
1360  }
1361  break;
1364  /* no additional handling needed */
1365  }
1366  break;
1370  break;
1372  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1374  pState->batteryCmdBuffer.lsb = 0x00u;
1375  pState->batteryCmdBuffer.msb = 0x00u;
1376  }
1378  break;
1379  case MXM_OP_BAL_ENTRY:
1380  /* Get the current time */
1382 
1383  /* NOTE: The overflow of the timer (coded on 32bits) is handled by the CPU
1384  Wait 'MXM_DELAY_BALANCING' milliseconds before processing the balancing */
1386  /* nothing to do, exit balancing state chain */
1388  } else {
1389  /* Balancing needs to be processed */
1391  /* First reset the balancing switches, and THEN
1392  set the balancing switches according to the database */
1394 
1395  /* Change the parity of cells to balance */
1396  if (mxm_evenCellsBalancingProcessed == 1u) {
1399  }
1400  /* Same for odd cells */
1401  if (mxm_oddCellsBalancingProcessed == 1u) {
1404  }
1405  }
1406  break;
1408  /* Send a WRITEALL command to open all balancing switches */
1409  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1411  /* CBRESTART is not reset to 0, not needed. */
1412  pState->batteryCmdBuffer.lsb = 0x00U;
1413  pState->batteryCmdBuffer.msb = 0x00U;
1414  }
1416  break;
1418  /* Send a WRITEDEVICE command to each module in a daisy-chain
1419  to close appropriate balancing switches */
1420  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1423 
1425  if (STD_OK == database_retval) {
1426  /* Construct the balancing buffer */
1428 
1429  if (retval == STD_OK) {
1430  if (mxm_cellsToBalance > 0u) {
1431  /* Some cells need to be balanced */
1434  pState->batteryCmdBuffer.lsb = (uint8_t)mxm_cellsToBalance;
1435  pState->batteryCmdBuffer.msb = (uint8_t)(mxm_cellsToBalance >> 8u);
1437  pState->pInstance5X,
1439  pState->batteryCmdBuffer,
1440  &pState->requestStatus5x);
1441  } else {
1442  /* It is not necessary to re-send 0 to the device, because it has been done previously
1443  in the BALANCING_CONTROL_RESET_ALL sub-state */
1445  }
1446 
1447  } else {
1448  /* this should not happen if the software works as expected */
1449  /* TODO review this trap */
1450  /* FAS_ASSERT(FAS_TRAP); */
1452  }
1453  } else {
1454  /* database read not successful, retry */
1456  }
1457  } else if (pState->requestStatus5x == MXM_5X_STATE_UNPROCESSED) {
1458  /* wait for processing */
1459  } else if (pState->requestStatus5x == MXM_5X_STATE_PROCESSED) {
1460  if (mxm_moduleBalancingIndex < pState->highest5xDevice) {
1461  /* Not all modules have been treated. Repeat this state with the next module */
1464  } else {
1465  /* Finished the iteration of all modules in a daisy chain, continue */
1467 
1468  /* Update flags for the end of balancing */
1469  if (mxm_evenCellsNeedBalancing == 1u) {
1471  } else if (mxm_oddCellsNeedBalancing == 1u) {
1473  }
1474  }
1475 
1476  /* Re-set the status to UNSENT to repeat the WRITE operation */
1479  } else if (pState->requestStatus5x == MXM_5X_STATE_ERROR) {
1481  }
1482  break;
1483  case MXM_OP_BAL_START:
1484  /* Initiate balancing for all devices in a daisy chain */
1485  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1487  /* Manual ON MODE + Balancing halt in case of High temperature
1488  + Alert when cell balancing is finished */
1489  pState->batteryCmdBuffer.lsb = 0x0EU;
1490  pState->batteryCmdBuffer.msb = 0x18U;
1491  }
1493  break;
1494  case MXM_OP_BAL_EXIT:
1496  break;
1497  /* "initialization" from here on */
1498  case MXM_INIT_DEVCFG1:
1499  /* switch to single UART with external loopback */
1500  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1502  pState->batteryCmdBuffer.lsb = 0x02u;
1503  pState->batteryCmdBuffer.msb = 0x01u;
1504  }
1506  break;
1507  case MXM_INIT_SET_FMEA2:
1508  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1510  pState->batteryCmdBuffer.lsb = 0x00u;
1511  pState->batteryCmdBuffer.msb = 0x00u;
1512  }
1514  break;
1515  case MXM_INIT_STATUS1:
1516  /* clear ALRTRST */
1517  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1519  pState->batteryCmdBuffer.lsb = 0x00u;
1520  pState->batteryCmdBuffer.msb = 0x00u;
1521  }
1523  break;
1524  case MXM_INIT_GET_VERSION:
1525  /* add version information to registry */
1527  uint8_t temp_len = BATTERY_MANAGEMENT_TX_LENGTH_READALL +
1528  (2u * MXM_5XGetNumberOfSatellites(pState->pInstance5X));
1529  MXM_MonRegistryParseVersionIntoDevices(pState, temp_len);
1530  }
1531  break;
1532  case MXM_INIT_GET_ID1:
1533  /* add ID1 to registry */
1534  if (true == MXM_HandleStateReadall(pState, MXM_REG_ID1, MXM_INIT_GET_ID2)) {
1535  uint8_t temp_len = BATTERY_MANAGEMENT_TX_LENGTH_READALL +
1536  (2u * MXM_5XGetNumberOfSatellites(pState->pInstance5X));
1538  }
1539  break;
1540  case MXM_INIT_GET_ID2:
1541  /* add ID2 to registry */
1542  if (true == MXM_HandleStateReadall(pState, MXM_REG_ID2, MXM_INIT_MEASUREEN1)) {
1543  uint8_t temp_len = BATTERY_MANAGEMENT_TX_LENGTH_READALL +
1544  (2u * MXM_5XGetNumberOfSatellites(pState->pInstance5X));
1546  }
1547  break;
1548  case MXM_INIT_MEASUREEN1:
1549  /* enable all 14 cells */
1550  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1552  pState->batteryCmdBuffer.lsb = 0xFFu;
1553  pState->batteryCmdBuffer.msb = 0x7Fu; /* TODO this also enables block measurement */
1554  }
1556  break;
1557  case MXM_INIT_MEASUREEN2:
1558  /* enable AUX0 and AUX2 */
1559  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1561  pState->batteryCmdBuffer.lsb = 0x65u;
1562  pState->batteryCmdBuffer.msb = 0x00u;
1563  }
1565  break;
1566  case MXM_INIT_AUXGPIOCFG:
1567  /* switch GPIO0 and GPIO2 to AUX */
1568  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1570  pState->batteryCmdBuffer.lsb = 0x00u;
1571  /* pState->batteryCmdBuffer.msb = 0x3Eu; */ /* conf for MAX17853 */
1572  /*pState->batteryCmdBuffer.msb = 0x8Eu; */ /* conf for MAX17852, I2C enable */
1573  /* conf for Autodrive test AUX0 and AUX2 */
1574  pState->batteryCmdBuffer.msb = 0x0Au;
1575  }
1577  break;
1578  case MXM_INIT_UVTHSETREG:
1579  /* configure UVTHSETREG */
1580  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1583  MXM_VoltageIntoUnipolar14Bit(1700u, 5000u),
1584  &pState->batteryCmdBuffer.lsb,
1585  &pState->batteryCmdBuffer.msb);
1586  }
1588  break;
1589  case MXM_INIT_OVTHSETREG:
1590  /* configure OVTHSETREG */
1591  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1594  MXM_VoltageIntoUnipolar14Bit(3300u, 5000u),
1595  &pState->batteryCmdBuffer.lsb,
1596  &pState->batteryCmdBuffer.msb);
1597  }
1599  break;
1600  case MXM_INIT_BALEXP1:
1601  /* set BALEXP1 to have 1 minute timeout in manual balancing */
1602  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1604  pState->batteryCmdBuffer.lsb = 0x01u;
1605  pState->batteryCmdBuffer.msb = 0x00u;
1606  }
1608  break;
1609  case MXM_INIT_BALEXP2:
1610  /* set BALEXP2 to have 1 minute timeout in manual balancing */
1611  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1613  pState->batteryCmdBuffer.lsb = 0x01u;
1614  pState->batteryCmdBuffer.msb = 0x00u;
1615  }
1617  break;
1618  case MXM_INIT_BALEXP3:
1619  /* set BALEXP3 to have 1 minute timeout in manual balancing */
1620  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1622  pState->batteryCmdBuffer.lsb = 0x01u;
1623  pState->batteryCmdBuffer.msb = 0x00u;
1624  }
1626  break;
1627  case MXM_INIT_BALEXP4:
1628  /* set BALEXP4 to have 1 minute timeout in manual balancing */
1629  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1631  pState->batteryCmdBuffer.lsb = 0x01u;
1632  pState->batteryCmdBuffer.msb = 0x00u;
1633  }
1635  break;
1636  case MXM_INIT_BALEXP5:
1637  /* set BALEXP5 to have 1 minute timeout in manual balancing */
1638  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1640  pState->batteryCmdBuffer.lsb = 0x01u;
1641  pState->batteryCmdBuffer.msb = 0x00u;
1642  }
1644  break;
1645  case MXM_INIT_BALEXP6:
1646  /* set BALEXP6 to have 1 minute timeout in manual balancing */
1647  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1649  pState->batteryCmdBuffer.lsb = 0x01u;
1650  pState->batteryCmdBuffer.msb = 0x00u;
1651  }
1653  break;
1654  case MXM_INIT_BALEXP7:
1655  /* set BALEXP7 to have 1 minute timeout in manual balancing */
1656  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1658  pState->batteryCmdBuffer.lsb = 0x01u;
1659  pState->batteryCmdBuffer.msb = 0x00u;
1660  }
1662  break;
1663  case MXM_INIT_BALEXP8:
1664  /* set BALEXP8 to have 1 minute timeout in manual balancing */
1665  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1667  pState->batteryCmdBuffer.lsb = 0x01u;
1668  pState->batteryCmdBuffer.msb = 0x00u;
1669  }
1671  break;
1672  case MXM_INIT_BALEXP9:
1673  /* set BALEXP9 to have 1 minute timeout in manual balancing */
1674  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1676  pState->batteryCmdBuffer.lsb = 0x01u;
1677  pState->batteryCmdBuffer.msb = 0x00u;
1678  }
1680  break;
1681  case MXM_INIT_BALEXP10:
1682  /* set BALEXP10 to have 1 minute timeout in manual balancing */
1683  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1685  pState->batteryCmdBuffer.lsb = 0x01u;
1686  pState->batteryCmdBuffer.msb = 0x00u;
1687  }
1689  break;
1690  case MXM_INIT_BALEXP11:
1691  /* set BALEXP11 to have 1 minute timeout in manual balancing */
1692  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1694  pState->batteryCmdBuffer.lsb = 0x01u;
1695  pState->batteryCmdBuffer.msb = 0x00u;
1696  }
1698  break;
1699  case MXM_INIT_BALEXP12:
1700  /* set BALEXP12 to have 1 minute timeout in manual balancing */
1701  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1703  pState->batteryCmdBuffer.lsb = 0x01u;
1704  pState->batteryCmdBuffer.msb = 0x00u;
1705  }
1707  break;
1708  case MXM_INIT_BALEXP13:
1709  /* set BALEXP13 to have 1 minute timeout in manual balancing */
1710  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1712  pState->batteryCmdBuffer.lsb = 0x01u;
1713  pState->batteryCmdBuffer.msb = 0x00u;
1714  }
1716  break;
1717  case MXM_INIT_BALEXP14:
1718  /* set BALEXP14 to have 1 minute timeout in manual balancing */
1719  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1721  pState->batteryCmdBuffer.lsb = 0x01u;
1722  pState->batteryCmdBuffer.msb = 0x00u;
1723  }
1725  break;
1726  case MXM_INIT_BALSWDLY:
1727  /* set BALSWDLY to 2 ms settling time after balancing */
1728  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1730  /* CELLDLY = 1920us (~2ms) --> 20*96us
1731  CELLDLY corresponds to the time to relax the cell before voltage measurement */
1732  pState->batteryCmdBuffer.lsb = 0x00u;
1733  pState->batteryCmdBuffer.msb = 0x14u;
1734  }
1736  break;
1737  case MXM_INIT_ALRTOVEN:
1738  /* enable ALRTOVEN */
1739  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1741  pState->batteryCmdBuffer.lsb = 0xFFu;
1742  pState->batteryCmdBuffer.msb = 0x3Fu;
1743  }
1745  break;
1746  case MXM_INIT_ALRTUVEN:
1747  /* enable ALRTUVEN */
1748  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1750  pState->batteryCmdBuffer.lsb = 0xFFu;
1751  pState->batteryCmdBuffer.msb = 0x3Fu;
1752  }
1754  break;
1755  case MXM_INIT_COMPOPNTHREG:
1756  /* configure COMPOPNTHREG */
1757  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1759  /* TODO 0.5V */
1761  MXM_VoltageIntoUnipolar14Bit(500u, 5000u),
1762  &pState->batteryCmdBuffer.lsb,
1763  &pState->batteryCmdBuffer.msb);
1764  }
1766  break;
1769  /* no additional handling needed */
1770  }
1771  break;
1772  case MXM_INIT_I2C_CFG:
1773  /* configure I2CCFG */
1774  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1776  pState->batteryCmdBuffer.lsb = 0x00u;
1777  pState->batteryCmdBuffer.msb = 0xA0u;
1778  }
1780  break;
1781  case MXM_INIT_I2C_PNTR:
1782  /* configure I2CPNTR */
1783  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1785  pState->batteryCmdBuffer.lsb = 0x06u;
1786  pState->batteryCmdBuffer.msb = 0x00u;
1787  }
1789  break;
1790  case MXM_INIT_I2C_WDATA2:
1791  /* configure I2CPNTR */
1792  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1794  pState->batteryCmdBuffer.lsb = 0x00u;
1795  pState->batteryCmdBuffer.msb = 0xFFu;
1796  }
1798  break;
1799  case MXM_INIT_I2C_SEND:
1800  /* configure I2CPNTR */
1801  if (pState->requestStatus5x == MXM_5X_STATE_UNSENT) {
1803  pState->batteryCmdBuffer.lsb = 0xE8u;
1804  pState->batteryCmdBuffer.msb = 0x08u;
1805  }
1807  break;
1810  /* no additional handling needed */
1811  }
1812  break;
1813  default:
1814  /* invalid state --> trap */
1816  break;
1817  }
1818 
1819  return;
1820 }
1821 
1822 /*========== Extern Function Implementations ================================*/
1823 
1825  FAS_ASSERT(pInstance != NULL_PTR);
1826 
1827  if (pInstance->state == MXM_STATEMACHINE_STATES_UNINITIALIZED) {
1828  pInstance->requestStatus5x = MXM_5X_STATE_UNSENT;
1829  MXM_MonRegistryInit(pInstance);
1831  }
1832 
1833  switch (pInstance->state) {
1835  /* TODO proper selfchecks, that are only executed during IBIT, CBIT and PBIT */
1836  pInstance->resultSelfCheck = MXM_PreInitSelfCheck(pInstance);
1837  if (pInstance->resultSelfCheck == STD_OK) {
1838  pInstance->requestStatus5x = MXM_5X_STATE_UNSENT;
1839  pInstance->state = MXM_STATEMACHINE_STATES_INIT;
1840  } else {
1841  /* software is broken by configuration/design */
1843  }
1844  break;
1846  if (pInstance->requestStatus5x == MXM_5X_STATE_UNSENT) {
1848  pInstance->pInstance5X,
1850  pInstance->batteryCmdBuffer,
1851  &pInstance->requestStatus5x);
1852  } else if (pInstance->requestStatus5x == MXM_5X_STATE_UNPROCESSED) {
1853  /* just wait */
1854  /* TODO timeout? */
1855  } else if (pInstance->requestStatus5x == MXM_5X_STATE_ERROR) {
1856  /* TODO error handling */
1857  } else if (pInstance->allowStartup == false) {
1858  /* do not start yet, just wait */
1859 
1860  } else if ((pInstance->requestStatus5x == MXM_5X_STATE_PROCESSED) && (pInstance->allowStartup == true)) {
1861  /* update registry */
1862  /* TODO handle return value of this function */
1864  pInstance->requestStatus5x = MXM_5X_STATE_UNSENT;
1866  } else {
1868  }
1869 
1870  break;
1872  /* TODO more checks */
1873  pInstance->selfCheck.fmeaStatusASCI = STD_NOT_OK;
1874  if (pInstance->requestStatus5x == MXM_5X_STATE_UNSENT) {
1876  pInstance->pInstance5X,
1878  pInstance->batteryCmdBuffer,
1879  &pInstance->requestStatus5x);
1880  } else if (pInstance->requestStatus5x == MXM_5X_STATE_UNPROCESSED) {
1881  /* just wait */
1882  /* TODO timeout? */
1883  } else if (pInstance->requestStatus5x == MXM_5X_STATE_ERROR) {
1884  pInstance->selfCheck.fmeaStatusASCI = STD_NOT_OK;
1885  /* TODO configuration or hardware failure */
1886  pInstance->resultSelfCheck = STD_NOT_OK;
1888  } else if (pInstance->requestStatus5x == MXM_5X_STATE_PROCESSED) {
1889  pInstance->selfCheck.fmeaStatusASCI = STD_OK;
1890  if ((pInstance->resultSelfCheck == STD_OK) && (pInstance->selfCheck.fmeaStatusASCI == STD_OK) &&
1892  pInstance->resultSelfCheck = STD_OK;
1893  pInstance->requestStatus5x = MXM_5X_STATE_UNSENT;
1894  pInstance->state = MXM_STATEMACHINE_STATES_IDLE;
1895  }
1896  } else {
1898  }
1899  break;
1901  pInstance->stopRequested = false;
1902  if (pInstance->operationRequested == true) {
1904  } else {
1905  /* Do nothing */
1906  }
1907  break;
1909  MXM_StateMachineOperation(pInstance);
1910  break;
1911  default:
1913  break;
1914  }
1915  return;
1916 }
1917 
1918 /*========== Externalized Static Function Implementations (Unit Test) =======*/
1919 #ifdef UNITY_UNIT_TEST
1921  return MXM_ParseVoltageReadallTest(pInstance);
1922 }
1924  return MXM_ParseVoltagesIntoDB(pInstance);
1925 }
1927  MXM_MONITORING_INSTANCE_s *pInstance,
1928  MXM_REG_NAME_e regAddress) {
1929  return MXM_MonGetVoltages(pInstance, regAddress);
1930 }
1932  MXM_MONITORING_INSTANCE_s *pInstance,
1934  MXM_HandleStateWriteall(pInstance, nextState);
1935 }
1937  MXM_MONITORING_INSTANCE_s *pInstance,
1938  MXM_REG_NAME_e registerName,
1940  return MXM_HandleStateReadall(pInstance, registerName, nextState);
1941 }
1943  uint8_t *volt_rx_buffer,
1944  uint16_t volt_rx_buffer_len,
1945  MXM_DATA_STORAGE_s *datastorage,
1946  MXM_CONVERSION_TYPE_e conversionType) {
1947  return MXM_ParseVoltageReadall(volt_rx_buffer, volt_rx_buffer_len, datastorage, conversionType);
1948 }
1950  MXM_ProcessOpenWire(pInstance, pDataOpenWire);
1951 }
1952 #endif
MXM_CONVERSION_BLOCK_VOLTAGE
@ MXM_CONVERSION_BLOCK_VOLTAGE
Definition: mxm_basic_defines.h:133
MXM_INIT_GET_VERSION
@ MXM_INIT_GET_VERSION
Definition: mxm_1785x_tools.h:88
os.h
Implementation of the tasks used by the system, headers.
MXM_OP_SET_SCAN_STROBE
@ MXM_OP_SET_SCAN_STROBE
Definition: mxm_1785x_tools.h:121
MXM_ExtractValueFromRegisterTest
STD_RETURN_TYPE_e must_check_return MXM_ExtractValueFromRegisterTest()
Test MXM_ExtractValueFromRegister().
Definition: mxm_1785x_tools.c:176
MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE
#define MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE
Maximum number of cells per module.
Definition: mxm_basic_defines.h:81
MXM_STATEMACHINE_STATES_IDLE
@ MXM_STATEMACHINE_STATES_IDLE
Definition: mxm_1785x_tools.h:79
MXM_REG_BLOCK
@ MXM_REG_BLOCK
Definition: mxm_register_map.h:338
MXM_MonRegistryParseVersionIntoDevices
void MXM_MonRegistryParseVersionIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength)
Parse Version into the registry.
Definition: mxm_registry.c:134
mxm_moduleBalancingIndex
static uint8_t mxm_moduleBalancingIndex
Module index in the daisy chain.
Definition: mxm_1785x.c:135
MXM_MONITORING_INSTANCE::mxmVoltageCellCounter
uint8_t mxmVoltageCellCounter
Definition: mxm_1785x_tools.h:199
MXM_REG_I2CWDATA2
@ MXM_REG_I2CWDATA2
Definition: mxm_register_map.h:598
MXM_INIT_I2C_CFG
@ MXM_INIT_I2C_CFG
Definition: mxm_1785x_tools.h:115
MXM_REG_BALSWCTRL
@ MXM_REG_BALSWCTRL
Definition: mxm_register_map.h:437
MXM_DATA_STORAGE
Definition: mxm_basic_defines.h:146
DATA_BLOCK_OPENWIRE
Definition: database_cfg.h:296
MXM_MONITORING_INSTANCE::pInstance5X
MXM_5X_INSTANCE_s * pInstance5X
Definition: mxm_1785x_tools.h:206
MXM_REG_MEASUREEN2
@ MXM_REG_MEASUREEN2
Definition: mxm_register_map.h:389
MXM_SELFCHECK::crc
STD_RETURN_TYPE_e crc
Definition: mxm_1785x_tools.h:152
MXM_PreInitSelfCheck
static STD_RETURN_TYPE_e must_check_return MXM_PreInitSelfCheck(MXM_MONITORING_INSTANCE_s *pState)
Execute all preinit selfchecks.
Definition: mxm_1785x.c:1256
TEST_MXM_HandleStateReadall
bool TEST_MXM_HandleStateReadall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e registerName, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Definition: mxm_1785x.c:1936
MXM_MONINTORING_STATE_e
enum MXM_MONITORING_STATE MXM_MONINTORING_STATE_e
MXM_CONVERSION_TYPE_e
enum MXM_CONVERSION_TYPE MXM_CONVERSION_TYPE_e
MXM_INIT_GET_ID2
@ MXM_INIT_GET_ID2
Definition: mxm_1785x_tools.h:90
MXM_SELFCHECK::addressSpaceChecker
STD_RETURN_TYPE_e addressSpaceChecker
Definition: mxm_1785x_tools.h:160
MXM_REG_ALRTCOMPUV
@ MXM_REG_ALRTCOMPUV
Definition: mxm_register_map.h:118
MXM_CRC8SelfTest
STD_RETURN_TYPE_e must_check_return MXM_CRC8SelfTest()
Test the CRC8-algorithm with a known pattern.
Definition: mxm_crc8.c:121
MXM_REG_CELL9
@ MXM_REG_CELL9
Definition: mxm_register_map.h:320
MXM_INIT_GET_I2C_STAT2
@ MXM_INIT_GET_I2C_STAT2
Definition: mxm_1785x_tools.h:119
MXM_HandleStateReadall
static bool must_check_return MXM_HandleStateReadall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e registerName, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a READALL.
Definition: mxm_1785x.c:418
MXM_REG_BALEXP1
@ MXM_REG_BALEXP1
Definition: mxm_register_map.h:443
MXM_MONITORING_INSTANCE
Definition: mxm_1785x_tools.h:188
BS_NR_OF_MODULES
#define BS_NR_OF_MODULES
number of modules in battery pack
Definition: battery_system_cfg.h:96
MXM_SELFCHECK::parseVoltageReadall
STD_RETURN_TYPE_e parseVoltageReadall
Definition: mxm_1785x_tools.h:158
MXM_REG_UVTHSET
@ MXM_REG_UVTHSET
Definition: mxm_register_map.h:185
DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
Definition: database_cfg.h:95
MXM_INIT_ALRTUVEN
@ MXM_INIT_ALRTUVEN
Definition: mxm_1785x_tools.h:112
MXM_OP_BAL_EXIT
@ MXM_OP_BAL_EXIT
Definition: mxm_1785x_tools.h:138
MXM_MONITORING_INSTANCE::dcByte
MXM_DC_BYTE_e dcByte
Definition: mxm_1785x_tools.h:198
DATA_BLOCK_ID_OPEN_WIRE_BASE
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
Definition: database_cfg.h:81
MXM_ConvertModuleToString
void MXM_ConvertModuleToString(const uint16_t moduleNumber, uint8_t *pStringNumber, uint16_t *pModuleNumberInString)
Get the string and module number from a global module number.
Definition: mxm_1785x_tools.c:224
MXM_INIT_BALEXP9
@ MXM_INIT_BALEXP9
Definition: mxm_1785x_tools.h:104
DATA_BLOCK_CELL_VOLTAGE::moduleVoltage_mV
uint32_t moduleVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
Definition: database_cfg.h:126
MXM_STATEMACHINE_OPERATION_STATES_e
MXM_STATEMACHINE_OPERATION_STATES_e
Definition: mxm_1785x_tools.h:85
MXM_OP_PINOPEN_GET_ALRT
@ MXM_OP_PINOPEN_GET_ALRT
Definition: mxm_1785x_tools.h:131
STD_RETURN_TYPE_e
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
MXM_STATEMACH_5X_41B_FMEA_CHECK
@ MXM_STATEMACH_5X_41B_FMEA_CHECK
Definition: mxm_battery_management.h:154
MXM_STATEMACHINE_STATES_INIT
@ MXM_STATEMACHINE_STATES_INIT
Definition: mxm_1785x_tools.h:77
MXM_MONITORING_STATE_PENDING
@ MXM_MONITORING_STATE_PENDING
Definition: mxm_1785x_tools.h:143
MXM_REG_I2CSEND
@ MXM_REG_I2CSEND
Definition: mxm_register_map.h:646
MXM_REG_CELL10
@ MXM_REG_CELL10
Definition: mxm_register_map.h:323
MXM_OP_PINOPEN_COMPSCAN
@ MXM_OP_PINOPEN_COMPSCAN
Definition: mxm_1785x_tools.h:129
BATTERY_MANAGEMENT_READALL
#define BATTERY_MANAGEMENT_READALL
READALL message (read single register of all daisy-chain devices)
Definition: mxm_battery_management.h:119
MXM_INIT_I2C_PNTR
@ MXM_INIT_I2C_PNTR
Definition: mxm_1785x_tools.h:116
MXM_SELFCHECK::fmeaStatusASCI
STD_RETURN_TYPE_e fmeaStatusASCI
Definition: mxm_1785x_tools.h:162
diag.h
Diagnosis driver header.
MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck
STD_RETURN_TYPE_e must_check_return MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck(void)
runs a selfcheck for the address space check
Definition: mxm_battery_management.c:981
MXM_OP_PINOPEN_PROCESS_OPENWIRE
@ MXM_OP_PINOPEN_PROCESS_OPENWIRE
Definition: mxm_1785x_tools.h:132
MXM_REG_ALRTUVEN
@ MXM_REG_ALRTUVEN
Definition: mxm_register_map.h:160
MXM_ParseVoltageReadallTest
static STD_RETURN_TYPE_e must_check_return MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
Test the MXM_ParseVoltageReadall()-function.
Definition: mxm_1785x.c:805
mxm_previousTime
static uint32_t mxm_previousTime
Timers used to guarantee that balancing is performed periodically.
Definition: mxm_1785x.c:168
MXM_Convert
void MXM_Convert(uint8_t lsb, uint8_t msb, uint16_t *pTarget, MXM_CONVERSION_TYPE_e convType, uint32_t fullScaleReference_mV)
Convert a measurement value to a voltage value.
Definition: mxm_1785x_tools.c:98
MXM_REG_AUX2
@ MXM_REG_AUX2
Definition: mxm_register_map.h:356
MXM_STATEMACHINE_STATES_SELFCHECK_PRE_INIT
@ MXM_STATEMACHINE_STATES_SELFCHECK_PRE_INIT
Definition: mxm_1785x_tools.h:76
BS_NR_OF_TEMP_SENSORS_PER_MODULE
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
Definition: battery_system_cfg.h:153
MXM_OP_PINOPEN_GET_SCAN_STROBE
@ MXM_OP_PINOPEN_GET_SCAN_STROBE
Definition: mxm_1785x_tools.h:130
MXM_REG_BALEXP11
@ MXM_REG_BALEXP11
Definition: mxm_register_map.h:515
DATA_WRITE_DATA
#define DATA_WRITE_DATA(...)
Definition: database.h:82
MXM_MONITORING_INSTANCE::batteryCmdBuffer
MXM_5X_COMMAND_PAYLOAD_s batteryCmdBuffer
Definition: mxm_1785x_tools.h:202
TEST_MXM_ParseVoltageReadallTest
STD_RETURN_TYPE_e TEST_MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
Definition: mxm_1785x.c:1920
DATA_BLOCK_CELL_VOLTAGE::packVoltage_mV
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:121
MXM_INIT_BALSWDLY
@ MXM_INIT_BALSWDLY
Definition: mxm_1785x_tools.h:110
MXM_REG_BALEXP3
@ MXM_REG_BALEXP3
Definition: mxm_register_map.h:459
MXM_OP_BAL_CONTROL_SET_ALL
@ MXM_OP_BAL_CONTROL_SET_ALL
Definition: mxm_1785x_tools.h:136
MXM_GetDataFrom5XStateMachine
static void MXM_GetDataFrom5XStateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Retrieves data from lower statemachine and writes it to the rx buffer.
Definition: mxm_1785x.c:387
MXM_OP_GET_ALRTSUM
@ MXM_OP_GET_ALRTSUM
Definition: mxm_1785x_tools.h:124
MXM_5X_STATE_ERROR
@ MXM_5X_STATE_ERROR
Definition: mxm_battery_management.h:234
MXM_MONITORING_INSTANCE::rxBuffer
uint8_t rxBuffer[MXM_RX_BUFFER_LENGTH]
Definition: mxm_1785x_tools.h:223
MXM_REG_BALEXP5
@ MXM_REG_BALEXP5
Definition: mxm_register_map.h:473
MXM_ConvertTest
STD_RETURN_TYPE_e must_check_return MXM_ConvertTest()
Test the MXM_Convert()-function.
Definition: mxm_1785x_tools.c:127
MXM_REG_CELL13
@ MXM_REG_CELL13
Definition: mxm_register_map.h:332
MXM_INIT_I2C_GET_STAT1
@ MXM_INIT_I2C_GET_STAT1
Definition: mxm_1785x_tools.h:114
MXM_INIT_SET_FMEA2
@ MXM_INIT_SET_FMEA2
Definition: mxm_1785x_tools.h:120
BS_NR_OF_CELLS_PER_MODULE
#define BS_NR_OF_CELLS_PER_MODULE
number of battery cells per battery module (parallel cells are counted as one)
Definition: battery_system_cfg.h:104
MXM_REG_BALEXP12
@ MXM_REG_BALEXP12
Definition: mxm_register_map.h:522
MXM_INIT_BALEXP11
@ MXM_INIT_BALEXP11
Definition: mxm_1785x_tools.h:106
MXM_SELFCHECK::conv
STD_RETURN_TYPE_e conv
Definition: mxm_1785x_tools.h:153
MXM_StateMachineOperation
static void MXM_StateMachineOperation(MXM_MONITORING_INSTANCE_s *pState)
State-Machine implementation for operation state.
Definition: mxm_1785x.c:1277
BATTERY_MANAGEMENT_HELLOALL
#define BATTERY_MANAGEMENT_HELLOALL
HELLOALL message.
Definition: mxm_battery_management.h:94
MXM_MAXIMUM_NR_OF_AUX_PER_MODULE
#define MXM_MAXIMUM_NR_OF_AUX_PER_MODULE
Maximum number of AUX ports per module.
Definition: mxm_basic_defines.h:89
MXM_REG_VERSION
@ MXM_REG_VERSION
Definition: mxm_register_map.h:71
MXM_MonGetVoltages
static MXM_MONINTORING_STATE_e must_check_return MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pState, MXM_REG_NAME_e regAddress)
Encapsulation for reading voltages from a register.
Definition: mxm_1785x.c:1166
MXM_REG_CELL4
@ MXM_REG_CELL4
Definition: mxm_register_map.h:305
MXM_OP_BAL_CONTROL_RESET_ALL
@ MXM_OP_BAL_CONTROL_RESET_ALL
Definition: mxm_1785x_tools.h:135
MXM_REG_BALCTRL
@ MXM_REG_BALCTRL
Definition: mxm_register_map.h:564
MXM_REG_BALEXP14
@ MXM_REG_BALEXP14
Definition: mxm_register_map.h:536
MXM_REG_DEVCFG1
@ MXM_REG_DEVCFG1
Definition: mxm_register_map.h:134
MXM_OP_PINOPEN_RESTORE_CURRENT_SOURCE_CONF
@ MXM_OP_PINOPEN_RESTORE_CURRENT_SOURCE_CONF
Definition: mxm_1785x_tools.h:133
mxm_oddCellsNeedBalancing
static uint8_t mxm_oddCellsNeedBalancing
Odd cells group needs to be balanced.
Definition: mxm_1785x.c:147
MXM_MAXIMUM_NR_OF_MODULES
#define MXM_MAXIMUM_NR_OF_MODULES
Maximum number of modules.
Definition: mxm_basic_defines.h:73
MXM_FirstSetBitTest
STD_RETURN_TYPE_e must_check_return MXM_FirstSetBitTest()
Test MXM_FirstSetBit().
Definition: mxm_1785x_tools.c:85
MXM_5X_STATE_UNPROCESSED
@ MXM_5X_STATE_UNPROCESSED
Definition: mxm_battery_management.h:231
MXM_STATEMACH_5X_WRITEALL
@ MXM_STATEMACH_5X_WRITEALL
Definition: mxm_battery_management.h:156
MXM_HandleStateWriteall
static void MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a WRITEALL.
Definition: mxm_1785x.c:392
mxm_oddCellsBalancingProcessed
static uint8_t mxm_oddCellsBalancingProcessed
Odd cells group balancing done.
Definition: mxm_1785x.c:159
MXM_MEASURE_CELL_VOLTAGE
@ MXM_MEASURE_CELL_VOLTAGE
Definition: mxm_basic_defines.h:138
mxm_1785x_tools.h
This is a collection of helper functions for the MAX1785x ICs.
MXM_CONVERSION_UNIPOLAR
@ MXM_CONVERSION_UNIPOLAR
Definition: mxm_basic_defines.h:131
MXM_REG_OVTHSET
@ MXM_REG_OVTHSET
Definition: mxm_register_map.h:179
MXM_MEASURE_BLOCK_VOLTAGE
@ MXM_MEASURE_BLOCK_VOLTAGE
Definition: mxm_basic_defines.h:140
MXM_OP_BAL_ENTRY
@ MXM_OP_BAL_ENTRY
Definition: mxm_1785x_tools.h:134
MXM_INIT_BALEXP1
@ MXM_INIT_BALEXP1
Definition: mxm_1785x_tools.h:96
DATA_BLOCK_BALANCING_CONTROL::header
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:249
FAS_ASSERT
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:233
MXM_MonRegistryParseIdIntoDevices
void MXM_MonRegistryParseIdIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength, MXM_REG_NAME_e type)
Parse ID (1 or 2) into the registry.
Definition: mxm_registry.c:105
tsi.h
Temperature Sensor Interface on Slave Unit driver header.
MXM_STATEMACH_5X_WRITE_DEVICE
@ MXM_STATEMACH_5X_WRITE_DEVICE
Definition: mxm_battery_management.h:157
MXM_VOLTAGE_READ_ARRAY_LENGTH
#define MXM_VOLTAGE_READ_ARRAY_LENGTH
Definition: mxm_1785x.c:71
MXM_REG_ID2
@ MXM_REG_ID2
Definition: mxm_register_map.h:662
MXM_REG_ALRTOVEN
@ MXM_REG_ALRTOVEN
Definition: mxm_register_map.h:157
MXM_REG_BALEXP13
@ MXM_REG_BALEXP13
Definition: mxm_register_map.h:529
MXM_CONVERSION_BIPOLAR
@ MXM_CONVERSION_BIPOLAR
Definition: mxm_basic_defines.h:132
DATA_BLOCK_CELL_TEMPERATURE::header
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:135
MXM_REG_CTSTCFG
@ MXM_REG_CTSTCFG
Definition: mxm_register_map.h:428
MXM_5X_COMMAND_PAYLOAD_s::regAddress
MXM_REG_NAME_e regAddress
Definition: mxm_battery_management.h:241
TSI_GetTemperature
int16_t TSI_GetTemperature(uint16_t adcVoltage_mV)
translate a voltage to a temperature
Definition: epcos_b57251v5103j060_lookup-table.c:70
MXM_REG_CELL6
@ MXM_REG_CELL6
Definition: mxm_register_map.h:311
MXM_ParseVoltageLineReadall
static void MXM_ParseVoltageLineReadall(uint8_t *volt_rx_buffer, uint16_t volt_rx_buffer_len, uint8_t meas_offset, MXM_CONVERSION_TYPE_e conversionType, uint16_t *voltages_target, MXM_MEASURE_TYPE_e meas_type, uint32_t full_scale_reference_mV)
Parse voltage values from a READALL receive buffer into an array.
Definition: mxm_1785x.c:543
MXM_MONITORING_INSTANCE::state
MXM_STATEMACHINE_STATES_e state
Definition: mxm_1785x_tools.h:189
MXM_REG_I2CPNTR
@ MXM_REG_I2CPNTR
Definition: mxm_register_map.h:584
MXM_MONITORING_INSTANCE::stopRequested
bool stopRequested
Definition: mxm_1785x_tools.h:194
OS_GetTickCount
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os.c:182
MXM_STATEMACH_5X_INIT
@ MXM_STATEMACH_5X_INIT
Definition: mxm_battery_management.h:153
must_check_return
#define must_check_return
Allows functions to generate warnings in GCC for unused returns.
Definition: general.h:95
MXM_MONITORING_INSTANCE::openwireRequested
bool openwireRequested
Definition: mxm_1785x_tools.h:195
MXM_INIT_COMPOPNTHREG
@ MXM_INIT_COMPOPNTHREG
Definition: mxm_1785x_tools.h:113
MXM_OP_PINOPEN_SET_CURRENT_SOURCES
@ MXM_OP_PINOPEN_SET_CURRENT_SOURCES
Definition: mxm_1785x_tools.h:128
MXM_RX_BUFFER_LENGTH
#define MXM_RX_BUFFER_LENGTH
Length of RX buffer.
Definition: mxm_1785x_tools.h:185
MXM_ConstructBalancingBuffer
static STD_RETURN_TYPE_e MXM_ConstructBalancingBuffer(void)
Fill the balancing datastructure.
Definition: mxm_1785x.c:488
MXM_REG_AUXGPIOCFG
@ MXM_REG_AUXGPIOCFG
Definition: mxm_register_map.h:140
mxm_balancingControl
static DATA_BLOCK_BALANCING_CONTROL_s mxm_balancingControl
Balancing control.
Definition: mxm_1785x.c:129
MXM_REG_I2CSTAT
@ MXM_REG_I2CSTAT
Definition: mxm_register_map.h:626
DATA_BLOCK_ID_CELL_VOLTAGE_BASE
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
Definition: database_cfg.h:94
MXM_INIT_MEASUREEN2
@ MXM_INIT_MEASUREEN2
Definition: mxm_1785x_tools.h:92
MXM_INIT_STATUS1
@ MXM_INIT_STATUS1
Definition: mxm_1785x_tools.h:87
MXM_ParseVoltageReadall
static STD_RETURN_TYPE_e MXM_ParseVoltageReadall(uint8_t *volt_rx_buffer, uint16_t volt_rx_buffer_len, MXM_DATA_STORAGE_s *datastorage, MXM_CONVERSION_TYPE_e conversionType)
Parse a RX buffer containing voltage values.
Definition: mxm_1785x.c:584
STD_OK
@ STD_OK
Definition: fstd_types.h:72
MXM_5XSetStateRequest
STD_RETURN_TYPE_e MXM_5XSetStateRequest(MXM_5X_INSTANCE_s *pInstance5x, MXM_STATEMACHINE_5X_e state, MXM_5X_COMMAND_PAYLOAD_s commandPayload, MXM_5X_STATE_REQUEST_STATUS_e *processed)
Set state request for the Battery Management Statemachine.
Definition: mxm_battery_management.c:380
MXM_REG_CELL5
@ MXM_REG_CELL5
Definition: mxm_register_map.h:308
MXM_INIT_UVTHSETREG
@ MXM_INIT_UVTHSETREG
Definition: mxm_1785x_tools.h:94
MXM_INIT_BALEXP13
@ MXM_INIT_BALEXP13
Definition: mxm_1785x_tools.h:108
MXM_REG_ALRTSUM
@ MXM_REG_ALRTSUM
Definition: mxm_register_map.h:94
MXM_OP_BAL_START
@ MXM_OP_BAL_START
Definition: mxm_1785x_tools.h:137
MXM_REG_I2CCFG
@ MXM_REG_I2CCFG
Definition: mxm_register_map.h:619
MXM_REG_BALEXP9
@ MXM_REG_BALEXP9
Definition: mxm_register_map.h:501
MXM_INIT_I2C_SEND
@ MXM_INIT_I2C_SEND
Definition: mxm_1785x_tools.h:118
MXM_INIT_ALRTOVEN
@ MXM_INIT_ALRTOVEN
Definition: mxm_1785x_tools.h:111
MXM_5XGetNumberOfSatellitesGood
STD_RETURN_TYPE_e MXM_5XGetNumberOfSatellitesGood(MXM_5X_INSTANCE_s *pInstance)
Get the value of MXM_5X_INSTANCE::numberOfSatellitesIsGood.
Definition: mxm_battery_management.c:376
MXM_INIT_BALEXP8
@ MXM_INIT_BALEXP8
Definition: mxm_1785x_tools.h:103
TEST_MXM_ParseVoltagesIntoDB
STD_RETURN_TYPE_e TEST_MXM_ParseVoltagesIntoDB(MXM_MONITORING_INSTANCE_s *pInstance)
Definition: mxm_1785x.c:1923
mxm_voltageCellAddresses
static const MXM_REG_NAME_e mxm_voltageCellAddresses[MXM_VOLTAGE_READ_ARRAY_LENGTH]
Mapping of voltage registers.
Definition: mxm_1785x.c:84
MXM_REG_SCANCTRL
@ MXM_REG_SCANCTRL
Definition: mxm_register_map.h:393
MXM_INIT_BALEXP7
@ MXM_INIT_BALEXP7
Definition: mxm_1785x_tools.h:102
STD_NOT_OK
@ STD_NOT_OK
Definition: fstd_types.h:73
MXM_INIT_GET_ID1
@ MXM_INIT_GET_ID1
Definition: mxm_1785x_tools.h:89
MXM_OP_PINOPEN_EXIT
@ MXM_OP_PINOPEN_EXIT
Definition: mxm_1785x_tools.h:127
MXM_SELFCHECK::firstSetBit
STD_RETURN_TYPE_e firstSetBit
Definition: mxm_1785x_tools.h:154
DATA_BLOCK_CELL_VOLTAGE::cellVoltage_mV
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
Definition: database_cfg.h:122
MXM_REG_BALEXP10
@ MXM_REG_BALEXP10
Definition: mxm_register_map.h:508
MXM_REG_CELL1
@ MXM_REG_CELL1
Definition: mxm_register_map.h:296
MXM_OP_GET_SCAN_STROBE
@ MXM_OP_GET_SCAN_STROBE
Definition: mxm_1785x_tools.h:122
MXM_INIT_BALEXP6
@ MXM_INIT_BALEXP6
Definition: mxm_1785x_tools.h:101
MXM_REG_BALEXP4
@ MXM_REG_BALEXP4
Definition: mxm_register_map.h:466
BATTERY_MANAGEMENT_TX_LENGTH_READALL
#define BATTERY_MANAGEMENT_TX_LENGTH_READALL
Battery Management Protocol lengths of TX buffer.
Definition: mxm_battery_management.h:146
mxm_openwire
static DATA_BLOCK_OPEN_WIRE_s mxm_openwire
Local data structure for openwire results.
Definition: mxm_1785x.c:123
MXM_REG_CELL2
@ MXM_REG_CELL2
Definition: mxm_register_map.h:299
MXM_REG_CELL3
@ MXM_REG_CELL3
Definition: mxm_register_map.h:302
MXM_StateMachine
void MXM_StateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Battery monitoring driver for MAX1785x battery monitoring ICs.
Definition: mxm_1785x.c:1824
TEST_MXM_ProcessOpenWire
void TEST_MXM_ProcessOpenWire(MXM_MONITORING_INSTANCE_s *pInstance, DATA_BLOCK_OPEN_WIRE_s *pDataOpenWire)
Definition: mxm_1785x.c:1949
MXM_MonRegistryConnectDevices
STD_RETURN_TYPE_e MXM_MonRegistryConnectDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t numberOfDevices)
Mark devices as connected in the registry and set the address.
Definition: mxm_registry.c:83
DATA_BLOCK_CELL_TEMPERATURE
Definition: database_cfg.h:131
TEST_MXM_HandleStateWriteall
void TEST_MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Definition: mxm_1785x.c:1931
MXM_MONITORING_INSTANCE::allowStartup
bool allowStartup
Definition: mxm_1785x_tools.h:191
MXM_REG_NAME_e
enum MXM_REG_NAME MXM_REG_NAME_e
MAX1785x register names.
DATA_BLOCK_ID_BALANCING_CONTROL
@ DATA_BLOCK_ID_BALANCING_CONTROL
Definition: database_cfg.h:77
DATA_BLOCK_BALANCING_CONTROL::balancingState
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
Definition: database_cfg.h:253
MXM_MONITORING_INSTANCE::operationRequested
bool operationRequested
Definition: mxm_1785x_tools.h:192
MXM_REG_CELL14
@ MXM_REG_CELL14
Definition: mxm_register_map.h:335
MXM_MONITORING_INSTANCE::operationSubstate
MXM_STATEMACHINE_OPERATION_STATES_e operationSubstate
Definition: mxm_1785x_tools.h:190
MXM_5X_COMMAND_PAYLOAD_s::lsb
uint8_t lsb
Definition: mxm_battery_management.h:242
MXM_REG_BALEXP7
@ MXM_REG_BALEXP7
Definition: mxm_register_map.h:487
DATA_BLOCK_CELL_VOLTAGE
Definition: database_cfg.h:115
MXM_REG_COMPOPNTH
@ MXM_REG_COMPOPNTH
Definition: mxm_register_map.h:269
MXM_5XGetNumberOfSatellites
uint8_t MXM_5XGetNumberOfSatellites(MXM_5X_INSTANCE_s *pInstance)
Get number of satellites.
Definition: mxm_battery_management.c:372
MXM_REG_BALSWDLY
@ MXM_REG_BALSWDLY
Definition: mxm_register_map.h:382
MXM_INIT_AUXGPIOCFG
@ MXM_INIT_AUXGPIOCFG
Definition: mxm_1785x_tools.h:93
MXM_INIT_BALEXP5
@ MXM_INIT_BALEXP5
Definition: mxm_1785x_tools.h:100
DATA_READ_DATA
#define DATA_READ_DATA(...)
Definition: database.h:72
MXM_MonRegistryInit
void MXM_MonRegistryInit(MXM_MONITORING_INSTANCE_s *pState)
Initialize monitoring registry.
Definition: mxm_registry.c:70
DATA_BLOCK_OPENWIRE::openwire
uint8_t openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES *(BS_NR_OF_CELLS_PER_MODULE+1)]
Definition: database_cfg.h:304
MXM_MONITORING_INSTANCE::localVoltages
MXM_DATA_STORAGE_s localVoltages
Local storage for cell-voltages.
Definition: mxm_1785x_tools.h:221
MXM_MONITORING_INSTANCE::firstMeasurementDone
bool firstMeasurementDone
Definition: mxm_1785x_tools.h:193
MXM_VoltageIntoUnipolar14Bit
uint16_t MXM_VoltageIntoUnipolar14Bit(uint16_t voltage_mV, uint16_t fullscaleReference_mV)
convert a voltage value into a unipolar 14bit value
Definition: mxm_1785x_tools.c:216
MXM_STATEMACH_5X_READALL
@ MXM_STATEMACH_5X_READALL
Definition: mxm_battery_management.h:158
MXM_5X_COMMAND_PAYLOAD_s::deviceAddress
uint8_t deviceAddress
Definition: mxm_battery_management.h:245
mxm_evenCellsNeedBalancing
static uint8_t mxm_evenCellsNeedBalancing
Even cells group needs to be balanced.
Definition: mxm_1785x.c:141
MXM_REG_MEASUREEN1
@ MXM_REG_MEASUREEN1
Definition: mxm_register_map.h:386
database.h
Database module header.
MXM_Unipolar14BitInto16Bit
void MXM_Unipolar14BitInto16Bit(uint16_t inputValue, uint8_t *lsb, uint8_t *msb)
convert a unipolar 14bit-value and shifts it into the 16bit-format
Definition: mxm_1785x_tools.c:205
MXM_5XGetRXBuffer
STD_RETURN_TYPE_e MXM_5XGetRXBuffer(MXM_5X_INSTANCE_s *pInstance, uint8_t *rxBuffer, uint16_t rxBufferLength)
Copy RX buffer into variable.
Definition: mxm_battery_management.c:350
MXM_INIT_BALEXP3
@ MXM_INIT_BALEXP3
Definition: mxm_1785x_tools.h:98
NULL_PTR
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
TEST_MXM_ParseVoltageReadall
STD_RETURN_TYPE_e TEST_MXM_ParseVoltageReadall(uint8_t *volt_rx_buffer, uint16_t volt_rx_buffer_len, MXM_DATA_STORAGE_s *datastorage, MXM_CONVERSION_TYPE_e conversionType)
Definition: mxm_1785x.c:1942
MXM_INIT_I2C_WDATA2
@ MXM_INIT_I2C_WDATA2
Definition: mxm_1785x_tools.h:117
MXM_OP_GET_VOLTAGES
@ MXM_OP_GET_VOLTAGES
Definition: mxm_1785x_tools.h:123
MXM_REG_BALEXP8
@ MXM_REG_BALEXP8
Definition: mxm_register_map.h:494
MXM_5XGetLastDCByte
MXM_DC_BYTE_e MXM_5XGetLastDCByte(MXM_5X_INSTANCE_s *pInstance)
Returns the last received DC byte.
Definition: mxm_battery_management.c:368
mxm_currentTime
static uint32_t mxm_currentTime
Timers used to guarantee that balancing is performed periodically.
Definition: mxm_1785x.c:169
MXM_DATA_STORAGE::cellVoltages
uint16_t cellVoltages[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE]
Definition: mxm_basic_defines.h:148
MXM_INIT_OVTHSETREG
@ MXM_INIT_OVTHSETREG
Definition: mxm_1785x_tools.h:95
MXM_REG_CELL7
@ MXM_REG_CELL7
Definition: mxm_register_map.h:314
mxm_evenCellsBalancingProcessed
static uint8_t mxm_evenCellsBalancingProcessed
Even cells group balancing done.
Definition: mxm_1785x.c:153
MXM_REG_CELL8
@ MXM_REG_CELL8
Definition: mxm_register_map.h:317
MXM_INIT_BALEXP4
@ MXM_INIT_BALEXP4
Definition: mxm_1785x_tools.h:99
MXM_5X_STATE_UNSENT
@ MXM_5X_STATE_UNSENT
Definition: mxm_battery_management.h:230
MXM_5X_STATE_PROCESSED
@ MXM_5X_STATE_PROCESSED
Definition: mxm_battery_management.h:233
MXM_DATA_STORAGE::auxVoltages
uint16_t auxVoltages[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_AUX_PER_MODULE]
Definition: mxm_basic_defines.h:150
MXM_ProcessOpenWire
static void MXM_ProcessOpenWire(MXM_MONITORING_INSTANCE_s *pInstance, DATA_BLOCK_OPEN_WIRE_s *pDataOpenWire)
Processes the retrieved information on openwire.
Definition: mxm_1785x.c:447
mxm_registry.h
Functions in order to have a registry of monitoring ICs.
MXM_MONITORING_INSTANCE::requestStatus5x
MXM_5X_STATE_REQUEST_STATUS_e requestStatus5x
Definition: mxm_1785x_tools.h:201
TEST_MXM_MonGetVoltages
MXM_MONINTORING_STATE_e TEST_MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e regAddress)
Definition: mxm_1785x.c:1926
MXM_MEASURE_TEMP
@ MXM_MEASURE_TEMP
Definition: mxm_basic_defines.h:139
MXM_REG_CELL12
@ MXM_REG_CELL12
Definition: mxm_register_map.h:329
MXM_MEASURE_TYPE_e
enum MXM_MEASURE_TYPE MXM_MEASURE_TYPE_e
MXM_INIT_DEVCFG1
@ MXM_INIT_DEVCFG1
Definition: mxm_1785x_tools.h:86
mxm_1785x.h
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
MXM_REG_FMEA2
@ MXM_REG_FMEA2
Definition: mxm_register_map.h:91
MXM_5X_COMMAND_PAYLOAD_s::msb
uint8_t msb
Definition: mxm_battery_management.h:243
MXM_STATEMACHINE_STATES_UNINITIALIZED
@ MXM_STATEMACHINE_STATES_UNINITIALIZED
Definition: mxm_1785x_tools.h:75
MXM_DATA_STORAGE::blockVoltages
uint16_t blockVoltages[MXM_MAXIMUM_NR_OF_MODULES]
Definition: mxm_basic_defines.h:152
FAS_TRAP
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:108
MXM_ParseVoltagesIntoDB
static STD_RETURN_TYPE_e MXM_ParseVoltagesIntoDB(MXM_MONITORING_INSTANCE_s *pInstance)
Copies measured voltage data into the database.
Definition: mxm_1785x.c:1196
mxm_cellsToBalance
uint16_t mxm_cellsToBalance
Mask to control balacing.
Definition: mxm_1785x.c:165
DATA_BLOCK_OPENWIRE::header
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:300
MXM_INIT_BALEXP2
@ MXM_INIT_BALEXP2
Definition: mxm_1785x_tools.h:97
MXM_STATEMACHINE_STATES_OPERATION
@ MXM_STATEMACHINE_STATES_OPERATION
Definition: mxm_1785x_tools.h:80
MXM_INIT_MEASUREEN1
@ MXM_INIT_MEASUREEN1
Definition: mxm_1785x_tools.h:91
mxm_cellVoltages
static DATA_BLOCK_CELL_VOLTAGE_s mxm_cellVoltages
Local cell voltage data block.
Definition: mxm_1785x.c:114
MXM_MONITORING_INSTANCE::selfCheck
MXM_SELFCHECK_s selfCheck
Definition: mxm_1785x_tools.h:204
DATA_BLOCK_BALANCING_CONTROL
Definition: database_cfg.h:245
MXM_OP_PINOPEN_ENTRY
@ MXM_OP_PINOPEN_ENTRY
Definition: mxm_1785x_tools.h:126
DATA_BLOCK_CELL_VOLTAGE::header
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:119
MXM_INIT_BALEXP10
@ MXM_INIT_BALEXP10
Definition: mxm_1785x_tools.h:105
MXM_REG_CELL11
@ MXM_REG_CELL11
Definition: mxm_register_map.h:326
MXM_REG_BALEXP2
@ MXM_REG_BALEXP2
Definition: mxm_register_map.h:452
MXM_REG_ID1
@ MXM_REG_ID1
Definition: mxm_register_map.h:659
mxm_cellTemperatures
static DATA_BLOCK_CELL_TEMPERATURE_s mxm_cellTemperatures
Local cell temperature data block.
Definition: mxm_1785x.c:120
MXM_OP_PARSE_VOLTAGES_INTO_DB
@ MXM_OP_PARSE_VOLTAGES_INTO_DB
Definition: mxm_1785x_tools.h:125
MXM_REG_BALEXP6
@ MXM_REG_BALEXP6
Definition: mxm_register_map.h:480
MXM_INIT_BALEXP14
@ MXM_INIT_BALEXP14
Definition: mxm_1785x_tools.h:109
BS_NR_OF_STRINGS
#define BS_NR_OF_STRINGS
Definition: battery_system_cfg.h:89
MXM_MONITORING_INSTANCE::resultSelfCheck
STD_RETURN_TYPE_e resultSelfCheck
Definition: mxm_1785x_tools.h:203
MXM_STATEMACHINE_STATES_SELFCHECK_POST_INIT
@ MXM_STATEMACHINE_STATES_SELFCHECK_POST_INIT
Definition: mxm_1785x_tools.h:78
MXM_INIT_BALEXP12
@ MXM_INIT_BALEXP12
Definition: mxm_1785x_tools.h:107
DATA_BLOCK_CELL_TEMPERATURE::cellTemperature_ddegC
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS]
Definition: database_cfg.h:137
MXM_DELAY_BALANCING
#define MXM_DELAY_BALANCING
Delay in milliseconds before the balancing status is updated.
Definition: mxm_1785x.c:173
mxm_battery_management.h
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
MXM_SELFCHECK::extractValueFromRegister
STD_RETURN_TYPE_e extractValueFromRegister
Definition: mxm_1785x_tools.h:156
MXM_REG_STATUS1
@ MXM_REG_STATUS1
Definition: mxm_register_map.h:77
MXM_REG_AUX0
@ MXM_REG_AUX0
Definition: mxm_register_map.h:350
DATA_BLOCKHEADER::uniqueId
DATA_BLOCK_ID_e uniqueId
Definition: database_cfg.h:109
MXM_MONITORING_STATE_PASS
@ MXM_MONITORING_STATE_PASS
Definition: mxm_1785x_tools.h:144
MXM_MONITORING_STATE_FAIL
@ MXM_MONITORING_STATE_FAIL
Definition: mxm_1785x_tools.h:145