foxBMS - Unit Tests  1.5.0
The foxBMS Unit Tests API Documentation
nxpfs85xx.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 nxpfs85xx.h
44  * @author foxBMS Team
45  * @date 2020-03-18 (date of creation)
46  * @updated 2023-02-03 (date of last update)
47  * @version v1.5.0
48  * @ingroup DRIVERS
49  * @prefix FS85
50  *
51  * @brief Header for the driver for the FRAM module
52  *
53  * @details It must always be used when creating new c header files.
54  *
55  */
56 
57 #ifndef FOXBMS__NXPFS85XX_H_
58 #define FOXBMS__NXPFS85XX_H_
59 
60 /*========== Includes =======================================================*/
61 #include "fram_cfg.h"
62 #include "nxpfs85xx_cfg.h"
63 
64 #include "sbc_fs8x.h"
65 #include "sbc_fs8x_communication.h"
66 #include "spi.h"
67 
68 #include <stdint.h>
69 
70 /*========== Macros and Definitions =========================================*/
71 /** struct for fail-safe registers
72  * for register description see data sheet FS84_FS85 - Rev. 3.0 - 9 April 2019 */
73 typedef struct {
74  uint16_t grl_flags; /*!< FS8X_FS_GRL_FLAGS_ADDR */
75  uint16_t iOvervoltageUndervoltageSafeReaction1; /*!< FS8X_FS_I_OVUV_SAFE_REACTION1_ADDR */
76  uint16_t iOvervoltageUndervoltageSafeReaction2; /*!< FS8X_FS_I_OVUV_SAFE_REACTION2_ADDR */
77  uint16_t iWatchdogConfiguration; /*!< FS8X_FS_I_WD_CFG_ADDR */
78  uint16_t i_safe_inputs; /*!< FS8X_FS_I_SAFE_INPUTS_ADDR */
79  uint16_t iFailSafeSateMachine; /*!< FS8X_FS_I_FSSM_ADDR */
80  uint16_t i_svs; /*!< FS8X_FS_I_SVS_ADDR */
81  uint16_t watchdogWindow; /*!< FS8X_FS_WD_WINDOW_ADDR */
82  uint16_t watchdogSeed; /*!< FS8X_FS_WD_SEED_ADDR */
83  uint16_t watchdogAnswer; /*!< FS8X_FS_WD_ANSWER_ADDR */
84  uint16_t overvoltageUndervoltageRegisterStatus; /*!< FS8X_FS_OVUVREG_STATUS_ADDR */
85  uint16_t releaseFs0bPin; /*!< FS8X_FS_RELEASE_FS0B_ADDR */
86  uint16_t safeIos; /*!< FS8X_FS_SAFE_IOS_ADDR */
87  uint16_t diag_safety; /*!< FS8X_FS_DIAG_SAFETY_ADDR */
88  uint16_t intb_mask; /*!< FS8X_FS_INTB_MASK_ADDR */
89  uint16_t states; /*!< FS8X_FS_STATES_ADDR */
91 
92 /** struct for main registers
93  * for register description see data sheet FS84_FS85 - Rev. 3.0 - 9 April 2019 */
94 typedef struct {
95  uint16_t flag; /*!< FS8X_M_FLAG_ADDR */
96  uint16_t mode; /*!< FS8X_M_MODE_ADDR */
97  uint16_t registerControl1; /*!< FS8X_M_REG_CTRL1_ADDR */
98  uint16_t registerControl2; /*!< FS8X_M_REG_CTRL2_ADDR */
99  uint16_t analogMultiplexer; /*!< FS8X_M_AMUX_ADDR */
100  uint16_t clock; /*!< FS8X_M_CLOCK_ADDR */
101  uint16_t int_mask1; /*!< FS8X_M_INT_MASK1_ADDR */
102  uint16_t int_mask2; /*!< FS8X_M_INT_MASK2_ADDR */
103  uint16_t flag1; /*!< FS8X_M_FLAG1_ADDR */
104  uint16_t flag2; /*!< FS8X_M_FLAG2_ADDR */
105  uint16_t vmon_regx; /*!< FS8X_M_VMON_REGX_ADDR */
106  uint16_t lvb1_svs; /*!< FS8X_M_LVB1_SVS_ADDR */
107  uint16_t memory0; /*!< FS8X_M_MEMORY0_ADDR */
108  uint16_t memory1; /*!< FS8X_M_MEMORY1_ADDR */
109  uint16_t deviceId; /*!< FS8X_M_DEVICEID_ADDR */
111 
112 typedef enum {
116 
117 /** struct for FIN configuration */
118 typedef struct {
119  bool finUsed; /*!< flag if FIN feature of SBC is used */
120  STD_RETURN_TYPE_e finState; /*!< Is set to STD_NOT_OK if short circuit between FIN and RSTB pin detected */
121  volatile uint32_t *pGIOport; /*!< pointer to port where FIN pin of SBC is connected to */
122  uint32_t pin; /*!< pin where FIN pin of SBC is connected to */
124 
125 /** stores a pointer to the persistent entry in the FRAM */
126 typedef struct {
127  FRAM_BLOCK_ID_e entry; /*!< FRAM ID of persistent SBC entry in FRAM */
128  FRAM_SBC_INIT_s *data; /*!< pointer to SBC entry in FRAM module */
130 
131 /** state struct to create SBC instance */
132 typedef struct {
133  SPI_INTERFACE_CONFIG_s *pSpiInterface; /*< pointer to used SPI interface configuration */
134  fs8x_drv_data_t configValues; /*!< configuration of used communication interface */
135  FS85_FIN_CONFIGURATION_s fin; /*!< configurations for FIN functionality */
136  FS85_MAIN_REGISTERS_s mainRegister; /*!< FS85xx main registers */
137  FS85_FS_REGISTER_s fsRegister; /*!< FS85xx safety registers */
138  FS85_NVRAM_INFO_s nvram; /*!< configuration and data for persistent memory required for initialization */
139  FS85_OPERATION_MODE_e mode; /*!< current operation mode of FS85xx */
140 } FS85_STATE_s;
141 
142 /*========== Extern Constant and Variable Declarations ======================*/
144 
145 /*========== Extern Function Prototypes =====================================*/
146 /**
147  * @brief Configures SBC during INIT_FS phase
148  * @details Checks first if SBC currently is in INIT_FS phase and if
149  * not transfers SBC back into INIT_FS. Verifies basic checks,
150  * configures fail-safe registers and closes INIT_FS
151  * afterwards.
152  * @param[in,out] pInstance SBC instance that is initialized
153  * @return #STD_OK if all checks were successful and SBC configured
154  * correctly, otherwise #STD_NOT_OK
155  */
157 
158 /**
159  * @brief Calculates the number of required watchdog refresh to reset
160  * fault error counter
161  * @param[in,out] pInstance SBC instance that is
162  * initialized
163  * @param[out] requiredWatchdogRefreshes number of required good
164  * watchdog refreshes
165  * @return #STD_OK if required watchdog refreshes were calculated
166  * successfully, otherwise #STD_NOT_OK
167  */
169  FS85_STATE_s *pInstance,
170  uint8_t *requiredWatchdogRefreshes);
171 
172 /**
173  * @brief Checks if fault error counter is zero
174  * @param[in,out] pInstance SBC instance where fault error counter is
175  * checked
176  * @return #STD_OK if fault error counter equals zero, otherwise
177  * #STD_NOT_OK
178  */
180 
181 /**
182  * @brief Performs SBC safety path checks
183  * @details Function perform safety path checks for FIN, FS0B and RSTB
184  * to ensure that all pins work as expected
185  * @param[in,out] pInstance where the safety paths are checked
186  * @return #STD_OK if safety path check successful, otherwise
187  * #STD_NOT_OK
188  */
190 
191 /**
192  * @brief Trigger watchdog
193  * @details Triggers watchdog of passed SBC instance and verify if it
194  * was good refresh within the configured window
195  * @param[in,out] pInstance SBC instance where the watchdog is triggered
196  * @return #STD_OK if watchdog has been triggered successfully,
197  * otherwise #STD_NOT_OK
198  */
200 
201 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
202 #ifdef UNITY_UNIT_TEST
203 extern STD_RETURN_TYPE_e TEST_SBC_CheckRegisterValues(uint32_t registerValue, uint32_t expectedRegisterValue);
204 extern void TEST_SBC_UpdateRegister(
205  FS85_STATE_s *pInstance,
206  bool isFailSafe,
207  uint32_t registerAddress,
208  uint32_t registerValue);
210  FS85_FS_REGISTER_s *pFsRegister,
211  uint32_t registerAddress,
212  uint32_t registerValue);
213 extern void TEST_SBC_UpdateMainRegister(
214  FS85_MAIN_REGISTERS_s *pMainRegister,
215  uint32_t registerAddress,
216  uint32_t registerValue);
217 #endif
218 
219 #endif /* FOXBMS__NXPFS85XX_H_ */
Headers for the configuration for the FRAM module.
FRAM_BLOCK_ID_e
Definition: fram_cfg.h:104
STD_RETURN_TYPE_e
Definition: fstd_types.h:82
STD_RETURN_TYPE_e FS85_InitializeNumberOfRequiredWatchdogRefreshes(FS85_STATE_s *pInstance, uint8_t *requiredWatchdogRefreshes)
Calculates the number of required watchdog refresh to reset fault error counter.
Definition: nxpfs85xx.c:885
void TEST_SBC_UpdateRegister(FS85_STATE_s *pInstance, bool isFailSafe, uint32_t registerAddress, uint32_t registerValue)
Definition: nxpfs85xx.c:1246
FS85_STATE_s fs85xx_mcuSupervisor
Definition: nxpfs85xx.c:84
STD_RETURN_TYPE_e FS85_InitializeFsPhase(FS85_STATE_s *pInstance)
Configures SBC during INIT_FS phase.
Definition: nxpfs85xx.c:500
STD_RETURN_TYPE_e SBC_TriggerWatchdog(FS85_STATE_s *pInstance)
Trigger watchdog.
Definition: nxpfs85xx.c:1023
STD_RETURN_TYPE_e TEST_SBC_CheckRegisterValues(uint32_t registerValue, uint32_t expectedRegisterValue)
Definition: nxpfs85xx.c:1242
void TEST_SBC_UpdateFailSafeRegister(FS85_FS_REGISTER_s *pFsRegister, uint32_t registerAddress, uint32_t registerValue)
Definition: nxpfs85xx.c:1254
void TEST_SBC_UpdateMainRegister(FS85_MAIN_REGISTERS_s *pMainRegister, uint32_t registerAddress, uint32_t registerValue)
Definition: nxpfs85xx.c:1261
FS85_OPERATION_MODE_e
Definition: nxpfs85xx.h:112
@ SBC_DEBUG_MODE
Definition: nxpfs85xx.h:114
@ SBC_NORMAL_MODE
Definition: nxpfs85xx.h:113
STD_RETURN_TYPE_e FS85_SafetyPathChecks(FS85_STATE_s *pInstance)
Performs SBC safety path checks.
Definition: nxpfs85xx.c:957
STD_RETURN_TYPE_e FS85_CheckFaultErrorCounter(FS85_STATE_s *pInstance)
Checks if fault error counter is zero.
Definition: nxpfs85xx.c:942
Config header file for SBC module.
FS8x driver interface.
This file contains functions for SPI/I2C communication.
Headers for the driver for the SPI module.
volatile uint32_t * pGIOport
Definition: nxpfs85xx.h:121
STD_RETURN_TYPE_e finState
Definition: nxpfs85xx.h:120
uint16_t diag_safety
Definition: nxpfs85xx.h:87
uint16_t releaseFs0bPin
Definition: nxpfs85xx.h:85
uint16_t i_svs
Definition: nxpfs85xx.h:80
uint16_t iWatchdogConfiguration
Definition: nxpfs85xx.h:77
uint16_t watchdogAnswer
Definition: nxpfs85xx.h:83
uint16_t overvoltageUndervoltageRegisterStatus
Definition: nxpfs85xx.h:84
uint16_t i_safe_inputs
Definition: nxpfs85xx.h:78
uint16_t iOvervoltageUndervoltageSafeReaction2
Definition: nxpfs85xx.h:76
uint16_t safeIos
Definition: nxpfs85xx.h:86
uint16_t watchdogSeed
Definition: nxpfs85xx.h:82
uint16_t iFailSafeSateMachine
Definition: nxpfs85xx.h:79
uint16_t grl_flags
Definition: nxpfs85xx.h:74
uint16_t watchdogWindow
Definition: nxpfs85xx.h:81
uint16_t states
Definition: nxpfs85xx.h:89
uint16_t intb_mask
Definition: nxpfs85xx.h:88
uint16_t iOvervoltageUndervoltageSafeReaction1
Definition: nxpfs85xx.h:75
uint16_t registerControl1
Definition: nxpfs85xx.h:97
uint16_t registerControl2
Definition: nxpfs85xx.h:98
uint16_t analogMultiplexer
Definition: nxpfs85xx.h:99
FRAM_BLOCK_ID_e entry
Definition: nxpfs85xx.h:127
FRAM_SBC_INIT_s * data
Definition: nxpfs85xx.h:128
FS85_MAIN_REGISTERS_s mainRegister
Definition: nxpfs85xx.h:136
FS85_OPERATION_MODE_e mode
Definition: nxpfs85xx.h:139
FS85_FS_REGISTER_s fsRegister
Definition: nxpfs85xx.h:137
FS85_NVRAM_INFO_s nvram
Definition: nxpfs85xx.h:138
FS85_FIN_CONFIGURATION_s fin
Definition: nxpfs85xx.h:135
fs8x_drv_data_t configValues
Definition: nxpfs85xx.h:134
SPI_INTERFACE_CONFIG_s * pSpiInterface
Definition: nxpfs85xx.h:133
This data structure is used by the FS8x driver (this is the first parameter of most the FS8x function...