foxBMS - Unit Tests  1.3.0
The foxBMS Unit Tests API Documentation
can_cbs_tx_limits.c
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_cbs_tx_limits.c
44  * @author foxBMS Team
45  * @date 2021-07-21 (date of creation)
46  * @updated 2022-05-30 (date of last update)
47  * @version v1.3.0
48  * @ingroup DRIVER
49  * @prefix CAN
50  *
51  * @brief CAN driver Tx callback implementation
52  * @details CAN Tx callback for state messages
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "battery_cell_cfg.h"
57 
58 #include "can_cbs.h"
59 #include "can_helper.h"
60 
61 /*========== Macros and Definitions =========================================*/
62 
63 /*========== Static Constant and Variable Definitions =======================*/
64 
65 /*========== Extern Constant and Variable Definitions =======================*/
66 
67 /*========== Static Function Prototypes =====================================*/
68 
69 /*========== Static Function Implementations ================================*/
70 
71 /*========== Extern Function Implementations ================================*/
72 extern uint32_t CAN_TxLimitValues(
73  uint32_t id,
74  uint8_t dlc,
75  CAN_ENDIANNESS_e endianness,
76  uint8_t *pCanData,
77  uint8_t *pMuxId,
78  const CAN_SHIM_s *const kpkCanShim) {
79  /* pMuxId is not used here, therefore has to be NULL_PTR */
80  FAS_ASSERT(pMuxId == NULL_PTR);
81 
82  FAS_ASSERT(id < CAN_MAX_11BIT_ID); /* Currently standard ID, 11 bit */
83  FAS_ASSERT(dlc <= CAN_MAX_DLC); /* Currently max 8 bytes in a CAN frame */
84  FAS_ASSERT(pCanData != NULL_PTR);
85  FAS_ASSERT(kpkCanShim != NULL_PTR);
86  uint64_t message = 0;
87 
88  DATA_READ_DATA(kpkCanShim->pTableSof);
89 
90  /* AXIVION Disable Style Generic-NoMagicNumbers: Signal data defined in .dbc file. */
91  /* maximum charge current */
92  float signalData = (float)kpkCanShim->pTableSof->recommendedContinuousPackChargeCurrent_mA;
93  float offset = 0.0f;
94  float factor = 0.004f; /* convert mA to 250mA */
95  signalData = (signalData + offset) * factor;
96  uint64_t data = (int64_t)signalData;
97  /* set data in CAN frame */
98  CAN_TxSetMessageDataWithSignalData(&message, 11u, 12u, data, endianness);
99 
100  /* maximum discharge current */
101  signalData = (float)kpkCanShim->pTableSof->recommendedContinuousPackDischargeCurrent_mA;
102  offset = 0.0f;
103  factor = 0.004f; /* convert mA to 250mA */
104  signalData = (signalData + offset) * factor;
105  data = (int64_t)signalData;
106  /* set data in CAN frame */
107  CAN_TxSetMessageDataWithSignalData(&message, 7u, 12u, data, endianness);
108 
109  /* TODO: maximum charge power */
110  /* TODO: maximum discharge power */
111 
112  /* minimum pack voltage */
114  offset = 0.0f;
115  factor = 0.00025f; /* convert mV to 4V */
116  signalData = (signalData + offset) * factor;
117  data = (int64_t)signalData;
118  /* set data in CAN frame */
119  CAN_TxSetMessageDataWithSignalData(&message, 63u, 8u, data, endianness);
120 
121  /* maximum pack voltage */
123  offset = 0.0f;
124  factor = 0.00025f; /* convert mV to 4V */
125  signalData = (signalData + offset) * factor;
126  data = (int64_t)signalData;
127  /* set data in CAN frame */
128  CAN_TxSetMessageDataWithSignalData(&message, 55u, 8u, data, endianness);
129  /* AXIVION Enable Style Generic-NoMagicNumbers: */
130 
131  /* now copy data in the buffer that will be used to send data */
132  CAN_TxSetCanDataWithMessageData(message, pCanData, endianness);
133 
134  return 0;
135 }
136 
137 /*========== Externalized Static Function Implementations (Unit Test) =======*/
138 #ifdef UNITY_UNIT_TEST
139 
140 #endif
Configuration of the battery cell (e.g., minimum and maximum cell voltage)
#define BC_VOLTAGE_MIN_MSL_mV
Minimum cell voltage limit.
#define BC_VOLTAGE_MAX_MSL_mV
Maximum cell voltage limit.
#define BS_NR_OF_CELL_BLOCKS_PER_STRING
CAN callbacks header.
uint32_t CAN_TxLimitValues(uint32_t id, uint8_t dlc, CAN_ENDIANNESS_e endianness, uint8_t *pCanData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
can tx callback function for limit values
CAN_ENDIANNESS_e
Definition: can_cfg.h:298
#define CAN_MAX_11BIT_ID
Definition: can_cfg.h:86
#define CAN_MAX_DLC
Definition: can_cfg.h:88
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:167
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:206
Headers for the helper functions for the CAN module.
#define DATA_READ_DATA(...)
Definition: database.h:83
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:76
DATA_BLOCK_SOF_s * pTableSof
Definition: can_cfg.h:320
float recommendedContinuousPackChargeCurrent_mA
Definition: database_cfg.h:412
float recommendedContinuousPackDischargeCurrent_mA
Definition: database_cfg.h:413