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