Skip to content

Commit 4f24e49

Browse files
Increase the maximum KVS entries our implementation can handle
1 parent 96e687b commit 4f24e49

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/platform/silabs/KeyValueStoreManagerImpl.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ uint16_t KeyValueStoreManagerImpl::hashKvsKeyString(const char * key) const
8888
CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint16_t hash, uint32_t & nvm3Key, bool isSlotNeeded) const
8989
{
9090
CHIP_ERROR err;
91-
char * strPrefix = nullptr;
92-
uint8_t firstEmptyKeySlot = kMaxEntries;
93-
for (uint8_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++)
91+
char * strPrefix = nullptr;
92+
uint16_t firstEmptyKeySlot = kMaxEntries;
93+
for (uint16_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++)
9494
{
9595
if (mKvsKeyMap[keyIndex] == hash)
9696
{
@@ -165,7 +165,7 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
165165
Commit the key map in nvm once it as stabilized.
166166
*/
167167
SystemLayer().StartTimer(
168-
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SILABS_KVS_SAVE_DELAY_SECONDS)),
168+
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SL_KVS_SAVE_DELAY_SECONDS)),
169169
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
170170
}
171171

@@ -247,7 +247,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
247247
void KeyValueStoreManagerImpl::ErasePartition(void)
248248
{
249249
// Iterate over all the Matter Kvs nvm3 records and delete each one...
250-
for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kMaxConfigKey_MatterKvs; nvm3Key++)
250+
for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kConfigKey_KvsLastKeySlot; nvm3Key++)
251251
{
252252
SilabsConfig::ClearConfigValue(nvm3Key);
253253
}

src/platform/silabs/SilabsConfig.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
#endif
3636

3737
// Delay before Key/Value is actually saved in NVM
38-
#define SILABS_KVS_SAVE_DELAY_SECONDS 5
38+
#ifndef SL_KVS_SAVE_DELAY_SECONDS
39+
#define SL_KVS_SAVE_DELAY_SECONDS 2
40+
#endif
3941

40-
static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries");
42+
static_assert((KVS_MAX_ENTRIES <= 511), "Implementation supports up to 511 Kvs entries");
4143
static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met");
4244

4345
namespace chip {
@@ -89,7 +91,8 @@ class SilabsConfig
8991
// Persistent counter values set at runtime. Retained during factory reset.
9092
static constexpr uint8_t kMatterCounter_KeyBase = 0x74;
9193
// Persistent config values set at runtime. Cleared during factory reset.
92-
static constexpr uint8_t kMatterKvs_KeyBase = 0x75;
94+
static constexpr uint8_t kMatterKvs_KeyBase = 0x75;
95+
static constexpr uint8_t kMatterKvs_ExtendedRange = 0x76;
9396

9497
// Key definitions for well-known configuration values.
9598
// Factory config keys
@@ -167,7 +170,8 @@ class SilabsConfig
167170
// Matter KVS storage Keys
168171
static constexpr Key kConfigKey_KvsStringKeyMap = SilabsConfigKey(kMatterKvs_KeyBase, 0x00);
169172
static constexpr Key kConfigKey_KvsFirstKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, 0x01);
170-
static constexpr Key kConfigKey_KvsLastKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, KVS_MAX_ENTRIES);
173+
static constexpr Key kConfigKey_KvsLastKeySlot =
174+
SilabsConfigKey(kMatterKvs_KeyBase + (KVS_MAX_ENTRIES >> 8), KVS_MAX_ENTRIES & UINT8_MAX);
171175

172176
// Set key id limits for each group.
173177
static constexpr Key kMinConfigKey_MatterFactory = SilabsConfigKey(kMatterFactory_KeyBase, 0x00);
@@ -180,7 +184,9 @@ class SilabsConfig
180184
static constexpr Key kMaxConfigKey_MatterCounter = SilabsConfigKey(kMatterCounter_KeyBase, 0x1F);
181185

182186
static constexpr Key kMinConfigKey_MatterKvs = kConfigKey_KvsStringKeyMap;
183-
static constexpr Key kMaxConfigKey_MatterKvs = kConfigKey_KvsLastKeySlot;
187+
static constexpr Key kMaxConfigKey_MatterKvs = SilabsConfigKey(kMatterKvs_ExtendedRange, 0xFF);
188+
static_assert(kConfigKey_KvsLastKeySlot <= kMaxConfigKey_MatterKvs,
189+
"Configured KVS_MAX_ENTRIES overflows the reserved KVS Key range");
184190

185191
static CHIP_ERROR Init(void);
186192
static void DeInit(void);

0 commit comments

Comments
 (0)