foxBMS  1.4.1
The foxBMS Battery Management System API Documentation
can_cfg_tx_boot-message.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_cfg_tx_boot-message.c
44  * @author foxBMS Team
45  * @date 2019-12-04 (date of creation)
46  * @updated 2022-10-27 (date of last update)
47  * @version v1.4.1
48  * @ingroup DRIVERS
49  * @prefix CANTX
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 =======================================================*/
59 
60 #include "version_cfg.h"
61 
62 #include "HL_het.h"
63 #include "HL_reg_system.h"
64 
65 #include "can.h"
67 #include "can_helper.h"
68 #include "database.h"
69 #include "foxmath.h"
70 #include "ftask.h"
71 
72 /*========== Macros and Definitions =========================================*/
73 /** maximum distance from release that can be encoded in the boot message */
74 #define CANTX_BOOT_MESSAGE_MAXIMUM_RELEASE_DISTANCE (31u)
75 #if CANTX_BOOT_MESSAGE_MAXIMUM_RELEASE_DISTANCE > UINT8_MAX
76 #error "This code assumes that the define is smaller or equal to UINT8_MAX")
77 #endif
78 
79 /** bit position of boot message byte 3 version control flag */
80 #define CANTX_BOOT_MESSAGE_BYTE_3_BIT_VERSION_CONTROL (0u)
81 
82 /** bit position of boot message byte 3 dirty flag */
83 #define CANTX_BOOT_MESSAGE_BYTE_3_BIT_DIRTY_FLAG (1u)
84 
85 /** bit position of boot message byte 3 release distance overflow flag */
86 #define CANTX_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_OVERFLOW_FLAG (2u)
87 
88 /** bit position of boot message byte 3 release distance counter */
89 #define CANTX_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_COUNTER (3u)
90 
91 /*========== Static Constant and Variable Definitions =======================*/
92 
93 /*========== Extern Constant and Variable Definitions =======================*/
94 
95 /*========== Static Function Prototypes =====================================*/
96 
97 /*========== Static Function Implementations ================================*/
98 
99 /*========== Extern Function Implementations ================================*/
100 
102  uint8_t data[] = {GEN_REPEAT_U(0u, GEN_STRIP(CAN_MAX_DLC))};
103 
104  /* Set major number */
106  /* Set minor number */
108  /* Set patch number */
110 
111  /* intermediate variable for message byte 3 */
112  uint8_t versionControlByte = 0u;
113 
114  /* Set version control flags */
116  versionControlByte |= (0x01u << CANTX_BOOT_MESSAGE_BYTE_3_BIT_VERSION_CONTROL);
117  }
119  versionControlByte |= (0x01u << CANTX_BOOT_MESSAGE_BYTE_3_BIT_DIRTY_FLAG);
120  }
121  /* Set overflow flag (if release distance is larger than 31) */
123  /* we need to set the overflow flag */
124  versionControlByte |= (0x01u << CANTX_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_OVERFLOW_FLAG);
125  }
126 
127  /* Set release distance (capped to maximum value) */
128  const uint8_t distanceCapped = (uint8_t)MATH_MinimumOfTwoUint16_t(
130  versionControlByte |= (distanceCapped << CANTX_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_COUNTER);
131 
132  /* assign assembled byte to data byte */
133  data[CAN_BYTE_3_POSITION] = versionControlByte;
134 
135  /* Read out device register with unique ID */
136  const uint32_t deviceRegister = systemREG1->DEVID;
137 
138  /* Set unique ID */
139  data[CAN_BYTE_4_POSITION] = (uint8_t)((deviceRegister >> 24u) & 0xFFu);
140  data[CAN_BYTE_5_POSITION] = (uint8_t)((deviceRegister >> 16u) & 0xFFu);
141  data[CAN_BYTE_6_POSITION] = (uint8_t)((deviceRegister >> 8u) & 0xFFu);
142  data[CAN_BYTE_7_POSITION] = (uint8_t)(deviceRegister & 0xFFu);
143 
145 
146  return retval;
147 }
148 
150  uint8_t data[] = {GEN_REPEAT_U(0u, GEN_STRIP(CAN_MAX_DLC))};
151 
152  /* Read out device register with die ID low and high */
153  const uint32_t dieIdLow = systemREG1->DIEIDL;
154  const uint32_t dieIdHigh = systemREG1->DIEIDH;
155 
156  /* set die ID */
157  /* AXIVION Disable Style Generic-NoMagicNumbers: The magic numbers are used to divide down the registers into the CAN message */
158  data[CAN_BYTE_0_POSITION] = (uint8_t)((dieIdHigh >> 24u) & 0xFFu);
159  data[CAN_BYTE_1_POSITION] = (uint8_t)((dieIdHigh >> 16u) & 0xFFu);
160  data[CAN_BYTE_2_POSITION] = (uint8_t)((dieIdHigh >> 8u) & 0xFFu);
161  data[CAN_BYTE_3_POSITION] = (uint8_t)(dieIdHigh & 0xFFu);
162  data[CAN_BYTE_4_POSITION] = (uint8_t)((dieIdLow >> 24u) & 0xFFu);
163  data[CAN_BYTE_5_POSITION] = (uint8_t)((dieIdLow >> 16u) & 0xFFu);
164  data[CAN_BYTE_6_POSITION] = (uint8_t)((dieIdLow >> 8u) & 0xFFu);
165  data[CAN_BYTE_7_POSITION] = (uint8_t)(dieIdLow & 0xFFu);
166  /* AXIVION Enable Style Generic-NoMagicNumbers: */
167 
169 
170  return retval;
171 }
172 
173 /*========== Getter for static Variables (Unit Test) ========================*/
174 
175 /*========== Externalized Static Function Implementations (Unit Test) =======*/
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 message boxes and marks the...
Definition: can.c:200
Header for the driver for the CAN module.
#define CAN_NODE_1
Definition: can_cfg.h:71
#define CAN_MAX_DLC
Definition: can_cfg.h:91
Header for the driver for the CAN module.
#define CANTX_BOOT_ID
#define CANTX_DIE_ID_ID
#define CANTX_BOOT_MESSAGE_BYTE_3_BIT_DIRTY_FLAG
#define CANTX_BOOT_MESSAGE_MAXIMUM_RELEASE_DISTANCE
STD_RETURN_TYPE_e CANTX_TransmitDieId(void)
Transmit chip id.
#define CANTX_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_OVERFLOW_FLAG
#define CANTX_BOOT_MESSAGE_BYTE_3_BIT_VERSION_CONTROL
STD_RETURN_TYPE_e CANTX_TransmitBootMessage(void)
Transmit startup boot message.
#define CANTX_BOOT_MESSAGE_BYTE_3_BIT_DISTANCE_COUNTER
Header file of some software.
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.
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:146
math library for often used math functions
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
Header of task driver implementation.
#define GEN_REPEAT_U(x, n)
Macro that helps to generate a series of literals (for array initializers).
Definition: general.h:250
#define GEN_STRIP(x)
Definition: general.h:261
const bool isDirty
Definition: version_cfg.h:80
const uint8_t major
Definition: version_cfg.h:81
const bool underVersionControl
Definition: version_cfg.h:79
const uint8_t minor
Definition: version_cfg.h:82
const uint8_t patch
Definition: version_cfg.h:83
const uint16_t distanceFromLastRelease
Definition: version_cfg.h:84
Header file for the version information that is generated by the toolchain.
const VER_VERSION_s ver_foxbmsVersionInformation