foxBMS  1.2.1
The foxBMS Battery Management System API Documentation
spi.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 spi.h
44  * @author foxBMS Team
45  * @date 2019-12-12 (date of creation)
46  * @updated 2021-12-08 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix SPI
49  *
50  * @brief Headers for the driver for the SPI module.
51  *
52  */
53 
54 #ifndef FOXBMS__SPI_H_
55 #define FOXBMS__SPI_H_
56 
57 /*========== Includes =======================================================*/
58 #include "spi_cfg.h"
59 
60 /*========== Macros and Definitions =========================================*/
61 
62 /*========== Extern Constant and Variable Declarations ======================*/
63 
64 /*========== Extern Function Prototypes =====================================*/
65 
66 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-dummy-start-include */
67 /**
68  * @brief Sends a dummy byte to wake up the SPI interface.
69  *
70  * @param pSpiInterface pointer to SPI interface configuration
71  * @param delay delay to wait after dummy byte transfer
72  *
73  * @return status of the SPI transfer
74  */
75 extern STD_RETURN_TYPE_e SPI_TransmitDummyByte(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint32_t delay);
76 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-dummy-stop-include */
77 
78 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-transmit-start-include */
79 /**
80  * @brief Transmits data on SPI without DMA.
81  * @details This function can be used to send and receive data via SPI. SPI
82  * communication is performed in blocking mode and chip select is
83  * set/reset automatically.
84  * @param pSpiInterface pointer to SPI interface configuration
85  * @param pTxBuff pointer to data that is transmitted by the SPI interface
86  * @param frameLength number of bytes to be transmitted by the SPI interface
87  * @return status of the SPI transfer
88  */
89 extern STD_RETURN_TYPE_e SPI_TransmitData(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint32 frameLength);
90 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-transmit-stop-include */
91 
92 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-transmit-receive-start-include */
93 /**
94  * @brief Transmits and receives data on SPI without DMA.
95  * @details This function can be used to send and receive data via SPI. SPI
96  * communication is performed in blocking mode and chip select is
97  * set/reset automatically.
98  * @param pSpiInterface pointer to SPI interface configuration
99  * @param pTxBuff pointer to data that is transmitted by the SPI interface
100  * @param pRxBuff pointer to data that is received by the SPI interface
101  * @param frameLength number of bytes to be transmitted by the SPI interface
102  * @return status of the SPI transfer
103  */
105  SPI_INTERFACE_CONFIG_s *pSpiInterface,
106  uint16 *pTxBuff,
107  uint16 *pRxBuff,
108  uint32 frameLength);
109 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-transmit-receive-stop-include */
110 
111 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-fram-start-include */
112 /**
113  * @brief Transmits and receives data on SPI without DMA, wrappe for FRAM
114  * @details This function can be used to send and receive data via SPI. SPI
115  * communication is performed in blocking mode and chip select is
116  * set/reset automatically.
117  * It does not drive the Chip Select (neither hardware nor software)
118  * as this is done directly in the FRAM functions.
119  * @param pSpiInterface pointer to SPI interface configuration
120  * @param pTxBuff pointer to data that is transmitted by the SPI interface
121  * @param pRxBuff pointer to data that is received by the SPI interface
122  * @param frameLength number of bytes to be transmitted by the SPI interface
123  * @return status of the SPI transfer
124  */
125 extern void SPI_FramTransmitReceiveData(
126  SPI_INTERFACE_CONFIG_s *pSpiInterface,
127  uint16 *pTxBuff,
128  uint16 *pRxBuff,
129  uint32 frameLength);
130 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-fram-stop-include */
131 
132 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-transmit-receive-dma-start-include */
133 /**
134  * @brief Transmits and receives data on SPI with DMA.
135  * @details This function can be used to send and receive data via SPI. SPI
136  * communication is performed in blocking mode and chip select is
137  * set/reset automatically..
138  * @param pSpiInterface pointer to SPI interface configuration
139  * @param pTxBuff pointer to data that is transmitted by the SPI interface
140  * @param pRxBuff pointer to data that is received by the SPI interface
141  * @param frameLength number of bytes to be transmitted by the SPI interface
142  * @return status of the SPI transfer
143  */
145  SPI_INTERFACE_CONFIG_s *pSpiInterface,
146  uint16_t *pTxBuff,
147  uint16_t *pRxBuff,
148  uint32_t frameLength);
149 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-transmit-receive-dma-stop-include */
150 
151 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-slave-receive-dma-start-include */
152 /**
153  * @brief Transmits and receives data on SPI with DMA.
154  * @details This function can be used to send and receive data via SPI. SPI
155  * communication is performed in blocking mode and chip select is
156  * set/reset automatically..
157  * @param pSpiInterface pointer to SPI interface configuration
158  * @param pTxBuff pointer to data that is transmitted by the SPI interface
159  * @param pRxBuff pointer to data that is received by the SPI interface
160  * @param frameLength number of bytes to be transmitted by the SPI interface
161  * @return status of the SPI transfer
162  */
164  SPI_INTERFACE_CONFIG_s *pSpiInterface,
165  uint16_t *pTxBuff,
166  uint16_t *pRxBuff,
167  uint32_t frameLength);
168 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-slave-receive-dma-stop-include */
169 
170 /**
171  * @brief Locks SPI interfaces.
172  * @details This function is used to change the state of the SPI_busy_flags
173  * variable to "locked".
174  * @param spi SPI interface to be locked (0-4 on the TMS570LC4357)
175  * @return #STD_OK if SPI interface could be locked, #STD_NOT_OK otherwise
176  */
177 extern STD_RETURN_TYPE_e SPI_Lock(uint8_t spi);
178 
179 /**
180  * @brief Unlocks SPI interfaces.
181  * @details This function is used to change the state of the SPI_busy_flags
182  * variable to "unlocked".
183  * @param spi SPI interface to be unlocked (0-4 on the TMS570LC4357)
184  */
185 extern void SPI_Unlock(uint8_t spi);
186 
187 /**
188  * @brief Sets the functional of a SPI pin
189  * @details SPI pins in this HAL can have functional state SPI (for when it is
190  * controlled by the SPI hardware) and functional state GIO (for when
191  * it is controlled as a GIO pin).
192  * @param[in,out] pNode handle of the SPI node that should be configured
193  * @param[in] bit bit that should be manipulated, other pins remain
194  * unchanged
195  * @param[in] hardwareControlled Whether the bit should be hardware
196  * controlled (true) or not (false)
197  */
198 extern void SPI_SetFunctional(spiBASE_t *pNode, enum spiPinSelect bit, bool hardwareControlled);
199 
200 /**
201  * @brief Used to send last byte per SPI.
202  * @details This function is called in the DMA Tx callback. It is used
203  * to send the last byte with CSHOLD = 0.
204  * @param spiIndex SPI node in use
205  */
206 extern void SPI_DmaSendLastByte(uint8_t spiIndex);
207 
208 /**
209  * @brief Returns #STD_OK if the SPI interface can be used again
210  * @details This function just checks for SPI_PENDING and groups SPI_READY and
211  * SPI_...
212  * @param[in] pNode handle of the SPI node that should be checked
213  * @returns #STD_RETURN_TYPE_e indicating wether the interface is ok to be used.
214  */
215 extern STD_RETURN_TYPE_e SPI_CheckInterfaceAvailable(spiBASE_t *pNode);
216 
217 /**
218  * @brief Returns index of SPI node
219  * @param[in] pNode handle of the SPI node that should be checked
220  * @returns index of SPI node
221  */
222 extern uint8_t SPI_GetSpiIndex(spiBASE_t *pNode);
223 
224 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
225 
226 #endif /* FOXBMS__SPI_H_ */
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
STD_RETURN_TYPE_e SPI_TransmitReceiveDataDma(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength)
Transmits and receives data on SPI with DMA.
Definition: spi.c:214
void SPI_SetFunctional(spiBASE_t *pNode, enum spiPinSelect bit, bool hardwareControlled)
Sets the functional of a SPI pin.
Definition: spi.c:338
STD_RETURN_TYPE_e SPI_CheckInterfaceAvailable(spiBASE_t *pNode)
Returns STD_OK if the SPI interface can be used again.
Definition: spi.c:445
void SPI_DmaSendLastByte(uint8_t spiIndex)
Used to send last byte per SPI.
Definition: spi.c:436
STD_RETURN_TYPE_e SPI_TransmitDummyByte(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint32_t delay)
Sends a dummy byte to wake up the SPI interface.
Definition: spi.c:83
void SPI_FramTransmitReceiveData(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint16 *pRxBuff, uint32 frameLength)
Transmits and receives data on SPI without DMA, wrappe for FRAM.
Definition: spi.c:201
STD_RETURN_TYPE_e SPI_Lock(uint8_t spi)
Locks SPI interfaces.
Definition: spi.c:315
STD_RETURN_TYPE_e SPI_SlaveSetReceiveDataDma(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16_t *pTxBuff, uint16_t *pRxBuff, uint32_t frameLength)
Transmits and receives data on SPI with DMA.
Definition: spi.c:372
void SPI_Unlock(uint8_t spi)
Unlocks SPI interfaces.
Definition: spi.c:330
STD_RETURN_TYPE_e SPI_TransmitData(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint32 frameLength)
Transmits data on SPI without DMA.
Definition: spi.c:91
STD_RETURN_TYPE_e SPI_TransmitReceiveData(SPI_INTERFACE_CONFIG_s *pSpiInterface, uint16 *pTxBuff, uint16 *pRxBuff, uint32 frameLength)
Transmits and receives data on SPI without DMA.
Definition: spi.c:143
uint8_t SPI_GetSpiIndex(spiBASE_t *pNode)
Returns index of SPI node.
Definition: spi.c:455
Headers for the configuration for the SPI module.