foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
nxp_mc33775a_defs.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 nxp_mc33775a_defs.h
44  * @author foxBMS Team
45  * @date 2020-09-01 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS
49  * @prefix N775
50  *
51  * @brief Definitions for the driver for the MC33775A analog front-end.
52  *
53  */
54 
55 #ifndef FOXBMS__NXP_MC33775A_DEFS_H_
56 #define FOXBMS__NXP_MC33775A_DEFS_H_
57 
58 /*========== Includes =======================================================*/
59 
60 #include "database.h"
61 #include "spi.h"
62 
63 #include <stdint.h>
64 
65 /*========== Macros and Definitions =========================================*/
66 
67 /*========== Extern Constant and Variable Declarations ======================*/
68 
69 /* Use of mux for temperature measurement */
70 #define N775_USE_MUX_FOR_TEMP (true)
71 /* Read mux state after setting it */
72 #define N775_CHECK_MUX_STATE (true)
73 /* Check supply current (part of MC33775A DIAG) */
74 #define N775_CHECK_SUPPLY_CURRENT (false)
75 /* Broadcast address for the N775 slaves */
76 #define N775_BROADCAST_ADDRESS (63u)
77 /* Time to wait between activity on bus and wake up of slave */
78 #define N775_WAKEUP_TIME_MS (3u)
79 /* Timeout in 10ms to go into sleep, max 255 (corresponding to 2550ms) */
80 #define N775_TIMEOUT_TO_SLEEP_10MS (200u)
81 /* Timeout enable, 0u in register = enabled */
82 #define N775_TIMEOUT_ENABLED (0u)
83 /* Timeout enable, 0x5A in register = disabled */
84 #define N775_TIMEOUT_DISABLED (0x5Au)
85 /* Timeout enable switch*/
86 #define N775_TIMEOUT_SWITCH (N775_TIMEOUT_ENABLED)
87 /* Time to wait after measurements started */
88 #define N775_TIME_AFTER_MEASUREMENT_START_MS (5u)
89 /* Default chain address */
90 #define N775_DEFAULT_CHAIN_ADDRESS (1u)
91 /* Measurement capture time */
92 /* + 1 to take balancing pause time before measurement into account */
93 #define N775_MEASUREMENT_CAPTURE_TIME_MS (5u + 1u)
94 /* Time to wait after measurement capture for measurements to be ready */
95 #define N775_MEASUREMENT_READY_TIME_MS (1u)
96 /* Value stored in N775A register when not valid */
97 #define N775_INVALID_REGISTER_VALUE (0x8000u)
98 /* Length of the mux measurement sequence */
99 #define N775_MUX_SEQUENCE_LENGTH (8u)
100 /* Time in 10us for pause of balancing before measurement start */
101 /* Wait time afer capture must be increased if this value is too high */
102 #define N775_BALPAUSELEN_10US (100u)
103 /**
104  * Upper bits of ADG728 mux address byte
105  * Set to 0: bit2, bit1 (address), bit0 (R/W)
106  */
107 #define N775_ADG728_ADDRESS_UPPERBITS (0x98u)
108 /* I2C R/W bit, read */
109 #define N775_I2C_READ (1u)
110 /* I2C R/W bit, write */
111 #define N775_I2C_WRITE (0u)
112 /* Dummy byte for I2C, replaced by read data */
113 #define N775_I2C_DUMMY_BYTE (0x0u)
114 /* GPIO position (0 to 7) used for multiplexed temperature measurement */
115 #define N775_MUXED_TEMP_GPIO_POSITION (0u)
116 /* Global balancing timer (0x0 - 0xFFFF) */
117 #define N775_GLOBAL_BALANCING_TIMER (0xFFFFu)
118 /* Pre-balancing timer (0x0 - 0xFFFF) */
119 #define N775_PRE_BALANCING_TIMER (0x0u)
120 /* All channel balancing timer (0x0 - 0xFFFF) */
121 #define N775_ALL_CHANNEL_BALANCING_TIMER (0xFFFFu)
122 /* Global balancing timer value to reach to reset it to max */
123 #define N775_GLOBAL_BALANCING_TIMER_VALUE_SET_TO_MAX_AGAIN (0x1000u)
124 /* Maximum number of tries to avoid endless loop when waiting for a flag to be ready */
125 #define N775_FLAG_READY_TRIES (5u)
126 
127 /* Timeout in ms when waiting for an I2C transaction over NXP slave */
128 #define N775_I2C_FINISHED_TIMEOUT_ms (50u)
129 
130 /** error table for the LTC driver */
131 typedef struct {
132  bool communicationOk[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]; /*!< */
133  bool noCommunicationTimeout[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]; /*!< */
140 
141 /** error table for the LTC driver */
142 typedef struct {
145 
146 /** configuration of the mux channels */
147 typedef struct {
148  uint8_t muxId; /*!< multiplexer ID 0 - 3 */
149  uint8_t muxChannel; /*!< multiplexer channel 0 - 7 */
151 
152 /** State requests for the N775 state machine */
153 typedef enum {
157 
158 /**
159  * Possible return values when state requests are made to the N775 state machine
160  */
161 typedef enum {
162  N775_OK = 0, /*!< N775 --> ok */
163  N775_BUSY_OK = 1, /*!< N775 under load --> ok */
164  N775_REQUEST_PENDING = 2, /*!< requested to be executed */
165  N775_ILLEGAL_REQUEST = 3, /*!< Request can not be executed */
166  N775_SPI_ERROR = 4, /*!< Error state: Source: SPI */
167  N775_PEC_ERROR = 5, /*!< Error state: Source: PEC */
168  N775_MUX_ERROR = 6, /*!< Error state: Source: MUX */
169  N775_INIT_ERROR = 7, /*!< Error state: Source: Initialization */
170  N775_OK_FROM_ERROR = 8, /*!< Return from error --> ok */
171  N775_GENERAL_ERROR = 20, /*!< General error state */
172  N775_ALREADY_INITIALIZED = 30, /*!< Initialization of N775 already finished */
173  N775_ILLEGAL_TASK_TYPE = 99, /*!< Illegal */
175 
176 /** This struct contains pointer to used data buffers */
177 typedef struct {
186  DATA_BLOCK_OPEN_WIRE_s *openWire; /* Wie genau open wire check behandeln? Was genau abspeichern? */
191 
192 /** This struct contains error counter and pointer to used error buffers */
193 typedef struct {
194  uint32_t *errPECCnt; /* array length: Number of used N775s */
195  uint32_t *errSPICnt; /* array length: Number of used N775s */
196  uint8_t *n775Status; /* array length: Number of used N775s */
197  uint8_t errPECRetryCnt;
198  uint8_t errSPIRetryCnt;
199  uint8_t errOccurred;
201 } N775_ERROR_s;
202 
203 /**
204  * This struct contains the measurement configuration for the N775
205  * Measurement is deactivated with value = N775_STATE_NO_REQUEST
206  */
207 typedef struct {
208  N775_STATE_REQUEST_e measVoltage; /* activated = N775_STATE_VOLTAGEMEASUREMENT_REQUEST */
209  N775_STATE_REQUEST_e measVoltage2Cells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_2CELLS_REQUEST */
210  N775_STATE_REQUEST_e measVoltageSumOfCells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_SC_REQUEST */
211  N775_STATE_REQUEST_e measMux; /* activated = N775_STATE_MUXMEASUREMENT_REQUEST */
212  N775_STATE_REQUEST_e balancing; /* activated = N775_STATE_BALANCECONTROL_REQUEST */
213  N775_STATE_REQUEST_e balancing_feedback; /* activated = N775_STATE_BALANCEFEEDBACK_REQUEST */
214  N775_STATE_REQUEST_e measAllGpio; /* activated = N775_STATE_ALL_GPIO_MEASUREMENT_REQUEST */
215  N775_STATE_REQUEST_e userIO; /* activated = N775_STATE_USER_IO_REQUEST */
216  N775_STATE_REQUEST_e readEEPROM; /* activated = N775_STATE_EEPROM_READ_UID_REQUEST */
217  N775_STATE_REQUEST_e measTemperature; /* activated = N775_STATE_TEMP_SENS_READ_REQUEST */
218  N775_STATE_REQUEST_e openWireCheck; /* activated = N775_STATE_OPENWIRE_CHECK_REQUEST */
219  N775_STATE_REQUEST_e deviceParameterCheck; /* activated = N775_STATEMACH_DEVICE_PARAMETER_REQUEST */
220  N775_STATE_REQUEST_e accuracyADCverification; /* activated = N775_STATEMACH_ADC_ACCURACY_REQUEST */
221  N775_STATE_REQUEST_e digitalFilterCheck; /* activated = N775_STATEMACH_DIGITAL_FILTER_REQUEST */
222  uint8_t taskCycleCnt; /* holds the current state machine index */
223  uint8_t numberActiveOfStates; /* number of active states */
224  uint8_t activeStates[12]; /* array holds the different substates that are executed one after another */
225  /* maximum number of states : 12 */
226 } N775_CONFIG_s;
227 
228 /**
229  *
230  */
231 typedef enum {
236 
237 /** TI port expander IO direction (input or output) */
238 typedef enum {
242 
243 /**
244  * This structure contains all the variables relevant for the N775 state machine.
245  * The user can get the current state of the N775 state machine with this variable
246  */
247 typedef struct {
248  bool firstMeasurementMade; /*!< flag that indicates if the first measurement cycle was completed */
249  uint8_t currentString; /*!< string currently being addressed */
250  SPI_INTERFACE_CONFIG_s *pSpiTxSequenceStart; /*!< pointer to the start of SPI sequence to be used for Tx */
251  SPI_INTERFACE_CONFIG_s *pSpiTxSequence; /*!< pointer to the SPI sequence to be used for Tx */
252  SPI_INTERFACE_CONFIG_s *pSpiRxSequenceStart; /*!< pointer to the start of SPI sequence to be used for Rx */
253  SPI_INTERFACE_CONFIG_s *pSpiRxSequence; /*!< pointer to the SPI sequence to be used for Rx */
254  uint8_t currentMux[BS_NR_OF_STRINGS]; /*!< mux currently being addressed */
255  N775_MUX_CH_CFG_s *pMuxSequenceStart
256  [BS_NR_OF_STRINGS]; /*!< pointer to the multiplexer sequence to be measured (contains a list of elements [multiplexer id, multiplexer channels]) (1,-1)...(3,-1),(0,1),...(0,7) */
257  N775_MUX_CH_CFG_s *pMuxSequence
258  [BS_NR_OF_STRINGS]; /*!< pointer to the multiplexer sequence to be measured (contains a list of elements [multiplexer id, multiplexer channels]) (1,-1)...(3,-1),(0,1),...(0,7) */
260 } N775_STATE_s;
261 
262 /** This structure reflects the messages used by the NXP MC33775A */
263 typedef struct {
264  uint16_t head;
265  uint16_t dataHead;
266  uint16_t data[4];
267  uint16_t crc;
268  uint16_t dataLength;
270 
271 /*========== Extern Function Prototypes =====================================*/
272 
273 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
274 #ifdef UNITY_UNIT_TEST
275 #endif
276 
277 #endif /* FOXBMS__NXP_MC33775A_DEFS_H_ */
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
Database module header.
N775_PORT_EXPANDER_TI_DIRECTION_e
@ N775_PORT_EXPANDER_TI_OUTPUT
@ N775_PORT_EXPANDER_TI_INPUT
N775_RETURN_TYPE_e
@ N775_SPI_ERROR
@ N775_REQUEST_PENDING
@ N775_ILLEGAL_TASK_TYPE
@ N775_OK
@ N775_GENERAL_ERROR
@ N775_INIT_ERROR
@ N775_PEC_ERROR
@ N775_MUX_ERROR
@ N775_ALREADY_INITIALIZED
@ N775_OK_FROM_ERROR
@ N775_ILLEGAL_REQUEST
@ N775_BUSY_OK
N775_REUSE_MODE_e
@ N775_REUSE_READ_VOLTAGE_FOR_ADOW_PDOWN
@ N775_REUSE_READ_VOLTAGE_FOR_ADOW_PUP
@ N775_NOT_REUSED
N775_STATE_REQUEST_e
@ N775_STATE_NO_REQUEST
@ N775_STATE_INITIALIZATION_REQUEST
Headers for the driver for the SPI module.
N775_STATE_REQUEST_e measVoltageSumOfCells
N775_STATE_REQUEST_e balancing
N775_STATE_REQUEST_e measTemperature
uint8_t numberActiveOfStates
N775_STATE_REQUEST_e measMux
N775_STATE_REQUEST_e accuracyADCverification
N775_STATE_REQUEST_e digitalFilterCheck
N775_STATE_REQUEST_e balancing_feedback
N775_STATE_REQUEST_e measVoltage
N775_STATE_REQUEST_e readEEPROM
N775_STATE_REQUEST_e measVoltage2Cells
N775_STATE_REQUEST_e openWireCheck
N775_STATE_REQUEST_e measAllGpio
N775_STATE_REQUEST_e userIO
N775_STATE_REQUEST_e deviceParameterCheck
DATA_BLOCK_BALANCING_CONTROL_s * balancingControl
N775_ERROR_TABLE_s * errorTable
DATA_BLOCK_CELL_TEMPERATURE_s * cellTemperature
DATA_BLOCK_ALL_GPIO_VOLTAGES_s * allGpioVoltage
DATA_BLOCK_OPEN_WIRE_s * openWire
DATA_BLOCK_USER_MUX_s * userMux
N775_SUPPLY_CURRENT_s * supplyCurrent
DATA_BLOCK_SLAVE_CONTROL_s * slaveControl
DATA_BLOCK_MIN_MAX_s * minMax
DATA_BLOCK_CELL_VOLTAGE_s * cellVoltage
DATA_BLOCK_BALANCING_FEEDBACK_s * balancingFeedback
uint32_t nrOfConsecutiveErrors
uint8_t errPECRetryCnt
uint8_t * n775Status
uint32_t * errPECCnt
uint8_t errSPIRetryCnt
uint32_t * errSPICnt
SPI_INTERFACE_CONFIG_s * pSpiRxSequenceStart
SPI_INTERFACE_CONFIG_s * pSpiTxSequenceStart
SPI_INTERFACE_CONFIG_s * pSpiTxSequence
SPI_INTERFACE_CONFIG_s * pSpiRxSequence
N775_DATAPTR_s n775Data