foxBMS  1.2.0
The foxBMS Battery Management System API Documentation
can_cbs_rx_command.c
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_cbs_rx_command.c
44  * @author foxBMS Team
45  * @date 2021-07-28 (date of creation)
46  * @updated 2021-07-28 (date of last update)
47  * @ingroup DRIVER
48  * @prefix CAN
49  *
50  * @brief CAN driver Rx callback implementation
51  * @details CAN Rx callback for command message
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "bms_cfg.h"
56 
57 #include "bal.h"
58 #include "can_cbs.h"
59 #include "can_helper.h"
60 #include "diag.h"
61 
62 /*========== Macros and Definitions =========================================*/
63 
64 /*========== Static Constant and Variable Definitions =======================*/
65 
66 /*========== Extern Constant and Variable Definitions =======================*/
67 
68 /*========== Static Function Prototypes =====================================*/
69 
70 /*========== Static Function Implementations ================================*/
71 
72 /*========== Extern Function Implementations ================================*/
73 extern uint32_t CAN_RxRequest(
74  uint32_t id,
75  uint8_t dlc,
76  CAN_ENDIANNESS_e endianness,
77  uint8_t *pCanData,
78  uint8_t *pMuxId,
79  const CAN_SHIM_s *const kpkCanShim) {
80  /* pMuxId is not used here, therefore has to be NULL_PTR */
81  FAS_ASSERT(pMuxId == NULL_PTR);
82 
83  FAS_ASSERT(id < CAN_MAX_11BIT_ID); /* Currently standard ID, 11 bit */
84  FAS_ASSERT(dlc <= CAN_MAX_DLC); /* Currently max 8 bytes in a CAN frame */
85  FAS_ASSERT(pCanData != NULL_PTR);
86  FAS_ASSERT(kpkCanShim != NULL_PTR);
87  uint64_t message = 0;
88  uint64_t signalData = 0;
89 
91 
92  CAN_RxGetMessageDataFromCanData(&message, pCanData, endianness);
93 
94  /* AXIVION Disable Style Generic-NoMagicNumbers: Signal data defined in .dbc file. */
95  CAN_RxGetSignalDataFromMessageData(message, 1u, 2u, &signalData, endianness);
96  /* AXIVION Enable Style Generic-NoMagicNumbers: */
97 
98  /** 0x00: Disconnect strings from HV bus
99  * 0x01: Connect strings to HV bus to start discharge
100  * 0x02: Connect strings to HV bus to start charging
101  */
102  uint8_t stateRequest = BMS_REQ_ID_NOREQ;
103 
104  switch (signalData) {
105  case 0u:
106  stateRequest = BMS_REQ_ID_STANDBY;
107  break;
108  case 1u:
109  stateRequest = BMS_REQ_ID_NORMAL;
110  break;
111  case 2u:
112  stateRequest = BMS_REQ_ID_CHARGE;
113  break;
114  default:
115  stateRequest = BMS_REQ_ID_NOREQ;
116  break;
117  }
119  kpkCanShim->pTableStateRequest->stateRequestViaCan = stateRequest;
120  if ((kpkCanShim->pTableStateRequest->stateRequestViaCan !=
122  ((OS_GetTickCount() - kpkCanShim->pTableStateRequest->header.timestamp) > 3000U)) { /* TODO: check pointer */
123  kpkCanShim->pTableStateRequest->stateRequestViaCanPending = stateRequest;
124  }
125  kpkCanShim->pTableStateRequest->state++;
126 
127  /* Get balancing request */
128  /* AXIVION Disable Style Generic-NoMagicNumbers: Signal data defined in .dbc file. */
129  CAN_RxGetSignalDataFromMessageData(message, 8u, 1u, &signalData, endianness);
130  /* AXIVION Enable Style Generic-NoMagicNumbers: */
131 
133  if ((uint8_t)signalData == 0u) {
135  } else {
137  }
138  }
139 
140  /* Get balancing threshold */
141  /* AXIVION Disable Style Generic-NoMagicNumbers: Signal data defined in .dbc file. */
142  CAN_RxGetSignalDataFromMessageData(message, 23u, 8u, &signalData, endianness);
143  /* AXIVION Enable Style Generic-NoMagicNumbers: */
144 
145  /* TODO: Implement missing signals */
146 
147  DATA_WRITE_DATA(kpkCanShim->pTableStateRequest);
148 
149  return 0;
150 }
151 
152 /*========== Externalized Static Function Implementations (Unit Test) =======*/
153 #ifdef UNITY_UNIT_TEST
154 
155 #endif
Header for the driver for balancing.
STD_RETURN_TYPE_e BAL_GetInitializationState(void)
gets the initialization state.
BAL_RETURN_TYPE_e BAL_SetStateRequest(BAL_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable bal_state.
@ BAL_STATE_GLOBAL_ENABLE_REQUEST
Definition: bal.h:105
@ BAL_STATE_GLOBAL_DISABLE_REQUEST
Definition: bal.h:104
bms driver configuration header
#define BMS_REQ_ID_STANDBY
Definition: bms_cfg.h:67
#define BMS_REQ_ID_NOREQ
Definition: bms_cfg.h:64
#define BMS_REQ_ID_CHARGE
Definition: bms_cfg.h:73
#define BMS_REQ_ID_NORMAL
Definition: bms_cfg.h:70
CAN callbacks header.
uint32_t CAN_RxRequest(uint32_t id, uint8_t dlc, CAN_ENDIANNESS_e endianness, uint8_t *pCanData, uint8_t *pMuxId, const CAN_SHIM_s *const kpkCanShim)
can rx callback function for state requests
#define CAN_MAX_11BIT_ID
Definition: can_cfg.h:85
enum CAN_ENDIANNESS CAN_ENDIANNESS_e
#define CAN_MAX_DLC
Definition: can_cfg.h:87
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_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
Headers for the helper functions for the CAN module.
#define DATA_READ_DATA(...)
Definition: database.h:76
#define DATA_WRITE_DATA(...)
Definition: database.h:86
Diagnosis driver header.
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
@ STD_OK
Definition: fstd_types.h:72
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os.c:182
DATA_BLOCK_STATEREQUEST_s * pTableStateRequest
Definition: can_cfg.h:310
uint32_t timestamp
Definition: database_cfg.h:112
uint8_t previousStateRequestViaCan
Definition: database_cfg.h:504
DATA_BLOCK_HEADER_s header
Definition: database_cfg.h:502