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