foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
can_helper.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_helper.h
44  * @author foxBMS Team
45  * @date 2021-04-22 (date of creation)
46  * @updated 2021-06-24 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix CAN
49  *
50  * @brief Headers for the helper functions for the CAN module
51  *
52  *
53  */
54 
55 #ifndef FOXBMS__CAN_HELPER_H_
56 #define FOXBMS__CAN_HELPER_H_
57 
58 /*========== Includes =======================================================*/
59 #include "general.h"
60 
61 #include "can_cfg.h"
62 
63 /*========== Macros and Definitions =========================================*/
64 
65 /** position for CAN byte 0 to 7
66  * @{
67  */
68 #define CAN_BYTE_0_POSITION (0u)
69 #define CAN_BYTE_1_POSITION (1u)
70 #define CAN_BYTE_2_POSITION (2u)
71 #define CAN_BYTE_3_POSITION (3u)
72 #define CAN_BYTE_4_POSITION (4u)
73 #define CAN_BYTE_5_POSITION (5u)
74 #define CAN_BYTE_6_POSITION (6u)
75 #define CAN_BYTE_7_POSITION (7u)
76 /**@}*/
77 
78 /** type definition for fields of a CAN signal */
79 typedef struct CAN_SIGNAL_TYPE {
80  uint8_t bitStart; /*!< start bit of signal in CAN message */
81  uint8_t bitLength; /*!< length bit of signal in CAN message */
82  float factor; /*!< scaling factor applied to data */
83  float offset; /*!< offset applied to data */
84  float min; /*!< minimum allowed value for signal */
85  float max; /*!< maximum allowed value for signal */
87 
88 /*========== Extern Constant and Variable Declarations ======================*/
89 
90 /*========== Extern Function Prototypes =====================================*/
91 
92 /**
93  * @brief Prepare signal data.
94  * This function takes the signal data and
95  * applies factor, applies offset and compares
96  * with signal minimum and maximum values.
97  * @param[in,out] pSignal signal data
98  * @param[in] signalProperties signal properties (factor, offset, min, max)
99  */
100 extern void CAN_TxPrepareSignalData(float *pSignal, CAN_SIGNAL_TYPE_s signalProperties);
101 
102 /**
103  * @brief Convert raw signal data.
104  * This function takes the raw signal data and
105  * applies offset and factor to convert
106  * the raw value.
107  * @param[out] pSignalConverted coverted signal data
108  * @param[in] signalRaw raw signal data
109  * @param[in] signalProperties signal properties (factor, offset, min, max)
110  */
111 extern void CAN_RxConvertRawSignalData(float *pSignalConverted, float signalRaw, CAN_SIGNAL_TYPE_s signalProperties);
112 
113 /**
114  * @brief Puts CAN signal data in a 64-bit variable.
115  * This function is used to compose a 64-bit CAN message.
116  * It takes signal data, signal bit start, signal bit length
117  * and puts the data in the 64-bit variable.
118  * @param[out] pMessage 64-bit variable containing the CAN data
119  * @param[in] bitStart starting bit were the signal data must be put
120  * @param[in] bitLength length of the signal data to be put in CAN message
121  * @param[in] canSignal signal data to be put in message
122  * @param[in] endianness big or little endianness of data
123  */
125  uint64_t *pMessage,
126  uint64_t bitStart,
127  uint8_t bitLength,
128  uint64_t canSignal,
129  CAN_ENDIANNESS_e endianness);
130 
131 /**
132  * @brief Copy CAN data from a 64-bit variable to 8 bytes.
133  * This function is used to copy a 64-bit CAN message to 8 bytes.
134  * @param[in] message 64-bit variable containing the CAN data
135  * @param[out] pCanData 8 bytes where the data is copied
136  * @param[in] endianness big or little endianness of data
137  */
138 extern void CAN_TxSetCanDataWithMessageData(uint64_t message, uint8_t *pCanData, CAN_ENDIANNESS_e endianness);
139 
140 /**
141  * @brief Gets CAN signal data from a 64-bit variable.
142  * This function is used to get signal data from a 64-bit
143  * CAN message.
144  * It takes signal bit start, signal bit length and extract
145  * signal data from the the 64-bit variable.
146  * @param[in] message 64-bit variable containing the CAN data
147  * @param[in] bitStart starting bit were the signal data must be put
148  * @param[in] bitLength length of the signal data to be put in CAN message
149  * @param[out] pCanSignal signal data to be retrieved from message
150  * @param[in] endianness big or little endianness of data
151  */
153  uint64_t message,
154  uint64_t bitStart,
155  uint8_t bitLength,
156  uint64_t *pCanSignal,
157  CAN_ENDIANNESS_e endianness);
158 
159 /**
160  * @brief Copy CAN data from 8 bytes to a 64-bit variable.
161  * @details This function is used to copy data from a 64-bit variable to 8
162  * bytes.
163  * @param[in] pMessage 64-bit where the data is copied
164  * @param[out] kpkCanData 8 bytes containing the data
165  * @param[in] endianness big or little endianness of data
166  */
168  uint64_t *pMessage,
169  const uint8_t *const kpkCanData,
170  CAN_ENDIANNESS_e endianness);
171 
172 /*========== Externalized Static Function Implementations (Unit Test) =======*/
173 
174 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
175 
176 #endif /* FOXBMS__CAN_HELPER_H_ */
Headers for the configuration for the CAN module.
enum CAN_ENDIANNESS CAN_ENDIANNESS_e
struct CAN_SIGNAL_TYPE CAN_SIGNAL_TYPE_s
void CAN_TxSetMessageDataWithSignalData(uint64_t *pMessage, uint64_t bitStart, uint8_t bitLength, uint64_t canSignal, CAN_ENDIANNESS_e endianness)
Puts CAN signal data in a 64-bit variable. This function is used to compose a 64-bit CAN message....
Definition: can_helper.c:166
void CAN_TxSetCanDataWithMessageData(uint64_t message, uint8_t *pCanData, CAN_ENDIANNESS_e endianness)
Copy CAN data from a 64-bit variable to 8 bytes. This function is used to copy a 64-bit CAN message t...
Definition: can_helper.c:205
void CAN_RxGetMessageDataFromCanData(uint64_t *pMessage, const uint8_t *const kpkCanData, CAN_ENDIANNESS_e endianness)
Copy CAN data from 8 bytes to a 64-bit variable.
Definition: can_helper.c:288
void CAN_TxPrepareSignalData(float *pSignal, CAN_SIGNAL_TYPE_s signalProperties)
Prepare signal data. This function takes the signal data and applies factor, applies offset and compa...
Definition: can_helper.c:141
void CAN_RxConvertRawSignalData(float *pSignalConverted, float signalRaw, CAN_SIGNAL_TYPE_s signalProperties)
Convert raw signal data. This function takes the raw signal data and applies offset and factor to con...
Definition: can_helper.c:160
void CAN_RxGetSignalDataFromMessageData(uint64_t message, uint64_t bitStart, uint8_t bitLength, uint64_t *pCanSignal, CAN_ENDIANNESS_e endianness)
Gets CAN signal data from a 64-bit variable. This function is used to get signal data from a 64-bit C...
Definition: can_helper.c:248
General macros and definitions for the whole platform.
uint8_t bitStart
Definition: can_helper.h:80
uint8_t bitLength
Definition: can_helper.h:81