foxBMS  1.0.0
The foxBMS Battery Management System API Documentation
mxm_registry.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
38  * ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file mxm_registry.c
44  * @author foxBMS Team
45  * @date 2020-07-16 (date of creation)
46  * @updated 2020-07-16 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix MXM
49  *
50  * @brief Functions in order to have a registry of monitoring ICs
51  *
52  * @details Monitoring registry stores information about the connected ICs.
53  *
54  */
55 
56 /*========== Includes =======================================================*/
57 #include "mxm_registry.h"
58 
59 /*========== Macros and Definitions =========================================*/
60 
61 /*========== Static Constant and Variable Definitions =======================*/
62 
63 /*========== Extern Constant and Variable Definitions =======================*/
64 
65 /*========== Static Function Prototypes =====================================*/
66 
67 /*========== Static Function Implementations ================================*/
68 
69 /*========== Extern Function Implementations ================================*/
71  FAS_ASSERT(pState != NULL_PTR);
72  for (uint8_t i = 0; i < MXM_MAXIMUM_NR_OF_MODULES; i++) {
73  MXM_REGISTRY_ENTRY_s *entry = &pState->registry[i];
74  entry->connected = false;
75  entry->deviceAddress = 0u;
76  entry->deviceID = 0u;
77  entry->model = MXM_MODEL_ID_NONE;
79  }
80  return;
81 }
82 
84  FAS_ASSERT(pState != NULL_PTR);
85  STD_RETURN_TYPE_e retval = STD_OK;
86  if (numberOfDevices > MXM_MAXIMUM_NR_OF_MODULES) {
87  retval = STD_NOT_OK;
88  } else {
89  for (uint8_t i = 0; i < numberOfDevices; i++) {
90  pState->registry[i].connected = true;
93  }
94  }
95 
96  return retval;
97 }
98 
100  FAS_ASSERT(pState != NULL_PTR);
101  /* return highest connected device */
102  return pState->highest5xDevice;
103 }
104 
107  uint8_t rxBufferLength,
108  MXM_REG_NAME_e type) {
109  FAS_ASSERT(pState != NULL_PTR);
110  /* only ID1 or ID2 are valid */
111  FAS_ASSERT((type == MXM_REG_ID1) || (type == MXM_REG_ID2));
112 
113  /* find highest connected device */
114  uint8_t highestConnectedDevice = MXM_MonRegistryGetHighestConnected5XDevice(pState);
115 
116  const uint8_t startBytes = 2u;
117 
118  for (uint8_t i = 0; i <= highestConnectedDevice; i++) {
119  uint8_t bufferPosition = startBytes + (i * 2u);
120  MXM_REGISTRY_ENTRY_s *currentDevice = &pState->registry[highestConnectedDevice - i];
121  FAS_ASSERT((bufferPosition + 1u) <= rxBufferLength);
122  uint16_t id = 0;
124  pState->rxBuffer[bufferPosition], pState->rxBuffer[bufferPosition + 1u], MXM_BM_WHOLE_REG, &id);
125  if (type == MXM_REG_ID1) {
126  currentDevice->deviceID = id;
127  } else {
128  /* (type == MXM_REG_ID2) */
129  currentDevice->deviceID = ((uint32_t)id << 16u) | currentDevice->deviceID;
130  }
131  }
132 }
133 
134 extern void MXM_MonRegistryParseVersionIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength) {
135  FAS_ASSERT(pState != NULL_PTR);
136 
137  /* find highest connected device */
138  uint8_t highestConnectedDevice = MXM_MonRegistryGetHighestConnected5XDevice(pState);
139 
140  const uint8_t startBytes = 2u;
141 
142  for (uint8_t i = 0; i <= highestConnectedDevice; i++) {
143  uint8_t bufferPosition = startBytes + (i * 2u);
144  MXM_REGISTRY_ENTRY_s *currentDevice = &pState->registry[highestConnectedDevice - i];
145  FAS_ASSERT((bufferPosition + 1u) <= rxBufferLength);
146  uint16_t model = 0;
148  pState->rxBuffer[bufferPosition], pState->rxBuffer[bufferPosition + 1u], MXM_REG_VERSION_MOD, &model);
149  currentDevice->model = (MXM_MODEL_ID_e)model;
150 
151  uint16_t version = 0;
153  pState->rxBuffer[bufferPosition], pState->rxBuffer[bufferPosition + 1u], MXM_REG_VERSION_VER, &version);
154  currentDevice->siliconVersion = (MXM_siliconVersion_e)version;
155  }
156 }
157 
158 /*========== Externalized Static Function Implementations (Unit Test) =======*/
MXM_MonRegistryParseVersionIntoDevices
void MXM_MonRegistryParseVersionIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength)
Parse Version into the registry.
Definition: mxm_registry.c:134
MXM_MODEL_ID_e
enum MXM_MODEL_ID MXM_MODEL_ID_e
Type of monitoring device.
MXM_siliconVersion_0
@ MXM_siliconVersion_0
Definition: mxm_basic_defines.h:120
MXM_REGISTRY_ENTRY::model
MXM_MODEL_ID_e model
Definition: mxm_1785x_tools.h:172
MXM_MONITORING_INSTANCE
Definition: mxm_1785x_tools.h:188
STD_RETURN_TYPE_e
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
MXM_REGISTRY_ENTRY::deviceAddress
uint8_t deviceAddress
Definition: mxm_1785x_tools.h:171
MXM_MONITORING_INSTANCE::rxBuffer
uint8_t rxBuffer[MXM_RX_BUFFER_LENGTH]
Definition: mxm_1785x_tools.h:223
MXM_REGISTRY_ENTRY::siliconVersion
MXM_siliconVersion_e siliconVersion
Definition: mxm_1785x_tools.h:173
MXM_REG_VERSION_VER
#define MXM_REG_VERSION_VER
Monitoring Register Version/Silicon Version.
Definition: mxm_register_map.h:731
MXM_REGISTRY_ENTRY::connected
bool connected
Definition: mxm_1785x_tools.h:170
MXM_MAXIMUM_NR_OF_MODULES
#define MXM_MAXIMUM_NR_OF_MODULES
Maximum number of modules.
Definition: mxm_basic_defines.h:73
FAS_ASSERT
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
MXM_MonRegistryParseIdIntoDevices
void MXM_MonRegistryParseIdIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength, MXM_REG_NAME_e type)
Parse ID (1 or 2) into the registry.
Definition: mxm_registry.c:105
MXM_REG_ID2
@ MXM_REG_ID2
Definition: mxm_register_map.h:662
MXM_MonRegistryGetHighestConnected5XDevice
uint8_t MXM_MonRegistryGetHighestConnected5XDevice(MXM_MONITORING_INSTANCE_s *pState)
Parse number of highest connected device from monitoring- register.
Definition: mxm_registry.c:99
STD_OK
@ STD_OK
Definition: fstd_types.h:72
STD_NOT_OK
@ STD_NOT_OK
Definition: fstd_types.h:73
MXM_MonRegistryConnectDevices
STD_RETURN_TYPE_e MXM_MonRegistryConnectDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t numberOfDevices)
Mark devices as connected in the registry and set the address.
Definition: mxm_registry.c:83
MXM_siliconVersion_e
enum MXM_siliconVersion MXM_siliconVersion_e
MXM_REG_NAME_e
enum MXM_REG_NAME MXM_REG_NAME_e
MAX1785x register names.
MXM_REGISTRY_ENTRY
Definition: mxm_1785x_tools.h:169
MXM_MonRegistryInit
void MXM_MonRegistryInit(MXM_MONITORING_INSTANCE_s *pState)
Initialize monitoring registry.
Definition: mxm_registry.c:70
HELLOALL_START_SEED
#define HELLOALL_START_SEED
Definition: mxm_battery_management.h:77
NULL_PTR
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:66
MXM_REG_VERSION_MOD
#define MXM_REG_VERSION_MOD
Monitoring Register Version/Model.
Definition: mxm_register_map.h:727
MXM_REGISTRY_ENTRY::deviceID
uint32_t deviceID
Definition: mxm_1785x_tools.h:174
MXM_ExtractValueFromRegister
void MXM_ExtractValueFromRegister(uint8_t lsb, uint8_t msb, MXM_REG_BM bitmask, uint16_t *pValue)
Extract a value from a single register.
Definition: mxm_1785x_tools.c:157
mxm_registry.h
Functions in order to have a registry of monitoring ICs.
MXM_MONITORING_INSTANCE::highest5xDevice
uint8_t highest5xDevice
Definition: mxm_1785x_tools.h:200
MXM_BM_WHOLE_REG
#define MXM_BM_WHOLE_REG
All bits of monitoring register.
Definition: mxm_register_map.h:723
MXM_REG_ID1
@ MXM_REG_ID1
Definition: mxm_register_map.h:659
MXM_MODEL_ID_NONE
@ MXM_MODEL_ID_NONE
Definition: mxm_basic_defines.h:99
MXM_MONITORING_INSTANCE::registry
MXM_REGISTRY_ENTRY_s registry[MXM_MAXIMUM_NR_OF_MODULES]
Definition: mxm_1785x_tools.h:222