foxBMS-UnitTests  1.0.0
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
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
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 2019-12-04 (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 /** macro for the register that handles the CAN-interface */
68 #define CAN_HET1_GIO (hetREG1)
69 
70 /** register pin that handles enable */
71 #define CAN_HET1_EN_PIN (14U)
72 /** register pin that handles standby */
73 #define CAN_HET1_STB_PIN (16U)
74 
75 /** Buffer element used to store the ID and data of a CAN RX message */
76 typedef struct CAN_BUFFERELEMENT {
77  uint32_t id; /*!< ID of the CAN message */
78  uint8_t data[8]; /*!< payload of the CAN message */
80 
81 /* **************************************************************************************
82  * CAN BUFFER OPTIONS
83  *****************************************************************************************/
84 
85 /** CAN node enabling */
86 #define CAN_USE_CAN_NODE0 (1U)
87 
88 /** CAN node enabling */
89 #define CAN_USE_CAN_NODE1 (0U)
90 
91 /** CAN message ID to perform a software reset */
92 #define CAN_ID_SOFTWARE_RESET_MSG (0x95U)
93 
94 /** delay in &micro;s used in #CAN_InitializeTransceiver for pin-toggling */
95 #define CAN_PIN_TOGGLE_DELAY_US (5u)
96 
97 /** enum for byte order */
98 typedef enum {
102 
103 /** type definition for callback functions used in CAN messages */
104 typedef uint32_t (
105  *can_callback_funcPtr)(uint32_t ID, uint8_t DLC, CAN_byteOrder_e byteorder, uint8_t *candata, uint32_t *pMuxId);
106 
107 /** type definition for structure of a TX CAN message */
108 typedef struct CAN_MSG_TX_TYPE {
109  uint32_t id; /*!< CAN message id */
110  uint8_t dlc; /*!< CAN message data length code */
111  uint32_t repetitionTime; /*!< CAN message cycle time */
112  uint32_t repetitionPhase; /*!< CAN message startup (first send) offset */
113  CAN_byteOrder_e byteOrder; /*!< Byte order (big or little endian) */
114  can_callback_funcPtr callbackFunction; /*!< CAN message callback after message is sent */
115  uint32_t *pMuxId; /*!< for multiplexed signals: callback can use this as pointer to a mux variable */
117 
118 /** type definition for structure of an RX CAN message */
119 typedef struct CAN_MSG_RX_TYPE {
120  uint32_t id; /*!< message ID */
121  uint8_t dlc; /*!< data length */
122  uint8_t rtr; /*!< rtr bit */
123  CAN_byteOrder_e byteOrder; /*!< Byte order (big or little endian) */
124  can_callback_funcPtr callbackFunction; /*!< CAN message callback after message is received */
126 
127 /*========== Extern Constant and Variable Declarations ======================*/
128 extern const CAN_MSG_TX_TYPE_s can_txMessages[];
129 extern const CAN_MSG_RX_TYPE_s can_rxMessages[];
130 
131 /** array length for transmission CAN0 message definition @{*/
132 extern const uint8_t can_txLength;
133 extern const uint8_t can_rxLength;
134 /**@}*/
135 
136 /*========== Extern Function Prototypes =====================================*/
137 
138 /*========== Externalized Static Function Implementations (Unit Test) =======*/
139 #ifdef UNITY_UNIT_TEST
141 
142 /* TX callback functions */
143 extern uint32_t TEST_CAN_TxVoltage(
144  uint32_t id,
145  uint8_t dlc,
146  CAN_byteOrder_e byteOrder,
147  uint8_t *pCanData,
148  uint32_t *pMuxId);
149 extern uint32_t TEST_CAN_TxPcbTemperature(
150  uint32_t id,
151  uint8_t dlc,
152  CAN_byteOrder_e byteOrder,
153  uint8_t *pCanData,
154  uint32_t *pMuxId);
155 extern uint32_t TEST_CAN_TxExternalTemperature(
156  uint32_t id,
157  uint8_t dlc,
158  CAN_byteOrder_e byteOrder,
159  uint8_t *pCanData,
160  uint32_t *pMuxId);
161 extern uint32_t TEST_CAN_TxVoltageMinMax(
162  uint32_t id,
163  uint8_t dlc,
164  CAN_byteOrder_e byteOrder,
165  uint8_t *pCanData,
166  uint32_t *pMuxId);
167 
168 /* RX callback functions */
169 extern uint32_t TEST_CAN_RxRequest(
170  uint32_t id,
171  uint8_t dlc,
172  CAN_byteOrder_e byteOrder,
173  uint8_t *pCanData,
174  uint32_t *pMuxId);
175 extern uint32_t TEST_CAN_RxSwReset(
176  uint32_t id,
177  uint8_t dlc,
178  CAN_byteOrder_e byteOrder,
179  uint8_t *pCanData,
180  uint32_t *pMuxId);
181 extern uint32_t TEST_CAN_RxCurrentSensor(
182  uint32_t id,
183  uint8_t dlc,
184  CAN_byteOrder_e byteOrder,
185  uint8_t *pCanData,
186  uint32_t *pMuxId);
187 extern uint32_t TEST_CAN_RxDebug(
188  uint32_t id,
189  uint8_t dlc,
190  CAN_byteOrder_e byteOrder,
191  uint8_t *pCanData,
192  uint32_t *pMuxId);
193 extern uint32_t TEST_CAN_RxSwVersion(
194  uint32_t id,
195  uint8_t dlc,
196  CAN_byteOrder_e byteOrder,
197  uint8_t *pCanData,
198  uint32_t *pMuxId);
199 #endif
200 
201 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
202 
203 #endif /* FOXBMS__CAN_CFG_H_ */
TEST_CAN_RxDebug
uint32_t TEST_CAN_RxDebug(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:961
general.h
TODO.
CAN_MSG_RX_TYPE
Definition: can_cfg.h:119
TEST_CAN_RxRequest
uint32_t TEST_CAN_RxRequest(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:937
CAN_BUFFERELEMENT_s
struct CAN_BUFFERELEMENT CAN_BUFFERELEMENT_s
littleEndian
@ littleEndian
Definition: can_cfg.h:99
CAN_MSG_TX_TYPE
Definition: can_cfg.h:108
CAN_MSG_RX_TYPE::dlc
uint8_t dlc
Definition: can_cfg.h:121
CAN_MSG_TX_TYPE::byteOrder
CAN_byteOrder_e byteOrder
Definition: can_cfg.h:113
CAN_MSG_RX_TYPE::id
uint32_t id
Definition: can_cfg.h:120
TEST_CAN_RxCurrentSensor
uint32_t TEST_CAN_RxCurrentSensor(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:953
TEST_CAN_TxVoltage
uint32_t TEST_CAN_TxVoltage(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:903
CAN_MSG_RX_TYPE::rtr
uint8_t rtr
Definition: can_cfg.h:122
can_rxLength
const uint8_t can_rxLength
Definition: can_cfg.c:267
TEST_CAN_TxExternalTemperature
uint32_t TEST_CAN_TxExternalTemperature(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:919
CAN_MSG_TX_TYPE::id
uint32_t id
Definition: can_cfg.h:109
CAN_MSG_RX_TYPE::callbackFunction
can_callback_funcPtr callbackFunction
Definition: can_cfg.h:124
CAN_MSG_TX_TYPE_s
struct CAN_MSG_TX_TYPE CAN_MSG_TX_TYPE_s
CAN_BUFFERELEMENT::id
uint32_t id
Definition: can_cfg.h:77
can_rxMessages
const CAN_MSG_RX_TYPE_s can_rxMessages[]
Definition: can_cfg.c:222
DATA_BLOCK_CELL_VOLTAGE
Definition: database_cfg.h:115
can_txMessages
const CAN_MSG_TX_TYPE_s can_txMessages[]
Definition: can_cfg.c:180
CAN_MSG_TX_TYPE::repetitionTime
uint32_t repetitionTime
Definition: can_cfg.h:111
CAN_BUFFERELEMENT
Definition: can_cfg.h:76
TEST_CAN_RxSwReset
uint32_t TEST_CAN_RxSwReset(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:945
database.h
Database module header.
CAN_byteOrder_e
CAN_byteOrder_e
Definition: can_cfg.h:98
TEST_CAN_TxVoltageMinMax
uint32_t TEST_CAN_TxVoltageMinMax(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:927
can_callback_funcPtr
uint32_t(* can_callback_funcPtr)(uint32_t ID, uint8_t DLC, CAN_byteOrder_e byteorder, uint8_t *candata, uint32_t *pMuxId)
Definition: can_cfg.h:105
CAN_MSG_RX_TYPE_s
struct CAN_MSG_RX_TYPE CAN_MSG_RX_TYPE_s
CAN_MSG_TX_TYPE::repetitionPhase
uint32_t repetitionPhase
Definition: can_cfg.h:112
TEST_CAN_GetCellvoltageTab
DATA_BLOCK_CELL_VOLTAGE_s * TEST_CAN_GetCellvoltageTab(void)
Definition: can_cfg.c:898
CAN_MSG_TX_TYPE::pMuxId
uint32_t * pMuxId
Definition: can_cfg.h:115
can_txLength
const uint8_t can_txLength
Definition: can_cfg.c:266
CAN_MSG_TX_TYPE::callbackFunction
can_callback_funcPtr callbackFunction
Definition: can_cfg.h:114
bigEndian
@ bigEndian
Definition: can_cfg.h:100
TEST_CAN_RxSwVersion
uint32_t TEST_CAN_RxSwVersion(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:969
CAN_MSG_TX_TYPE::dlc
uint8_t dlc
Definition: can_cfg.h:110
CAN_MSG_RX_TYPE::byteOrder
CAN_byteOrder_e byteOrder
Definition: can_cfg.h:123
CAN_BUFFERELEMENT::data
uint8_t data[8]
Definition: can_cfg.h:78
TEST_CAN_TxPcbTemperature
uint32_t TEST_CAN_TxPcbTemperature(uint32_t id, uint8_t dlc, CAN_byteOrder_e byteOrder, uint8_t *pCanData, uint32_t *pMuxId)
Definition: can_cfg.c:911