foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
i2c.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 i2c.h
44  * @author foxBMS Team
45  * @date 2021-07-22 (date of creation)
46  * @updated 2021-12-08 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix I2C
49  *
50  * @brief Header for the driver for the I2C module
51  *
52  */
53 
54 #ifndef FOXBMS__I2C_H_
55 #define FOXBMS__I2C_H_
56 
57 /*========== Includes =======================================================*/
58 #include "general.h"
59 
60 #include "HL_i2c.h"
61 
62 /*========== Macros and Definitions =========================================*/
63 
64 /** Timeout to avoid infinite loops when waiting for flags */
65 #define I2C_TIMEOUT_ITERATIONS (1000u)
66 
67 /** Transmitter DMA enable */
68 #define I2C_TXDMAEN (0x2u)
69 /** Receiver DMA enable */
70 #define I2C_RXDMAEN (0x1u)
71 
72 /*========== Extern Constant and Variable Declarations ======================*/
73 
74 /*========== Extern Function Prototypes =====================================*/
75 /** Initialize the I2C hardware
76  *
77  * This function has to be called before any call to the rest of this API
78  */
79 extern void I2C_Initialize(void);
80 
81 /**
82  * @brief reads from an I2C slave, blocking.
83  *
84  * @param slaveAddress: address of slave to communicate with
85  * @param readAddress: address of first register to read from
86  * @param nrBytes: number of registers to read
87  * @param readData: buffer containing the read data
88  *
89  * @return retVal: STD_OK if transmission OK, STD_NOT_OK otherwise
90  *
91  */
92 extern STD_RETURN_TYPE_e I2C_Read(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData);
93 
94 /**
95  * @brief reads from an I2C slave, no register address written first, blocking.
96  *
97  * @param slaveAddress: address of slave to communicate with
98  * @param nrBytes: number of registers to read
99  * @param readData: buffer containing the read data
100  *
101  * @return retVal: STD_OK if transmission OK, STD_NOT_OK otherwise
102  *
103  */
104 extern STD_RETURN_TYPE_e I2C_ReadDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData);
105 
106 /**
107  * @brief writes to an I2C slave, blocking.
108  *
109  * @param slaveAddress: address of slave to communicate with
110  * @param writeAddress: address of first register to write to
111  * @param nrBytes: number of registers to write
112  * @param writeData: buffer containing the data to write
113  *
114  * @return retVal: STD_OK if transmission OK, STD_NOT_OK otherwise
115  *
116  */
117 extern STD_RETURN_TYPE_e I2C_Write(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData);
118 
119 /**
120  * @brief writes to an I2C slave, no register address written first, blocking.
121  *
122  * @param slaveAddress: address of slave to communicate with
123  * @param nrBytes: number of registers to write
124  * @param writeData: buffer containing the data to write
125  *
126  * @return retVal: STD_OK if transmission OK, STD_NOT_OK otherwise
127  *
128  */
129 extern STD_RETURN_TYPE_e I2C_WriteDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData);
130 
131 /**
132  * @brief reads from an I2C slave, using DMA.
133  *
134  * @param slaveAddress: address of slave to communicate with
135  * @param readAddress: address of first register to read from
136  * @param nrBytes: number of registers to read
137  * @param readData: buffer containing the read data
138  *
139  * @return retVal: STD_OK if transmission OK, STD_NOT_OK otherwise
140  *
141  */
142 extern STD_RETURN_TYPE_e I2C_ReadDma(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData);
143 
144 /**
145  * @brief writes to an I2C slave, using DMA.
146  *
147  * @param slaveAddress: address of slave to communicate with
148  * @param writeAddress: address of first register to write to
149  * @param nrBytes: number of registers to write
150  * @param writeData: buffer containing the data to write
151  *
152  * @return retVal: STD_OK if transmission OK, STD_NOT_OK otherwise
153  *
154  */
156  uint32_t slaveAddress,
157  uint8_t writeAddress,
158  uint32_t nrBytes,
159  uint8_t *writeData);
160 
161 /**
162  * @brief sets stop condition.
163  *
164  */
165 extern void I2C_SetStopNow(void);
166 
167 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
168 #ifdef UNITY_UNIT_TEST
169 
170 #endif
171 
172 #endif /* FOXBMS__I2C_H_ */
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
General macros and definitions for the whole platform.
STD_RETURN_TYPE_e I2C_WriteDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, no register address written first, blocking.
Definition: i2c.c:356
void I2C_SetStopNow(void)
sets stop condition.
Definition: i2c.c:563
STD_RETURN_TYPE_e I2C_ReadDma(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, using DMA.
Definition: i2c.c:433
STD_RETURN_TYPE_e I2C_Write(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, blocking.
Definition: i2c.c:256
STD_RETURN_TYPE_e I2C_ReadDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, no register address written first, blocking.
Definition: i2c.c:183
void I2C_Initialize(void)
Definition: i2c.c:74
STD_RETURN_TYPE_e I2C_WriteDma(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, using DMA.
Definition: i2c.c:499
STD_RETURN_TYPE_e I2C_Read(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, blocking.
Definition: i2c.c:78