foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
can_cfg.h
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.h
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 CAN
50  *
51  * @brief Headers for the configuration for the CAN module
52  *
53  * @details The activation and the length of the message buffers as well as the
54  * number of the messages that are received are to be configured here.
55  *
56  */
57 
58 #ifndef FOXBMS__CAN_CFG_H_
59 #define FOXBMS__CAN_CFG_H_
60 
61 /*========== Includes =======================================================*/
62 #include "general.h"
63 
64 #include "HL_can.h"
65 
66 #include "database.h"
67 
68 /*========== Macros and Definitions =========================================*/
69 
70 /** register on which the CAN interface is connected @{*/
71 #define CAN_NODE_1 (canREG1)
72 #define CAN_NODE_2 (canREG2)
73 /**@}*/
74 
75 #define CAN_NODE_IMD (CAN_NODE_1)
76 #define CAN_NODE_CURRENT_SENSOR (CAN_NODE_1)
77 
78 /**
79  * Configuration of CAN transceiver pins to the respective port expander pins.
80  * @{
81  */
82 #define CAN1_ENABLE_PIN (PEX_PIN00)
83 #define CAN1_STANDBY_PIN (PEX_PIN01)
84 #define CAN2_ENABLE_PIN (PEX_PIN02)
85 #define CAN2_STANDBY_PIN (PEX_PIN03)
86 /**@}*/
87 
88 /** Maximum ID if 11 bits are used */
89 #define CAN_MAX_11BIT_ID (2048u)
90 /** Maximum length of Data Length Code */
91 #define CAN_MAX_DLC (8u)
92 /** Default DLC */
93 #define CAN_DEFAULT_DLC (8u)
94 /** Default DLC for messages that are defined by the foxBMS project, i.e., not
95  * defined by third party software and/or hardware. */
96 #define CAN_FOXBMS_MESSAGES_DEFAULT_DLC (8u)
97 
98 /* **************************************************************************************
99  * CAN BUFFER OPTIONS
100  *****************************************************************************************/
101 
102 /** Enum for byte order (endianness)
103  * \verbatim
104  * CAN data example:
105  *
106  * LittleEndian
107  * bitStart = 27; bitLength = 19
108  * DataLE: 45-44-43-42-41-40-39-38-37-36-35-34-33-32-31-30-29-28-27
109  * MSB LSB
110  *
111  * BigEndian
112  * bitStart = 21; bitLength = 19
113  * DataBE: 21-20-19-18-17-16-31-30-29-28-27-26-25-24-39-38-37-36-35
114  * MSB LSB
115  * |||
116  * Receive data on CAN bus
117  * |||
118  * |||
119  * \_/
120  * LE | BE
121  * CAN Data Byte 0 07 06 05 04 03 02 01 00 | CAN Data Byte 0 07 06 05 04 03 02 01 00
122  * CAN Data Byte 1 15 14 13 12 11 10 09 08 | CAN Data Byte 1 15 14 13 12 11 10 09 08
123  * 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
124  * 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
125  * 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
126  * 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
127  * CAN Data Byte 6 55 54 53 52 51 50 49 48 | CAN Data Byte 6 55 54 53 52 51 50 49 48
128  * CAN Data Byte 7 63 62 61 60 59 58 57 56 | CAN Data Byte 7 63 62 61 60 59 58 57 56
129  * |||
130  * Store received data in RAM
131  * |||
132  * |||
133  * \_/
134  * LE | BE
135  * 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]
136  * 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]
137  * 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]
138  * 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]
139  * 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]
140  * 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]
141  * 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]
142  * 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]
143  * DataLE = DataBE
144  * \endverbatim
145  */
146 typedef enum {
150 
151 /** Buffer element used to store the ID and data of a CAN RX message */
152 typedef struct {
153  canBASE_t *canNode; /*!< CAN node on which the message has been received */
154  uint32_t id; /*!< ID of the CAN message */
155  uint8_t data[CAN_MAX_DLC]; /*!< payload of the CAN message */
157 
158 /** composite type for storing and passing on the local database table handles */
159 typedef struct {
160  OS_QUEUE *pQueueImd; /*!< handle of the message queue */
161  DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage; /*!< database table with cell voltages */
162  DATA_BLOCK_CELL_TEMPERATURE_s *pTableCellTemperature; /*!< database table with cell temperatures */
163  DATA_BLOCK_MIN_MAX_s *pTableMinMax; /*!< database table with min/max values */
164  DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor; /*!< database table with current sensor measurements */
165  DATA_BLOCK_OPEN_WIRE_s *pTableOpenWire; /*!< database table with open wire status */
166  DATA_BLOCK_STATEREQUEST_s *pTableStateRequest; /*!< database table with state requests */
167  DATA_BLOCK_PACK_VALUES_s *pTablePackValues; /*!< database table with pack values */
168  DATA_BLOCK_SOF_s *pTableSof; /*!< database table with SOF values */
169  DATA_BLOCK_SOX_s *pTableSox; /*!< database table with SOC and SOE values */
170  DATA_BLOCK_ERRORSTATE_s *pTableErrorState; /*!< database table with error state variables */
171  DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulation; /*!< database table with insulation monitoring info */
172  DATA_BLOCK_MSL_FLAG_s *pTableMsl; /*!< database table with MSL flags */
173  DATA_BLOCK_RSL_FLAG_s *pTableRsl; /*!< database table with RSL flags */
174  DATA_BLOCK_MOL_FLAG_s *pTableMol; /*!< database table with MOL flags */
175 } CAN_SHIM_s;
176 
177 /** definition of a CAN message (without data) */
178 typedef struct {
179  uint32_t id; /*!< message ID */
180  uint8_t dlc; /*!< data length */
181  CAN_ENDIANNESS_e endianness; /*!< Byte order (big or little endian) */
183 
184 /** timing information of a CAN TX message */
185 typedef struct {
186  uint32_t period; /*!< CAN message cycle time */
187  uint32_t phase; /*!< CAN message startup (first send) offset */
189 
190 /** timing information of a CAN RX message */
191 typedef struct {
192  uint32_t period; /*!< expected CAN message cycle time */
194 
195 /** type definition for tx callback functions used in CAN messages */
196 typedef uint32_t (*CAN_TxCallbackFunction_f)(
197  CAN_MESSAGE_PROPERTIES_s message,
198  uint8_t *canData,
199  uint8_t *pMuxId,
200  const CAN_SHIM_s *const kpkCanShim);
201 
202 /** type definition for rx callback functions used in CAN messages */
203 typedef uint32_t (*CAN_RxCallbackFunction_f)(
204  CAN_MESSAGE_PROPERTIES_s message,
205  const uint8_t *const kpkCanData,
206  const CAN_SHIM_s *const kpkCanShim);
207 
208 /** type definition for structure of a TX CAN message */
209 typedef struct {
210  canBASE_t *canNode; /*!< CAN node on which the message is transmitted */
211  CAN_MESSAGE_PROPERTIES_s message; /*!< CAN message */
212  CAN_TX_MESSAGE_TIMING_s timing; /*!< time and phase */
213  CAN_TxCallbackFunction_f callbackFunction; /*!< CAN message callback after message is sent */
214  uint8_t *pMuxId; /*!< for multiplexed signals: callback can use this as pointer to a mux variable, NULL_PTR if
215  unused*/
217 
218 /** type definition for structure of an RX CAN message */
219 typedef struct {
220  canBASE_t *canNode; /*!< CAN node on which the message is received */
221  CAN_MESSAGE_PROPERTIES_s message; /*!< CAN message */
222  CAN_RX_MESSAGE_TIMING_s timing; /*!< time and phase */
223  CAN_RxCallbackFunction_f callbackFunction; /*!< CAN message callback after message is received */
225 
226 /** variable for storing and passing on the local database table handles */
227 extern const CAN_SHIM_s can_kShim;
228 
229 /*========== Extern Constant and Variable Declarations ======================*/
232 
233 /** array length for transmission CAN0 message definition @{*/
234 extern const uint8_t can_txLength;
235 extern const uint8_t can_rxLength;
236 /**@}*/
237 
238 /*========== Extern Function Prototypes =====================================*/
239 
240 /*========== Externalized Static Function Implementations (Unit Test) =======*/
241 
242 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
243 
244 #endif /* FOXBMS__CAN_CFG_H_ */
const CAN_RX_MESSAGE_TYPE_s can_rxMessages[]
Definition: can_cfg_rx.c:74
CAN_ENDIANNESS_e
Definition: can_cfg.h:146
@ CAN_LITTLE_ENDIAN
Definition: can_cfg.h:147
@ CAN_BIG_ENDIAN
Definition: can_cfg.h:148
uint32_t(* CAN_TxCallbackFunction_f)(CAN_MESSAGE_PROPERTIES_s message, uint8_t *canData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
Definition: can_cfg.h:196
const uint8_t can_txLength
Definition: can_cfg_tx.c:101
const CAN_TX_MESSAGE_TYPE_s can_txMessages[]
Definition: can_cfg_tx.c:84
const CAN_SHIM_s can_kShim
Definition: can_cfg.c:92
const uint8_t can_rxLength
Definition: can_cfg_rx.c:92
uint32_t(* CAN_RxCallbackFunction_f)(CAN_MESSAGE_PROPERTIES_s message, const uint8_t *const kpkCanData, const CAN_SHIM_s *const kpkCanShim)
Definition: can_cfg.h:203
#define CAN_MAX_DLC
Definition: can_cfg.h:91
Database module header.
General macros and definitions for the whole platform.
canBASE_t * canNode
Definition: can_cfg.h:153
CAN_ENDIANNESS_e endianness
Definition: can_cfg.h:181
CAN_RX_MESSAGE_TIMING_s timing
Definition: can_cfg.h:222
CAN_RxCallbackFunction_f callbackFunction
Definition: can_cfg.h:223
canBASE_t * canNode
Definition: can_cfg.h:220
CAN_MESSAGE_PROPERTIES_s message
Definition: can_cfg.h:221
DATA_BLOCK_STATEREQUEST_s * pTableStateRequest
Definition: can_cfg.h:166
DATA_BLOCK_CELL_VOLTAGE_s * pTableCellVoltage
Definition: can_cfg.h:161
DATA_BLOCK_PACK_VALUES_s * pTablePackValues
Definition: can_cfg.h:167
DATA_BLOCK_RSL_FLAG_s * pTableRsl
Definition: can_cfg.h:173
DATA_BLOCK_SOX_s * pTableSox
Definition: can_cfg.h:169
DATA_BLOCK_CURRENT_SENSOR_s * pTableCurrentSensor
Definition: can_cfg.h:164
DATA_BLOCK_ERRORSTATE_s * pTableErrorState
Definition: can_cfg.h:170
DATA_BLOCK_CELL_TEMPERATURE_s * pTableCellTemperature
Definition: can_cfg.h:162
DATA_BLOCK_MSL_FLAG_s * pTableMsl
Definition: can_cfg.h:172
DATA_BLOCK_MOL_FLAG_s * pTableMol
Definition: can_cfg.h:174
DATA_BLOCK_MIN_MAX_s * pTableMinMax
Definition: can_cfg.h:163
DATA_BLOCK_OPEN_WIRE_s * pTableOpenWire
Definition: can_cfg.h:165
DATA_BLOCK_INSULATION_MONITORING_s * pTableInsulation
Definition: can_cfg.h:171
OS_QUEUE * pQueueImd
Definition: can_cfg.h:160
DATA_BLOCK_SOF_s * pTableSof
Definition: can_cfg.h:168
CAN_TxCallbackFunction_f callbackFunction
Definition: can_cfg.h:213
canBASE_t * canNode
Definition: can_cfg.h:210
CAN_MESSAGE_PROPERTIES_s message
Definition: can_cfg.h:211
uint8_t * pMuxId
Definition: can_cfg.h:214
CAN_TX_MESSAGE_TIMING_s timing
Definition: can_cfg.h:212