foxBMS - Unit Tests  1.4.1
The foxBMS Unit Tests API Documentation
spi_cfg.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 spi_cfg.h
44  * @author foxBMS Team
45  * @date 2020-03-05 (date of creation)
46  * @updated 2022-10-27 (date of last update)
47  * @version v1.4.1
48  * @ingroup DRIVERS_CONFIGURATION
49  * @prefix SPI
50  *
51  * @brief Headers for the configuration for the SPI module
52  *
53  *
54  */
55 
56 #ifndef FOXBMS__SPI_CFG_H_
57 #define FOXBMS__SPI_CFG_H_
58 
59 /*========== Includes =======================================================*/
60 #include "general.h"
61 
62 #include "battery_system_cfg.h"
63 
64 #include "HL_het.h"
65 #include "HL_spi.h"
66 
67 /*========== Macros and Definitions =========================================*/
68 
69 /** Index for the SPI nodes @{ */
70 #define SPI_SPI1_INDEX (0u)
71 #define SPI_SPI2_INDEX (1u)
72 #define SPI_SPI3_INDEX (2u)
73 #define SPI_SPI4_INDEX (3u)
74 #define SPI_SPI5_INDEX (4u)
75 /**@}*/
76 
77 /** Bit in SPIDAT1 register that activates hardware Chip Select hold */
78 #define SPI_CSHOLD_BIT (0x10000000u)
79 
80 /** Bit in SPIDAT1 register that activates delay between words */
81 #define SPI_WDEL_BIT (0x04000000u)
82 
83 /** Position of CSNR field in SPIDAT1 register */
84 #define SPI_HARDWARE_CHIP_SELECT_FIELD_POSITION (16u)
85 
86 /** Position of DFSEL field in SPIDAT1 register */
87 #define SPI_DATA_FORMAT_FIELD_POSITION (24u)
88 
89 /** Position of TX buffer empty flag in SPIFLG register */
90 #define SPI_TX_BUFFER_EMPTY_FLAG_POSITION (9u)
91 
92 /** Mask used to clear all HW CS bits */
93 #define SPI_PC0_CLEAR_HW_CS_MASK (0xFFFFFF00u)
94 
95 /** Time to avoid infinite loop when waiting for Tx empty flag in a while loop */
96 #define SPI_TX_EMPTY_TIMEOUT_ITERATIONS (6000u)
97 
98 /** Max number of hardware chip select pins */
99 #define SPI_MAX_NUMBER_HW_CS (6u)
100 
101 /** GIO defines for SPI for Smart Power Switches @{ */
102 #define SPI_SPS_CS_GIOPORT (hetREG2->DOUT)
103 #define SPI_SPS_CS_GIOPORT_DIR (hetREG2->DIR)
104 #define SPI_SPS_CS_PIN (1u)
105 /**@}*/
106 
107 /** enum for spi interface state */
108 typedef enum {
112 
113 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-cs-type-start-include */
114 /** type of chip select for spi */
115 typedef enum {
119 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-cs-type-stop-include */
120 
121 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-configuration-start-include */
122 /** configuration of the SPI interface */
123 typedef struct {
124  spiDAT1_t *pConfig;
125  spiBASE_t *pNode;
126  volatile uint32_t *pGioPort;
127  uint32_t csPin;
130 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE spi-documentation-configuration-stop-include */
131 
132 /*========== Extern Constant and Variable Declarations ======================*/
142 
144 
145 extern const uint8_t spi_nrBusyFlags;
146 
147 /*========== Extern Function Prototypes =====================================*/
148 /**
149  * @brief Switch the SPS spi handle to high speed
150  * @param[out] pSpiSpsInterface handle of the SPS spi config
151  */
152 extern void SPI_SpsInterfaceSwitchToHighSpeed(SPI_INTERFACE_CONFIG_s *pSpiSpsInterface);
153 
154 /**
155  * @brief Switch the SPS spi handle to low speed
156  * @param[out] pSpiSpsInterface handle of the SPS spi config
157  */
158 extern void SPI_SpsInterfaceSwitchToLowSpeed(SPI_INTERFACE_CONFIG_s *pSpiSpsInterface);
159 
160 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
161 
162 #endif /* FOXBMS__SPI_CFG_H_ */
Configuration of the battery system (e.g., number of battery modules, battery cells,...
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
General macros and definitions for the whole platform.
void SPI_SpsInterfaceSwitchToLowSpeed(SPI_INTERFACE_CONFIG_s *pSpiSpsInterface)
Switch the SPS spi handle to low speed.
Definition: spi_cfg.c:281
SPI_BUSY_STATE_e
Definition: spi_cfg.h:108
@ SPI_IDLE
Definition: spi_cfg.h:109
@ SPI_BUSY
Definition: spi_cfg.h:110
SPI_INTERFACE_CONFIG_s spi_mxmInterface
Definition: spi_cfg.c:184
SPI_INTERFACE_CONFIG_s spi_adc0Interface
Definition: spi_cfg.c:233
SPI_INTERFACE_CONFIG_s spi_kSbcMcuInterface
Definition: spi_cfg.c:251
SPI_INTERFACE_CONFIG_s spi_nxp775InterfaceTx[BS_NR_OF_STRINGS]
Definition: spi_cfg.c:193
SPI_BUSY_STATE_e spi_busyFlags[]
Definition: spi_cfg.c:260
SPI_INTERFACE_CONFIG_s spi_framInterface
Definition: spi_cfg.c:215
SPI_INTERFACE_CONFIG_s spi_adc1Interface
Definition: spi_cfg.c:242
void SPI_SpsInterfaceSwitchToHighSpeed(SPI_INTERFACE_CONFIG_s *pSpiSpsInterface)
Switch the SPS spi handle to high speed.
Definition: spi_cfg.c:276
SPI_INTERFACE_CONFIG_s spi_nxp775InterfaceRx[BS_NR_OF_STRINGS]
Definition: spi_cfg.c:204
SPI_INTERFACE_CONFIG_s spi_ltcInterface[BS_NR_OF_STRINGS]
Definition: spi_cfg.c:173
const uint8_t spi_nrBusyFlags
Definition: spi_cfg.c:269
SPI_CHIP_SELECT_TYPE_e
Definition: spi_cfg.h:115
@ SPI_CHIP_SELECT_SOFTWARE
Definition: spi_cfg.h:117
@ SPI_CHIP_SELECT_HARDWARE
Definition: spi_cfg.h:116
SPI_INTERFACE_CONFIG_s spi_spsInterface
Definition: spi_cfg.c:224
SPI_CHIP_SELECT_TYPE_e csType
Definition: spi_cfg.h:128
volatile uint32_t * pGioPort
Definition: spi_cfg.h:126
spiDAT1_t * pConfig
Definition: spi_cfg.h:124
spiBASE_t * pNode
Definition: spi_cfg.h:125