foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
adi_ades1830_balancing.c
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 adi_ades1830_balancing.c
44  * @author foxBMS Team
45  * @date 2019-08-27 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup SOME_GROUP
49  * @prefix ADI
50  *
51  * @brief Implementation of some software
52  *
53  */
54 
55 /*========== Includes =======================================================*/
56 /* clang-format off */
57 #include "adi_ades183x_balancing.h"
58 /* clang-format on */
59 
60 #include "adi_ades183x_cfg.h"
61 
62 #include "adi_ades183x_buffers.h"
63 #include "adi_ades183x_commands.h"
64 #include "adi_ades183x_defs.h"
65 #include "adi_ades183x_helpers.h"
66 #include "adi_ades183x_voltages.h"
67 
68 /*========== Macros and Definitions =========================================*/
69 
70 /*========== Static Constant and Variable Definitions =======================*/
71 
72 /*========== Extern Constant and Variable Definitions =======================*/
73 
74 /*========== Static Function Prototypes =====================================*/
75 
76 /*========== Static Function Implementations ================================*/
77 
78 /*========== Extern Function Implementations ================================*/
79 extern void ADI_DeactivateBalancing(ADI_STATE_s *adiState) {
80  FAS_ASSERT(adiState != NULL_PTR);
81 
82  /* Deactivate balancing before sending unmute command */
83  for (uint16_t m = 0; m < BS_NR_OF_MODULES_PER_STRING; m++) {
84  const uint16_t reverseModuleNumber = BS_NR_OF_MODULES_PER_STRING - m - 1u;
87  [(reverseModuleNumber * ADI_WRCFGB_LEN) + ADI_REGISTER_OFFSET4],
88  0u,
93  [(reverseModuleNumber * ADI_WRCFGB_LEN) + ADI_REGISTER_OFFSET5],
94  0u,
97  }
99  /* Send Unmute command */
101  ADI_TransmitCommand(adi_command, adiState);
102 }
103 
105  FAS_ASSERT(adiState != NULL_PTR);
106  uint16_t storedVoltageIndex = 0u;
107 
108  for (uint16_t m = 0; m < BS_NR_OF_MODULES_PER_STRING; m++) {
109  const uint16_t reverseModuleNumber = BS_NR_OF_MODULES_PER_STRING - m - 1u;
110  uint8_t dccRegisterLow = 0u;
111  uint8_t dccRegisterHigh = 0u;
112  for (uint8_t c = 0u; c < ADI_MAX_SUPPORTED_CELLS; c++) {
113  if (adi_voltageInputsUsed[c] == 1u) {
114  storedVoltageIndex = ADI_GetStoredVoltageIndex(c);
115  if (adiState->data.balancingControl
116  ->balancingState[adiState->currentString]
117  [(m * (BS_NR_OF_CELL_BLOCKS_PER_MODULE)) + storedVoltageIndex] == 1u) {
118  if (c < ADI_CFGRB_NUMBER_OF_DCC_BITS_PER_BYTE) { /* 0 - 7 cells */
119  dccRegisterLow |= (uint8_t)(1u << c);
120  } else { /* 8 - 15 cells */
121  dccRegisterHigh |= (uint8_t)(1u << (c - ADI_CFGRB_NUMBER_OF_DCC_BITS_PER_BYTE));
122  }
123  }
124  }
125  }
128  [(reverseModuleNumber * ADI_WRCFGB_LEN) + ADI_REGISTER_OFFSET4],
129  dccRegisterLow,
134  [(reverseModuleNumber * ADI_WRCFGB_LEN) + ADI_REGISTER_OFFSET5],
135  dccRegisterHigh,
138  }
140 }
141 
142 /*========== Externalized Static Function Implementations (Unit Test) =======*/
143 #ifdef UNITY_UNIT_TEST
144 #endif
void ADI_DeactivateBalancing(ADI_STATE_s *adiState)
Disable balancing.
void ADI_DetermineBalancingRegisterConfiguration(ADI_STATE_s *adiState)
Determines how the balancing registers need to be set.
const uint8_t adi_voltageInputsUsed[ADI_MAX_SUPPORTED_CELLS]
#define ADI_MAX_SUPPORTED_CELLS
Headers for the driver for the ADI analog front-end.
uint8_t adi_configurationRegisterBgroup[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING *ADI_MAX_REGISTER_SIZE_IN_BYTES]
uint16_t adi_command[ADI_COMMAND_DEFINITION_LENGTH]
Header for the buffers used by the driver for the ADI analog front-end.
Header for the configuration for the ADI analog front-end.
const uint16_t adi_cmdUnmute[ADI_COMMAND_DEFINITION_LENGTH]
Header file of some software.
Headers for the driver for the ades183x analog front-end.
#define ADI_CFGRB5_DCC_9_16_MASK
#define ADI_CFGRB4_DCC_1_8_POS
#define ADI_CFGRB4_DCC_1_8_MASK
#define ADI_REGISTER_OFFSET5
#define ADI_CFGRB_NUMBER_OF_DCC_BITS_PER_BYTE
#define ADI_CFGRB5_DCC_9_16_POS
#define ADI_WRCFGB_LEN
#define ADI_REGISTER_OFFSET4
void ADI_WriteDataBits(uint8_t *pSentData, uint8_t dataToWrite, uint8_t position, uint8_t mask)
Helper function to write specific bits in data to be sent.
void ADI_StoredConfigurationWriteToAfeGlobal(ADI_STATE_s *adiState)
Sends data in the configuration stored in driver to all AFEs in the daisy chain, for all configuratio...
void ADI_TransmitCommand(uint16_t *command, ADI_STATE_s *adiState)
send command to the ades183x daisy-chain (e.g., start voltage measurement).
void ADI_CopyCommandBits(const uint16_t *sourceCommand, uint16_t *destinationCommand)
copy command bits in variables.
Headers for the diagnostic driver for the ADI analog front-end.
uint16_t ADI_GetStoredVoltageIndex(uint16_t registerVoltageIndex)
Converts index of read voltages.
Header file of some software.
#define BS_NR_OF_CELL_BLOCKS_PER_MODULE
number of cells per module
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:255
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
DATA_BLOCK_BALANCING_CONTROL_s * balancingControl
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
Definition: database_cfg.h:260