foxBMS  1.5.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-02-03 (date of last update)
47  * @version v1.5.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 /** States of the N775 state machine */
153 typedef enum {
164 
165 /** General substates */
166 typedef enum {
167  N775_ENTRY, /*!< */
173 
174 /** Substates for the uninitialized state */
175 typedef enum {
176  N775_ENTRY_UNINITIALIZED = 0, /*!< Initialize-sequence */
178 
179 /** Substates for the initialization state */
180 typedef enum {
181  /* Init-Sequence */
189 
190 /** State requests for the N775 statemachine */
191 typedef enum {
195 
196 /**
197  * Possible return values when state requests are made to the N775 statemachine
198  */
199 typedef enum {
200  N775_OK = 0, /*!< N775 --> ok */
201  N775_BUSY_OK = 1, /*!< N775 under load --> ok */
202  N775_REQUEST_PENDING = 2, /*!< requested to be executed */
203  N775_ILLEGAL_REQUEST = 3, /*!< Request can not be executed */
204  N775_SPI_ERROR = 4, /*!< Error state: Source: SPI */
205  N775_PEC_ERROR = 5, /*!< Error state: Source: PEC */
206  N775_MUX_ERROR = 6, /*!< Error state: Source: MUX */
207  N775_INIT_ERROR = 7, /*!< Error state: Source: Initialization */
208  N775_OK_FROM_ERROR = 8, /*!< Return from error --> ok */
209  N775_GENERAL_ERROR = 20, /*!< General error state */
210  N775_ALREADY_INITIALIZED = 30, /*!< Initialization of N775 already finished */
211  N775_ILLEGAL_TASK_TYPE = 99, /*!< Illegal */
213 
214 /** This struct contains pointer to used data buffers */
215 typedef struct {
224  DATA_BLOCK_OPEN_WIRE_s *openWire; /* Wie genau open wire check behandeln? Was genau abspeichern? */
229 
230 /** This struct contains error counter and pointer to used error buffers */
231 typedef struct {
232  uint32_t *errPECCnt; /* array length: Number of used N775s */
233  uint32_t *errSPICnt; /* array length: Number of used N775s */
234  uint8_t *n775Status; /* array length: Number of used N775s */
235  uint8_t errPECRetryCnt;
236  uint8_t errSPIRetryCnt;
237  uint8_t errOccurred;
239 } N775_ERROR_s;
240 
241 /**
242  * This struct contains the measurement configuration for the N775
243  * Measurement is deactivated with value = N775_STATE_NO_REQUEST
244  */
245 typedef struct {
246  N775_STATE_REQUEST_e measVoltage; /* activated = N775_STATE_VOLTAGEMEASUREMENT_REQUEST */
247  N775_STATE_REQUEST_e measVoltage2Cells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_2CELLS_REQUEST */
248  N775_STATE_REQUEST_e measVoltageSumOfCells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_SC_REQUEST */
249  N775_STATE_REQUEST_e measMux; /* activated = N775_STATE_MUXMEASUREMENT_REQUEST */
250  N775_STATE_REQUEST_e balancing; /* activated = N775_STATE_BALANCECONTROL_REQUEST */
251  N775_STATE_REQUEST_e balancing_feedback; /* activated = N775_STATE_BALANCEFEEDBACK_REQUEST */
252  N775_STATE_REQUEST_e measAllGpio; /* activated = N775_STATE_ALL_GPIO_MEASUREMENT_REQUEST */
253  N775_STATE_REQUEST_e userIO; /* activated = N775_STATE_USER_IO_REQUEST */
254  N775_STATE_REQUEST_e readEEPROM; /* activated = N775_STATE_EEPROM_READ_UID_REQUEST */
255  N775_STATE_REQUEST_e measTemperature; /* activated = N775_STATE_TEMP_SENS_READ_REQUEST */
256  N775_STATE_REQUEST_e openWireCheck; /* activated = N775_STATE_OPENWIRE_CHECK_REQUEST */
257  N775_STATE_REQUEST_e deviceParameterCheck; /* activated = N775_STATEMACH_DEVICE_PARAMETER_REQUEST */
258  N775_STATE_REQUEST_e accuracyADCverification; /* activated = N775_STATEMACH_ADC_ACCURACY_REQUEST */
259  N775_STATE_REQUEST_e digitalFilterCheck; /* activated = N775_STATEMACH_DIGITAL_FILTER_REQUEST */
260  uint8_t taskCycleCnt; /* holds the current state machine index */
261  uint8_t numberActiveOfStates; /* number of active states */
262  uint8_t activeStates[12]; /* array holds the different substates that are executed one after another */
263  /* maximum number of states : 12 */
264 } N775_CONFIG_s;
265 
266 /**
267  *
268  */
269 typedef enum {
274 
275 /** TI port expander IO direction (input or output) */
276 typedef enum {
280 
281 /**
282  * This structure contains all the variables relevant for the N775 state machine.
283  * The user can get the current state of the N775 state machine with this variable
284  */
285 typedef struct {
286  bool firstMeasurementMade; /*!< flag that indicates if the first measurement cycle was completed */
287  uint8_t currentString; /*!< string currently being addressed */
288  SPI_INTERFACE_CONFIG_s *pSpiTxSequenceStart; /*!< pointer to the start of SPI sequence to be used for Tx */
289  SPI_INTERFACE_CONFIG_s *pSpiTxSequence; /*!< pointer to the SPI sequence to be used for Tx */
290  SPI_INTERFACE_CONFIG_s *pSpiRxSequenceStart; /*!< pointer to the start of SPI sequence to be used for Rx */
291  SPI_INTERFACE_CONFIG_s *pSpiRxSequence; /*!< pointer to the SPI sequence to be used for Rx */
292  uint8_t currentMux[BS_NR_OF_STRINGS]; /*!< mux currently being addressed */
293  N775_MUX_CH_CFG_s *pMuxSequenceStart
294  [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) */
295  N775_MUX_CH_CFG_s *pMuxSequence
296  [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) */
298 } N775_STATE_s;
299 
300 /** This structure reflects the messages used by the NXP MC33775A */
301 typedef struct {
302  uint16_t head;
303  uint16_t dataHead;
304  uint16_t data[4];
305  uint16_t crc;
306  uint16_t dataLength;
308 
309 /*========== Extern Function Prototypes =====================================*/
310 
311 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
312 #ifdef UNITY_UNIT_TEST
313 #endif
314 
315 #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_STATEMACH_SUB_e
@ N775_ENTRY
@ N775_ERROR_ENTRY
@ N775_SECOND_WAKEUP
@ N775_CHECK_ENUMERATION
@ N775_ERROR_PROCESSED
N775_REUSE_MODE_e
@ N775_REUSE_READ_VOLTAGE_FOR_ADOW_PDOWN
@ N775_REUSE_READ_VOLTAGE_FOR_ADOW_PUP
@ N775_NOT_REUSED
N775_STATEMACH_INITIALIZATION_SUB_e
@ N775_EXIT_INITIALIZATION
@ N775_RE_ENTRY_INITIALIZATION
@ N775_ENTRY_INITIALIZATION
@ N775_START_INIT_INITIALIZATION
@ N775_CHECK_INITIALIZATION
@ N775_READ_INITIALIZATION_REGISTER
N775_STATE_REQUEST_e
@ N775_STATE_NO_REQUEST
@ N775_STATE_INITIALIZATION_REQUEST
N775_STATEMACH_UNINITIALIZED_SUB_e
@ N775_ENTRY_UNINITIALIZED
N775_STATEMACH_e
@ N775_STATEMACH_ENUMERATE
@ N775_STATEMACH_WAKEUP
@ N775_STATEMACH_BALANCECONTROL
@ N775_STATEMACH_STARTMEAS
@ N775_STATEMACH_READVOLTAGE
@ N775_STATEMACH_IDLE
@ N775_STATEMACH_INITIALIZED
@ N775_STATEMACH_INITIALIZATION
@ N775_STATEMACH_UNINITIALIZED
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
N775_ERRORTABLE_s * errorTable
DATA_BLOCK_BALANCING_CONTROL_s * balancingControl
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