foxBMS  1.5.0
The foxBMS Battery Management System API Documentation
mxm_17841b.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 mxm_17841b.c
44  * @author foxBMS Team
45  * @date 2018-12-14 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.0
48  * @ingroup DRIVERS
49  * @prefix MXM
50  *
51  * @brief Driver for the MAX17841B ASCI and MAX1785x analog front-end
52  *
53  * @details def
54  *
55  */
56 
57 /*========== Includes =======================================================*/
58 #include "mxm_17841b.h"
59 
60 #include "fassert.h"
61 #include "fstd_types.h"
62 #include "mxm_41b_register_map.h"
63 #include "mxm_bitextract.h"
64 #include "os.h"
65 
66 #include <stdint.h>
67 
68 /*========== Macros and Definitions =========================================*/
69 /** bit shift half byte length */
70 #define MXM_41B_BIT_SHIFT_HALF_BYTE (4u)
71 
72 /** low nibble (of uint8_t) bit mask */
73 #define MXM_41B_BIT_MASK_LOW_NIBBLE (0xFu)
74 
75 /** high nibble (of uint8_t) bit mask */
76 #define MXM_41B_BIT_MASK_HIGH_NIBBLE (0xF0u)
77 
78 /** (uint8_t) one byte bit mask */
79 #define MXM_41B_BIT_MASK_ONE_BYTE (0xFFu)
80 
81 /** threshold above which a reset in this driver occurs in case of hangup */
82 #define MXM_41B_WAIT_COUNTER_THRESHOLD (75u)
83 #if MXM_41B_WAIT_COUNTER_THRESHOLD > (UINT8_MAX - 1)
84 #error "invalid wait counter threshold (counter is implemented in uint8_t)"
85 #endif
86 
87 /**
88  * time interval that shall ensure that the bridge IC is completely reset in ms
89  */
90 #define MXM_41B_BRIDGE_RESET_TIME_MS (100u)
91 
92 /** default config register bank length
93  *
94  * Length of the array that writes the registers referenced in
95  * mxm_41B_reg_default_values in #MXM_41BStateHandlerInit().
96  */
97 #define MXM_41B_CONFIG_REGISTER_LENGTH (7u)
98 
99 /*========== Static Constant and Variable Definitions =======================*/
100 
101 /*========== Extern Constant and Variable Definitions =======================*/
102 
103 /*========== Static Function Prototypes =====================================*/
104 /* static MXM_SPI_STATE_s mxm_proto_enable_keep_alive(void); */
105 /**
106  * @brief Write one or multiple registers of MAX17841B.
107  *
108  * This function puts together a SPI message consisting of command
109  * and payload and writes it to the assigned SPI interface.
110  *
111  * The command should be one of the #MXM_41B_REG_ADD_t commands.
112  * The function checks whether the chosen command is a write command.
113  *
114  * The payload-length has to be consistent with the payload.
115  * Payload-lengths of one will write to one register only. Longer payloads
116  * will write to adjacent registers. Please see the MAX17841B data sheet
117  * for reference.
118  *
119  * @param[in,out] pInstance pointer to the state of the MAX17841B-state-machine
120  * @param[in] command register command of #MXM_41B_REG_ADD_t
121  * @param[in] kpkPayload pointer to an array of data to be written
122  * @param[in] lengthPayload length of the payload array
123  * @return #STD_NOT_OK for inconsistent input or a blocked SPI interface,
124  * otherwise #STD_OK
125  */
127  MXM_41B_INSTANCE_s *pInstance,
128  MXM_41B_REG_ADD_t command,
129  const uint8_t *const kpkPayload,
130  uint8_t lengthPayload);
131 
132 /**
133  * @brief Read one or multiple registers of MAX17841B.
134  *
135  * This function puts together a SPI message consisting of command
136  * and bit-stuffing and writes it to the assigned SPI-interface.
137  *
138  * The command should be one of the #MXM_41B_REG_ADD_t commands.
139  * The function checks whether the chosen command is a read command.
140  *
141  * The RX buffer length has to be consistent with the RX buffer.
142  * RX buffer lengths of one will read one register only. Longer RX buffers
143  * will read also from adjacent registers. Please see the MAX17841B data sheet
144  * for reference.
145  *
146  * @param[in,out] pInstance pointer to the state of the MAX17841B-state-machine
147  * @param[in] command register command of #MXM_41B_REG_ADD_t
148  * @param[out] pRxBuffer pointer to an array into which read data will be written
149  * @param[in] length length of the RX buffer array
150  * @return #STD_NOT_OK for inconsistent input or a blocked SPI interface,
151  * otherwise #STD_OK
152  */
154  MXM_41B_INSTANCE_s *pInstance,
155  MXM_41B_REG_ADD_t command,
156  uint16_t *pRxBuffer,
157  uint8_t length);
158 
159 /**
160  * @brief Write the config register of MAX17841B.
161  *
162  * This functions writes the config registers with the values
163  * from the local register copies. It puts together a
164  * buffer from these register values and calls MXM_41BRegisterWrite()
165  * with this data.
166  * Calling this function will clear the interrupt registers and reset them
167  * to their default values (which is #MXM_41B_RX_INT_FLAG_DEFAULT_VALUE and
168  * #MXM_41B_TX_INT_FLAG_DEFAULT_VALUE).
169  *
170  * @param[in,out] pInstance state pointer
171  * @return returnvalue of #MXM_41BRegisterWrite()
172  */
174 
175 /**
176  * @brief Write a buffer transaction to MAX17841B.
177  *
178  * Writes into the load-queue-buffer.
179  * The supplied-message-length marks the length of the Battery Management
180  * Protocol message without any stuffing-bytes for read-commands.
181  * The extendMessage parameter describes with how much bytes the
182  * command shall be stretched. This number will be added to the
183  * length of the command and written into the length field of the
184  * buffer.
185  * After this action the user has to select the next load queue with
186  * the appropriate command in order to mark the load queue as sendable.
187  *
188  * @param[in,out] pInstance pointer to the state of the MAX17841B-state-machine
189  * @param[in] kpkMessage pointer to an array containing the message
190  * @param[in] messageLength length of the supplied array
191  * @param[in] extendMessage stretch the message by number of bytes
192  * @return #STD_NOT_OK for inconsistent input or a blocked SPI interface,
193  * otherwise #STD_OK
194  */
196  MXM_41B_INSTANCE_s *pInstance,
197  const uint16_t *const kpkMessage,
198  uint8_t messageLength,
199  uint8_t extendMessage);
200 
201 /**
202  * @brief Transition into idle, mark as successful
203  * @param[out] pInstance pointer to the state-struct
204  */
205 static void MXM_41BTransitionToIdleSuccess(MXM_41B_INSTANCE_s *pInstance);
206 
207 /**
208  * @brief Transition into idle, mark as an error occurred
209  * @param[out] pInstance pointer to the state-struct
210  */
211 static void MXM_41BTransitionToIdleError(MXM_41B_INSTANCE_s *pInstance);
212 
213 /**
214  * @brief Reset register copies to default
215  * @param[out] pInstance pointer to the state-struct
216  */
218 
219 /**
220  * \defgroup mxm-41b-state-handlers State handler functions for #MXM_41BStateMachine()
221  * @{
222  */
223 
224 /**
225  * @brief init state handler
226  * @details This function contains all states for #MXM_STATEMACH_41B_INIT.
227  * @param[in,out] pInstance pointer to the state-struct
228  */
229 static void MXM_41BStateHandlerInit(MXM_41B_INSTANCE_s *pInstance);
230 
231 /**
232  * @brief state handler for "get version"
233  * @details This function contains all states for #MXM_STATEMACH_41B_GET_VERSION.
234  * @param[in,out] pInstance pointer to the state-struct
235  */
236 static void MXM_41BStateHandlerGetVersion(MXM_41B_INSTANCE_s *pInstance);
237 
238 /**
239  * @brief state handler for "idle"
240  * @details This function contains all states for #MXM_STATEMACH_41B_IDLE.
241  * @param[in,out] pInstance pointer to the state-struct
242  */
243 static void MXM_41BStateHandlerIdle(MXM_41B_INSTANCE_s *pInstance);
244 
245 /**
246  * @brief state handler for "write conf and int register"
247  * @details This functions contains all states for #MXM_STATEMACH_41B_WRITE_CONF_AND_INT_REGISTER.
248  * @param[in,out] pInstance pointer to the state-struct
249  */
251 
252 /**
253  * @brief state handler for "read status register"
254  * @details This functions contains all states for #MXM_STATEMACH_41B_READ_STATUS_REGISTER.
255  * @param[in,out] pInstance pointer to the state-struct
256  */
258 
259 /**
260  * @brief state handler for "uart transaction"
261  * @details This functions contains all states for #MXM_STATEMACH_41B_UART_TRANSACTION.
262  * @param[in,out] pInstance pointer to the state-struct
263  */
265 
266 /**
267  * @brief state handler for "check fmea"
268  * @details This functions contains all states for #MXM_STATEMACH_41B_CHECK_FMEA.
269  * @param[in,out] pInstance pointer to the state-struct
270  */
271 static void MXM_41BStateHandlerCheckFmea(MXM_41B_INSTANCE_s *pInstance);
272 
273 /**
274  * @brief state handler for "clear receive buffer"
275  * @details This functions contains all states for #MXM_STATEMACH_41B_CLEAR_RECEIVE_BUFFER.
276  * @param[in,out] pInstance pointer to the state-struct
277  */
279 
280 /**
281  * @brief state handler for "clear transmit buffer"
282  * @details This functions contains all states for #MXM_STATEMACH_41B_CLEAR_TRANSMIT_BUFFER.
283  * @param[in,out] pInstance pointer to the state-struct
284  */
286 
287 /** @} */
288 
289 /*========== Static Function Implementations ================================*/
291  MXM_41B_INSTANCE_s *pInstance,
292  MXM_41B_REG_ADD_t command,
293  const uint8_t *const kpkPayload,
294  uint8_t lengthPayload) {
295  /* sanity check: state-pointer may not be null */
296  FAS_ASSERT(pInstance != NULL_PTR);
297  FAS_ASSERT(lengthPayload < (MXM_SPI_TX_BUFFER_LENGTH - 1u));
298  /* AXIVION Routine Generic-MissingParameterAssert: command: parameter accepts whole range */
299  /* AXIVION Routine Generic-MissingParameterAssert: kpkPayload: pointer may be NULL */
300 
301  STD_RETURN_TYPE_e retval = STD_NOT_OK;
302  /* check if command is a write command (write addresses in MAX17841B are even) */
303  if ((command % 2u) == 0u) {
304  /* construct tx buffer */
305  pInstance->spiTXBuffer[0] = command;
306  /* message has payload --> copy into buffer */
307  if ((kpkPayload != NULL_PTR) && (lengthPayload != 0u)) {
308  for (uint8_t i = 0u; i < lengthPayload; i++) {
309  pInstance->spiTXBuffer[i + 1u] = kpkPayload[i];
310  }
311  /* null rest of tx buffer */
312  for (uint8_t i = lengthPayload + 1u; i < MXM_SPI_TX_BUFFER_LENGTH; i++) {
313  pInstance->spiTXBuffer[i] = 0u;
314  }
315  /* send command with payload */
316  retval = MXM_SendData(pInstance->spiTXBuffer, (uint16_t)lengthPayload + 1u);
317  } else if ((kpkPayload == NULL_PTR) && (lengthPayload == 0u)) {
318  /* send command without payload */
319  retval = MXM_SendData(pInstance->spiTXBuffer, 1);
320  } else {
321  /* invalid configuration */
322  }
323  }
324  return retval;
325 }
326 
328  MXM_41B_INSTANCE_s *pInstance,
329  MXM_41B_REG_ADD_t command,
330  uint16_t *pRxBuffer,
331  uint8_t length) {
332  /* sanity check: state-pointer may not be null */
333  FAS_ASSERT(pInstance != NULL_PTR);
334  /* RX Buffer may not be NULL pointer for this function */
335  FAS_ASSERT(pRxBuffer != NULL_PTR);
337  /* AXIVION Routine Generic-MissingParameterAssert: command: parameter accepts whole range */
338 
339  STD_RETURN_TYPE_e retval = STD_NOT_OK;
340  /* check if command is a read command (read addresses in MAX17841B are odd) */
341  if ((command % 2u) != 0u) {
342  /* construct tx buffer */
343  pInstance->spiTXBuffer[0] = command;
344  /* null rest of tx buffer */
345  for (uint16_t i = 1u; i < MXM_SPI_TX_BUFFER_LENGTH; i++) {
346  pInstance->spiTXBuffer[i] = 0u;
347  }
348  /* send command with payload */
349  retval = MXM_ReceiveData(pInstance->spiTXBuffer, pRxBuffer, ((uint16_t)length + 1u));
350  }
351  return retval;
352 }
353 
355  /* sanity check: state-pointer may not be null */
356  FAS_ASSERT(pInstance != NULL_PTR);
357  uint8_t mxm_spi_temp_buffer[MXM_41B_CONFIG_REGISTER_LENGTH] = {0};
358 
359  /* AXIVION Disable Style Generic-NoMagicNumbers: Magic numbers for index value of array is clear in usage */
360  mxm_spi_temp_buffer[0u] = pInstance->regRXIntEnable;
361  mxm_spi_temp_buffer[1u] = pInstance->regTXIntEnable;
362  mxm_spi_temp_buffer[2u] = MXM_41B_RX_INT_FLAG_DEFAULT_VALUE;
363  mxm_spi_temp_buffer[3u] = MXM_41B_TX_INT_FLAG_DEFAULT_VALUE;
364  mxm_spi_temp_buffer[4u] = pInstance->regConfig1;
365  mxm_spi_temp_buffer[5u] = pInstance->regConfig2;
366  mxm_spi_temp_buffer[6u] = pInstance->regConfig3;
367  /* AXIVION Enable Style Generic-NoMagicNumbers: */
368  FAS_STATIC_ASSERT((6u < MXM_41B_CONFIG_REGISTER_LENGTH), "Revise this function and config register length!");
369 
370  return MXM_41BRegisterWrite(
371  pInstance, MXM_REG_RX_INTERRUPT_ENABLE_W, mxm_spi_temp_buffer, MXM_41B_CONFIG_REGISTER_LENGTH);
372 }
373 
375  MXM_41B_INSTANCE_s *pInstance,
376  const uint16_t *const kpkMessage,
377  uint8_t messageLength,
378  uint8_t extendMessage) {
379  /* sanity check: state-pointer may not be null */
380  FAS_ASSERT(pInstance != NULL_PTR);
381  /* check if message-pointer is valid */
382  FAS_ASSERT(kpkMessage != NULL_PTR);
383  FAS_ASSERT(messageLength >= 1u);
384  FAS_ASSERT(messageLength <= 6u);
385  /* AXIVION Routine Generic-MissingParameterAssert: extendMessage: parameter accepts whole range */
386 
387  /* write address and length to buffer */
388  pInstance->spiTXBuffer[0] = (uint16_t)MXM_BUF_WR_LD_Q_0;
389  pInstance->spiTXBuffer[1] = (uint16_t)messageLength + extendMessage;
390  /* iterate of complete TX buffer and
391  * write into proper fields, null rest
392  */
393  for (uint8_t i = 0; i < (MXM_SPI_TX_BUFFER_LENGTH - 2u); i++) {
394  if (i < messageLength) {
395  pInstance->spiTXBuffer[i + 2u] = kpkMessage[i];
396  } else {
397  pInstance->spiTXBuffer[i + 2u] = 0x00u;
398  }
399  }
400 
401  /* send data */
402  return MXM_SendData(pInstance->spiTXBuffer, ((uint16_t)messageLength + 2u));
403 }
404 
406  FAS_ASSERT(pInstance != NULL_PTR);
407  FAS_ASSERT(pInstance->processed != NULL_PTR);
408  pInstance->state = MXM_STATEMACH_41B_IDLE;
409  pInstance->substate = MXM_41B_ENTRY_SUBSTATE;
410  *pInstance->processed = MXM_41B_STATE_PROCESSED;
411  return;
412 }
413 
415  FAS_ASSERT(pInstance != NULL_PTR);
416  FAS_ASSERT(pInstance->processed != NULL_PTR);
417  pInstance->state = MXM_STATEMACH_41B_IDLE;
418  pInstance->substate = MXM_41B_ENTRY_SUBSTATE;
419  *pInstance->processed = MXM_41B_STATE_ERROR;
420  return;
421 }
422 
424  FAS_ASSERT(pInstance != NULL_PTR);
425  pInstance->regRXStatus = 0u;
426  pInstance->regTXStatus = 0u;
432  return;
433 }
434 
436  FAS_ASSERT(pInstance != NULL_PTR);
437 
438  if (pInstance->substate == MXM_41B_ENTRY_SUBSTATE) {
439  /* entry of state --> set to first substate */
441  }
442 
443  if (pInstance->substate == MXM_41B_INIT_RESET_BRIDGE_IC) {
445  pInstance->shutdownTimeStamp = OS_GetTickCount();
447  } else if (pInstance->substate == MXM_41B_INIT_START_BRIDGE_IC) {
448  const bool resetTimeHasPassed =
450  if (resetTimeHasPassed) {
453  }
454  } else if (pInstance->substate == MXM_41B_INIT_WRITE_DEFAULT_VALUES) {
455  /* set default register values according to data sheet */
457  const STD_RETURN_TYPE_e retval = MXM_41BConfigRegisterWrite(pInstance);
458  if (retval == STD_OK) {
460  }
461  } else if (pInstance->substate == MXM_41B_INIT_READ_CONFIG_REGISTERS) {
462  const STD_RETURN_TYPE_e retval = MXM_41BRegisterRead(
464 
465  if (retval == STD_OK) {
467  }
468  } else if (pInstance->substate == MXM_41B_INIT_CHECK_INITIALIZATION) {
469  STD_RETURN_TYPE_e retval = STD_OK;
470 
471  if (MXM_GetSPIStateReady() == STD_OK) {
472  /**
473  * @brief Default values for the configuration and interrupt registers
474  * @details This constant array contains the default values to which the
475  * configuration is compared when resetting it.
476  * The array is 7 entries long in order to fit onto the following
477  * registers which are placed in succession in the memory of
478  * MAX17841B:
479  * - RX_Interrupt_Enable
480  * - TX_Interrupt_Enable
481  * - RX_Interrupt_Flags
482  * - TX_Interrupt_Flags
483  * - Configuration_1
484  * - Configuration_2
485  * - Configuration_3
486  */
487  const uint8_t mxm_41B_reg_default_values[MXM_41B_CONFIG_REGISTER_LENGTH] = {
495 
496  for (uint8_t i = 0; i < MXM_41B_CONFIG_REGISTER_LENGTH; i++) {
497  if (pInstance->spiRXBuffer[i + 1u] != mxm_41B_reg_default_values[i]) {
498  retval = STD_NOT_OK;
499  }
500  }
501  } else {
502  retval = STD_NOT_OK;
503  }
504 
505  if (retval == STD_NOT_OK) {
506  MXM_41BTransitionToIdleError(pInstance);
507  } else {
509  }
510  } else {
511  MXM_41BTransitionToIdleError(pInstance);
512  }
513 }
514 
516  FAS_ASSERT(pInstance != NULL_PTR);
517  if (pInstance->substate == MXM_41B_ENTRY_SUBSTATE) {
519  }
520 
521  if (pInstance->substate == MXM_41B_VERSION_REQUEST_REGISTER) {
522  /* read two byte in order to read also the adjacent version register */
523  const STD_RETURN_TYPE_e retval = MXM_41BRegisterRead(pInstance, MXM_REG_MODEL_R, pInstance->spiRXBuffer, 2);
524 
525  if (retval == STD_OK) {
526  pInstance->substate = MXM_41B_VERSION_VERIFY;
527  }
528  } else if (pInstance->substate == MXM_41B_VERSION_VERIFY) {
529  if (MXM_GetSPIStateReady() == STD_OK) {
530  /* get model from model register and high nibble of mask revision (should be 0x8410) */
531  pInstance->hwModel =
532  (uint16_t)((pInstance->spiRXBuffer[1] & MXM_41B_BIT_MASK_ONE_BYTE) << MXM_41B_BIT_SHIFT_HALF_BYTE);
533  pInstance->hwModel |=
535  /* extract mask revision from low nibble */
536  pInstance->hwMaskRevision = (uint8_t)(pInstance->spiRXBuffer[2] & MXM_41B_BIT_MASK_LOW_NIBBLE);
537 
539  }
540  } else {
541  /* something is very broken */
542  MXM_41BTransitionToIdleError(pInstance);
543  }
544 }
545 
547  FAS_ASSERT(pInstance != NULL_PTR);
548  /* do nothing in idle state
549  just clean up substate */
550  pInstance->substate = MXM_41B_ENTRY_SUBSTATE;
551 }
552 
554  FAS_ASSERT(pInstance != NULL_PTR);
555  const STD_RETURN_TYPE_e retval = MXM_41BConfigRegisterWrite(pInstance);
556 
557  if (retval == STD_NOT_OK) {
558  MXM_41BTransitionToIdleError(pInstance);
559  } else {
561  }
562 }
563 
565  FAS_ASSERT(pInstance != NULL_PTR);
566  /* TODO read status register and parse into static variables */
567  if (pInstance->substate == MXM_41B_ENTRY_SUBSTATE) {
568  /* entry of state --> set to first substate */
570  }
571 
572  if (pInstance->substate == MXM_41B_READ_STATUS_REGISTER_SEND) {
573  /* read rx and tx status register */
574  const STD_RETURN_TYPE_e retval = MXM_41BRegisterRead(pInstance, MXM_REG_RX_STATUS_R, pInstance->spiRXBuffer, 2);
575  if (retval == STD_NOT_OK) {
576  MXM_41BTransitionToIdleError(pInstance);
577  } else {
579  }
580  } else if (pInstance->substate == MXM_41B_READ_STATUS_REGISTER_PROCESS) {
581  pInstance->regRXStatus = (uint8_t)(pInstance->spiRXBuffer[1] & 0xFFu);
582  pInstance->regTXStatus = (uint8_t)(pInstance->spiRXBuffer[2] & 0xFFu);
584  } else {
585  /* something is very broken */
586  MXM_41BTransitionToIdleError(pInstance);
587  }
588 }
589 
591  FAS_ASSERT(pInstance != NULL_PTR);
592  if (pInstance->substate == MXM_41B_ENTRY_SUBSTATE) {
593  /* entry of state --> set to first substate */
595  }
596 
597  if (pInstance->substate == MXM_41B_UART_READ_RX_SPACE) {
598  const STD_RETURN_TYPE_e retval = MXM_41BRegisterRead(pInstance, MXM_REG_RX_SPACE_R, pInstance->spiRXBuffer, 1u);
599  if (retval == STD_NOT_OK) {
600  MXM_41BTransitionToIdleError(pInstance);
601  } else {
603  }
604  } else if (pInstance->substate == MXM_41B_UART_READ_RX_SPACE_PARSE) {
605  pInstance->regRxSpace = (uint8_t)(pInstance->spiRXBuffer[1] & MXM_41B_BIT_MASK_ONE_BYTE);
607 
608  } else if (pInstance->substate == MXM_41B_UART_WRITE_LOAD_QUEUE) {
609  /* load queue with message */
610  const STD_RETURN_TYPE_e retval =
611  MXM_41BBufferWrite(pInstance, pInstance->pPayload, pInstance->payloadLength, pInstance->extendMessageBytes);
612 
613  if (retval == STD_NOT_OK) {
614  MXM_41BTransitionToIdleError(pInstance);
615  } else {
617  }
618  } else if (pInstance->substate == MXM_41B_UART_READ_LOAD_QUEUE) {
619  /* check assumption that incremented payloadlength fits into uint8_t */
620  FAS_ASSERT(pInstance->payloadLength < (uint8_t)UINT8_MAX);
621  const uint8_t payloadLength = pInstance->payloadLength + 1u;
622  /* send read load queue */
623  const STD_RETURN_TYPE_e retval =
624  MXM_41BRegisterRead(pInstance, MXM_BUF_RD_LD_Q_0, pInstance->spiRXBuffer, payloadLength);
625 
626  if (retval == STD_NOT_OK) {
627  MXM_41BTransitionToIdleError(pInstance);
628  } else {
630  }
631  } else if (pInstance->substate == MXM_41B_UART_VERIFY_LOAD_QUEUE_AND_TRANSMIT) {
632  /* verify load queue */
633  STD_RETURN_TYPE_e retval = STD_OK;
634  /* check message length */
635  if (pInstance->spiRXBuffer[1] != (pInstance->payloadLength + (uint16_t)pInstance->extendMessageBytes)) {
636  retval = STD_NOT_OK;
637  }
638  for (uint8_t i = 0; i < pInstance->payloadLength; i++) {
639  FAS_ASSERT(pInstance->pPayload != NULL_PTR);
640  if (pInstance->spiRXBuffer[i + 2u] != pInstance->pPayload[i]) {
641  /* message corrupted during SPI transfer */
642  retval = STD_NOT_OK;
643  }
644  }
645  if (retval == STD_NOT_OK) {
646  MXM_41BTransitionToIdleError(pInstance);
647  } else {
648  /* transmit queue */
649  retval = MXM_41BRegisterWrite(pInstance, MXM_BUF_WR_NXT_LD_Q_0, NULL_PTR, 0);
650 
651  if (retval == STD_NOT_OK) {
652  MXM_41BTransitionToIdleError(pInstance);
653  } else {
655  }
656  }
657  } else if (pInstance->substate == MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_WRITE) {
658  /* poll RX status change */
659  const STD_RETURN_TYPE_e retval = MXM_41BRegisterRead(pInstance, MXM_REG_RX_STATUS_R, pInstance->spiRXBuffer, 1);
660 
661  if (retval == STD_NOT_OK) {
662  MXM_41BTransitionToIdleError(pInstance);
663  } else {
665  }
667  /* update RX status register copy with received buffer */
668  pInstance->regRXStatus = (uint8_t)(pInstance->spiRXBuffer[1] & MXM_41B_BIT_MASK_ONE_BYTE);
669  /* check if RX_OVERFLOW_Status is 1 */
670  MXM_41B_REG_BIT_VALUE rx_overflow_status_value = MXM_41B_REG_FALSE;
671  const STD_RETURN_TYPE_e resultWrongRegisterOverflow =
672  MXM_41BReadRegisterFunction(pInstance, MXM_41B_REG_FUNCTION_RX_OVERFLOW_STATUS, &rx_overflow_status_value);
673  FAS_ASSERT(resultWrongRegisterOverflow == STD_OK);
674  /* check if RX_STOP_Status is 1 */
675  MXM_41B_REG_BIT_VALUE rx_stop_status_value = MXM_41B_REG_FALSE;
676  const STD_RETURN_TYPE_e resultWrongRegisterStop =
677  MXM_41BReadRegisterFunction(pInstance, MXM_41B_REG_FUNCTION_RX_STOP_STATUS, &rx_stop_status_value);
678  FAS_ASSERT(resultWrongRegisterStop == STD_OK);
679  if (rx_overflow_status_value == MXM_41B_REG_TRUE) {
680  /* overflow, we have to discard the rx buffer */
681  const STD_RETURN_TYPE_e retval = MXM_41BRegisterWrite(pInstance, MXM_BUF_CLR_RX_BUF, NULL_PTR, 0);
682  if (retval == STD_NOT_OK) {
683  MXM_41BTransitionToIdleError(pInstance);
684  } else {
685  MXM_41BTransitionToIdleError(pInstance);
686  }
687  } else if (rx_stop_status_value == MXM_41B_REG_TRUE) {
688  /* received full UART frame --> continue */
689  /* check assumption that payload length fits into uint8_t */
690  FAS_ASSERT((pInstance->payloadLength + (uint16_t)1u + pInstance->extendMessageBytes) <= (uint8_t)UINT8_MAX);
691  const uint8_t payloadLength = pInstance->payloadLength + 1u + pInstance->extendMessageBytes;
692  /* read back receive buffer */
693  const STD_RETURN_TYPE_e retval =
694  MXM_41BRegisterRead(pInstance, MXM_BUF_RD_NXT_MSG, pInstance->spiRXBuffer, payloadLength);
695 
696  if (retval == STD_NOT_OK) {
697  MXM_41BTransitionToIdleError(pInstance);
698  } else {
700  pInstance->waitCounter = 0u;
701  }
702  } else {
703  /* no UART frame received yet --> check again */
705  /* increment wait counter (only to 1 above MXM_41B_WAIT_COUNTER_THRESHOLD,
706  then other parts of the code will reset). */
707  if (pInstance->waitCounter <= MXM_41B_WAIT_COUNTER_THRESHOLD) {
708  pInstance->waitCounter++;
709  }
710  }
711  } else if (pInstance->substate == MXM_41B_UART_READ_BACK_RECEIVE_BUFFER_SAVE) {
712  if ((pInstance->spiRXBuffer != NULL_PTR) && (pInstance->pRxBuffer != NULL_PTR)) {
713  for (uint16_t i = 0; i < ((uint16_t)pInstance->payloadLength + pInstance->extendMessageBytes); i++) {
714  if (i < pInstance->rxBufferLength) {
715  pInstance->pRxBuffer[i] = pInstance->spiRXBuffer[i + 1u];
716  }
717  }
718  }
720  } else {
721  /* we should not be here */
723  }
724 }
725 
727  FAS_ASSERT(pInstance != NULL_PTR);
728  if (pInstance->substate == MXM_41B_ENTRY_SUBSTATE) {
730  }
731 
732  if (pInstance->substate == MXM_41B_FMEA_REQUEST_REGISTER) {
733  const STD_RETURN_TYPE_e retval = MXM_41BRegisterRead(pInstance, MXM_REG_FMEA_R, pInstance->spiRXBuffer, 1);
734 
735  if (retval == STD_OK) {
736  pInstance->substate = MXM_41B_FMEA_VERIFY;
737  }
738  } else if (pInstance->substate == MXM_41B_FMEA_VERIFY) {
739  STD_RETURN_TYPE_e retval = STD_NOT_OK;
740  if (MXM_GetSPIStateReady() == STD_OK) {
741  pInstance->regFmea = pInstance->spiRXBuffer[1u];
742  if (pInstance->regFmea == 0u) {
743  retval = STD_OK;
744  }
745  }
746 
747  if (retval == STD_NOT_OK) {
748  /* FMEA check went bad */
749  MXM_41BTransitionToIdleError(pInstance);
750  } else {
752  }
753  } else {
754  /* something is very broken */
755  MXM_41BTransitionToIdleError(pInstance);
756  }
757 }
758 
760  FAS_ASSERT(pInstance != NULL_PTR);
761  /* clear receive buffer --> reset UART RX into defined state */
762  const STD_RETURN_TYPE_e retval = MXM_41BRegisterWrite(pInstance, MXM_BUF_CLR_RX_BUF, NULL_PTR, 0);
763 
764  if (retval == STD_OK) {
765  /* writing successful, return to idle */
767  } else {
768  /* an error has occurred, retry and set error */
769  MXM_41BTransitionToIdleError(pInstance);
770  }
771 }
772 
774  FAS_ASSERT(pInstance != NULL_PTR);
775  /* clear receive buffer --> reset UART RX into defined state */
776  const STD_RETURN_TYPE_e retval = MXM_41BRegisterWrite(pInstance, MXM_BUF_CLR_TX_BUF, NULL_PTR, 0);
777 
778  if (retval == STD_OK) {
779  /* writing successful, return to idle */
781  } else {
782  /* an error has occurred, retry and set error */
783  MXM_41BTransitionToIdleError(pInstance);
784  }
785 }
786 
787 /*========== Extern Function Implementations ================================*/
789  MXM_41B_INSTANCE_s *pInstance,
790  MXM_STATEMACH_41B_e state,
791  uint16_t *pPayload,
792  uint8_t payloadLength,
793  uint8_t extendMessageBytes,
794  uint16_t *pRxBuffer,
795  uint16_t rxBufferLength,
796  MXM_41B_STATE_REQUEST_STATUS_e *processed) {
797  /* sanity check: state-pointer may not be null */
798  FAS_ASSERT(pInstance != NULL_PTR);
799  /* AXIVION Routine Generic-MissingParameterAssert: state: parameter accepts whole range */
800  /* AXIVION Routine Generic-MissingParameterAssert: pPayload: pointer may be NULL */
801  /* AXIVION Routine Generic-MissingParameterAssert: payloadLength: parameter accepts whole range */
802  /* AXIVION Routine Generic-MissingParameterAssert: extendMessageBytes: parameter accepts whole range */
803  /* AXIVION Routine Generic-MissingParameterAssert: pRxBuffer: pointer may be NULL */
804  /* AXIVION Routine Generic-MissingParameterAssert: rxBufferLength: parameter accepts whole range */
805 
806  STD_RETURN_TYPE_e retval = STD_OK;
807  /* start by checking for input inconsistency */
808  if (state >= MXM_STATEMACH_41B_MAXSTATE) {
809  retval = STD_NOT_OK;
810  } else if ((pPayload == NULL_PTR) && (payloadLength != 0u)) {
811  retval = STD_NOT_OK;
812  } else if ((payloadLength == 0u) && (pPayload != NULL_PTR)) {
813  retval = STD_NOT_OK;
814  } else if ((pRxBuffer == NULL_PTR) && (rxBufferLength != 0u)) {
815  retval = STD_NOT_OK;
816  } else if ((rxBufferLength == 0u) && (pRxBuffer != NULL_PTR)) {
817  retval = STD_NOT_OK;
818  } else if (processed == NULL_PTR) {
819  retval = STD_NOT_OK;
820  } else if (pInstance->state == MXM_STATEMACH_41B_UNINITIALIZED) {
821  if (state == MXM_STATEMACH_41B_INIT) {
822  pInstance->state = state;
823  pInstance->substate = MXM_41B_ENTRY_SUBSTATE;
824  pInstance->pPayload = pPayload;
825  pInstance->payloadLength = payloadLength;
826  pInstance->extendMessageBytes = extendMessageBytes;
827  pInstance->pRxBuffer = pRxBuffer;
828  pInstance->rxBufferLength = rxBufferLength;
829  pInstance->processed = processed;
830  *pInstance->processed = MXM_41B_STATE_UNPROCESSED;
831  } else {
832  retval = STD_NOT_OK;
833  }
834  } else if (pInstance->state == MXM_STATEMACH_41B_IDLE) {
835  pInstance->state = state;
836  pInstance->substate = MXM_41B_ENTRY_SUBSTATE;
837  pInstance->pPayload = pPayload;
838  pInstance->payloadLength = payloadLength;
839  pInstance->extendMessageBytes = extendMessageBytes;
840  pInstance->pRxBuffer = pRxBuffer;
841  pInstance->rxBufferLength = rxBufferLength;
842  pInstance->processed = processed;
843  *pInstance->processed = MXM_41B_STATE_UNPROCESSED;
844  } else {
845  retval = STD_NOT_OK;
846  }
847  return retval;
848 }
849 
851  MXM_41B_INSTANCE_s *pInstance,
852  MXM_41B_REG_FUNCTION_e registerFunction,
853  MXM_41B_REG_BIT_VALUE value) {
854  /* sanity check: state-pointer may not be null */
855  FAS_ASSERT(pInstance != NULL_PTR);
856  /* AXIVION Routine Generic-MissingParameterAssert: registerFunction: parameter accepts whole range */
857  /* AXIVION Routine Generic-MissingParameterAssert: value: parameter accepts whole range */
858 
859  STD_RETURN_TYPE_e retval = STD_OK;
860  /* TODO sanitize value */
861 
862  switch (registerFunction) {
864  pInstance->regConfig2 = mxm_41bWriteValue(
865  value,
866  1,
868  pInstance->regConfig2); /* MXM_41B_TX_PREAMBLES is 5th bit of regConfig2 */
869  break;
871  pInstance->regConfig3 = mxm_41bWriteValue(
872  value, 4, MXM_41B_KEEP_ALIVE, pInstance->regConfig3); /* MXM_41B_KEEP_ALIVE is 0st bit of regConfig3 */
873  break;
875  pInstance->regRXIntEnable = mxm_41bWriteValue(
876  value,
877  1,
879  pInstance->regRXIntEnable); /* MXM_41B_RX_ERROR is 7th bit of regRXIntEnable */
880  break;
882  pInstance->regRXIntEnable = mxm_41bWriteValue(
883  value,
884  1,
886  pInstance->regRXIntEnable); /* MXM_41B_RX_OVERFLOW is 2nd bit of regRXIntEnable */
887  break;
888  default:
889  retval = STD_NOT_OK;
890  break;
891  }
892 
893  return retval;
894 }
895 
897  const MXM_41B_INSTANCE_s *const kpkInstance,
898  MXM_41B_REG_FUNCTION_e registerFunction,
899  MXM_41B_REG_BIT_VALUE *pValue) {
900  /* sanity check: state-pointer may not be null */
901  FAS_ASSERT(kpkInstance != NULL_PTR);
902  /* sanity check: pValue may not be null */
903  FAS_ASSERT(pValue != NULL_PTR);
904  STD_RETURN_TYPE_e retval = STD_OK;
905 
906  switch (registerFunction) {
908  *pValue = mxm_41bReadValue(kpkInstance->regRXStatus, 1, MXM_41B_RX_BUSY_STATUS); /* 5th bit */
909  break;
911  *pValue = mxm_41bReadValue(kpkInstance->regRXStatus, 1, MXM_41B_RX_STOP_STATUS); /* 1st bit */
912  break;
914  *pValue = mxm_41bReadValue(kpkInstance->regRXStatus, 1, MXM_41B_RX_OVERFLOW_STATUS); /* 3rd bit */
915  break;
917  *pValue = mxm_41bReadValue(kpkInstance->regRXStatus, 1, MXM_41B_RX_EMPTY_STATUS); /* 0th bit */
918  break;
920  *pValue = mxm_41bReadValue(kpkInstance->regConfig2, 1, MXM_41B_TX_PREAMBLES); /* 5th bit */
921  break;
922  default:
923  *pValue = MXM_41B_REG_FALSE;
924  retval = STD_NOT_OK;
925  break;
926  }
927 
928  return retval;
929 }
930 
932  /* sanity check: state-pointer may not be null */
933  FAS_ASSERT(pInstance != NULL_PTR);
934 
935  if (pInstance->waitCounter > MXM_41B_WAIT_COUNTER_THRESHOLD) {
936  /* error, reset to idle state */
937  MXM_41BTransitionToIdleError(pInstance);
938  pInstance->waitCounter = 0u;
939  }
940  switch (pInstance->state) {
942  break;
944  MXM_41BStateHandlerInit(pInstance);
945  break;
948  break;
950  MXM_41BStateHandlerIdle(pInstance);
951  break;
954  break;
957  break;
960  break;
962  MXM_41BStateHandlerCheckFmea(pInstance);
963  break;
966  break;
969  break;
970  default:
971  /* this default case should never be reached */
973  break;
974  }
975 }
976 
978  FAS_ASSERT(pInstance != NULL_PTR);
979 
981 
983  pInstance->substate = MXM_41B_ENTRY_SUBSTATE;
984  pInstance->pPayload = NULL_PTR;
985  pInstance->payloadLength = 0u;
986  pInstance->pRxBuffer = NULL_PTR;
987  pInstance->rxBufferLength = 0u;
988  pInstance->processed = NULL_PTR;
989  pInstance->extendMessageBytes = 0u;
990  pInstance->waitCounter = 0u;
991  pInstance->regRxSpace = 0u;
992  pInstance->regFmea = 0u;
993  pInstance->hwModel = 0u;
994  pInstance->hwMaskRevision = 0u;
995  pInstance->shutdownTimeStamp = 0u;
996 
997  for (uint32_t i = 0u; i < MXM_SPI_RX_BUFFER_LENGTH; i++) {
998  pInstance->spiRXBuffer[i] = 0u;
999  }
1000 
1001  for (uint32_t i = 0u; i < MXM_SPI_TX_BUFFER_LENGTH; i++) {
1002  pInstance->spiTXBuffer[i] = 0u;
1003  }
1004 }
1005 
1006 /*========== Externalized Static Function Implementations (Unit Test) =======*/
1007 #ifdef UNITY_UNIT_TEST
1008 #endif
Assert macro implementation.
#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
#define FAS_STATIC_ASSERT(cond, msg)
Definition: fassert.h:284
Definition of foxBMS standard types.
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
static void MXM_41BStateHandlerClearTransmitBuffer(MXM_41B_INSTANCE_s *pInstance)
state handler for "clear transmit buffer"
Definition: mxm_17841b.c:773
static void MXM_41BStateHandlerIdle(MXM_41B_INSTANCE_s *pInstance)
state handler for "idle"
Definition: mxm_17841b.c:546
static void MXM_41BStateHandlerClearReceiveBuffer(MXM_41B_INSTANCE_s *pInstance)
state handler for "clear receive buffer"
Definition: mxm_17841b.c:759
static void MXM_41BStateHandlerUartTransaction(MXM_41B_INSTANCE_s *pInstance)
state handler for "uart transaction"
Definition: mxm_17841b.c:590
static void MXM_41BStateHandlerWriteConfAndIntRegister(MXM_41B_INSTANCE_s *pInstance)
state handler for "write conf and int register"
Definition: mxm_17841b.c:553
static void MXM_41BStateHandlerReadStatusRegister(MXM_41B_INSTANCE_s *pInstance)
state handler for "read status register"
Definition: mxm_17841b.c:564
static void MXM_41BStateHandlerGetVersion(MXM_41B_INSTANCE_s *pInstance)
state handler for "get version"
Definition: mxm_17841b.c:515
static void MXM_41BStateHandlerCheckFmea(MXM_41B_INSTANCE_s *pInstance)
state handler for "check fmea"
Definition: mxm_17841b.c:726
static void MXM_41BStateHandlerInit(MXM_41B_INSTANCE_s *pInstance)
init state handler
Definition: mxm_17841b.c:435
STD_RETURN_TYPE_e MXM_41BSetStateRequest(MXM_41B_INSTANCE_s *pInstance, MXM_STATEMACH_41B_e state, uint16_t *pPayload, uint8_t payloadLength, uint8_t extendMessageBytes, uint16_t *pRxBuffer, uint16_t rxBufferLength, MXM_41B_STATE_REQUEST_STATUS_e *processed)
Set state transition for MAX17841B-state-machine.
Definition: mxm_17841b.c:788
void MXM_41BStateMachine(MXM_41B_INSTANCE_s *pInstance)
Execute state-machine for the MAX17841B.
Definition: mxm_17841b.c:931
static STD_RETURN_TYPE_e MXM_41BRegisterWrite(MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_ADD_t command, const uint8_t *const kpkPayload, uint8_t lengthPayload)
Write one or multiple registers of MAX17841B.
Definition: mxm_17841b.c:290
STD_RETURN_TYPE_e MXM_41BWriteRegisterFunction(MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_FUNCTION_e registerFunction, MXM_41B_REG_BIT_VALUE value)
Write a register function.
Definition: mxm_17841b.c:850
static STD_RETURN_TYPE_e MXM_41BConfigRegisterWrite(MXM_41B_INSTANCE_s *pInstance)
Write the config register of MAX17841B.
Definition: mxm_17841b.c:354
static void MXM_41BTransitionToIdleError(MXM_41B_INSTANCE_s *pInstance)
Transition into idle, mark as an error occurred.
Definition: mxm_17841b.c:414
static void MXM_41BInitializeRegisterCopies(MXM_41B_INSTANCE_s *pInstance)
Reset register copies to default.
Definition: mxm_17841b.c:423
static STD_RETURN_TYPE_e MXM_41BRegisterRead(MXM_41B_INSTANCE_s *pInstance, MXM_41B_REG_ADD_t command, uint16_t *pRxBuffer, uint8_t length)
Read one or multiple registers of MAX17841B.
Definition: mxm_17841b.c:327
#define MXM_41B_CONFIG_REGISTER_LENGTH
Definition: mxm_17841b.c:97
#define MXM_41B_BIT_MASK_HIGH_NIBBLE
Definition: mxm_17841b.c:76
#define MXM_41B_BIT_MASK_ONE_BYTE
Definition: mxm_17841b.c:79
void MXM_41BInitializeStateStruct(MXM_41B_INSTANCE_s *pInstance)
Initializes the state struct with default values.
Definition: mxm_17841b.c:977
static void MXM_41BTransitionToIdleSuccess(MXM_41B_INSTANCE_s *pInstance)
Transition into idle, mark as successful.
Definition: mxm_17841b.c:405
STD_RETURN_TYPE_e MXM_41BReadRegisterFunction(const MXM_41B_INSTANCE_s *const kpkInstance, MXM_41B_REG_FUNCTION_e registerFunction, MXM_41B_REG_BIT_VALUE *pValue)
Read the value of a register function.
Definition: mxm_17841b.c:896
static STD_RETURN_TYPE_e MXM_41BBufferWrite(MXM_41B_INSTANCE_s *pInstance, const uint16_t *const kpkMessage, uint8_t messageLength, uint8_t extendMessage)
Write a buffer transaction to MAX17841B.
Definition: mxm_17841b.c:374
#define MXM_41B_BIT_SHIFT_HALF_BYTE
Definition: mxm_17841b.c:70
#define MXM_41B_BRIDGE_RESET_TIME_MS
Definition: mxm_17841b.c:90
#define MXM_41B_WAIT_COUNTER_THRESHOLD
Definition: mxm_17841b.c:82
#define MXM_41B_BIT_MASK_LOW_NIBBLE
Definition: mxm_17841b.c:73
Headers for the driver for the MAX17841B ASCI and MAX1785x analog front-end.
#define MXM_SPI_TX_BUFFER_LENGTH
SPI TX buffer length.
Definition: mxm_17841b.h:79
MXM_STATEMACH_41B_e
States of the MAX17841B state-machine.
Definition: mxm_17841b.h:87
@ MXM_STATEMACH_41B_MAXSTATE
Definition: mxm_17841b.h:98
@ MXM_STATEMACH_41B_GET_VERSION
Definition: mxm_17841b.h:92
@ MXM_STATEMACH_41B_CLEAR_RECEIVE_BUFFER
Definition: mxm_17841b.h:96
@ MXM_STATEMACH_41B_CLEAR_TRANSMIT_BUFFER
Definition: mxm_17841b.h:97
@ MXM_STATEMACH_41B_UNINITIALIZED
Definition: mxm_17841b.h:88
@ MXM_STATEMACH_41B_INIT
Definition: mxm_17841b.h:89
@ MXM_STATEMACH_41B_WRITE_CONF_AND_INT_REGISTER
Definition: mxm_17841b.h:93
@ MXM_STATEMACH_41B_CHECK_FMEA
Definition: mxm_17841b.h:91
@ MXM_STATEMACH_41B_READ_STATUS_REGISTER
Definition: mxm_17841b.h:94
@ MXM_STATEMACH_41B_IDLE
Definition: mxm_17841b.h:90
@ MXM_STATEMACH_41B_UART_TRANSACTION
Definition: mxm_17841b.h:95
@ MXM_41B_FMEA_REQUEST_REGISTER
Definition: mxm_17841b.h:111
@ MXM_41B_INIT_RESET_BRIDGE_IC
Definition: mxm_17841b.h:106
@ MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_WRITE
Definition: mxm_17841b.h:121
@ MXM_41B_VERSION_VERIFY
Definition: mxm_17841b.h:114
@ MXM_41B_UART_READ_RX_SPACE
Definition: mxm_17841b.h:116
@ MXM_41B_INIT_CHECK_INITIALIZATION
Definition: mxm_17841b.h:110
@ MXM_41B_FMEA_VERIFY
Definition: mxm_17841b.h:112
@ MXM_41B_UART_READ_BACK_RECEIVE_BUFFER_SAVE
Definition: mxm_17841b.h:123
@ MXM_41B_VERSION_REQUEST_REGISTER
Definition: mxm_17841b.h:113
@ MXM_41B_ENTRY_SUBSTATE
Definition: mxm_17841b.h:105
@ MXM_41B_UART_WRITE_LOAD_QUEUE
Definition: mxm_17841b.h:118
@ MXM_41B_UART_READ_LOAD_QUEUE
Definition: mxm_17841b.h:119
@ MXM_41B_INIT_START_BRIDGE_IC
Definition: mxm_17841b.h:107
@ MXM_41B_UART_READ_RX_SPACE_PARSE
Definition: mxm_17841b.h:117
@ MXM_41B_INIT_READ_CONFIG_REGISTERS
Definition: mxm_17841b.h:109
@ MXM_41B_UART_VERIFY_LOAD_QUEUE_AND_TRANSMIT
Definition: mxm_17841b.h:120
@ MXM_41B_READ_STATUS_REGISTER_SEND
Definition: mxm_17841b.h:124
@ MXM_41B_READ_STATUS_REGISTER_PROCESS
Definition: mxm_17841b.h:125
@ MXM_41B_INIT_WRITE_DEFAULT_VALUES
Definition: mxm_17841b.h:108
@ MXM_41B_UART_WAIT_FOR_RX_STATUS_CHANGE_READ_AND_READ_BACK_RCV_BUF
Definition: mxm_17841b.h:122
#define MXM_SPI_RX_BUFFER_LENGTH
Definition: mxm_17841b.h:82
MXM_41B_REG_FUNCTION_e
Register functions.
Definition: mxm_17841b.h:144
@ MXM_41B_REG_FUNCTION_RX_BUSY_STATUS
Definition: mxm_17841b.h:145
@ MXM_41B_REG_FUNCTION_RX_EMPTY_STATUS
Definition: mxm_17841b.h:148
@ MXM_41B_REG_FUNCTION_RX_STOP_STATUS
Definition: mxm_17841b.h:147
@ MXM_41B_REG_FUNCTION_RX_OVERFLOW_STATUS
Definition: mxm_17841b.h:146
@ MXM_41B_REG_FUNCTION_TX_PREAMBLES
Definition: mxm_17841b.h:149
@ MXM_41B_REG_FUNCTION_RX_ERROR_INT
Definition: mxm_17841b.h:151
@ MXM_41B_REG_FUNCTION_KEEP_ALIVE
Definition: mxm_17841b.h:150
@ MXM_41B_REG_FUNCTION_RX_OVERFLOW_INT
Definition: mxm_17841b.h:152
MXM_41B_STATE_REQUEST_STATUS_e
Request status of MAX17841B states.
Definition: mxm_17841b.h:134
@ MXM_41B_STATE_ERROR
Definition: mxm_17841b.h:138
@ MXM_41B_STATE_UNPROCESSED
Definition: mxm_17841b.h:136
@ MXM_41B_STATE_PROCESSED
Definition: mxm_17841b.h:137
Register map of the MAX17841 bridge IC.
#define MXM_REG_RX_INTERRUPT_ENABLE_W
RX interrupt enable register write address.
#define MXM_BUF_RD_LD_Q_0
Read load queue starting from location 0.
#define MXM_REG_RX_SPACE_R
RX space register read address.
#define MXM_BUF_CLR_RX_BUF
Reset receive buffer and pointers to default state.
#define MXM_REG_FMEA_R
FMEA register read address.
#define MXM_REG_RX_INTERRUPT_ENABLE_R
RX interrupt enable register read address.
#define MXM_BUF_RD_NXT_MSG
Read receive buffer starting at the oldest unread message.
#define MXM_REG_RX_STATUS_R
RX status register read address.
#define MXM_REG_MODEL_R
Model register read address.
#define MXM_BUF_WR_LD_Q_0
Write load queue starting from location 0.
#define MXM_BUF_CLR_TX_BUF
Reset transmit buffer to default state and clear TX_Q and LD_Q.
#define MXM_BUF_WR_NXT_LD_Q_0
Select next load queue and write starting from location 0.
uint8_t MXM_41B_REG_ADD_t
MAX17841B register addresses.
MXM_41B_REG_BIT_VALUE mxm_41bWriteValue(MXM_41B_REG_BIT_VALUE value, uint8_t numberOfBits, MXM_41B_REG_BITS shift, uint8_t reg)
write a value to a register supplied as variable
MXM_41B_REG_BIT_VALUE mxm_41bReadValue(uint8_t reg, uint8_t numberOfBits, MXM_41B_REG_BITS position)
read a value from a register supplied as variable
Bit extraction function for MXM_17841b.
#define MXM_41B_KEEP_ALIVE
#define MXM_41B_RX_BUSY_STATUS
#define MXM_41B_REG_FALSE
#define MXM_41B_RX_EMPTY_STATUS
#define MXM_41B_RX_OVERFLOW_STATUS
uint8_t MXM_41B_REG_BIT_VALUE
Bit-values for registers.
#define MXM_41B_RX_STOP_STATUS
#define MXM_41B_RX_OVERFLOW_INT_ENABLE
#define MXM_41B_RX_ERROR
#define MXM_41B_TX_PREAMBLES
#define MXM_41B_REG_TRUE
STD_RETURN_TYPE_e MXM_ReceiveData(uint16_t *txBuffer, uint16_t *rxBuffer, uint16_t length)
Send and Receive data over SPI.
Definition: mxm_cfg.c:99
STD_RETURN_TYPE_e MXM_GetSPIStateReady(void)
Return whether SPI interface is ready.
Definition: mxm_cfg.c:86
void MXM_ShutDownBridgeIc(void)
Pulls the shutdown of the bridge IC low.
Definition: mxm_cfg.c:109
void MXM_EnableBridgeIc(void)
Pulls the shutdown of the bridge IC high.
Definition: mxm_cfg.c:113
STD_RETURN_TYPE_e MXM_SendData(uint16_t *txBuffer, uint16_t length)
Transmit data over SPI.
Definition: mxm_cfg.c:90
#define MXM_41B_CONFIG_3_DEFAULT_VALUE
Definition: mxm_cfg.h:111
#define MXM_41B_CONFIG_1_DEFAULT_VALUE
Definition: mxm_cfg.h:99
#define MXM_41B_CONFIG_2_DEFAULT_VALUE
Definition: mxm_cfg.h:105
#define MXM_41B_RX_INT_ENABLE_DEFAULT_VALUE
Definition: mxm_cfg.h:88
#define MXM_41B_RX_INT_FLAG_DEFAULT_VALUE
Definition: mxm_cfg.h:90
#define MXM_41B_TX_INT_ENABLE_DEFAULT_VALUE
Definition: mxm_cfg.h:89
#define MXM_41B_TX_INT_FLAG_DEFAULT_VALUE
Definition: mxm_cfg.h:91
bool OS_CheckTimeHasPassed(uint32_t oldTimeStamp_ms, uint32_t timeToPass_ms)
This function checks if timeToPass has passed since the last timestamp to now.
Definition: os.c:150
Declaration of the OS wrapper interface.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:142
Struct for the state-variable of state-machine.
Definition: mxm_17841b.h:161
uint8_t regRXIntEnable
Definition: mxm_17841b.h:171
uint16_t * pRxBuffer
Definition: mxm_17841b.h:166
uint16_t * pPayload
Definition: mxm_17841b.h:164
uint8_t regTXIntEnable
Definition: mxm_17841b.h:172
uint8_t hwMaskRevision
Definition: mxm_17841b.h:181
uint16_t rxBufferLength
Definition: mxm_17841b.h:167
MXM_41B_STATE_REQUEST_STATUS_e * processed
Definition: mxm_17841b.h:168
uint16_t spiRXBuffer[MXM_SPI_RX_BUFFER_LENGTH]
Definition: mxm_17841b.h:183
uint16_t spiTXBuffer[MXM_SPI_TX_BUFFER_LENGTH]
Definition: mxm_17841b.h:184
uint32_t shutdownTimeStamp
Definition: mxm_17841b.h:182
MXM_41B_SUBSTATES_e substate
Definition: mxm_17841b.h:163
MXM_STATEMACH_41B_e state
Definition: mxm_17841b.h:162
uint8_t extendMessageBytes
Definition: mxm_17841b.h:169
uint8_t payloadLength
Definition: mxm_17841b.h:165