foxBMS - Unit Tests  1.3.0
The foxBMS Unit Tests API Documentation
can.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 can.c
44  * @author foxBMS Team
45  * @date 2019-12-04 (date of creation)
46  * @updated 2022-05-30 (date of last update)
47  * @version v1.3.0
48  * @ingroup DRIVERS
49  * @prefix CAN
50  *
51  * @brief Driver for the CAN module
52  *
53  * @details Implementation of the CAN Interrupts, initialization, buffers,
54  * receive and transmit interfaces.
55  */
56 
57 /*========== Includes =======================================================*/
58 #include "can.h"
59 
60 #include "version_cfg.h"
61 
62 #include "HL_het.h"
63 #include "HL_reg_system.h"
64 
65 #include "bender_iso165c.h"
66 #include "can_helper.h"
67 #include "database.h"
68 #include "diag.h"
69 #include "foxmath.h"
70 #include "ftask.h"
71 #include "pex.h"
72 
73 /*========== Macros and Definitions =========================================*/
74 /** lower limit of timestamp counts for a valid CAN timing */
75 #define CAN_TIMING_LOWER_LIMIT_COUNTS (95u)
76 
77 /** upper limit of timestamp counts for a valid CAN timing */
78 #define CAN_TIMING_UPPER_LIMIT_COUNTS (105u)
79 
80 /** maximum distance from release that can be encoded in the boot message */
81 #define CAN_BOOT_MESSAGE_MAXIMUM_RELEASE_DISTANCE (31u)
82 #if CAN_BOOT_MESSAGE_MAXIMUM_RELEASE_DISTANCE > UINT8_MAX
83 #error "This code assumes that the define is smaller or equal to UINT8_MAX")
84 #endif
85 
86 /** bit position of boot message byte 3 version control flag */
87 #define CAN_BOOT_MESSAGE_BYTE_3_BIT_VERSION_CONTROL (0u)
88 
89 /** bit position of boot message byte 3 dirty flag */
90 #define CAN_BOOT_MESSAGE_BYTE_3_BIT_DIRTY_FLAG (1u)
91 
92 /** bit position of boot message byte 3 release distance overflow flag */
93 #define CAN_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_OVERFLOW_FLAG (2u)
94 
95 /** bit position of boot message byte 3 release distance counter */
96 #define CAN_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_COUNTER (3u)
97 
98 /** return value of function canGetData if no data was lost during reception */
99 #define CAN_HAL_RETVAL_NO_DATA_LOST (1u)
100 
101 /*========== Static Constant and Variable Definitions =======================*/
102 
103 /** tracks the local state of the can module */
105  .periodicEnable = false,
106  .currentSensorPresent = {REPEAT_U(false, STRIP(BS_NR_OF_STRINGS))},
107  .currentSensorCCPresent = {REPEAT_U(false, STRIP(BS_NR_OF_STRINGS))},
108  .currentSensorECPresent = {REPEAT_U(false, STRIP(BS_NR_OF_STRINGS))},
109 };
110 
111 /*========== Extern Constant and Variable Definitions =======================*/
112 
113 /*========== Static Function Prototypes =====================================*/
114 
115 /**
116  * @brief Called in case of CAN TX interrupt.
117  * @param pNode CAN interface on which message was sent
118  * @param messageBox message box on which message was sent
119  */
120 static void CAN_TxInterrupt(canBASE_t *pNode, uint32 messageBox);
121 
122 /**
123  * @brief Called in case of CAN RX interrupt.
124  * @param pNode CAN interface on which message was received
125  * @param messageBox message box on which message was received
126  */
127 static void CAN_RxInterrupt(canBASE_t *pNode, uint32 messageBox);
128 
129 /**
130  * @brief Handles the processing of messages that are meant to be transmitted.
131  * This function looks for the repetition times and the repetition phase of
132  * messages that are intended to be sent periodically. If a comparison with
133  * an internal counter (i.e., the counter how often this function has been called)
134  * states that a transmit is pending, the message is composed by call of CANS_ComposeMessage
135  * and transferred to the buffer of the CAN module. If a callback function
136  * is declared in configuration, this callback is called after successful transmission.
137  * @return #STD_OK if a CAN transfer was made, #STD_NOT_OK otherwise
138  */
140 
141 /**
142  * @brief Checks if the CAN messages come in the specified time window
143  * If the (current time stamp) - (previous time stamp) > 96ms and < 104ms,
144  * the check is true, false otherwise. The result is reported via flags
145  * in the DIAG module.
146  */
147 static void CAN_CheckCanTiming(void);
148 
149 #if CURRENT_SENSOR_PRESENT == true
150 /**
151  * @brief Sets flag to indicate current sensor is present.
152  *
153  * @param command true if current sensor present, otherwise false
154  * @param stringNumber string addressed
155  *
156  * @return none
157  */
158 static void CAN_SetCurrentSensorPresent(bool command, uint8_t stringNumber);
159 
160 /**
161  * @brief Sets flag to indicate current sensor sends C-C values.
162  *
163  * @param command true if coulomb counting message detected, otherwise false
164  * @param stringNumber string addressed
165  *
166  * @return none
167  */
168 static void CAN_SetCurrentSensorCcPresent(bool command, uint8_t stringNumber);
169 
170 /**
171  * @brief Sets flag to indicate current sensor sends C-C values.
172  *
173  * @param command true if energy counting message detected, otherwise false
174  * @param stringNumber string addressed
175  *
176  * @return none
177  */
178 static void CAN_SetCurrentSensorEcPresent(bool command, uint8_t stringNumber);
179 #endif /* CURRENT_SENSOR_PRESENT == true */
180 
181 /** initialize the SPI interface to the CAN transceiver */
182 static void CAN_InitializeTransceiver(void);
183 
184 /*========== Static Function Implementations ================================*/
185 
186 static void CAN_InitializeTransceiver(void) {
187  /** Initialize transceiver for CAN1 */
192 
193  /** Initialize transceiver for CAN2 */
198 }
199 
200 /*========== Extern Function Implementations ================================*/
201 
202 extern void CAN_Initialize(void) {
204 }
205 
206 extern STD_RETURN_TYPE_e CAN_DataSend(canBASE_t *pNode, uint32_t id, uint8 *pData) {
207  FAS_ASSERT(pNode != NULL_PTR);
208  FAS_ASSERT(pData != NULL_PTR);
209  FAS_ASSERT((pNode == CAN1_NODE) || (pNode == CAN2_NODE));
210  /* AXIVION Routine Generic-MissingParameterAssert: id: parameter accepts whole range */
211 
212  STD_RETURN_TYPE_e result = STD_NOT_OK;
213 
214  /**
215  * Parse all TX message boxes until we find a free one,
216  * then use it to send the CAN message.
217  * In the HAL, message box numbers start from 1, not 0.
218  */
219  for (uint8_t messageBox = 1u; messageBox <= CAN_NR_OF_TX_MESSAGE_BOX; messageBox++) {
220  if (canIsTxMessagePending(pNode, messageBox) == 0u) {
221  /* id shifted by 18 to use standard frame */
222  /* standard frame: bits [28:18] */
223  /* extended frame: bits [28:0] */
224  /* bit 29 set to 1: to set direction Tx in IF2ARB register */
225  canUpdateID(pNode, messageBox, ((id << 18) | (1U << 29)));
226  canTransmit(pNode, messageBox, pData);
227  result = STD_OK;
228  break;
229  }
230  }
231  return result;
232 }
233 
234 extern void CAN_MainFunction(void) {
236  if (can_state.periodicEnable == true) {
238  }
239 }
240 
242  STD_RETURN_TYPE_e retVal = STD_NOT_OK;
243  static uint32_t counterTicks = 0;
244  uint8_t data[8] = {0};
245 
246  for (uint16_t i = 0u; i < can_txLength; i++) {
247  if (((counterTicks * CAN_TICK_MS) % (can_txMessages[i].repetitionTime)) == can_txMessages[i].repetitionPhase) {
248  if (can_txMessages[i].callbackFunction != NULL_PTR) {
250  can_txMessages[i].id,
251  can_txMessages[i].dlc,
252  can_txMessages[i].endianness,
253  data,
254  can_txMessages[i].pMuxId,
255  &can_kShim);
256  /* CAN messages are currently discarded if all message boxes
257  * are full. They will not be retransmitted within the next
258  * call of CAN_PeriodicTransmit() */
259  CAN_DataSend(can_txMessages[i].canNode, can_txMessages[i].id, data);
260  retVal = STD_OK;
261  }
262  }
263  }
264 
265  counterTicks++;
266  return retVal;
267 }
268 
269 static void CAN_CheckCanTiming(void) {
270  uint32_t current_time;
273 #if CURRENT_SENSOR_PRESENT == true
275 #endif /* CURRENT_SENSOR_PRESENT == true */
276 
277  current_time = OS_GetTickCount();
278  DATA_READ_DATA(&staterequestTab, &errorFlagsTab);
279 
280  /* Is the BMS still getting CAN messages? */
281  if ((current_time - staterequestTab.header.timestamp) <= CAN_TIMING_UPPER_LIMIT_COUNTS) {
282  if (((staterequestTab.header.timestamp - staterequestTab.header.previousTimestamp) >=
284  ((staterequestTab.header.timestamp - staterequestTab.header.previousTimestamp) <=
287  } else {
289  }
290  } else {
292  }
293 
294 #if CURRENT_SENSOR_PRESENT == true
295  /* check time stamps of current measurements */
296  DATA_READ_DATA(&currentTab);
297 
298  for (uint8_t s = 0u; s < BS_NR_OF_STRINGS; s++) {
299  /* Current has been measured at least once */
300  if (currentTab.timestampCurrent[s] != 0u) {
301  /* Check time since last received string current data */
302  if ((current_time - currentTab.timestampCurrent[s]) > BS_CURRENT_MEASUREMENT_RESPONSE_TIMEOUT_MS) {
304  } else {
306  if (can_state.currentSensorPresent[s] == false) {
308  }
309  }
310  }
311 
312  /* check time stamps of CC measurements */
313  /* if timestamp_cc != 0, this means current sensor cc message has been received at least once */
314  if (currentTab.timestampCurrentCounting[s] != 0) {
315  if ((current_time - currentTab.timestampCurrentCounting[s]) >
318  } else {
320  if (can_state.currentSensorCCPresent[s] == false) {
322  }
323  }
324  }
325 
326  /* check time stamps of EC measurements */
327  /* if timestamp_ec != 0, this means current sensor ec message has been received at least once */
328  if (currentTab.timestampEnergyCounting[s] != 0) {
329  if ((current_time - currentTab.timestampEnergyCounting[s]) >
332  } else {
334  if (can_state.currentSensorECPresent[s] == false) {
336  }
337  }
338  }
339  }
340 #endif /* CURRENT_SENSOR_PRESENT == true */
341 }
342 
343 extern void CAN_ReadRxBuffer(void) {
344  CAN_BUFFERELEMENT_s can_rxBuffer = {0};
345  if (ftsk_allQueuesCreated == true) {
346  while (OS_ReceiveFromQueue(ftsk_canRxQueue, (void *)&can_rxBuffer, 0u) == OS_SUCCESS) {
347  /* data queue was not empty */
348  for (uint16_t i = 0u; i < can_rxLength; i++) {
349  if ((can_rxBuffer.canNode == can_rxMessages[i].canNode) && (can_rxBuffer.id == can_rxMessages[i].id)) {
350  if (can_rxMessages[i].callbackFunction != NULL_PTR) {
352  can_rxMessages[i].id,
353  can_rxMessages[i].dlc,
354  can_rxMessages[i].endianness,
355  can_rxBuffer.data,
356  &can_kShim);
357  }
358  }
359  }
360  }
361  }
362 }
363 
364 /**
365  * @brief enable/disable the periodic transmit/receive.
366  */
367 extern void CAN_EnablePeriodic(bool command) {
368  if (command == true) {
369  can_state.periodicEnable = true;
370  } else {
371  can_state.periodicEnable = false;
372  }
373 }
374 
375 #if CURRENT_SENSOR_PRESENT == true
376 static void CAN_SetCurrentSensorPresent(bool command, uint8_t stringNumber) {
377  if (command == true) {
379  can_state.currentSensorPresent[stringNumber] = true;
381  } else {
383  can_state.currentSensorPresent[stringNumber] = false;
385  }
386 }
387 
388 static void CAN_SetCurrentSensorCcPresent(bool command, uint8_t stringNumber) {
389  if (command == true) {
391  can_state.currentSensorCCPresent[stringNumber] = true;
393  } else {
395  can_state.currentSensorCCPresent[stringNumber] = false;
397  }
398 }
399 
400 static void CAN_SetCurrentSensorEcPresent(bool command, uint8_t stringNumber) {
401  if (command == true) {
403  can_state.currentSensorECPresent[stringNumber] = true;
405  } else {
407  can_state.currentSensorECPresent[stringNumber] = false;
409  }
410 }
411 #endif /* CURRENT_SENSOR_PRESENT == true */
412 
413 extern bool CAN_IsCurrentSensorPresent(uint8_t stringNumber) {
414  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
415  return can_state.currentSensorPresent[stringNumber];
416 }
417 
418 extern bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber) {
419  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
420  return can_state.currentSensorCCPresent[stringNumber];
421 }
422 
423 extern bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber) {
424  FAS_ASSERT(stringNumber < BS_NR_OF_STRINGS);
425  return can_state.currentSensorECPresent[stringNumber];
426 }
427 
428 static void CAN_TxInterrupt(canBASE_t *pNode, uint32 messageBox) {
429  /* AXIVION Routine Generic-MissingParameterAssert: pNode: unused parameter */
430  /* AXIVION Routine Generic-MissingParameterAssert: messageBox: unused parameter */
431  (void)pNode;
432  (void)messageBox;
433 }
434 
435 static void CAN_RxInterrupt(canBASE_t *pNode, uint32 messageBox) {
436  FAS_ASSERT(pNode != NULL_PTR);
437 
438  CAN_BUFFERELEMENT_s can_rxBuffer = {0u};
439  uint8_t messageData[CAN_DLC] = {0u};
440  /**
441  * Read even if queues are not created, otherwise message boxes get full.
442  * Possible return values:
443  * - 0: no new data
444  * - 1: no data lost
445  * - 3: data lost */
446  uint32_t retval = canGetData(pNode, messageBox, (uint8 *)&messageData[0]); /* copy to RAM */
447 
448  /* Check that CAN RX queue is started before using it and data is valid */
449  if ((ftsk_allQueuesCreated == true) && (retval == CAN_HAL_RETVAL_NO_DATA_LOST)) {
450  /* id shifted by 18 to use standard frame from IF2ARB register*/
451  /* standard frame: bits [28:18] */
452  /* extended frame: bits [28:0] */
453  uint32_t id = canGetID(pNode, messageBox) >> 18u;
454 
455  can_rxBuffer.canNode = pNode;
456  can_rxBuffer.id = id;
457  can_rxBuffer.data[0] = messageData[0];
458  can_rxBuffer.data[1] = messageData[1];
459  can_rxBuffer.data[2] = messageData[2];
460  can_rxBuffer.data[3] = messageData[3];
461  can_rxBuffer.data[4] = messageData[4];
462  can_rxBuffer.data[5] = messageData[5];
463  can_rxBuffer.data[6] = messageData[6];
464  can_rxBuffer.data[7] = messageData[7];
465 
466  if (OS_SendToBackOfQueueFromIsr(ftsk_canRxQueue, (void *)&can_rxBuffer, NULL_PTR) == OS_SUCCESS) {
467  /* queue is not full */
469  } else {
470  /* queue is full */
472  }
473  }
474 }
475 
476 /** called in case of CAN interrupt, defined as weak in HAL */
477 /* AXIVION Next Line Style Linker-Multiple_Definition: TI HAL only provides a weak implementation */
478 void UNIT_TEST_WEAK_IMPL canMessageNotification(canBASE_t *node, uint32 messageBox) {
479  /* AXIVION Routine Generic-MissingParameterAssert: node: unchecked in interrupt */
480  /* AXIVION Routine Generic-MissingParameterAssert: messageBox: unchecked in interrupt */
481 
482  if (messageBox <= CAN_NR_OF_TX_MESSAGE_BOX) {
483  CAN_TxInterrupt(node, messageBox);
484  } else {
485  CAN_RxInterrupt(node, messageBox);
486  }
487 }
488 
490  uint8_t data[] = {REPEAT_U(0u, STRIP(CAN_MAX_DLC))};
491 
492  /* Set major number */
494  /* Set minor number */
496  /* Set patch number */
498 
499  /* intermediate variable for message byte 3 */
500  uint8_t versionControlByte = 0u;
501 
502  /* Set version control flags */
504  versionControlByte |= (0x01u << CAN_BOOT_MESSAGE_BYTE_3_BIT_VERSION_CONTROL);
505  }
506  if (foxbmsVersionInfo.isDirty == true) {
507  versionControlByte |= (0x01u << CAN_BOOT_MESSAGE_BYTE_3_BIT_DIRTY_FLAG);
508  }
509  /* Set overflow flag (if release distance is larger than 31) */
511  /* we need to set the overflow flag */
512  versionControlByte |= (0x01u << CAN_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_OVERFLOW_FLAG);
513  }
514 
515  /* Set release distance (capped to maximum value) */
516  const uint8_t distanceCapped = (uint8_t)MATH_MinimumOfTwoUint16_t(
518  versionControlByte |= (distanceCapped << CAN_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_COUNTER);
519 
520  /* assign assembled byte to databyte */
521  data[CAN_BYTE_3_POSITION] = versionControlByte;
522 
523  /* Read out device register with unique ID */
524  const uint32_t deviceRegister = systemREG1->DEVID;
525 
526  /* Set unique ID */
527  data[CAN_BYTE_4_POSITION] = (uint8_t)((deviceRegister >> 24u) & 0xFFu);
528  data[CAN_BYTE_5_POSITION] = (uint8_t)((deviceRegister >> 16u) & 0xFFu);
529  data[CAN_BYTE_6_POSITION] = (uint8_t)((deviceRegister >> 8u) & 0xFFu);
530  data[CAN_BYTE_7_POSITION] = (uint8_t)(deviceRegister & 0xFFu);
531 
533 
534  return retval;
535 }
536 
538  uint8_t data[] = {REPEAT_U(0u, STRIP(CAN_MAX_DLC))};
539 
540  /* Read out device register with die ID low and high */
541  const uint32_t dieIdLow = systemREG1->DIEIDL;
542  const uint32_t dieIdHigh = systemREG1->DIEIDH;
543 
544  /* set die ID */
545  /* AXIVION Disable Style Generic-NoMagicNumbers: The magic numbers are used to divide down the registers into the CAN message */
546  data[CAN_BYTE_0_POSITION] = (uint8_t)((dieIdHigh >> 24u) & 0xFFu);
547  data[CAN_BYTE_1_POSITION] = (uint8_t)((dieIdHigh >> 16u) & 0xFFu);
548  data[CAN_BYTE_2_POSITION] = (uint8_t)((dieIdHigh >> 8u) & 0xFFu);
549  data[CAN_BYTE_3_POSITION] = (uint8_t)(dieIdHigh & 0xFFu);
550  data[CAN_BYTE_4_POSITION] = (uint8_t)((dieIdLow >> 24u) & 0xFFu);
551  data[CAN_BYTE_5_POSITION] = (uint8_t)((dieIdLow >> 16u) & 0xFFu);
552  data[CAN_BYTE_6_POSITION] = (uint8_t)((dieIdLow >> 8u) & 0xFFu);
553  data[CAN_BYTE_7_POSITION] = (uint8_t)(dieIdLow & 0xFFu);
554  /* AXIVION Enable Style Generic-NoMagicNumbers: */
555 
557 
558  return retval;
559 }
560 
561 /*========== Getter for static Variables (Unit Test) ========================*/
562 #ifdef UNITY_UNIT_TEST
564  return &can_state;
565 }
566 #endif
567 
568 /*========== Externalized Static Function Implementations (Unit Test) =======*/
#define BS_COULOMB_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_MS
#define BS_ENERGY_COUNTING_MEASUREMENT_RESPONSE_TIMEOUT_MS
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_CURRENT_MEASUREMENT_RESPONSE_TIMEOUT_MS
Headers for the driver for the insulation monitoring.
static void CAN_RxInterrupt(canBASE_t *pNode, uint32 messageBox)
Called in case of CAN RX interrupt.
Definition: can.c:435
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
Definition: can.c:418
void CAN_MainFunction(void)
Calls the functions to drive the CAN interface. Makes the CAN timing checks and sends the periodic me...
Definition: can.c:234
static void CAN_SetCurrentSensorCcPresent(bool command, uint8_t stringNumber)
Sets flag to indicate current sensor sends C-C values.
Definition: can.c:388
static STD_RETURN_TYPE_e CAN_PeriodicTransmit(void)
Handles the processing of messages that are meant to be transmitted. This function looks for the repe...
Definition: can.c:241
CAN_STATE_s * TEST_CAN_GetCANState(void)
Definition: can.c:563
STD_RETURN_TYPE_e CAN_TransmitDieId(void)
Transmit chip id.
Definition: can.c:537
#define CAN_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_OVERFLOW_FLAG
Definition: can.c:93
#define CAN_HAL_RETVAL_NO_DATA_LOST
Definition: can.c:99
static void CAN_CheckCanTiming(void)
Checks if the CAN messages come in the specified time window If the (current time stamp) - (previous ...
Definition: can.c:269
#define CAN_TIMING_LOWER_LIMIT_COUNTS
Definition: can.c:75
static void CAN_InitializeTransceiver(void)
Definition: can.c:186
void UNIT_TEST_WEAK_IMPL canMessageNotification(canBASE_t *node, uint32 messageBox)
Definition: can.c:478
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:423
static void CAN_TxInterrupt(canBASE_t *pNode, uint32 messageBox)
Called in case of CAN TX interrupt.
Definition: can.c:428
#define CAN_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_COUNTER
Definition: can.c:96
STD_RETURN_TYPE_e CAN_DataSend(canBASE_t *pNode, uint32_t id, uint8 *pData)
Sends over CAN the data passed in parameters. This function goes over the messageboxes and marks the ...
Definition: can.c:206
void CAN_ReadRxBuffer(void)
Checks the data received per CAN. A receive buffer is used because CAN frames are received in an inte...
Definition: can.c:343
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:413
static void CAN_SetCurrentSensorEcPresent(bool command, uint8_t stringNumber)
Sets flag to indicate current sensor sends C-C values.
Definition: can.c:400
STD_RETURN_TYPE_e CAN_TransmitBootMessage(void)
Transmit startup boot message.
Definition: can.c:489
#define CAN_TIMING_UPPER_LIMIT_COUNTS
Definition: can.c:78
#define CAN_BOOT_MESSAGE_MAXIMUM_RELEASE_DISTANCE
Definition: can.c:81
static void CAN_SetCurrentSensorPresent(bool command, uint8_t stringNumber)
Sets flag to indicate current sensor is present.
Definition: can.c:376
#define CAN_BOOT_MESSAGE_BYTE_3_BIT_DIRTY_FLAG
Definition: can.c:90
void CAN_Initialize(void)
Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver....
Definition: can.c:202
static CAN_STATE_s can_state
Definition: can.c:104
void CAN_EnablePeriodic(bool command)
enable/disable the periodic transmit/receive.
Definition: can.c:367
#define CAN_BOOT_MESSAGE_BYTE_3_BIT_VERSION_CONTROL
Definition: can.c:87
Header for the driver for the CAN module.
#define CAN_NR_OF_TX_MESSAGE_BOX
Definition: can.h:71
#define CAN_TICK_MS
Definition: can.h:76
const CAN_MSG_RX_TYPE_s can_rxMessages[]
Definition: can_cfg.c:202
const uint8_t can_txLength
Definition: can_cfg.c:346
const CAN_MSG_TX_TYPE_s can_txMessages[]
Definition: can_cfg.c:89
const CAN_SHIM_s can_kShim
Definition: can_cfg.c:369
const uint8_t can_rxLength
Definition: can_cfg.c:347
#define CAN2_ENABLE_PIN
Definition: can_cfg.h:81
#define CAN1_STANDBY_PIN
Definition: can_cfg.h:80
#define CAN2_NODE
Definition: can_cfg.h:72
#define CAN1_ENABLE_PIN
Definition: can_cfg.h:79
#define CAN2_STANDBY_PIN
Definition: can_cfg.h:82
#define CAN_DLC
Definition: can_cfg.h:91
#define CAN_ID_DIE_ID
Definition: can_cfg.h:98
#define CAN1_NODE
Definition: can_cfg.h:71
#define CAN_MAX_DLC
Definition: can_cfg.h:88
#define CAN_ID_BOOT_MESSAGE
Definition: can_cfg.h:96
Headers for the helper functions for the CAN module.
#define CAN_BYTE_2_POSITION
Definition: can_helper.h:71
#define CAN_BYTE_4_POSITION
Definition: can_helper.h:73
#define CAN_BYTE_0_POSITION
Definition: can_helper.h:69
#define CAN_BYTE_6_POSITION
Definition: can_helper.h:75
#define CAN_BYTE_7_POSITION
Definition: can_helper.h:76
#define CAN_BYTE_3_POSITION
Definition: can_helper.h:72
#define CAN_BYTE_5_POSITION
Definition: can_helper.h:74
#define CAN_BYTE_1_POSITION
Definition: can_helper.h:70
Database module header.
#define DATA_READ_DATA(...)
Definition: database.h:83
@ DATA_BLOCK_ID_CURRENT_SENSOR
Definition: database_cfg.h:79
@ DATA_BLOCK_ID_ERRORSTATE
Definition: database_cfg.h:86
@ DATA_BLOCK_ID_STATEREQUEST
Definition: database_cfg.h:95
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diag_id, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
Definition: diag.c:229
Diagnosis driver header.
@ DIAG_EVENT_NOT_OK
Definition: diag_cfg.h:239
@ DIAG_EVENT_OK
Definition: diag_cfg.h:238
@ DIAG_SYSTEM
Definition: diag_cfg.h:251
@ DIAG_STRING
Definition: diag_cfg.h:252
@ DIAG_ID_CAN_CC_RESPONDING
Definition: diag_cfg.h:167
@ DIAG_ID_CAN_TIMING
Definition: diag_cfg.h:165
@ DIAG_ID_CURRENT_SENSOR_RESPONDING
Definition: diag_cfg.h:169
@ DIAG_ID_CAN_RX_QUEUE_FULL
Definition: diag_cfg.h:166
@ DIAG_ID_CAN_EC_RESPONDING
Definition: diag_cfg.h:168
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
uint16_t MATH_MinimumOfTwoUint16_t(const uint16_t value1, const uint16_t value2)
Returns the minimum of the passed uint16_t values.
Definition: foxmath.c:145
math library for often used math functions
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
@ STD_NOT_OK
Definition: fstd_types.h:83
@ STD_OK
Definition: fstd_types.h:82
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:76
Header of task driver implementation.
volatile bool ftsk_allQueuesCreated
QueueHandle_t ftsk_canRxQueue
#define STRIP(x)
Definition: general.h:261
#define REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
Definition: general.h:249
#define UNIT_TEST_WEAK_IMPL
Definition: general.h:95
@ OS_SUCCESS
Definition: os.h:78
OS_STD_RETURN_e OS_ReceiveFromQueue(OS_QUEUE xQueue, void *const pvBuffer, uint32_t ticksToWait)
Receive an item from a queue.
Definition: os_freertos.c:157
OS_STD_RETURN_e OS_SendToBackOfQueueFromIsr(OS_QUEUE xQueue, const void *const pvItemToQueue, long *const pxHigherPriorityTaskWoken)
Post an item to the back the provided queue during an ISR.
Definition: os_freertos.c:182
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
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:139
void PEX_SetPin(uint8_t portExpander, uint8_t pin)
sets pin to high.
Definition: pex.c:321
void PEX_SetPinDirectionOutput(uint8_t portExpander, uint8_t pin)
sets pin to input.
Definition: pex.c:394
Header for the driver for the NXP PCA9539 port expander module.
#define PEX_PORT_EXPANDER2
Definition: pex_cfg.h:75
uint8_t data[CAN_MAX_DLC]
Definition: can_cfg.h:307
canBASE_t * canNode
Definition: can_cfg.h:305
CAN_RxCallbackFunction_f callbackFunction
Definition: can_cfg.h:365
canBASE_t * canNode
Definition: can_cfg.h:361
uint32_t id
Definition: can_cfg.h:362
CAN_TxCallbackFunction_f callbackFunction
Definition: can_cfg.h:354
bool currentSensorCCPresent[BS_NR_OF_STRINGS]
Definition: can.h:82
bool currentSensorECPresent[BS_NR_OF_STRINGS]
Definition: can.h:83
bool currentSensorPresent[BS_NR_OF_STRINGS]
Definition: can.h:81
bool periodicEnable
Definition: can.h:80
uint32_t timestampCurrent[BS_NR_OF_STRINGS]
Definition: database_cfg.h:216
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:211
uint32_t timestampEnergyCounting[BS_NR_OF_STRINGS]
Definition: database_cfg.h:231
uint32_t timestampCurrentCounting[BS_NR_OF_STRINGS]
Definition: database_cfg.h:227
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:329
uint32_t previousTimestamp
Definition: database_cfg.h:121
DATA_BLOCK_ID_e uniqueId
Definition: database_cfg.h:119
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:532
const uint16_t distanceFromLastRelease
Definition: version_cfg.h:84
const uint8_t minor
Definition: version_cfg.h:82
const bool underVersionControl
Definition: version_cfg.h:79
const bool isDirty
Definition: version_cfg.h:80
const uint8_t major
Definition: version_cfg.h:81
const uint8_t patch
Definition: version_cfg.h:83
Header file for the version information that is generated by the toolchain.
const VERSION_s foxbmsVersionInfo
Definition: test_can.c:78