Skip to content

Commit

Permalink
Delay HandleApply by EFR32_KVS_SAVE_DELAY_SECONDS + 1
Browse files Browse the repository at this point in the history
Delay HandleApply() to give KVS time to store the data in StoreCurrentUpdateInfo(). Introduce EFR32_KVS_SAVE_DELAY_SECONDS to represent the delay amount KeyValueStoreManagerImpl uses before saving the key/vaule pair
  • Loading branch information
selissia committed May 18, 2022
1 parent a55086f commit e312dcd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/platform/EFR32/EFR32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define KVS_MAX_ENTRIES 75 // Available key slot count for Kvs Key mapping.
#endif

// Delay before Key/Value is actually saved in NVM
#define EFR32_KVS_SAVE_DELAY_SECONDS 5

static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries");
static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met");

Expand Down
2 changes: 1 addition & 1 deletion src/platform/EFR32/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
During commissioning, the key map will be modified multiples times subsequently.
Commit the key map in nvm once it as stabilized.
*/
SystemLayer().StartTimer(std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(5)),
SystemLayer().StartTimer(std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(EFR32_KVS_SAVE_DELAY_SECONDS)),
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
}

Expand Down
8 changes: 6 additions & 2 deletions src/platform/EFR32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern "C" {
#include "platform/emlib/inc/em_bus.h" // For CORE_CRITICAL_SECTION
}

#include "EFR32Config.h"

/// No error, operation OK
#define SL_BOOTLOADER_OK 0L

Expand All @@ -49,7 +51,9 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
}
CHIP_ERROR OTAImageProcessorImpl::Apply()
{
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
// Delay HandleApply() to give KVS time to store the data in StoreCurrentUpdateInfo()
ChipLogError(SoftwareUpdate, "Scheduling HandleApply");
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(EFR32_KVS_SAVE_DELAY_SECONDS + 1), HandleApply, nullptr);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -175,7 +179,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
}

void OTAImageProcessorImpl::HandleApply(intptr_t context)
void OTAImageProcessorImpl::HandleApply(chip::System::Layer * systemLayer, void *context)
{
uint32_t err = SL_BOOTLOADER_OK;

Expand Down
2 changes: 1 addition & 1 deletion src/platform/EFR32/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
//////////// Actual handlers for the OTAImageProcessorInterface ///////////////
static void HandlePrepareDownload(intptr_t context);
static void HandleFinalize(intptr_t context);
static void HandleApply(intptr_t context);
static void HandleApply(chip::System::Layer * systemLayer, void *);
static void HandleAbort(intptr_t context);
static void HandleProcessBlock(intptr_t context);
CHIP_ERROR ProcessHeader(ByteSpan & block);
Expand Down

0 comments on commit e312dcd

Please sign in to comment.