foxBMS - Unit Tests  1.3.0
The foxBMS Unit Tests API Documentation
n775.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file n775.c
44  * @author foxBMS Team
45  * @date 2020-05-08 (date of creation)
46  * @updated 2022-05-30 (date of last update)
47  * @version v1.3.0
48  * @ingroup DRIVERS
49  * @prefix N775
50  *
51  * @brief Driver for the MC33775A monitoring chip.
52  *
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "n775.h"
57 
58 #include "HL_system.h"
59 
60 #include "MC33775A.h"
61 #include "afe_dma.h"
62 #include "database.h"
63 #include "diag.h"
64 #include "os.h"
65 
66 /*========== Macros and Definitions =========================================*/
67 
68 /** maximum number of supported cells per slave-module */
69 #define N775_MAX_SUPPORTED_CELLS (12u)
70 
71 /**
72  * Saves the last state and the last substate
73  */
74 #define N775_SAVELASTSTATES() \
75  n775_state.lastState = n775_state.state; \
76  n775_state.lastSubState = n775_state.subState
77 
78 /*========== Static Constant and Variable Definitions =======================*/
79 
80 /*========== Extern Constant and Variable Definitions =======================*/
81 /**
82  * PEC buffer for RX and TX
83  * @{
84  */
85 /* AXIVION Disable Style MisraC2012-1.2: The Pec buffer must be put in the shared RAM section for performance reasons */
86 #pragma SET_DATA_SECTION(".sharedRAM")
89 #pragma SET_DATA_SECTION()
90 /* AXIVION Enable Style MisraC2012-1.2: only Pec buffer needed to be in the shared RAM setcion */
91 /**@}*/
92 
95 
96 uint8_t n775_enumerateAddress = 1u;
97 
98 /* static int16_t n775_voltage_min = INT16_MAX;
99 static int16_t n775_voltage_max = INT16_MIN;
100 static int32_t n775_voltage_sum = 0;
101 
102 static uint8_t n775_voltage_module_number_min = 0;
103 static uint8_t n775_voltage_module_number_max = 0;
104 static uint8_t n775_voltage_cell_number_min = 0;
105 static uint8_t n775_voltage_cell_number_max = 0;
106 static uint16_t n775_voltage_nrValidCellVoltages = 0; */
107 
108 /** local copies of database tables */
109 /**@{*/
114 /**@}*/
115 
117  .timer = 0,
118  .stateReq = N775_STATE_NO_REQUEST,
120  .subState = 0,
121  .lastState = N775_STATEMACH_UNINITIALIZED,
122  .lastSubState = 0,
123  .errRequestCounter = 0,
124  .triggerEntry = 0,
125  .firstMeasurementMade = STD_NOT_OK,
126  .checkSpiFlag = STD_NOT_OK,
127  .balanceControlDone = STD_NOT_OK,
128  .txTransmitOngoing = false,
129  .rxTransmitOngoing = false,
130  .totalMessages = 0u,
131  .remainingMessages = 0u,
132 };
133 
134 /*========== Static Function Prototypes =====================================*/
136 static void N775_CopyStructToTxBuffer(N775_MESSAGE_s *message, uint16_t *buffer);
137 static void N775_WakeUp(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress);
138 static void N775_Write(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t data);
139 static void N775_Read(
140  uint16_t daisyChainAddress,
141  uint16_t deviceAddress,
142  uint16_t registerAddress,
143  uint16_t totalNumberOfRequestedRegister);
144 static void N775_Initialize_Database(void);
145 /* static void N775_Get_BalancingControlValues(void); */
146 static void N775_StateTransition(N775_STATEMACH_e state, uint8_t substate, uint16_t timer_ms);
147 /* static void N775_CondBasedStateTransition(STD_RETURN_TYPE_e retVal, DIAG_ID_e diagCode,
148  N775_STATEMACH_e state_ok, uint8_t substate_ok, uint16_t timer_ms_ok,
149  N775_STATEMACH_e state_nok, uint8_t substate_nok, uint16_t timer_ms_nok); */
150 
151 uint16_t n775_CrcAddItem(uint16_t remainder, uint16_t item);
152 
154 uint16_t n775_CalcCrc(const N775_MESSAGE_s *msg);
155 
156 /*========== Static Function Implementations ================================*/
157 
158 /*========== Extern Function Implementations ================================*/
159 
160 /* TODO: use own function */
161 /**
162  * @brief Called to calculate the CRC of a message. NXP function.
163  *
164  * @param remainder
165  * @param item
166  *
167  * @return remainder
168  *
169  */
170 uint16_t n775_CrcAddItem(uint16_t remainder, uint16_t item) {
171  int i;
172  uint16_t local_remainder = remainder;
173 
174  local_remainder ^= item;
175 
176  for (i = 0; i < 16; i++) {
177  /*
178  * Try to divide the current data bit.
179  */
180  if ((local_remainder & 0x8000u) > 0u) {
181  local_remainder = (local_remainder << 1u) ^ ((0x9eb2u << 1u) + 0x1u);
182  } else {
183  local_remainder = (local_remainder << 1u);
184  }
185  }
186 
187  return (local_remainder);
188 }
189 
190 /* TODO: use own function */
191 /**
192  * @brief Calculate the CRC of a message. NXP function.
193  *
194  * @param msg
195  *
196  * @return crc
197  *
198  */
199 uint16_t n775_CalcCrc(const N775_MESSAGE_s *msg) {
200  uint16_t remainder = 0;
201  int i;
202 
203  remainder = n775_CrcAddItem(remainder, msg->head);
204  remainder = n775_CrcAddItem(remainder, msg->dataHead);
205 
206  for (i = 0; i < (msg->dataLength - 3); i++) {
207  remainder = n775_CrcAddItem(remainder, msg->data[i]);
208  }
209 
210  return (remainder);
211 }
212 
213 /**
214  * @brief in the database, initializes the fields related to the N775 driver.
215  *
216  * This function loops through all the N775-related data fields in the database
217  * and sets them to 0. It should be called in the initialization or re-initialization
218  * routine of the N775 driver.
219  */
220 static void N775_Initialize_Database(void) {
221  uint16_t i = 0;
222 
223  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
231  for (i = 0; i < BS_NR_OF_CELL_BLOCKS_PER_STRING; i++) {
233  }
234 
242  for (i = 0; i < BS_NR_OF_TEMP_SENSORS_PER_STRING; i++) {
244  }
245 
246  for (i = 0; i < BS_NR_OF_CELL_BLOCKS_PER_STRING; i++) {
248  }
249  }
250 
255 }
256 
257 /**
258  * @brief function for setting N775_Trigger state transitions
259  *
260  * @param state: state to transition into
261  * @param subState: substate to transition into
262  * @param timer_ms: transition into state, substate after timer elapsed
263  */
264 static void N775_StateTransition(N775_STATEMACH_e state, uint8_t subState, uint16_t timer_ms) {
265  n775_state.state = state;
266  n775_state.subState = subState;
267  n775_state.timer = timer_ms;
268 }
269 
270 /**
271  * @brief re-entrance check of N775 state machine trigger function
272  *
273  * This function is not re-entrant and should only be called time- or event-triggered.
274  * It increments the triggerentry counter from the state variable n775_state.
275  * It should never be called by two different processes, so if it is the case, triggerentry
276  * should never be higher than 0 when this function is called.
277  *
278  *
279  * @return retval 0 if no further instance of the function is active, 0xff else
280  *
281  */
282 uint8_t N775_CheckReEntrance(void) {
283  uint8_t retval = 0;
284 
286  if (!n775_state.triggerEntry) {
288  } else {
289  retval = 0xFF; /* multiple calls of function */
290  }
292 
293  return (retval);
294 }
296  return N775_CheckReEntrance();
297 }
298 
299 /**
300  * @brief gets the current state request.
301  *
302  * This function is used in the functioning of the N775 state machine.
303  *
304  * @return retval current state request, taken from N775_STATE_REQUEST_e
305  */
308 
310  retval = n775_state.stateReq;
312 
313  return (retval);
314 }
315 
316 /**
317  * @brief gets the current state.
318  *
319  * This function is used in the functioning of the N775 state machine.
320  *
321  * @return current state, taken from N775_STATEMACH_e
322  */
324  return (n775_state.state);
325 }
326 
327 /**
328  * @brief transfers the current state request to the state machine.
329  *
330  * This function takes the current state request from n775_state and transfers it to the state machine.
331  * It resets the value from n775_state to N775_STATE_NO_REQUEST
332  *
333  * @return retVal current state request, taken from N775_STATE_REQUEST_e
334  *
335  */
338 
340  retval = n775_state.stateReq;
343 
344  return (retval);
345 }
346 
349 
351  retVal = N775_CheckStateRequest(statereq);
352 
353  if ((retVal == N775_OK) || (retVal == N775_BUSY_OK) || (retVal == N775_OK_FROM_ERROR)) {
354  n775_state.stateReq = statereq;
355  }
357 
358  return (retVal);
359 }
360 
361 void N775_Trigger(void) {
363  bool n775_goToTrigger = true;
364 
365  N775_Write(0, 0, 0, 0); /* TODO: just to compile, remove */
366  N775_Read(0, 0, 0, 0); /* TODO: just to compile, remove */
367 
368  /* Check re-entrance of function */
369  if (N775_CheckReEntrance() > 0u) {
370  n775_goToTrigger = false;
371  }
372 
374  if (n775_state.timer > 0u) {
375  if ((--n775_state.timer) > 0u) {
377  n775_goToTrigger = false;
378  ; /* handle state machine only if timer has elapsed */
379  }
380  }
381  } else {
382  if (AFE_IsTxTransmitOngoing() == true) {
383  if (n775_state.timer > 0u) {
384  if ((--n775_state.timer) > 0u) {
386  n775_goToTrigger = false;
387  ; /* handle state machine only if timer has elapsed */
388  }
389  }
390  }
391  if (AFE_IsRxTransmitOngoing() == true) {
392  if (n775_state.timer > 0u) {
393  if ((--n775_state.timer) > 0u) {
395  n775_goToTrigger = false;
396  ; /* handle state machine only if timer has elapsed */
397  }
398  }
399  }
400  }
401 
402  if (n775_goToTrigger == true) {
403  switch (n775_state.state) {
404  /****************************UNINITIALIZED***********************************/
406  /* waiting for Initialization Request */
407  n775_stateReq = N775_TransferStateRequest();
408  if (n775_stateReq == N775_STATE_INIT_REQUEST) {
412  } else if (n775_stateReq == N775_STATE_NO_REQUEST) {
413  /* no actual request pending */
414  } else {
415  n775_state.errRequestCounter++; /* illegal request pending */
416  }
417  break;
418 
419  /****************************INITIALIZATION**********************************/
423  break;
424 
425  /****************************INITIALIZED*************************************/
429  break;
430 
431  /****************************START MEASUREMENT*******************************/
433  if (n775_state.subState == N775_ENTRY) {
435  /* Send first wake-up command */
436  N775_WakeUp(0u, 0u, 0u);
438  } else if (n775_state.subState == N775_SECOND_WAKEUP) {
440  /* Send second wake-up command */
441  N775_WakeUp(0u, 0u, 0u);
443  }
444  break;
445 
446  /****************************START MEASUREMENT*******************************/
448  if (n775_state.subState == N775_ENTRY) {
450  /* Enumerate first slave; first address is 1 and not 0; 0 means unenumerated */
451  N775_Write(
452  0u,
454  MC33775_SYS_COM_CFG_OFFSET,
455  (n775_enumerateAddress << MC33775_SYS_COM_CFG_DADD_POS) |
456  (MC33775_SYS_COM_CFG_BUSFW_ENABLED_ENUM_VAL << MC33775_SYS_COM_CFG_BUSFW_POS));
462  /* Enumerate next slave */
463  N775_Write(
464  0u,
466  MC33775_SYS_COM_CFG_OFFSET,
467  (n775_enumerateAddress << MC33775_SYS_COM_CFG_DADD_POS) |
468  (MC33775_SYS_COM_CFG_BUSFW_ENABLED_ENUM_VAL << MC33775_SYS_COM_CFG_BUSFW_POS));
472  } else {
473  /* All slave enumerated */
475  }
476  }
477  break;
478 
479  /****************************START MEASUREMENT*******************************/
481 
482  break;
483 
484  /****************************READ VOLTAGE************************************/
486 
487  break;
488 
489  /****************************BALANCE CONTROL*********************************/
491 
492  break;
493 
494  /****************************DEFAULT**************************/
495  default:
496  /* invalid state */
498  break;
499  }
500  }
501 
502  n775_state.triggerEntry--; /* reentrance counter */
503 }
504 
505 /**
506  * @brief checks the state requests that are made.
507  *
508  * This function checks the validity of the state requests.
509  * The results of the checked is returned immediately.
510  *
511  * @param statereq state request to be checked
512  *
513  * @return result of the state request that was made, taken from N775_RETURN_TYPE_e
514  */
516  N775_RETURN_TYPE_e retVal = N775_OK; /* Default: request is OK */
517 
519  /* init only allowed from the uninitialized state */
520  if (statereq == N775_STATE_INIT_REQUEST) {
522  retVal = N775_OK;
523  } else {
524  retVal = N775_ALREADY_INITIALIZED;
525  }
526  }
527 
528  } else {
529  retVal = N775_REQUEST_PENDING;
530  }
531  return retVal;
532 }
533 
534 /**
535  * @brief gets the measurement initialization status.
536  *
537  * @return retval true if a first measurement cycle was made, false otherwise
538  *
539  */
541  bool retval = false;
542 
546 
547  return (retval);
548 }
549 
550 /**
551  * @brief sets the measurement initialization status.
552  */
557 }
558 
561 }
562 
563 /**
564  * @brief sends a write command to the daisy-chain.
565  * @param message message to be sent
566  * @param buffer buffer used for SPI
567  */
568 static void N775_CopyStructToTxBuffer(N775_MESSAGE_s *message, uint16_t *buffer) {
569  uint8_t i = 0;
570 
571  buffer[0] = message->head;
572  buffer[1] = message->dataHead;
573  if (((message->dataLength) >= 1u) && ((message->dataLength) <= 4u)) {
574  for (i = 0; i < (message->dataLength); i++) {
575  buffer[i + 2u] = message->data[i];
576  }
577  buffer[i + 3u] = message->crc;
578  } else {
579  /* this should not happen, stay here */
581  }
582 }
583 
584 /**
585  * @brief sends a wake-up command to the daisy-chain.
586  *
587  * @param daisyChainAddress parameter CADD in the message format
588  * @param deviceAddress parameter DADD in the message format lies
589  * between 1 and 62, 63 means all devices
590  * @param registerAddress address of register to be written to
591  */
592 static void N775_WakeUp(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress) {
593  uint16_t messageCounter = 0u;
594 
595  /**
596  * Set Head part or WRITE message
597  */
598  /* Set command field of WRITE message */
599  n775_sentData.head = ((N775_CMD_WAKEUP_NOP & 0x3u) << 14u) | ((n775_sentData.head) & 0x3FFFu);
600  /* Set MADD field of WRITE message */
601  n775_sentData.head = ((N775_MADD_MASTER0 & 0x1u) << 13u) | ((n775_sentData.head) & 0xDFFFu);
602  /* Set CADD field of WRITE message */
603  n775_sentData.head = ((daisyChainAddress & 0x7u) << 10u) | ((n775_sentData.head) & 0xE3FFu);
604  /* Set DADD field of WRITE message; device addresses start at 1 */
605  n775_sentData.head = ((deviceAddress & 0x3Fu) << 4u) | ((n775_sentData.head) & 0xFC0Fu);
606  /* Set message counter; not used for WRITE messages, set to 0 */
607  (n775_sentData.head) = (messageCounter & 0xFu) | ((n775_sentData.head) & 0xFFF0u);
608 
609  /**
610  * Set Data head part or WRITE message
611  */
612  /* Set DATLEN field of WRITE message */
613  /* Number of registers addressed per message: 1, which is coded by DATLEN as 0 in the frame */
614  n775_sentData.dataHead = ((0u & 0x3u) << 14u) | ((n775_sentData.dataHead) & 0x3FFFu);
615  /* Set REGADD field of WRITE message (address of register to be addressed)) */
616  n775_sentData.dataHead = (registerAddress & 0x3FFFu) | ((n775_sentData.dataHead) & 0xC000u);
617 
618  /**
619  * Set Data part or WRITE message
620  */
621  /* Set data fields; only first field is used. */
622  /* Set all data fields to 0. */
623  n775_sentData.data[0] = 0u;
624  n775_sentData.data[1] = 0u;
625  n775_sentData.data[2] = 0u;
626  n775_sentData.data[3] = 0u;
627  /* Set data length, used internally in the strcut */
629 
630  /**
631  * Set CRC part or WRITE message
632  */
634 
635  /* Copy strcut data to SPI buffer */
637 
638  /* Send WRITE command to daisy-chain */
640 }
641 
642 /**
643  * @brief sends a write command to the daisy-chain.
644  *
645  * @param daisyChainAddress parameter CADD in the message format
646  * @param deviceAddress parameter DADD in the message format lies
647  * between 1 and 62, 63 means all devices
648  * @param registerAddress address of register to be written to
649  * @param data data to be written in the device register
650  */
651 static void N775_Write(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t data) {
652  uint16_t messageCounter = 0u;
653 
654  /**
655  * Set Head part or WRITE message
656  */
657  /* Set command field of WRITE message */
658  n775_sentData.head = ((N775_CMD_WRITE & 0x3u) << 14u) | ((n775_sentData.head) & 0x3FFFu);
659  /* Set MADD field of WRITE message */
660  n775_sentData.head = ((N775_MADD_MASTER0 & 0x1u) << 13u) | ((n775_sentData.head) & 0xDFFFu);
661  /* Set CADD field of WRITE message */
662  n775_sentData.head = ((daisyChainAddress & 0x7u) << 10u) | ((n775_sentData.head) & 0xE3FFu);
663  /* Set DADD field of WRITE message; device addresses start at 1 */
664  n775_sentData.head = ((deviceAddress & 0x3Fu) << 4u) | ((n775_sentData.head) & 0xFC0Fu);
665  /* Set message counter; not used for WRITE messages, set to 0 */
666  (n775_sentData.head) = (messageCounter & 0xFu) | ((n775_sentData.head) & 0xFFF0u);
667 
668  /**
669  * Set Data head part or WRITE message
670  */
671  /* Set DATLEN field of WRITE message */
672  /* Number of registers addressed per message: 1, which is coded by DATLEN as 0 in the frame */
673  n775_sentData.dataHead = ((0u & 0x3u) << 14u) | ((n775_sentData.dataHead) & 0x3FFFu);
674  /* Set REGADD field of WRITE message (address of register to be addressed)) */
675  n775_sentData.dataHead = (registerAddress & 0x3FFFu) | ((n775_sentData.dataHead) & 0xC000u);
676 
677  /**
678  * Set Data part or WRITE message
679  */
680  /* Set data fields; only first field is used. */
681  n775_sentData.data[0] = data;
682  /* Set other data fields to 0. */
683  n775_sentData.data[1] = 0u;
684  n775_sentData.data[2] = 0u;
685  n775_sentData.data[3] = 0u;
686  /* Set data length, used internally in the strcut */
688 
689  /**
690  * Set CRC part or WRITE message
691  */
693 
694  /* Copy strcut data to SPI buffer */
696 
697  /* Send WRITE command to daisy-chain */
699 }
700 
701 /**
702  * @brief sends a read command to the daisy-chain.
703  * @param daisyChainAddress parameter CADD in the message
704  * format
705  * @param deviceAddress parameter DADD in the message
706  * format lies between 1 and 62
707  * @param registerAddress address of first consecutive
708  * register to be read from
709  * @param totalNumberOfRequestedRegister total number of registers values
710  * sent by daisy-chain lies between 1
711  * and 256
712  */
713 static void N775_Read(
714  uint16_t daisyChainAddress,
715  uint16_t deviceAddress,
716  uint16_t registerAddress,
717  uint16_t totalNumberOfRequestedRegister) {
718  uint16_t messageCounter = 0u;
719  uint16_t dataLen = 0u;
720  uint16_t readParameters = 0u;
721 
722  /**
723  * Set Head part or WRITE message
724  */
725  /* Set command field of WRITE message */
726  n775_sentData.head = ((N775_CMD_READ & 0x3u) << 14u) | ((n775_sentData.head) & 0x3FFFu);
727  /* Set MADD field of WRITE message */
728  n775_sentData.head = ((N775_MADD_MASTER0 & 0x1u) << 13u) | ((n775_sentData.head) & 0xDFFFu);
729  /* Set CADD field of WRITE message */
730  n775_sentData.head = ((daisyChainAddress & 0x7u) << 10u) | ((n775_sentData.head) & 0xE3FFu);
731  /* Set DADD field of WRITE message; device addresses start at 1 */
732  n775_sentData.head = ((deviceAddress & 0x3Fu) << 4u) | ((n775_sentData.head) & 0xFC0Fu);
733  /* Set message counter; not used for READ messages, set to 0 */
734  (n775_sentData.head) = (messageCounter & 0xFu) | ((n775_sentData.head) & 0xFFF0u);
735 
736  /**
737  * Set Data head part or WRITE message
738  */
739  /* Set DATALEN field of WRITE message; number of registers addressed per mssage: 1 */
740  n775_sentData.dataHead = ((dataLen & 0x3u) << 14u) | ((n775_sentData.dataHead) & 0x3FFFu);
741  /* Set REGADD field of WRITE message (address of register t be addressed)) */
742  n775_sentData.dataHead = (registerAddress & 0x3FFFu) | ((n775_sentData.dataHead) & 0xC000u);
743 
744  /**
745  * Set Data part or WRITE message
746  */
747  readParameters = (0u << 11u) + /* First five bits must be written with 0 */
748  (0u << 10u) + /* PAD = 0: no padding */
749  (0u << 8u) + /* RESPLEN = 0: oneregister per frame */
750  ((totalNumberOfRequestedRegister - 1u) << 0); /* NUMREG: number of consecutive registers to read */
751  /* 0 means 1 register, therefore 1u is subtracted */
752  /* Set data field; only first of the 4 fields is used */
753  n775_sentData.data[0] = readParameters;
754  /* Set other data fields to 0. */
755  n775_sentData.data[1] = 0u;
756  n775_sentData.data[2] = 0u;
757  n775_sentData.data[3] = 0u;
758  /* Set data length, used internally in the struct */
760 
761  /**
762  * Set CRC part or WRITE message
763  */
765 
766  /* Copy strcut data to SPI buffer */
768 
769  n775_state.totalMessages = totalNumberOfRequestedRegister;
770  n775_state.remainingMessages = totalNumberOfRequestedRegister;
771 
772  /* Send WRITE command to daisy-chain */
774 }
775 
776 /*========== Externalized Static Function Implementations (Unit Test) =======*/
Headers for the driver for the general DMA module of monitoring ICs.
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_NR_OF_CELL_BLOCKS_PER_STRING
#define BS_NR_OF_TEMP_SENSORS_PER_STRING
Database module header.
#define DATA_WRITE_DATA(...)
Definition: database.h:93
@ DATA_BLOCK_ID_BALANCING_CONTROL
Definition: database_cfg.h:80
@ DATA_BLOCK_ID_MIN_MAX
Definition: database_cfg.h:78
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
Definition: database_cfg.h:98
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
Definition: database_cfg.h:97
Diagnosis driver header.
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:115
@ STD_NOT_OK
Definition: fstd_types.h:83
@ STD_OK
Definition: fstd_types.h:82
uint16_t n775_TXbuffer[N775_TX_MESSAGE_LENGTH]
Definition: n775.c:88
void TEST_N775_SetFirstMeasurementCycleFinished(N775_STATE_s *n775_state)
Definition: n775.c:559
N775_STATE_REQUEST_e N775_TransferStateRequest()
transfers the current state request to the state machine.
Definition: n775.c:336
N775_MESSAGE_s n775_sentData
Definition: n775.c:93
bool N775_IsFirstMeasurementCycleFinished(void)
gets the measurement initialization status.
Definition: n775.c:540
uint16_t n775_CrcAddItem(uint16_t remainder, uint16_t item)
Called to calculate the CRC of a message. NXP function.
Definition: n775.c:170
N775_STATE_REQUEST_e N775_GetStateRequest(void)
gets the current state request.
Definition: n775.c:306
static DATA_BLOCK_MIN_MAX_s n775_minMax
Definition: n775.c:112
static void N775_Initialize_Database(void)
in the database, initializes the fields related to the N775 driver.
Definition: n775.c:220
static DATA_BLOCK_CELL_TEMPERATURE_s n775_cellTemperature
Definition: n775.c:111
uint16_t n775_CalcCrc(const N775_MESSAGE_s *msg)
Calculate the CRC of a message. NXP function.
Definition: n775.c:199
static void N775_Read(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t totalNumberOfRequestedRegister)
sends a read command to the daisy-chain.
Definition: n775.c:713
static void N775_SetFirstMeasurementCycleFinished(N775_STATE_s *n775_state)
sets the measurement initialization status.
Definition: n775.c:553
uint16_t n775_RXbuffer[N775_MAX_N_BYTES_FOR_DATA_RECEPTION]
Definition: n775.c:87
static DATA_BLOCK_CELL_VOLTAGE_s n775_cellVoltage
Definition: n775.c:110
N775_STATE_s n775_state
Definition: n775.c:116
static void N775_WakeUp(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress)
sends a wake-up command to the daisy-chain.
Definition: n775.c:592
#define N775_SAVELASTSTATES()
Definition: n775.c:74
static DATA_BLOCK_BALANCING_CONTROL_s n775_balancingControl
Definition: n775.c:113
uint8_t n775_enumerateAddress
Definition: n775.c:96
static N775_RETURN_TYPE_e N775_CheckStateRequest(N775_STATE_REQUEST_e statereq)
checks the state requests that are made.
Definition: n775.c:515
static void N775_CopyStructToTxBuffer(N775_MESSAGE_s *message, uint16_t *buffer)
sends a write command to the daisy-chain.
Definition: n775.c:568
static void N775_StateTransition(N775_STATEMACH_e state, uint8_t substate, uint16_t timer_ms)
function for setting N775_Trigger state transitions
Definition: n775.c:264
void N775_Trigger(void)
trigger function for the N775 driver state machine.
Definition: n775.c:361
uint8_t TEST_N775_CheckReEntrance(void)
Definition: n775.c:295
static void N775_Write(uint16_t daisyChainAddress, uint16_t deviceAddress, uint16_t registerAddress, uint16_t data)
sends a write command to the daisy-chain.
Definition: n775.c:651
N775_STATEMACH_e N775_GetState(void)
gets the current state.
Definition: n775.c:323
N775_RETURN_TYPE_e N775_SetStateRequest(N775_STATE_REQUEST_e statereq)
sets the current state request of the state variable n775_state.
Definition: n775.c:347
N775_MESSAGE_s n775_receivedData
Definition: n775.c:94
uint8_t N775_CheckReEntrance(void)
re-entrance check of N775 state machine trigger function
Definition: n775.c:282
Headers for the driver for the MC33775A monitoring chip.
#define N775_N_N775
Definition: n775_cfg.h:70
#define N775_MAX_N_BYTES_FOR_DATA_RECEPTION
Definition: n775_cfg.h:152
#define N775_TWAKECOM_MS
Definition: n775_cfg.h:118
#define N775_SendData(txbuf, rxbuf, length)
Definition: n775_cfg.h:157
#define N775_TIME_DAISYCHAIN_WAKEUP_MS
Definition: n775_cfg.h:129
#define N775_TX_MESSAGE_LENGTH
Definition: n775_cfg.h:80
#define N775_TIME_AFTER_ENUMERATION_MS
Definition: n775_cfg.h:139
#define N775_STATEMACH_SHORTTIME
Definition: n775_cfg.h:112
N775_RETURN_TYPE_e
Definition: n775_defs.h:129
@ N775_REQUEST_PENDING
Definition: n775_defs.h:132
@ N775_OK
Definition: n775_defs.h:130
@ N775_ERROR
Definition: n775_defs.h:139
@ N775_ALREADY_INITIALIZED
Definition: n775_defs.h:140
@ N775_OK_FROM_ERROR
Definition: n775_defs.h:138
@ N775_BUSY_OK
Definition: n775_defs.h:131
@ N775_ENTRY
Definition: n775_defs.h:97
@ N775_SECOND_WAKEUP
Definition: n775_defs.h:98
@ N775_CHECK_ENUMERATION
Definition: n775_defs.h:99
@ N775_MADD_MASTER0
Definition: n775_defs.h:78
N775_STATE_REQUEST_e
Definition: n775_defs.h:121
@ N775_STATE_NO_REQUEST
Definition: n775_defs.h:123
@ N775_STATE_INIT_REQUEST
Definition: n775_defs.h:122
@ N775_ENTRY_UNINITIALIZED
Definition: n775_defs.h:106
@ N775_CMD_READ
Definition: n775_defs.h:71
@ N775_CMD_WRITE
Definition: n775_defs.h:72
@ N775_CMD_WAKEUP_NOP
Definition: n775_defs.h:70
N775_STATEMACH_e
Definition: n775_defs.h:83
@ N775_STATEMACH_ENUMERATE
Definition: n775_defs.h:87
@ N775_STATEMACH_WAKEUP
Definition: n775_defs.h:86
@ N775_STATEMACH_BALANCECONTROL
Definition: n775_defs.h:92
@ N775_STATEMACH_STARTMEAS
Definition: n775_defs.h:90
@ N775_STATEMACH_READVOLTAGE
Definition: n775_defs.h:91
@ N775_STATEMACH_INITIALIZED
Definition: n775_defs.h:88
@ N775_STATEMACH_INITIALIZATION
Definition: n775_defs.h:85
@ N775_STATEMACH_UNINITIALIZED
Definition: n775_defs.h:84
bool AFE_IsTxTransmitOngoing(void)
gets the SPI transmit status.
Definition: nxp_afe_dma.c:74
bool AFE_IsRxTransmitOngoing(void)
gets the SPI transmit status.
Definition: nxp_afe_dma.c:80
Declaration of the OS wrapper interface.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:135
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:131
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:247
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:252
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:146
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
Definition: database_cfg.h:148
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:129
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:132
DATA_BLOCK_ID_e uniqueId
Definition: database_cfg.h:119
int16_t minimumTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:172
uint16_t nrSensorMinimumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:174
uint16_t nrModuleMinimumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:173
uint16_t nrModuleMaximumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:176
int16_t maximumTemperature_ddegC[BS_NR_OF_STRINGS]
Definition: database_cfg.h:175
uint16_t nrSensorMaximumTemperature[BS_NR_OF_STRINGS]
Definition: database_cfg.h:177
uint16_t nrCellMaximumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:169
uint16_t nrCellMinimumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:167
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:159
uint16_t nrModuleMinimumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:166
uint16_t nrModuleMaximumCellVoltage[BS_NR_OF_STRINGS]
Definition: database_cfg.h:168
int16_t maximumCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:164
int16_t minimumCellVoltage_mV[BS_NR_OF_STRINGS]
Definition: database_cfg.h:162
uint16_t dataLength
Definition: n775_defs.h:252
uint16_t dataHead
Definition: n775_defs.h:249
uint16_t crc
Definition: n775_defs.h:251
uint16_t head
Definition: n775_defs.h:248
uint16_t data[4]
Definition: n775_defs.h:250
STD_RETURN_TYPE_e firstMeasurementMade
Definition: n775_defs.h:237
uint16_t totalMessages
Definition: n775_defs.h:242
N775_STATE_REQUEST_e stateReq
Definition: n775_defs.h:230
uint8_t subState
Definition: n775_defs.h:232
uint16_t timer
Definition: n775_defs.h:229
STD_RETURN_TYPE_e checkSpiFlag
Definition: n775_defs.h:238
N775_STATEMACH_e state
Definition: n775_defs.h:231
uint32_t errRequestCounter
Definition: n775_defs.h:235
uint8_t triggerEntry
Definition: n775_defs.h:236
uint16_t remainingMessages
Definition: n775_defs.h:243