foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
sps_cfg.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 sps_cfg.h
44  * @author foxBMS Team
45  * @date 2020-10-14 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS_CONF
49  * @prefix SPS
50  *
51  * @brief Header for the configuration for the driver for the smart power switches
52  *
53  */
54 
55 #ifndef FOXBMS__SPS_CFG_H_
56 #define FOXBMS__SPS_CFG_H_
57 
58 /*========== Includes =======================================================*/
59 
60 #include "battery_system_cfg.h"
61 
62 #include "sps_types.h"
63 
64 #include <math.h>
65 #include <stdint.h>
66 
67 /*========== Macros and Definitions =========================================*/
68 
69 /** GIO defines for pin to drive reset line of SPS @{ */
70 #define SPS_RESET_GIO_PORT (hetREG2->DOUT)
71 #define SPS_RESET_GIO_PORT_DIR (hetREG2->DIR)
72 #define SPS_RESET_PIN (16u)
73 /**@}*/
74 
75 /** GIO defines for pin to drive feedback enable MOSFET of SPS @{ */
76 #define SPS_FEEDBACK_GIO_PORT (hetREG2->DOUT)
77 #define SPS_FEEDBACK_GIO_PORT_DIR (hetREG2->DIR)
78 #define SPS_FEEDBACK_PIN (9u)
79 /**@}*/
80 
81 /** Each SPS IC has four outputs */
82 #define SPS_NR_CONTACTOR_PER_IC (4u)
83 
84 /** Number of SPS IC that are populated on the hardware (in daisy-chain) */
85 #define SPS_NR_OF_IC (2u)
86 
87 /** Defines for the individual SPS channels @{ */
88 #define SPS_CHANNEL_0 ((SPS_CHANNEL_INDEX)0)
89 #define SPS_CHANNEL_1 ((SPS_CHANNEL_INDEX)1)
90 #define SPS_CHANNEL_2 ((SPS_CHANNEL_INDEX)2)
91 #define SPS_CHANNEL_3 ((SPS_CHANNEL_INDEX)3)
92 #define SPS_CHANNEL_4 ((SPS_CHANNEL_INDEX)4)
93 #define SPS_CHANNEL_5 ((SPS_CHANNEL_INDEX)5)
94 #define SPS_CHANNEL_6 ((SPS_CHANNEL_INDEX)6)
95 #define SPS_CHANNEL_7 ((SPS_CHANNEL_INDEX)7)
96 /**@}*/
97 
98 /** One channel for each contactor is required in this application */
99 #define SPS_NR_OF_REQUIRED_CONTACTOR_CHANNELS (BS_NR_OF_CONTACTORS)
100 
101 /** Calculate the number of available SPS channels */
102 #define SPS_NR_OF_AVAILABLE_SPS_CHANNELS (SPS_NR_CONTACTOR_PER_IC * SPS_NR_OF_IC)
103 
104 /* check if the number of contactors fits in the available channels */
105 #if (SPS_NR_OF_REQUIRED_CONTACTOR_CHANNELS > SPS_NR_OF_AVAILABLE_SPS_CHANNELS)
106 #error "Not enough contactor channels available for the required number of contactors."
107 #endif
108 
109 /** Defines the buffer size to communicate with the SPS IC.
110  *
111  * One 16 bit word per SPS IC so buffer size is equivalent to the number of
112  * SPS ICs.
113  *
114  * - 1 SPS IC -> Buffer size = 1
115  * - 2 SPS IC -> Buffer size = 2
116  * - 3 SPS IC -> Buffer size = 3
117  */
118 #define SPS_SPI_BUFFERSIZE SPS_NR_OF_IC
119 
120 /** Addresses of used control registers @{ */
121 #define SPS_GLOBAL_CONTROL_REGISTER_ADDRESS (0x00u)
122 #define SPS_OUTPUT_CONTROL_REGISTER_ADDRESS (0x02u)
123 #define SPS_C_CONTROL_REGISTER_ADDRESS (0x16u)
124 /**@}*/
125 /** Addresses of used diagnostic registers @{ */
126 #define SPS_ISR_IRQ_DIAG_REGISTER_ADDRESS (0x06u)
127 #define SPS_ISR_WARN_DIAG_REGISTER_ADDRESS (0x07u)
128 #define SPS_OD_IOUT1_DIAG_REGISTER_ADDRESS (0x08u)
129 #define SPS_OD_IOUT2_DIAG_REGISTER_ADDRESS (0x09u)
130 #define SPS_OD_IOUT3_DIAG_REGISTER_ADDRESS (0x0Au)
131 #define SPS_OD_IOUT4_DIAG_REGISTER_ADDRESS (0x0Bu)
132 /**@}*/
133 
134 /**
135  * These bits and positions are defined in
136  * figure 7 page 10 in data sheet Rev. 2 - 11 September 2019
137  */
138 /** This bit is set to 0 for a read register access, to 1 for a write register access */
139 #define SPS_RW_BIT_POSITION (15u)
140 /** Define for read register access */
141 #define SPS_RW_READ (0u)
142 /** Define for write register access */
143 #define SPS_RW_WRITE (1u)
144 /** In Tx SPI buffer, register address starts at bit 8 */
145 #define SPS_ADDRESS_BIT_START (8u)
146 /** This bit is set to 0 to read a diagnostic register, to 1 to read a control register */
147 #define SPS_DIAG_CTRL_BIT_POSITION (7u)
148 
149 /** value for the SPS normal mode */
150 #define SPS_NORMAL_MODE (0x01u)
151 /** value for the SPS strong drive */
152 #define SPS_STRONG_DRIVE (0x00u)
153 /** value for the SPS medium drive */
154 #define SPS_MEDIUM_DRIVE (0x01u)
155 /** bitshift for the mode bit in the SPS
156  *
157  * used for bitshifting #SPS_NORMAL_MODE to the right position
158  */
159 #define SPS_MODE_BIT_START (6u)
160 /** bitshift for the drive strength bit in the SPS */
161 #define SPS_DRIVE_STRENGTH_BIT_START (5u)
162 
163 /** LSB of current measurement of SPS channel in mA */
164 #define SPS_I_MEASUREMENT_LSB_mA (0.98f)
165 
166 /** current threshold that recognizes a contactor as closed */
167 #define SPS_CHANNEL_ON_DEFAULT_THRESHOLD_mA (20.0f)
168 
169 /** bitmask for reading the on-demand output current from a SPI transaction */
170 #define SPS_BITMASK_DIAGNOSTIC_ONDEMAND_OUTPUT_CURRENT (0x1FFFu)
171 
172 /** spi block identification numbers */
173 typedef enum {
178 
179 /** sps read types */
180 typedef enum {
181  SPS_READ_DIAGNOSTIC_REGISTER, /*!< diagnostic register read */
182  SPS_READ_CONTROL_REGISTER, /*!< control register read */
184 
185 /** functional state of a SPS channel */
186 typedef enum {
187  SPS_CHANNEL_OFF, /*!< sps channel is switched off */
188  SPS_CHANNEL_ON, /*!< sps channel is switched on */
190 
191 /** SPS channel state */
192 typedef struct {
193  SPS_CHANNEL_FUNCTION_e channelRequested; /*!< requested state of the channel */
194  SPS_CHANNEL_FUNCTION_e channel; /*!< state of the channel */
195  float_t current_mA; /*!< current flow in this channel in mA */
197  affiliation; /*!< affiliation of the channel (if it is contactor or something else) */
198  const float_t thresholdFeedbackOn_mA; /*!< current threshold in mA above which the channel is considered "on" */
200 
201 /** SPS channel mapping to feedback pin */
202 typedef struct {
203  const uint8_t pexDevice; /*!< port expander number */
204  const uint8_t pexChannel; /*!< pin number on the addresses port expander */
206 
207 /*================== Main precharge configuration ====================*/
208 
209 /*========== Extern Constant and Variable Declarations ======================*/
210 
211 /** State for the CONT handling */
212 typedef enum {
223 } SPS_STATE_e;
224 
225 /** Actions to do for the Smart Power Switch IC */
226 typedef enum {
234 } SPS_ACTION_e;
235 
237 
239 
240 /*========== Extern Function Prototypes =====================================*/
241 
242 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
243 #ifdef UNITY_UNIT_TEST
244 #endif
245 
246 #endif /* FOXBMS__SPS_CFG_H_ */
Configuration of the battery system (e.g., number of battery modules, battery cells,...
#define SPS_NR_OF_AVAILABLE_SPS_CHANNELS
Definition: sps_cfg.h:102
SPS_CHANNEL_STATE_s sps_channelStatus[SPS_NR_OF_AVAILABLE_SPS_CHANNELS]
Definition: sps_cfg.c:68
SPS_READ_TYPE_e
Definition: sps_cfg.h:180
@ SPS_READ_DIAGNOSTIC_REGISTER
Definition: sps_cfg.h:181
@ SPS_READ_CONTROL_REGISTER
Definition: sps_cfg.h:182
SPS_ACTION_e
Definition: sps_cfg.h:226
@ SPS_ACTION_READ_CURRENT_MEASUREMENT2
Definition: sps_cfg.h:230
@ SPS_ACTION_READ_CURRENT_MEASUREMENT1
Definition: sps_cfg.h:229
@ SPS_ACTION_TRIGGER_CURRENT_MEASUREMENT
Definition: sps_cfg.h:228
@ SPS_ACTION_READ_EN_IRQ_PIN
Definition: sps_cfg.h:233
@ SPS_ACTION_READ_CURRENT_MEASUREMENT4
Definition: sps_cfg.h:232
@ SPS_ACTION_CONFIGURE_CONTROL_REGISTER
Definition: sps_cfg.h:227
@ SPS_ACTION_READ_CURRENT_MEASUREMENT3
Definition: sps_cfg.h:231
SPS_CHANNEL_FUNCTION_e
Definition: sps_cfg.h:186
@ SPS_CHANNEL_ON
Definition: sps_cfg.h:188
@ SPS_CHANNEL_OFF
Definition: sps_cfg.h:187
const SPS_CHANNEL_FEEDBACK_MAPPING_s sps_kChannelFeedbackMapping[SPS_NR_OF_AVAILABLE_SPS_CHANNELS]
Definition: sps_cfg.c:85
SPS_WRITE_TYPE_e
Definition: sps_cfg.h:173
@ SPS_andWithCurrentValue
Definition: sps_cfg.h:176
@ SPS_orWithCurrentValue
Definition: sps_cfg.h:175
@ SPS_replaceCurrentValue
Definition: sps_cfg.h:174
SPS_STATE_e
Definition: sps_cfg.h:212
@ SPS_TRIGGER_CURRENT_MEASUREMENT
Definition: sps_cfg.h:217
@ SPS_CONFIGURE_CONTROL_REGISTER
Definition: sps_cfg.h:216
@ SPS_READ_MEASURED_CURRENT2
Definition: sps_cfg.h:219
@ SPS_READ_MEASURED_CURRENT1
Definition: sps_cfg.h:218
@ SPS_RESET_LOW
Definition: sps_cfg.h:214
@ SPS_READ_EN_IRQ_PIN
Definition: sps_cfg.h:222
@ SPS_READ_MEASURED_CURRENT3
Definition: sps_cfg.h:220
@ SPS_START
Definition: sps_cfg.h:213
@ SPS_READ_MEASURED_CURRENT4
Definition: sps_cfg.h:221
@ SPS_RESET_HIGH
Definition: sps_cfg.h:215
Types for the SPS driver.
SPS_CHANNEL_AFFILIATION_e
affiliation type of a sps channel
Definition: sps_types.h:73
const float_t thresholdFeedbackOn_mA
Definition: sps_cfg.h:198
SPS_CHANNEL_FUNCTION_e channelRequested
Definition: sps_cfg.h:193
float_t current_mA
Definition: sps_cfg.h:195
SPS_CHANNEL_FUNCTION_e channel
Definition: sps_cfg.h:194
const SPS_CHANNEL_AFFILIATION_e affiliation
Definition: sps_cfg.h:197