foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
can.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, 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 2023-02-03 (date of last update)
47  * @version v1.5.0
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 
63 #include "can_cfg.h"
64 
65 #include <stdint.h>
66 
67 /*========== Macros and Definitions =========================================*/
68 /** Total number of message boxes available for TMS570LC4357 */
69 #define CAN_TOTAL_NUMBER_OF_MESSAGE_BOXES (64u)
70 
71 /** Half of the 64 message boxes are defined for TX
72  * This is used to determined in the CAN interrupt routine if TX or RX case
73  */
74 #define CAN_NR_OF_TX_MESSAGE_BOX (32u)
75 
76 /** Task time slot where the CAN TX function is called. Repetition time of
77  * periodic CAN messages must be multiple of this (e.g., 1u, 10u or 100u)
78  */
79 #define CAN_TICK_ms (10u)
80 
81 /** This structure contains variables relevant for the CAN signal module. */
82 typedef struct {
83  bool periodicEnable; /*!< defines if periodic transmit and receive should run */
84  bool currentSensorPresent[BS_NR_OF_STRINGS]; /*!< defines if a current sensor is detected */
85  bool currentSensorCCPresent[BS_NR_OF_STRINGS]; /*!< defines if a CC info is being sent */
86  bool currentSensorECPresent[BS_NR_OF_STRINGS]; /*!< defines if a EC info is being sent */
87 } CAN_STATE_s;
88 
89 /*========== Extern Constant and Variable Declarations ======================*/
90 
91 /*========== Extern Function Prototypes =====================================*/
92 
93 /**
94  * @brief Sends over CAN the data passed in parameters.
95  * This function goes over the message boxes and marks the ones that should
96  * be sent.
97  * @param[in,out] pNode CAN interface to use
98  * @param id ID of message to send
99  * @param idType standard or extended identifier
100  * @param[out] pData data to send (8 bytes)
101  * @return #STD_OK if a message box was free to send, #STD_NOT_OK otherwise
102  */
103 extern STD_RETURN_TYPE_e CAN_DataSend(CAN_NODE_s *pNode, uint32_t id, CAN_IDENTIFIER_TYPE_e idType, uint8 *pData);
104 
105 /**
106  * @brief Calls the functions to drive the CAN interface.
107  * Makes the CAN timing checks and sends the periodic messages.
108  */
109 extern void CAN_MainFunction(void);
110 
111 /**
112  * @brief Checks the data received per CAN.
113  * A receive buffer is used because CAN frames are received in an interrupt routine.
114  * The TMS570LC4357 does not allow nested interrupts, so interrupts are deactivated during receive.
115  * Calls to the database do not work when interrupts are disabled.
116  * Receive callbacks are made within this function: as it is not called during an interrupt routine,
117  * calls to the database can be made.
118  */
119 extern void CAN_ReadRxBuffer(void);
120 
121 /**
122  * @brief Enables the CAN transceiver..
123  * This function sets th pins to enable the CAN transceiver.
124  * It must be called before using the CAN interface.
125  */
126 extern void CAN_Initialize(void);
127 
128 /**
129  * @brief Enables periodic sending per CAN.
130  * This is used to prevent sending uninitialized data per CAN
131  * (e.g., before the first LTC measurement cycle was completed).
132  */
133 extern void CAN_EnablePeriodic(bool command);
134 
135 /**
136  * @brief set flag for presence of current sensor.
137  * @return retval true if a current sensor is present, false otherwise
138  */
139 extern bool CAN_IsCurrentSensorPresent(uint8_t stringNumber);
140 
141 /**
142  * @brief get flag if CC message from current sensor is received.
143  * @param stringNumber addressed string
144  * @return true if CC message is being received, false otherwise
145  */
146 extern bool CAN_IsCurrentSensorCcPresent(uint8_t stringNumber);
147 
148 /**
149  * @brief get flag if EC message from current sensor is received
150  * @param stringNumber addressed string
151  * @return true if EC message is being received, false otherwise
152  */
153 extern bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber);
154 
155 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
156 #ifdef UNITY_UNIT_TEST
157 extern CAN_STATE_s *TEST_CAN_GetCANState(void);
158 #endif
159 
160 #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:862
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:824
CAN_STATE_s * TEST_CAN_GetCANState(void)
Definition: can.c:890
bool CAN_IsCurrentSensorEcPresent(uint8_t stringNumber)
get flag if EC message from current sensor is received
Definition: can.c:867
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:831
bool CAN_IsCurrentSensorPresent(uint8_t stringNumber)
set flag for presence of current sensor.
Definition: can.c:857
STD_RETURN_TYPE_e CAN_DataSend(CAN_NODE_s *pNode, uint32_t id, CAN_IDENTIFIER_TYPE_e idType, uint8 *pData)
Sends over CAN the data passed in parameters. This function goes over the message boxes and marks the...
Definition: can.c:781
void CAN_Initialize(void)
Enables the CAN transceiver.. This function sets th pins to enable the CAN transceiver....
Definition: can.c:771
void CAN_EnablePeriodic(bool command)
Enables periodic sending per CAN. This is used to prevent sending uninitialized data per CAN (e....
Definition: can.c:849
Headers for the configuration for the CAN module.
CAN_IDENTIFIER_TYPE_e
Definition: can_cfg.h:162
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
bool periodicEnable
Definition: can.h:83