foxBMS  1.1.0
The foxBMS Battery Management System API Documentation
can_cfg.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, 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.h
44  * @author foxBMS Team
45  * @date 2019-12-04 (date of creation)
46  * @updated 2021-07-29 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix CAN
49  *
50  * @brief Headers for the configuration for the CAN module
51  *
52  * The activation and the length of the message buffers as well as the number of
53  * the messages that are received are to be configured here
54  *
55  */
56 
57 #ifndef FOXBMS__CAN_CFG_H_
58 #define FOXBMS__CAN_CFG_H_
59 
60 /*========== Includes =======================================================*/
61 #include "general.h"
62 
63 #include "database.h"
64 
65 /*========== Macros and Definitions =========================================*/
66 
67 /** Maximum ID if 11 bits are used */
68 #define CAN_MAX_11BIT_ID (2048u)
69 /** Maximum length of Data Length Code */
70 #define CAN_MAX_DLC (8u)
71 
72 /** Default DLC */
73 #define CAN_DLC (8u)
74 
75 /** TX messages - pack related */
76 
77 /** CAN message ID to send voltages */
78 
79 /** CAN message ID to send state */
80 #define CAN_ID_TX_STATE (0x220U)
81 /** Periodicity of CAN state messages in ms */
82 #define CAN_TX_STATE_PERIOD_MS (100U)
83 /** Phase of CAN state messages in ms */
84 #define CAN_TX_STATE_PHASE_MS (0U)
85 
86 #define CAN_ID_TX_VOLTAGES (0x240U)
87 /** Periodicity of CAN voltage messages in ms */
88 #define CAN_TX_VOLTAGES_PERIOD_MS (100U)
89 /** Phase of CAN voltage messages in ms */
90 #define CAN_TX_VOLTAGES_PHASE_MS (10U)
91 
92 /** CAN message ID to send temperatures */
93 #define CAN_ID_TX_TEMPERATURES (0x250U)
94 /** Periodicity of CAN temperature messages in ms */
95 #define CAN_TX_TEMPERATURES_PERIOD_MS (200U)
96 /** Phase of CAN temperature messages in ms */
97 #define CAN_TX_TEMPERATURES_PHASE_MS (20U)
98 
99 /** CAN message ID to send limit values */
100 #define CAN_ID_TX_LIMIT_VALUES (0x224U)
101 /** Periodicity of CAN limit messages in ms */
102 #define CAN_TX_LIMIT_VALUES_PERIOD_MS (100U)
103 /** Phase of CAN limit messages in ms */
104 #define CAN_TX_LIMIT_VALUES_PHASE_MS (30U)
105 
106 /** CAN message ID to send minimum and maximum values */
107 #define CAN_ID_TX_MINIMUM_MAXIMUM_VALUES (0x223U)
108 /** Periodicity of CAN minimum and maximum value messages in ms */
109 #define CAN_TX_MINIMUM_MAXIMUM_VALUES_PERIOD_MS (100U)
110 /** Phase of CAN minimum and maximum value messages in ms */
111 #define CAN_TX_MINIMUM_MAXIMUM_VALUES_PHASE_MS (40U)
112 
113 /** CAN message ID to send pack state estimation values */
114 #define CAN_ID_TX_PACK_STATE_ESTIMATION (0x225U)
115 /** Periodicity of CAN pack state estimation messages in ms */
116 #define CAN_TX_PACK_STATE_ESTIMATION_PERIOD_MS (1000U)
117 /** Phase of CAN pack state estimation messages in ms */
118 #define CAN_TX_PACK_STATE_ESTIMATION_PHASE_MS (50U)
119 
120 /** CAN message ID to send pack values */
121 #define CAN_ID_TX_PACK_VALUES (0x222U)
122 /** Periodicity of CAN pack values messages in ms */
123 #define CAN_TX_PACK_VALUES_PERIOD_MS (100U)
124 /** Phase of CAN pack values messages in ms */
125 #define CAN_TX_PACK_VALUES_PHASE_MS (60U)
126 
127 /** TX messages - string related */
128 
129 /** CAN message ID to send string state */
130 #define CAN_ID_TX_STRING_STATE (0x221U)
131 /** Periodicity of CAN string state messages in ms */
132 #define CAN_TX_STRING_STATE_PERIOD_MS (100U)
133 /** Phase of CAN string state messages in ms */
134 #define CAN_TX_STRING_STATE_PHASE_MS (70U)
135 
136 /** CAN message ID to send string values */
137 #define CAN_ID_TX_STRING_VALUES (0x280U)
138 /** Periodicity of CAN string state messages in ms */
139 #define CAN_TX_STRING_VALUES_PERIOD_MS (100U)
140 /** Phase of CAN string state messages in ms */
141 #define CAN_TX_STRING_VALUES_PHASE_MS (80U)
142 
143 /** CAN message ID to send string minimum and maximum values */
144 #define CAN_ID_TX_STRING_MINIMUM_MAXIMUM (0x281U)
145 /** Periodicity of CAN string state messages in ms */
146 #define CAN_TX_STRING_MINIMUM_MAXIMUM_PERIOD_MS (100U)
147 /** Phase of CAN string state messages in ms */
148 #define CAN_TX_STRING_MINIMUM_MAXIMUM_PHASE_MS (90U)
149 
150 /** CAN message ID to send string minimum and maximum values */
151 #define CAN_ID_TX_STRING_STATE_ESTIMATION (0x282U)
152 /** Periodicity of CAN string state messages in ms */
153 #define CAN_TX_STRING_STATE_ESTIMATION_PERIOD_MS (1000U)
154 /** Phase of CAN string state messages in ms */
155 #define CAN_TX_STRING_STATE_ESTIMATION_PHASE_MS (0U)
156 
157 /** CAN message ID to send string values 2 */
158 #define CAN_ID_TX_STRING_VALUES_2 (0x283U)
159 /** Periodicity of CAN string state messages in ms */
160 #define CAN_TX_STRING_VALUES_2_PERIOD_MS (100U)
161 /** Phase of CAN string state messages in ms */
162 #define CAN_TX_STRING_VALUES_2_PHASE_MS (10U)
163 
164 /** RX messages */
165 
166 /** CAN message ID for boot message */
167 #define CAN_ID_BOOT_MESSAGE (0x199u)
168 
169 /** CAN message ID to perform a software reset */
170 #define CAN_ID_SOFTWARE_RESET (0x95U)
171 
172 /** CAN message ID to perform a state request */
173 #define CAN_ID_COMMAND (0x230U)
174 
175 /** CAN message ID for debug message */
176 #define CAN_ID_DEBUG (0x200U)
177 
178 /** CAN message ID to get software version */
179 #define CAN_ID_SW_VERSION (0x777U)
180 
181 /**
182  * -------------------------CAUTION-------------------------
183  * The 3 following defines are used by the insulation monitoring device (IMD).
184  * If they are changed, the IMD will not work anymore
185  * -------------------------CAUTION-------------------------
186  */
187 /** CAN message ID for info message from iso165c */
188 #define CAN_ID_IMD_INFO (0x37U)
189 /** CAN message ID for request message to iso165c */
190 #define CAN_ID_IMD_REQUEST (0x22U)
191 /** CAN message ID for response message from iso165c */
192 #define CAN_ID_IMD_RESPONSE (0x23U)
193 
194 /* IDs for the messages from the current sensors */
195 /* String 0 */
196 #define CAN_ID_STRING0_CURRENT (0x521u)
197 #define CAN_ID_STRING0_VOLTAGE1 (0x522u)
198 #define CAN_ID_STRING0_VOLTAGE2 (0x523u)
199 #define CAN_ID_STRING0_VOLTAGE3 (0x524u)
200 #define CAN_ID_STRING0_TEMPERATURE (0x525u)
201 #define CAN_ID_STRING0_POWER (0x526u)
202 #define CAN_ID_STRING0_CURRENT_COUNTER (0x527u)
203 #define CAN_ID_STRING0_ENERGY_COUNTER (0x528u)
204 /* String 1 */
205 #define CAN_ID_STRING1_CURRENT (0x621u)
206 #define CAN_ID_STRING1_VOLTAGE1 (0x622u)
207 #define CAN_ID_STRING1_VOLTAGE2 (0x623u)
208 #define CAN_ID_STRING1_VOLTAGE3 (0x624u)
209 #define CAN_ID_STRING1_TEMPERATURE (0x625u)
210 #define CAN_ID_STRING1_POWER (0x626u)
211 #define CAN_ID_STRING1_CURRENT_COUNTER (0x627u)
212 #define CAN_ID_STRING1_ENERGY_COUNTER (0x628u)
213 /* String 2 */
214 #define CAN_ID_STRING2_CURRENT (0x721u)
215 #define CAN_ID_STRING2_VOLTAGE1 (0x722u)
216 #define CAN_ID_STRING2_VOLTAGE2 (0x723u)
217 #define CAN_ID_STRING2_VOLTAGE3 (0x724u)
218 #define CAN_ID_STRING2_TEMPERATURE (0x725u)
219 #define CAN_ID_STRING2_POWER (0x726u)
220 #define CAN_ID_STRING2_CURRENT_COUNTER (0x727u)
221 #define CAN_ID_STRING2_ENERGY_COUNTER (0x728u)
222 
223 /** macro for the register that handles the CAN-interface */
224 #define CAN_HET1_GIO (hetREG1)
225 
226 /** register pin that handles enable */
227 #define CAN_HET1_EN_PIN (14U)
228 /** register pin that handles standby */
229 #define CAN_HET1_STB_PIN (16U)
230 
231 /** Buffer element used to store the ID and data of a CAN RX message */
232 typedef struct CAN_BUFFERELEMENT {
233  uint32_t id; /*!< ID of the CAN message */
234  uint8_t data[CAN_MAX_DLC]; /*!< payload of the CAN message */
236 
237 /* **************************************************************************************
238  * CAN BUFFER OPTIONS
239  *****************************************************************************************/
240 
241 /** delay in &micro;s used in #CAN_InitializeTransceiver for pin-toggling */
242 #define CAN_PIN_TOGGLE_DELAY_US (5u)
243 
244 /** Enum for byte order (endianness)
245  * \verbatim
246  * CAN data example:
247  *
248  * LittleEndian
249  * bitStart = 27; bitLength = 19
250  * DataLE: 45-44-43-42-41-40-39-38-37-36-35-34-33-32-31-30-29-28-27
251  * MSB LSB
252  *
253  * BigEndian
254  * bitStart = 21; bitLength = 19
255  * DataBE: 21-20-19-18-17-16-31-30-29-28-27-26-25-24-39-38-37-36-35
256  * MSB LSB
257  * |||
258  * Receive data on CAN bus
259  * |||
260  * |||
261  * \_/
262  * LE | BE
263  * CAN Data Byte 0 07 06 05 04 03 02 01 00 | CAN Data Byte 0 07 06 05 04 03 02 01 00
264  * CAN Data Byte 1 15 14 13 12 11 10 09 08 | CAN Data Byte 1 15 14 13 12 11 10 09 08
265  * CAN Data Byte 2 23 22 21 20 19 18 17 16 | CAN Data Byte 2 23 22 21-20-19-18-17-16 MSB
266  * CAN Data Byte 3 31-30-29-28-27 26 25 24 LSB | CAN Data Byte 3 31-30-29-28-27-26-25-24
267  * CAN Data Byte 4 39-38-37-36-35-34-33-32 | CAN Data Byte 4 39-38-37-36-35 34 33 32 LSB
268  * CAN Data Byte 5 47 46 45-44-43-42-41-40 MSB | CAN Data Byte 5 47 46 45 44 43 42 41 40
269  * CAN Data Byte 6 55 54 53 52 51 50 49 48 | CAN Data Byte 6 55 54 53 52 51 50 49 48
270  * CAN Data Byte 7 63 62 61 60 59 58 57 56 | CAN Data Byte 7 63 62 61 60 59 58 57 56
271  * |||
272  * Store received data in RAM
273  * |||
274  * |||
275  * \_/
276  * LE | BE
277  * CAN Data Byte 7 63 62 61 60 59 58 57 56 | CAN Data Byte 0 07 06 05 04 03 02 01 00 | RAM data[7]
278  * CAN Data Byte 6 55 54 53 52 51 50 49 48 | CAN Data Byte 1 15 14 13 12 11 10 09 08 | RAM data[6]
279  * CAN Data Byte 5 47 46 45-44-43-42-41-40 MSB | CAN Data Byte 2 23 22 21-20-19-18-17-16 MSB | RAM data[5]
280  * CAN Data Byte 4 39-38-37-36-35-34-33-32 | CAN Data Byte 3 31-30-29-28-27-26-25-24 | RAM data[4]
281  * CAN Data Byte 3 31-30-29-28-27 26 25 24 LSB | CAN Data Byte 4 39-38-37-36-35 34 33 32 LSB | RAM data[3]
282  * CAN Data Byte 2 23 22 21 20 19 18 17 16 | CAN Data Byte 5 47 46 45 44 43 42 41 40 | RAM data[2]
283  * CAN Data Byte 1 15 14 13 12 11 10 09 08 | CAN Data Byte 6 55 54 53 52 51 50 49 48 | RAM data[1]
284  * CAN Data Byte 0 07 06 05 04 03 02 01 00 | CAN Data Byte 7 63 62 61 60 59 58 57 56 | RAM data[0]
285  * DataLE = DataBE
286  * \endverbatim
287  */
288 typedef enum CAN_ENDIANNESS {
292 
293 /** composite type for storing and passing on the local database table handles */
294 typedef struct CAN_SHIM {
295  QueueHandle_t *pQueueImd;
296  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage; /*!< database table with cell voltages */
297  DATA_BLOCK_CELL_TEMPERATURE_s *pTableCellTemperature; /*!< database table with cell temperatures */
298  DATA_BLOCK_MIN_MAX_s *pTableMinMax; /*!< database table with min/max values */
299  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor; /*!< database table with current sensor measurements */
300  DATA_BLOCK_OPEN_WIRE_s *pTableOpenWire; /*!< database table with open wire status */
301  DATA_BLOCK_STATEREQUEST_s *pTableStateRequest; /*!< database table with state requests */
302  DATA_BLOCK_PACK_VALUES_s *pTablePackValues; /*!< database table with pack values */
303  DATA_BLOCK_SOF_s *pTableSof; /*!< database table with SOF values */
304  DATA_BLOCK_SOX_s *pTableSox; /*!< database table with SOC and SOE values */
305  DATA_BLOCK_ERRORSTATE_s *pTableErrorState; /*!< database table with error state variables */
306  DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulation; /*!< database table with insulation monitoring info */
307  DATA_BLOCK_MSL_FLAG_s *pTableMsl; /*!< database table with MSL flags */
308  DATA_BLOCK_RSL_FLAG_s *pTableRsl; /*!< database table with RSL flags */
309  DATA_BLOCK_MOL_FLAG_s *pTableMol; /*!< database table with MOL flags */
311 
312 /** type definition for callback functions used in CAN messages */
313 typedef uint32_t (*can_callback_funcPtr)(
314  uint32_t ID,
315  uint8_t DLC,
316  CAN_ENDIANNESS_e endianness,
317  uint8_t *candata,
318  uint8_t *pMuxId,
319  const CAN_SHIM_s *const kpkCanShim);
320 
321 /** type definition for structure of a TX CAN message */
322 typedef struct CAN_MSG_TX_TYPE {
323  uint32_t id; /*!< CAN message id */
324  uint8_t dlc; /*!< CAN message data length code */
325  uint32_t repetitionTime; /*!< CAN message cycle time */
326  uint32_t repetitionPhase; /*!< CAN message startup (first send) offset */
327  CAN_ENDIANNESS_e endianness; /*!< Byte order (big or little endian) */
328  can_callback_funcPtr callbackFunction; /*!< CAN message callback after message is sent */
329  uint8_t *pMuxId; /*!< for multiplexed signals: callback can use this as pointer to a mux variable, NULL_PTR if
330  unused*/
332 
333 /** type definition for structure of an RX CAN message */
334 typedef struct CAN_MSG_RX_TYPE {
335  uint32_t id; /*!< message ID */
336  uint8_t dlc; /*!< data length */
337  CAN_ENDIANNESS_e endianness; /*!< Byte order (big or little endian) */
338  can_callback_funcPtr callbackFunction; /*!< CAN message callback after message is received */
340 
341 /** variable for storing and passing on the local database table handles */
342 extern const CAN_SHIM_s can_kShim;
343 
344 /*========== Extern Constant and Variable Declarations ======================*/
345 extern const CAN_MSG_TX_TYPE_s can_txMessages[];
346 extern const CAN_MSG_RX_TYPE_s can_rxMessages[];
347 
348 /** array length for transmission CAN0 message definition @{*/
349 extern const uint8_t can_txLength;
350 extern const uint8_t can_rxLength;
351 /**@}*/
352 
353 /*========== Extern Function Prototypes =====================================*/
354 
355 /*========== Externalized Static Function Implementations (Unit Test) =======*/
356 
357 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
358 
359 #endif /* FOXBMS__CAN_CFG_H_ */
CAN_ENDIANNESS
Definition: can_cfg.h:288
@ CAN_LITTLE_ENDIAN
Definition: can_cfg.h:289
@ CAN_BIG_ENDIAN
Definition: can_cfg.h:290
const CAN_MSG_RX_TYPE_s can_rxMessages[]
Definition: can_cfg.c:180
struct CAN_SHIM CAN_SHIM_s
uint32_t(* can_callback_funcPtr)(uint32_t ID, uint8_t DLC, CAN_ENDIANNESS_e endianness, uint8_t *candata, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
Definition: can_cfg.h:313
struct CAN_MSG_RX_TYPE CAN_MSG_RX_TYPE_s
const uint8_t can_txLength
Definition: can_cfg.c:251
enum CAN_ENDIANNESS CAN_ENDIANNESS_e
const CAN_MSG_TX_TYPE_s can_txMessages[]
Definition: can_cfg.c:87
const CAN_SHIM_s can_kShim
Definition: can_cfg.c:274
const uint8_t can_rxLength
Definition: can_cfg.c:252
struct CAN_MSG_TX_TYPE CAN_MSG_TX_TYPE_s
struct CAN_BUFFERELEMENT CAN_BUFFERELEMENT_s
#define CAN_MAX_DLC
Definition: can_cfg.h:70
Database module header.
General macros and definitions for the whole platform.
uint8_t data[CAN_MAX_DLC]
Definition: can_cfg.h:234
uint32_t id
Definition: can_cfg.h:233
CAN_ENDIANNESS_e endianness
Definition: can_cfg.h:337
uint8_t dlc
Definition: can_cfg.h:336
uint32_t id
Definition: can_cfg.h:335
can_callback_funcPtr callbackFunction
Definition: can_cfg.h:338
uint32_t repetitionPhase
Definition: can_cfg.h:326
CAN_ENDIANNESS_e endianness
Definition: can_cfg.h:327
uint32_t repetitionTime
Definition: can_cfg.h:325
uint32_t id
Definition: can_cfg.h:323
uint8_t dlc
Definition: can_cfg.h:324
uint8_t * pMuxId
Definition: can_cfg.h:329
can_callback_funcPtr callbackFunction
Definition: can_cfg.h:328
DATA_BLOCK_MOL_FLAG_s * pTableMol
Definition: can_cfg.h:309
QueueHandle_t * pQueueImd
Definition: can_cfg.h:295
DATA_BLOCK_STATEREQUEST_s * pTableStateRequest
Definition: can_cfg.h:301
DATA_BLOCK_INSULATION_MONITORING_s * pTableInsulation
Definition: can_cfg.h:306
DATA_BLOCK_SOX_s * pTableSox
Definition: can_cfg.h:304
DATA_BLOCK_RSL_FLAG_s * pTableRsl
Definition: can_cfg.h:308
DATA_BLOCK_MSL_FLAG_s * pTableMsl
Definition: can_cfg.h:307
DATA_BLOCK_MIN_MAX_s * pTableMinMax
Definition: can_cfg.h:298
DATA_BLOCK_OPEN_WIRE_s * pTableOpenWire
Definition: can_cfg.h:300
DATA_BLOCK_CURRENT_SENSOR_s * pTableCurrentSensor
Definition: can_cfg.h:299
DATA_BLOCK_CELL_TEMPERATURE_s * pTableCellTemperature
Definition: can_cfg.h:297
DATA_BLOCK_CELL_VOLTAGE_s * pTableCellVoltage
Definition: can_cfg.h:296
DATA_BLOCK_ERRORSTATE_s * pTableErrorState
Definition: can_cfg.h:305
DATA_BLOCK_PACK_VALUES_s * pTablePackValues
Definition: can_cfg.h:302
DATA_BLOCK_SOF_s * pTableSof
Definition: can_cfg.h:303