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