Skip to content

Commit

Permalink
[Telink] Move SETTINGS_NVS_SECTOR_COUNT to common config
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiiSalamakha committed Dec 5, 2023
1 parent d875cd5 commit f999d92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
4 changes: 4 additions & 0 deletions config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ config NVS_LOOKUP_CACHE_SIZE
config SETTINGS_NVS_SECTOR_SIZE_MULT
default 1

# Set sector counter of NVS
config SETTINGS_NVS_SECTOR_COUNT
default 10

# Enable OpenThread

config NET_L2_OPENTHREAD
Expand Down
3 changes: 0 additions & 3 deletions examples/lock-app/telink/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y
# Disable CHIP shell support
CONFIG_CHIP_LIB_SHELL=n

# Set NVM sector
CONFIG_SETTINGS_NVS_SECTOR_COUNT=10

# Disable factory data support
CONFIG_CHIP_FACTORY_DATA=n
CONFIG_CHIP_FACTORY_DATA_BUILD=n
Expand Down
40 changes: 14 additions & 26 deletions examples/lock-app/telink/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,33 +667,21 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
#if LOCK_MANAGER_CONFIG_USE_NVM_CREDENTIAL_STORAGE
CHIP_ERROR err;

for (uint8_t i = 0; i < kNumCredentialTypes; i++)
{
// Save credential information in NVM flash
err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_Credential[i],
reinterpret_cast<const uint8_t *>(&mLockCredentials[i]),
sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials);
if (err != CHIP_NO_ERROR)
{
ChipLogError(
Zcl,
"Failed to write kConfigKey_Credential(%d). User data will be resetted during reboot. Not enough storage space \n",
i);
break;
}
// Save credential information in NVM flash
err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_Credential[to_underlying(credentialType)],
reinterpret_cast<const uint8_t *>(&mLockCredentials[to_underlying(credentialType)]),
sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials);
if (err != CHIP_NO_ERROR)
ChipLogError(
Zcl, "Failed to write kConfigKey_Credential. User data will be resetted during reboot. Not enough storage space \n");

err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData[i],
reinterpret_cast<const uint8_t *>(&mCredentialData[i]),
kMaxCredentials * kMaxCredentialSize);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl,
"Failed to write kConfigKey_CredentialData(%d). User data will be resetted during reboot. Not enough "
"storage space \n",
i);
break;
}
}
err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData[to_underlying(credentialType)],
reinterpret_cast<const uint8_t *>(&mCredentialData[to_underlying(credentialType)]),
kMaxCredentials * kMaxCredentialSize);
if (err != CHIP_NO_ERROR)
ChipLogError(
Zcl,
"Failed to write kConfigKey_CredentialData. User data will be resetted during reboot. Not enough storage space \n");
#endif

ChipLogProgress(Zcl, "Successfully set the credential [credentialType=%u]", to_underlying(credentialType));
Expand Down

0 comments on commit f999d92

Please sign in to comment.