Skip to content

Commit

Permalink
[NXP] Update smu2 manager api (project-chip#32799)
Browse files Browse the repository at this point in the history
* [k32w1] Remove persistent storage delegate usage in SMU2 manager

SMU2 manager can use the KeyValueStoreManager API directly, without needing
a persistent storage delegate instance.

Signed-off-by: marius-alex-tache <[email protected]>

* [k32w1] Update SMU2 init usage in lighting app

Signed-off-by: marius-alex-tache <[email protected]>

---------

Signed-off-by: marius-alex-tache <[email protected]>
  • Loading branch information
marius-alex-tache authored Apr 4, 2024
1 parent 660c928 commit 9080cd3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/lighting-app/nxp/k32w/k32w1/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void AppTask::InitServer(intptr_t arg)
#endif

#if defined(USE_SMU2_DYNAMIC)
VerifyOrDie(SMU2::Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR);
VerifyOrDie(SMU2::Init() == CHIP_NO_ERROR);
#endif

// Init ZCL Data Model and start server
Expand Down
19 changes: 9 additions & 10 deletions src/platform/nxp/k32w/k32w1/SMU2Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
*/

#include "SMU2Manager.h"

#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>

using namespace chip::DeviceLayer;
using namespace chip::DeviceLayer::Internal;
using namespace chip::DeviceLayer::PersistedStorage;

namespace chip::SMU2 {
namespace {
Expand All @@ -39,8 +42,6 @@ static const uint32_t AREA_SIZE = (AREA_END - AREA_START);

uint8_t mAreaId = 0;

PersistentStorageDelegate * mStorage = nullptr;

memAreaCfg_t mAreaDescriptor;
bool mDeviceCommissioned = false;
bool mUseAllocator = false;
Expand Down Expand Up @@ -92,7 +93,7 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t)
if (mDeviceCommissioned)
{
mUseAllocator = true;
mStorage->SyncSetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, (uint16_t) sizeof(mUseAllocator));
KeyValueStoreMgr().Put(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, (uint16_t) sizeof(mUseAllocator));
ResetBLEController();
RegisterArea();
}
Expand All @@ -103,22 +104,20 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t)

} // anonymous namespace

CHIP_ERROR Init(PersistentStorageDelegate * storage)
CHIP_ERROR Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint16_t size = (uint16_t) sizeof(mUseAllocator);
mStorage = storage;

VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INCORRECT_STATE);

PlatformMgr().AddEventHandler(EventHandler, reinterpret_cast<intptr_t>(nullptr));

err = mStorage->SyncGetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size);
size_t bytesRead = 0;
err = KeyValueStoreMgr().Get(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size, &bytesRead);

if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
mUseAllocator = false;
err = mStorage->SyncSetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size);
err = KeyValueStoreMgr().Put(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size);
}
ReturnErrorOnFailure(err);

Expand All @@ -137,7 +136,7 @@ CHIP_ERROR Deactivate(void)
if (mUseAllocator)
{
mUseAllocator = false;
err = mStorage->SyncDeleteKeyValue(GetSMU2AllocatorKey().KeyName());
err = KeyValueStoreMgr().Delete(GetSMU2AllocatorKey().KeyName());
ReturnErrorOnFailure(err);

UnregisterArea();
Expand Down
3 changes: 1 addition & 2 deletions src/platform/nxp/k32w/k32w1/SMU2Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
#pragma once

#include "fsl_component_mem_manager.h"
#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/support/DefaultStorageKeyAllocator.h>

namespace chip::SMU2 {

CHIP_ERROR Init(PersistentStorageDelegate * storage);
CHIP_ERROR Init();
CHIP_ERROR Deactivate(void);
void * Allocate(size_t size);

Expand Down

0 comments on commit 9080cd3

Please sign in to comment.