foxBMS  1.3.0
The foxBMS Battery Management System API Documentation
n775_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 n775_defs.h
44  * @author foxBMS Team
45  * @date 2015-09-01 (date of creation)
46  * @updated 2022-05-30 (date of last update)
47  * @version v1.3.0
48  * @ingroup DRIVERS
49  * @prefix N775
50  *
51  * @brief Definitions for the driver for the MC33775A monitoring chip.
52  *
53  */
54 
55 #ifndef FOXBMS__N775_DEFS_H_
56 #define FOXBMS__N775_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 /** Command types supported by the MC33775A */
69 typedef enum {
71  N775_CMD_READ = 0x01,
75 
76 /** MADD values supported by the MC33775A */
77 typedef enum {
80 } N775_MADD_e;
81 
82 /** States of the N775 state machine */
83 typedef enum {
94 
95 /** General substates */
96 typedef enum {
97  N775_ENTRY, /*!< */
103 
104 /** Substates for the uninitialized state */
105 typedef enum {
106  N775_ENTRY_UNINITIALIZED = 0, /*!< Initialize-sequence */
108 
109 /** Substates for the initialization state */
110 typedef enum {
111  /* Init-Sequence */
119 
120 /** State requests for the N775 statemachine */
121 typedef enum {
125 
126 /**
127  * Possible return values when state requests are made to the N775 statemachine
128  */
129 typedef enum {
130  N775_OK = 0, /*!< N775 --> ok */
131  N775_BUSY_OK = 1, /*!< N775 under load --> ok */
132  N775_REQUEST_PENDING = 2, /*!< requested to be executed */
133  N775_ILLEGAL_REQUEST = 3, /*!< Request can not be executed */
134  N775_SPI_ERROR = 4, /*!< Error state: Source: SPI */
135  N775_PEC_ERROR = 5, /*!< Error state: Source: PEC */
136  N775_MUX_ERROR = 6, /*!< Error state: Source: MUX */
137  N775_INIT_ERROR = 7, /*!< Error state: Source: Initialization */
138  N775_OK_FROM_ERROR = 8, /*!< Return from error --> ok */
139  N775_ERROR = 20, /*!< General error state */
140  N775_ALREADY_INITIALIZED = 30, /*!< Initialization of N775 already finished */
141  N775_ILLEGAL_TASK_TYPE = 99, /*!< Illegal */
143 
144 /** configuration of the mux channels */
145 typedef struct {
146  uint8_t muxID; /*!< multiplexer ID 0 - 3 */
147  uint8_t muxCh; /*!< multiplexer channel 0 - 7 */
149 
150 /** struct that holds the multiplexer sequence */
151 typedef struct {
152  uint8_t nr_of_steps; /*!< number of steps in the multiplexer sequence */
153  N775_MUX_CH_CFG_s *seqptr; /*!< pointer to the multiplexer sequence */
155 
156 /** This struct contains pointer to used data buffers */
157 typedef struct {
165  DATA_BLOCK_OPEN_WIRE_s *openWire_check; /* Wie genau open wire check behandeln? Was genau abspeichern? */
166  int *openWire_buffer; /* BS_NR_OF_CELL_BLOCKS_PER_STRING */
167  uint8_t *spi_TX_withPEC; /* 12 byte */
168  uint8_t *spi_RX_withPEC; /* 12 byte */
169  uint16_t *GPIOVoltages; /* N7752_NUMBER_OF_GPIOS * NR_OF_N775s */
170  uint16_t *valid_GPIOPECs; /* NR_OF_N775s */
172 
173 /** This struct contains error counter and pointer to used error buffers */
174 typedef struct {
175  uint32_t *errPECCnt; /* array length: Number of used N775s */
176  uint32_t *errSPICnt; /* array length: Number of used N775s */
177  uint8_t *n775Status; /* array length: Number of used N775s */
178  uint8_t errPECRetryCnt;
179  uint8_t errSPIRetryCnt;
180  uint8_t errOccurred;
182 } N775_ERROR_s;
183 
184 /**
185  * This struct contains the measurement configuration for the N775
186  * Measurement is deactivated with value = N775_STATE_NO_REQUEST
187  */
188 typedef struct {
189  N775_STATE_REQUEST_e measVoltage; /* activated = N775_STATE_VOLTAGEMEASUREMENT_REQUEST */
190  N775_STATE_REQUEST_e measVoltage2Cells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_2CELLS_REQUEST */
191  N775_STATE_REQUEST_e measVoltageSumofCells; /* activated = N775_STATE_VOLTAGEMEASUREMENT_SC_REQUEST */
192  N775_STATE_REQUEST_e measMux; /* activated = N775_STATE_MUXMEASUREMENT_REQUEST */
193  N775_STATE_REQUEST_e balancing; /* activated = N775_STATE_BALANCECONTROL_REQUEST */
194  N775_STATE_REQUEST_e balancing_feedback; /* activated = N775_STATE_BALANCEFEEDBACK_REQUEST */
195  N775_STATE_REQUEST_e measAllGPIO; /* activated = N775_STATE_ALLGPIOMEASUREMENT_REQUEST */
196  N775_STATE_REQUEST_e userIO; /* activated = N775_STATE_USER_IO_REQUEST */
197  N775_STATE_REQUEST_e readEEPROM; /* activated = N775_STATE_EEPROM_READ_UID_REQUEST */
198  N775_STATE_REQUEST_e measTemperature; /* activated = N775_STATE_TEMP_SENS_READ_REQUEST */
199  N775_STATE_REQUEST_e openWireCheck; /* activated = N775_STATE_OPENWIRE_CHECK_REQUEST */
200  N775_STATE_REQUEST_e deviceParameterCheck; /* activated = N775_STATEMACH_DEVICE_PARAMETER_REQUEST */
201  N775_STATE_REQUEST_e accuracyADCverification; /* activated = N775_STATEMACH_ADC_ACCURACY_REQUEST */
202  N775_STATE_REQUEST_e digitalFilterCheck; /* activated = N775_STATEMACH_DIGITAL_FILTER_REQUEST */
203  uint8_t taskCycleCnt; /* holds the current state machine index */
204  uint8_t numberActiveOfStates; /* number of active states */
205  uint8_t activeStates[12]; /* array holds the different substates that are executed one after another */
206  /* maximum number of states : 12 */
207 } N775_CONFIG_s;
208 
209 /**
210  *
211  */
212 typedef enum {
217 
218 /** TI port expander IO direction (input or output) */
219 typedef enum {
223 
224 /**
225  * This structure contains all the variables relevant for the N775 state machine.
226  * The user can get the current state of the N775 state machine with this variable
227  */
228 typedef struct {
229  uint16_t timer; /*!< time in ms before the state machine processes the next state, e.g. in counts of 1ms */
230  N775_STATE_REQUEST_e stateReq; /*!< current state request made to the state machine */
231  N775_STATEMACH_e state; /*!< state of Driver State Machine */
232  uint8_t subState; /*!< current substate of the state machine */
233  N775_STATEMACH_e lastState; /*!< previous state of the state machine */
234  uint8_t lastSubState; /*!< previous substate of the state machine */
235  uint32_t errRequestCounter; /*!< counts the number of illegal requests to the N775 state machine */
236  uint8_t triggerEntry; /*!< counter for re-entrance protection (function running flag) */
237  STD_RETURN_TYPE_e firstMeasurementMade; /*!< flag that indicates if the first measurement cycle was completed */
238  STD_RETURN_TYPE_e checkSpiFlag; /*!< indicates if interrupt flag or timer must be considered */
239  STD_RETURN_TYPE_e balanceControlDone; /*!< indicates if balance control was done */
240  bool txTransmitOngoing; /*!< indicates if a transmission is ongoing with the daisy-chain */
241  bool rxTransmitOngoing; /*!< indicates if a transmission is ongoing with the daisy-chain */
242  uint16_t totalMessages; /*!< total number of messages to be received from the daisy-chain */
243  uint16_t remainingMessages; /*!< counter of number of messages still to be received from the daisy-chain */
244 } N775_STATE_s;
245 
246 /** This structure reflects the messages used by the NXP MC33775A */
247 typedef struct {
248  uint16_t head;
249  uint16_t dataHead;
250  uint16_t data[4];
251  uint16_t crc;
252  uint16_t dataLength;
254 
255 /*========== Extern Function Prototypes =====================================*/
256 
257 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
258 
259 #endif /* FOXBMS__N775_DEFS_H_ */
Database module header.
STD_RETURN_TYPE_e
Definition: fstd_types.h:81
General macros and definitions for the whole platform.
N775_PORT_EXPANDER_TI_DIRECTION_e
Definition: n775_defs.h:219
@ N775_PORT_EXPANDER_TI_OUTPUT
Definition: n775_defs.h:220
@ N775_PORT_EXPANDER_TI_INPUT
Definition: n775_defs.h:221
N775_RETURN_TYPE_e
Definition: n775_defs.h:129
@ N775_SPI_ERROR
Definition: n775_defs.h:134
@ N775_REQUEST_PENDING
Definition: n775_defs.h:132
@ N775_ILLEGAL_TASK_TYPE
Definition: n775_defs.h:141
@ N775_OK
Definition: n775_defs.h:130
@ N775_INIT_ERROR
Definition: n775_defs.h:137
@ N775_ERROR
Definition: n775_defs.h:139
@ N775_PEC_ERROR
Definition: n775_defs.h:135
@ N775_MUX_ERROR
Definition: n775_defs.h:136
@ N775_ALREADY_INITIALIZED
Definition: n775_defs.h:140
@ N775_OK_FROM_ERROR
Definition: n775_defs.h:138
@ N775_ILLEGAL_REQUEST
Definition: n775_defs.h:133
@ N775_BUSY_OK
Definition: n775_defs.h:131
N775_STATEMACH_SUB_e
Definition: n775_defs.h:96
@ N775_ENTRY
Definition: n775_defs.h:97
@ N775_ERROR_ENTRY
Definition: n775_defs.h:100
@ N775_SECOND_WAKEUP
Definition: n775_defs.h:98
@ N775_CHECK_ENUMERATION
Definition: n775_defs.h:99
@ N775_ERROR_PROCESSED
Definition: n775_defs.h:101
N775_REUSE_MODE_e
Definition: n775_defs.h:212
@ N775_REUSE_READVOLT_FOR_ADOW_PDOWN
Definition: n775_defs.h:215
@ N775_REUSE_READVOLT_FOR_ADOW_PUP
Definition: n775_defs.h:214
@ N775_NOT_REUSED
Definition: n775_defs.h:213
N775_STATEMACH_INITIALIZATION_SUB_e
Definition: n775_defs.h:110
@ N775_EXIT_INITIALIZATION
Definition: n775_defs.h:117
@ N775_RE_ENTRY_INITIALIZATION
Definition: n775_defs.h:114
@ N775_ENTRY_INITIALIZATION
Definition: n775_defs.h:112
@ N775_START_INIT_INITIALIZATION
Definition: n775_defs.h:113
@ N775_CHECK_INITIALIZATION
Definition: n775_defs.h:116
@ N775_READ_INITIALIZATION_REGISTER
Definition: n775_defs.h:115
N775_MADD_e
Definition: n775_defs.h:77
@ N775_MADD_MASTER0
Definition: n775_defs.h:78
@ N775_MADD_MASTER1
Definition: n775_defs.h:79
N775_STATE_REQUEST_e
Definition: n775_defs.h:121
@ N775_STATE_NO_REQUEST
Definition: n775_defs.h:123
@ N775_STATE_INIT_REQUEST
Definition: n775_defs.h:122
N775_STATEMACH_UNINITIALIZED_SUB_e
Definition: n775_defs.h:105
@ N775_ENTRY_UNINITIALIZED
Definition: n775_defs.h:106
N775_COMMAND_e
Definition: n775_defs.h:69
@ N775_CMD_READ
Definition: n775_defs.h:71
@ N775_CMD_WRITE
Definition: n775_defs.h:72
@ N775_CMD_RESPONSE
Definition: n775_defs.h:73
@ N775_CMD_WAKEUP_NOP
Definition: n775_defs.h:70
N775_STATEMACH_e
Definition: n775_defs.h:83
@ N775_STATEMACH_ENUMERATE
Definition: n775_defs.h:87
@ N775_STATEMACH_WAKEUP
Definition: n775_defs.h:86
@ N775_STATEMACH_BALANCECONTROL
Definition: n775_defs.h:92
@ N775_STATEMACH_STARTMEAS
Definition: n775_defs.h:90
@ N775_STATEMACH_READVOLTAGE
Definition: n775_defs.h:91
@ N775_STATEMACH_IDLE
Definition: n775_defs.h:89
@ N775_STATEMACH_INITIALIZED
Definition: n775_defs.h:88
@ N775_STATEMACH_INITIALIZATION
Definition: n775_defs.h:85
@ N775_STATEMACH_UNINITIALIZED
Definition: n775_defs.h:84
Headers for the driver for the SPI module.
N775_STATE_REQUEST_e balancing
Definition: n775_defs.h:193
N775_STATE_REQUEST_e measTemperature
Definition: n775_defs.h:198
uint8_t numberActiveOfStates
Definition: n775_defs.h:204
N775_STATE_REQUEST_e measMux
Definition: n775_defs.h:192
N775_STATE_REQUEST_e accuracyADCverification
Definition: n775_defs.h:201
N775_STATE_REQUEST_e digitalFilterCheck
Definition: n775_defs.h:202
N775_STATE_REQUEST_e balancing_feedback
Definition: n775_defs.h:194
uint8_t taskCycleCnt
Definition: n775_defs.h:203
N775_STATE_REQUEST_e measVoltage
Definition: n775_defs.h:189
N775_STATE_REQUEST_e readEEPROM
Definition: n775_defs.h:197
N775_STATE_REQUEST_e measVoltage2Cells
Definition: n775_defs.h:190
N775_STATE_REQUEST_e openWireCheck
Definition: n775_defs.h:199
N775_STATE_REQUEST_e measAllGPIO
Definition: n775_defs.h:195
N775_STATE_REQUEST_e measVoltageSumofCells
Definition: n775_defs.h:191
N775_STATE_REQUEST_e userIO
Definition: n775_defs.h:196
N775_STATE_REQUEST_e deviceParameterCheck
Definition: n775_defs.h:200
uint8_t * spi_RX_withPEC
Definition: n775_defs.h:168
DATA_BLOCK_USER_MUX_s * user_mux
Definition: n775_defs.h:162
DATA_BLOCK_MIN_MAX_s * minmax
Definition: n775_defs.h:160
uint16_t * GPIOVoltages
Definition: n775_defs.h:169
DATA_BLOCK_OPEN_WIRE_s * openWire_check
Definition: n775_defs.h:165
DATA_BLOCK_CELL_TEMPERATURE_s * celltemperature
Definition: n775_defs.h:159
uint16_t * valid_GPIOPECs
Definition: n775_defs.h:170
DATA_BLOCK_SLAVE_CONTROL_s * user_io_control
Definition: n775_defs.h:164
DATA_BLOCK_CELL_VOLTAGE_s * cellvoltage
Definition: n775_defs.h:158
uint8_t * spi_TX_withPEC
Definition: n775_defs.h:167
DATA_BLOCK_BALANCING_CONTROL_s * balancing_control
Definition: n775_defs.h:163
DATA_BLOCK_BALANCING_FEEDBACK_s * balancing_feedback
Definition: n775_defs.h:161
int * openWire_buffer
Definition: n775_defs.h:166
uint32_t nrOfConsecutiveErrors
Definition: n775_defs.h:181
uint8_t errPECRetryCnt
Definition: n775_defs.h:178
uint8_t * n775Status
Definition: n775_defs.h:177
uint32_t * errPECCnt
Definition: n775_defs.h:175
uint8_t errSPIRetryCnt
Definition: n775_defs.h:179
uint32_t * errSPICnt
Definition: n775_defs.h:176
uint8_t errOccurred
Definition: n775_defs.h:180
uint16_t dataLength
Definition: n775_defs.h:252
uint16_t dataHead
Definition: n775_defs.h:249
uint16_t crc
Definition: n775_defs.h:251
uint16_t head
Definition: n775_defs.h:248
N775_MUX_CH_CFG_s * seqptr
Definition: n775_defs.h:153
uint8_t lastSubState
Definition: n775_defs.h:234
bool rxTransmitOngoing
Definition: n775_defs.h:241
STD_RETURN_TYPE_e firstMeasurementMade
Definition: n775_defs.h:237
uint16_t totalMessages
Definition: n775_defs.h:242
N775_STATE_REQUEST_e stateReq
Definition: n775_defs.h:230
uint8_t subState
Definition: n775_defs.h:232
uint16_t timer
Definition: n775_defs.h:229
STD_RETURN_TYPE_e checkSpiFlag
Definition: n775_defs.h:238
bool txTransmitOngoing
Definition: n775_defs.h:240
N775_STATEMACH_e state
Definition: n775_defs.h:231
uint32_t errRequestCounter
Definition: n775_defs.h:235
STD_RETURN_TYPE_e balanceControlDone
Definition: n775_defs.h:239
N775_STATEMACH_e lastState
Definition: n775_defs.h:233
uint8_t triggerEntry
Definition: n775_defs.h:236
uint16_t remainingMessages
Definition: n775_defs.h:243