20
20
#include < lib/core/CHIPEncoding.h>
21
21
#include < platform/CHIPDeviceError.h>
22
22
#include < platform/internal/testing/ConfigUnitTest.h>
23
- #include < platform/nxp/common/CHIPDeviceNXPPlatformDefaultConfig.h>
24
23
#include < settings.h>
25
24
26
25
/* Only for flash init, to be move to sdk framework */
27
26
#include " port/nvs_port.h"
28
- #if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1)
29
- #include " fwk_nvs_stats.h"
30
- #endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */
31
27
32
28
// These can be overridden by the application as needed.
33
29
#ifndef CHIP_DEVICE_INTEGER_SETTINGS_KEY
@@ -141,17 +137,6 @@ int DeleteSubtreeCallback(const char * name, size_t /* entrySize */, settings_re
141
137
142
138
return 0 ;
143
139
}
144
-
145
- #if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1)
146
- void OnFlashSectorWearCountUpdate (uint16_t sector_idx, const nvs_storage_wear_profile_t * flash_wear_profile)
147
- {
148
- char keyUser[] = CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY;
149
- const size_t flash_wear_profile_size = NVS_STORAGE_WEAR_PROFILE_SIZE (flash_wear_profile->sector_count );
150
-
151
- /* Update the NVS stats key in storage */
152
- NXPConfig::WriteConfigValueBin ((const char *) keyUser, (uint8_t *) flash_wear_profile, flash_wear_profile_size);
153
- }
154
- #endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */
155
140
} // namespace
156
141
157
142
CHIP_ERROR NXPConfig::Init ()
@@ -166,50 +151,8 @@ CHIP_ERROR NXPConfig::Init()
166
151
167
152
ReturnErrorCodeIf (settings_subsys_init (), CHIP_ERROR_PERSISTED_STORAGE_FAILED);
168
153
169
- #if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1)
170
- ReturnErrorOnFailure (InitStorageWearStats ());
171
- #endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */
172
-
173
- return CHIP_NO_ERROR;
174
- }
175
-
176
- #if (CHIP_DEVICE_CONFIG_KVS_WEAR_STATS == 1)
177
- CHIP_ERROR NXPConfig::InitStorageWearStats (void )
178
- {
179
- nvs_storage_wear_profile_t * flash_wear_profile = NULL ;
180
- const size_t flash_wear_profile_size = NVS_STORAGE_WEAR_PROFILE_SIZE ((uint32_t ) NV_STORAGE_MAX_SECTORS);
181
- size_t size;
182
- char keyUser[] = CHIP_DEVICE_CONFIG_KVS_WEAR_STATS_KEY;
183
-
184
- /* Create an empty flash wear profile */
185
- flash_wear_profile = (nvs_storage_wear_profile_t *) calloc (1 , flash_wear_profile_size);
186
- ReturnErrorCodeIf (flash_wear_profile == NULL , CHIP_ERROR_NO_MEMORY);
187
-
188
- /* Try to read the flash wear profile from the User Support diagnostic log key */
189
- CHIP_ERROR err = ReadConfigValueBin ((const char *) keyUser, (uint8_t *) flash_wear_profile, flash_wear_profile_size, size);
190
- if ((err != CHIP_NO_ERROR) || (size != flash_wear_profile_size) ||
191
- (flash_wear_profile->sector_count != (uint32_t ) NV_STORAGE_MAX_SECTORS))
192
- {
193
- /* Either the flash wear stats are not available in the persistent
194
- * storage or the flash wear statistics that we have read are not
195
- * compatible with the current persistent storage configuration. In
196
- * this case - just reset and save the flash wear statistics. */
197
- flash_wear_profile->sector_count = (uint32_t ) NV_STORAGE_MAX_SECTORS;
198
- memset (flash_wear_profile->erase_count , 0 , (uint32_t ) NV_STORAGE_MAX_SECTORS * sizeof (uint16_t ));
199
- WriteConfigValueBin ((const char *) keyUser, (uint8_t *) flash_wear_profile, flash_wear_profile_size);
200
- }
201
- else
202
- {
203
- /* Load the flash wear profile into the NVS statistics */
204
- nvs_stats_load_profile (flash_wear_profile);
205
- }
206
- free (flash_wear_profile);
207
-
208
- nvs_stats_config_event_handler (OnFlashSectorWearCountUpdate);
209
-
210
154
return CHIP_NO_ERROR;
211
155
}
212
- #endif /* CHIP_DEVICE_CONFIG_KVS_WEAR_STATS */
213
156
214
157
CHIP_ERROR NXPConfig::ReadConfigValue (Key key, bool & val)
215
158
{
0 commit comments