foxBMS  1.4.1
The foxBMS Battery Management System API Documentation
nxp_mc33775a_defs.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 nxp_mc33775a_defs.h
44  * @author foxBMS Team
45  * @date 2020-09-01 (date of creation)
46  * @updated 2022-10-27 (date of last update)
47  * @version v1.4.1
48  * @ingroup DRIVERS
49  * @prefix N775
50  *
51  * @brief Definitions for the driver for the MC33775A monitoring chip.
52  *
53  */
54 
55 #ifndef FOXBMS__NXP_MC33775A_DEFS_H_
56 #define FOXBMS__NXP_MC33775A_DEFS_H_
57 
58 /*========== Includes =======================================================*/
59 #include "general.h"
60 
61 #include "database.h"
62 #include "spi.h"
63 
64 /*========== Macros and Definitions =========================================*/
65 
66 /*========== Extern Constant and Variable Declarations ======================*/
67 
68 /* Use of mux for temperature measurement */
69 #define N775_USE_MUX_FOR_TEMP (true)
70 /* Read mux state after setting it */
71 #define N775_CHECK_MUX_STATE (true)
72 /* Check supply current (part of MC33775A DIAG) */
73 #define N775_CHECK_SUPPLY_CURRENT (false)
74 /* Broadcast address for the N775 slaves */
75 #define N775_BROADCAST_ADDRESS (63u)
76 /* Time to wait between activity on bus and wake up of slave */
77 #define N775_WAKEUP_TIME_MS (3u)
78 /* Timeout in 10ms to go into sleep, max 255 (corresponding to 2550ms) */
79 #define N775_TIMEOUT_TO_SLEEP_10MS (200u)
80 /* Timeout enable, 0u in register = enabled */
81 #define N775_TIMEOUT_ENABLED (0u)
82 /* Timeout enable, 0x5A in register = disabled */
83 #define N775_TIMEOUT_DISABLED (0x5Au)
84 /* Timeout enable switch*/
85 #define N775_TIMEOUT_SWITCH (N775_TIMEOUT_ENABLED)
86 /* Time to wait after measurements started */
87 #define N775_TIME_AFTER_MEASUREMENT_START_MS (5u)
88 /* Default chain address */
89 #define N775_DEFAULT_CHAIN_ADDRESS (1u)
90 /* Measurement capture time */
91 /* + 1 to take balancing pause time before measurement into account */
92 #define N775_MEASUREMENT_CAPTURE_TIME_MS (5u + 1u)
93 /* Time to wait after measurement capture for measurements to be ready */
94 #define N775_MEASUREMENT_READY_TIME_MS (1u)
95 /* Value stored in N775A register when not valid */
96 #define N775_INVALID_REGISTER_VALUE (0x8000u)
97 /* Length of the mux measurement sequence */
98 #define N775_MUX_SEQUENCE_LENGTH (8u)
99 /* Time in 10us for pause of balancing before measurement start */
100 /* Wait time afer capture must be increased if this value is too high */
101 #define N775_BALPAUSELEN_10US (100u)
102 /**
103  * Upper bits of ADG728 mux address byte
104  * Set to 0: bit2, bit1 (address), bit0 (R/W)
105  */
106 #define N775_ADG728_ADDRESS_UPPERBITS (0x98u)
107 /* I2C R/W bit, read */
108 #define N775_I2C_READ (1u)
109 /* I2C R/W bit, write */
110 #define N775_I2C_WRITE (0u)
111 /* Dummy byte for I2C, replaced by read data */
112 #define N775_I2C_DUMMY_BYTE (0x0u)
113 /* GPIO position (0 to 7) used for multiplexed temperature measurement */
114 #define N775_MUXED_TEMP_GPIO_POSITION (0u)
115 /* Global balancing timer (0x0 - 0xFFFF) */
116 #define N775_GLOBAL_BALANCING_TIMER (0xFFFFu)
117 /* Pre-balancing timer (0x0 - 0xFFFF) */
118 #define N775_PRE_BALANCING_TIMER (0x0u)
119 /* All channel balancing timer (0x0 - 0xFFFF) */
120 #define N775_ALL_CHANNEL_BALANCING_TIMER (0xFFFFu)
121 /* Global balancing timer value to reach to reset it to max */
122 #define N775_GLOBAL_BALANCING_TIMER_VALUE_SET_TO_MAX_AGAIN (0x1000u)
123 /* Timeout used to avoid endless loop when waiting for a flag to be ready */
124 #define N775_FLAG_READY_TIMEOUT (2000u)
125 
126 /** error table for the LTC driver */
127 typedef struct {
128  bool communicationOk[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]; /*!< */
129  bool noCommunicationTimeout[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]; /*!< */
136 
137 /** error table for the LTC driver */
138 typedef struct {
141 
142 /** configuration of the mux channels */
143 typedef struct {
144  uint8_t muxId; /*!< multiplexer ID 0 - 3 */
145  uint8_t muxChannel; /*!< multiplexer channel 0 - 7 */
147 
148 /** States of the N775 state machine */
149 typedef enum {
160 
161 /** General substates */
162 typedef enum {
163  N775_ENTRY, /*!< */
169 
170 /** Substates for the uninitialized state */
171 typedef enum {
172  N775_ENTRY_UNINITIALIZED = 0, /*!< Initialize-sequence */
174 
175 /** Substates for the initialization state */
176 typedef enum {
177  /* Init-Sequence */
185 
186 /** State requests for the N775 statemachine */
187 typedef enum {
191 
192 /**
193  * Possible return values when state requests are made to the N775 statemachine
194  */
195 typedef enum {
196  N775_OK = 0, /*!< N775 --> ok */
197  N775_BUSY_OK = 1, /*!< N775 under load --> ok */
198  N775_REQUEST_PENDING = 2, /*!< requested to be executed */
199  N775_ILLEGAL_REQUEST = 3, /*!< Request can not be executed */
200  N775_SPI_ERROR = 4, /*!< Error state: Source: SPI */
201  N775_PEC_ERROR = 5, /*!< Error state: Source: PEC */
202  N775_MUX_ERROR = 6, /*!< Error state: Source: MUX */
203  N775_INIT_ERROR = 7, /*!< Error state: Source: Initialization */
204  N775_OK_FROM_ERROR = 8, /*!< Return from error --> ok */
205  N775_GENERAL_ERROR = 20, /*!< General error state */
206  N775_ALREADY_INITIALIZED = 30, /*!< Initialization of N775 already finished */
207  N775_ILLEGAL_TASK_TYPE = 99, /*!< Illegal */
209 
210 /** This struct contains pointer to used data buffers */
211 typedef struct {
220  DATA_BLOCK_OPEN_WIRE_s *openWire; /* Wie genau open wire check behandeln? Was genau abspeichern? */
225 
226 /** This struct contains error counter and pointer to used error buffers */
227 typedef struct {
228  uint32_t *errPECCnt; /* array length: Number of used N775s */
229  uint32_t *errSPICnt; /* array length: Number of used N775s */
230  uint8_t *n775Status; /* array length: Number of used N775s */
231  uint8_t errPECRetryCnt;
232  uint8_t errSPIRetryCnt;
233  uint8_t errOccurred;
235 } N775_ERROR_s;
236 
237 /**
238  * This struct contains the measurement configuration for the N775
239  * Measurement is deactivated with value = N775_STATE_NO_REQUEST
240  */
241 typedef struct {
242  N775_STATE_REQUEST_e measVoltage; /* activated = N775_STATE_VOLTAGEMEASUREMENT_REQUEST */
243  N775_STATE_REQUEST_e measVoltage2Cells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_2CELLS_REQUEST */
244  N775_STATE_REQUEST_e measVoltageSumOfCells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_SC_REQUEST */
245  N775_STATE_REQUEST_e measMux; /* activated = N775_STATE_MUXMEASUREMENT_REQUEST */
246  N775_STATE_REQUEST_e balancing; /* activated = N775_STATE_BALANCECONTROL_REQUEST */
247  N775_STATE_REQUEST_e balancing_feedback; /* activated = N775_STATE_BALANCEFEEDBACK_REQUEST */
248  N775_STATE_REQUEST_e measAllGpio; /* activated = N775_STATE_ALL_GPIO_MEASUREMENT_REQUEST */
249  N775_STATE_REQUEST_e userIO; /* activated = N775_STATE_USER_IO_REQUEST */
250  N775_STATE_REQUEST_e readEEPROM; /* activated = N775_STATE_EEPROM_READ_UID_REQUEST */
251  N775_STATE_REQUEST_e measTemperature; /* activated = N775_STATE_TEMP_SENS_READ_REQUEST */
252  N775_STATE_REQUEST_e openWireCheck; /* activated = N775_STATE_OPENWIRE_CHECK_REQUEST */
253  N775_STATE_REQUEST_e deviceParameterCheck; /* activated = N775_STATEMACH_DEVICE_PARAMETER_REQUEST */
254  N775_STATE_REQUEST_e accuracyADCverification; /* activated = N775_STATEMACH_ADC_ACCURACY_REQUEST */
255  N775_STATE_REQUEST_e digitalFilterCheck; /* activated = N775_STATEMACH_DIGITAL_FILTER_REQUEST */
256  uint8_t taskCycleCnt; /* holds the current state machine index */
257  uint8_t numberActiveOfStates; /* number of active states */
258  uint8_t activeStates[12]; /* array holds the different substates that are executed one after another */
259  /* maximum number of states : 12 */
260 } N775_CONFIG_s;
261 
262 /**
263  *
264  */
265 typedef enum {
270 
271 /** TI port expander IO direction (input or output) */
272 typedef enum {
276 
277 /**
278  * This structure contains all the variables relevant for the N775 state machine.
279  * The user can get the current state of the N775 state machine with this variable
280  */
281 typedef struct {
282  bool firstMeasurementMade; /*!< flag that indicates if the first measurement cycle was completed */
283  uint8_t currentString; /*!< string currently being addressed */
284  SPI_INTERFACE_CONFIG_s *pSpiTxSequenceStart; /*!< pointer to the start of SPI sequence to be used for Tx */
285  SPI_INTERFACE_CONFIG_s *pSpiTxSequence; /*!< pointer to the SPI sequence to be used for Tx */
286  SPI_INTERFACE_CONFIG_s *pSpiRxSequenceStart; /*!< pointer to the start of SPI sequence to be used for Rx */
287  SPI_INTERFACE_CONFIG_s *pSpiRxSequence; /*!< pointer to the SPI sequence to be used for Rx */
288  uint8_t currentMux[BS_NR_OF_STRINGS]; /*!< mux currently being addressed */
289  N775_MUX_CH_CFG_s *pMuxSequenceStart
290  [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) */
291  N775_MUX_CH_CFG_s *pMuxSequence
292  [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) */
294 } N775_STATE_s;
295 
296 /** This structure reflects the messages used by the NXP MC33775A */
297 typedef struct {
298  uint16_t head;
299  uint16_t dataHead;
300  uint16_t data[4];
301  uint16_t crc;
302  uint16_t dataLength;
304 
305 /*========== Extern Function Prototypes =====================================*/
306 
307 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
308 
309 #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.
General macros and definitions for the whole platform.
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