foxBMS  1.4.1
The foxBMS Battery Management System API Documentation
can.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.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 Header for the driver for the CAN module
52  *
53  * @details Provides the interfaces for initialization, receive
54  * and transmit handling
55  *
56  */
57 
58 #ifndef FOXBMS__CAN_H_
59 #define FOXBMS__CAN_H_
60 
61 /*========== Includes =======================================================*/
62 #include "general.h"
63 
64 #include "can_cfg.h"
65 
66 /*========== Macros and Definitions =========================================*/
67 
68 /** Half of the 64 message boxes are defined for TX
69  * This is used to determined in the CAN interrupt routine if TX or RX case
70  */
71 #define CAN_NR_OF_TX_MESSAGE_BOX (32u)
72 
73 /** Task time slot where the CAN TX function is called. Repetition time of
74  * periodic CAN messages must be multiple of this (e.g., 1u, 10u or 100u)
75  */
76 #define CAN_TICK_ms (10u)
77 
78 /** This structure contains variables relevant for the CAN signal module. */
79 typedef struct {
80  bool periodicEnable; /*!< defines if periodic transmit and receive should run */
81  bool currentSensorPresent[BS_NR_OF_STRINGS]; /*!< defines if a current sensor is detected */
82  bool currentSensorCCPresent[BS_NR_OF_STRINGS]; /*!< defines if a CC info is being sent */
83  bool currentSensorECPresent[BS_NR_OF_STRINGS]; /*!< defines if a EC info is being sent */
84 } CAN_STATE_s;
85 
86 /*========== Extern Constant and Variable Declarations ======================*/
87 
88 /*========== Extern Function Prototypes =====================================*/
89 
90 /**
91  * @brief Sends over CAN the data passed in parameters.
92  * This function goes over the message boxes and marks the ones that should
93  * be sent.
94  * @param[in,out] pNode CAN interface to use
95  * @param[in] id ID of message to send
96  * @param[out] pData data to send (8 bytes)
97  * @return #STD_OK if a message box was free to send, #STD_NOT_OK otherwise
98  */
99 extern STD_RETURN_TYPE_e CAN_DataSend(canBASE_t *pNode, uint32_t id, uint8 *pData);
100 
101 /**
102  * @brief Calls the functions to drive the CAN interface.
103  * Makes the CAN timing checks and sends the periodic messages.
104  */
105 extern void CAN_MainFunction(void);
106 
107 /**
108  * @brief Checks the data received per CAN.
109  * A receive buffer is used because CAN frames are received in an interrupt routine.
110  * The TMS570LC4357 does not allow nested interrupts, so interrupts are deactivated during receive.
111  * Calls to the database do not work when interrupts are disabled.
112  * Receive callbacks are made within this function: as it is not called during an interrupt routine,
113  * calls to the database can be made.
114  */
115 extern void CAN_ReadRxBuffer(void);
116 
117 /**
118  * @brief Enables the CAN transceiver..
119  * This function sets th pins to enable the CAN transceiver.
120  * It must be called before using the CAN interface.
121  */
122 extern void CAN_Initialize(void);
123 
124 /**
125  * @brief Enables periodic sending per CAN.
126  * This is used to prevent sending uninitialized data per CAN
127  * (e.g., before the first LTC measurement cycle was completed).
128  */
129 extern void CAN_EnablePeriodic(bool command);
130 
131 /**
132  * @brief set flag for presence of current sensor.
133  * @return retval true if a current sensor is present, false otherwise
134  */
135 extern bool CAN_IsCurrentSensorPresent(uint8_t stringNumber);
136 
137 /**
138  * @brief get flag if CC message from current sensor is received.
139  * @param stringNumber addressed string
140  * @return true if CC message is being received, false otherwise
141  */
142 extern bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber);
143 
144 /**
145  * @brief get flag if EC message from current sensor is received
146  * @param stringNumber addressed string
147  * @return true if EC message is being received, false otherwise
148  */
149 extern bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber);
150 
151 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
152 #ifdef UNITY_UNIT_TEST
153 extern CAN_STATE_s *TEST_CAN_GetCANState(void);
154 #endif
155 
156 #endif /* FOXBMS__CAN_H_ */
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber)
get flag if CC message from current sensor is received.
Definition: can.c:403
void CAN_MainFunction(void)
Calls the functions to drive the CAN interface. Makes the CAN timing checks and sends the periodic me...
Definition: can.c:228
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:408
STD_RETURN_TYPE_e CAN_DataSend(canBASE_t *pNode, uint32_t id, uint8 *pData)
Sends over CAN the data passed in parameters. This function goes over the message boxes and marks the...
Definition: can.c:200
void CAN_ReadRxBuffer(void)
Checks the data received per CAN. A receive buffer is used because CAN frames are received in an inte...
Definition: can.c:332
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:398
void CAN_Initialize(void)
Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver....
Definition: can.c:195
void CAN_EnablePeriodic(bool command)
Enables periodic sending per CAN. This is used to prevent sending uninitialized data per CAN (e....
Definition: can.c:352
Headers for the configuration for the CAN module.
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
General macros and definitions for the whole platform.
bool periodicEnable
Definition: can.h:80