Skip to content

Commit ad8b86b

Browse files
[NXP] Rework common & mcxw71 ConfigurationManagerImpl.cpp (#41553)
* [nxp][platform][mcxw71] ConfigurationManagerImpl changes * Move GetBootReason to DetermineBootReason * Align with nxp/common ConfigurationManagerImpl * Add nxp/common missing functions * Update copyright, description Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][common] Update DetermineBootReason in ConfigurationManagerImpl * Update DetermineBootReason signature, parameter type * Update copyright Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][mcxw72][gn] Switch to mcxw ConfigurationManagerImpl Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][gn][mcxw71] Add CONFIG_CHIP_NXP_PLATFORM_MCXW71 Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][mcxw71] Set StoreRebootCount(0) and check return DetermineBootReason Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * Restyled by gn --------- Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 4f17295 commit ad8b86b

File tree

6 files changed

+113
-68
lines changed

6 files changed

+113
-68
lines changed

src/platform/nxp/common/ConfigurationManagerImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
6666
return sInstance;
6767
}
6868

69-
CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint8_t rebootCause)
69+
CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint32_t rebootCause)
7070
{
7171
#if CONFIG_BOOT_REASON_SDK_SUPPORT
7272
/*
@@ -114,7 +114,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
114114
uint32_t rebootCount = 0;
115115

116116
#if CONFIG_BOOT_REASON_SDK_SUPPORT
117-
uint8_t rebootCause = POWER_GetResetCause();
117+
uint32_t rebootCause = POWER_GetResetCause();
118118
POWER_ClearResetCause(rebootCause);
119119
#endif
120120

src/platform/nxp/common/ConfigurationManagerImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2020 Project CHIP Authors
3+
* Copyright (c) 2020, 2025 Project CHIP Authors
44
* Copyright (c) 2020 Nest Labs, Inc.
55
* All rights reserved.
66
*
@@ -83,7 +83,7 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana
8383

8484
static void DoFactoryReset(intptr_t arg);
8585

86-
CHIP_ERROR DetermineBootReason(uint8_t rebootCause);
86+
CHIP_ERROR DetermineBootReason(uint32_t rebootCause);
8787
};
8888

8989
/**

src/platform/nxp/mcxw71/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ config("nxp_platform_config") {
7676

7777
static_library("nxp_platform") {
7878
defines = [
79+
"CONFIG_CHIP_NXP_PLATFORM_MCXW71=1",
7980
"NXP_DEVICE_MCXW7X=1",
8081
"NXP_USE_MML=1",
8182
]

src/platform/nxp/mcxw71/ConfigurationManagerImpl.cpp

Lines changed: 99 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2020 Project CHIP Authors
3+
* Copyright (c) 2020, 2025 Project CHIP Authors
44
* Copyright (c) 2020 Nest Labs, Inc.
55
* All rights reserved.
66
*
@@ -20,7 +20,7 @@
2020
/**
2121
* @file
2222
* Provides the implementation of the Device Layer ConfigurationManager object
23-
* for K32W platforms using the NXP SDK.
23+
* for NXP MCXW7X platforms using the NXP SDK.
2424
*/
2525

2626
/* this file behaves like a config.h, comes first */
@@ -33,28 +33,70 @@
3333
#include <src/platform/nxp/mcxw71/SMU2Manager.h>
3434
#endif
3535

36-
// #include <openthread/platform/misc.h>
3736
#include "fsl_cmc.h"
3837
#include "fsl_device_registers.h"
3938

39+
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
40+
#include "OtaSupport.h"
41+
#endif
42+
4043
namespace chip {
4144
namespace DeviceLayer {
4245

4346
using namespace ::chip::DeviceLayer::Internal;
4447

45-
// TODO: Define a Singleton instance of CHIP Group Key Store here
46-
4748
ConfigurationManagerImpl & ConfigurationManagerImpl::GetDefaultInstance()
4849
{
4950
static ConfigurationManagerImpl sInstance;
5051
return sInstance;
5152
}
5253

54+
CHIP_ERROR ConfigurationManagerImpl::DetermineBootReason(uint32_t reason)
55+
{
56+
BootReasonType bootReason = BootReasonType::kUnspecified;
57+
58+
if ((reason & CMC_SRS_POR_MASK) || (reason & CMC_SRS_PIN_MASK))
59+
{
60+
bootReason = BootReasonType::kPowerOnReboot;
61+
}
62+
else if (reason & CMC_SRS_SW_MASK)
63+
{
64+
bootReason = BootReasonType::kSoftwareReset;
65+
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
66+
OtaImgState_t img_state = OTA_GetImgState();
67+
if (img_state == OtaImgState_RunCandidate)
68+
{
69+
bootReason = BootReasonType::kSoftwareUpdateCompleted;
70+
}
71+
#endif
72+
}
73+
else if ((reason & CMC_SRS_WDOG0_MASK) || (reason & CMC_SRS_WDOG1_MASK))
74+
{
75+
bootReason = BootReasonType::kSoftwareWatchdogReset;
76+
}
77+
else
78+
{
79+
bootReason = BootReasonType::kUnspecified;
80+
}
81+
82+
return StoreBootReason(to_underlying(bootReason));
83+
}
84+
85+
CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareUpdateCompleted()
86+
{
87+
/* Empty implementation*/
88+
return CHIP_NO_ERROR;
89+
}
90+
5391
CHIP_ERROR ConfigurationManagerImpl::Init()
5492
{
5593
CHIP_ERROR err;
5694
uint32_t rebootCount = 0;
5795

96+
// Initialize the generic implementation base class.
97+
err = Internal::GenericConfigurationManagerImpl<NXPConfig>::Init();
98+
SuccessOrExit(err);
99+
58100
if (NXPConfig::ConfigValueExists(NXPConfig::kCounterKey_RebootCount))
59101
{
60102
err = GetRebootCount(rebootCount);
@@ -76,16 +118,15 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
76118
SuccessOrExit(err);
77119
}
78120

121+
err = DetermineBootReason(CMC_GetSystemResetStatus(CMC0));
122+
SuccessOrExit(err);
123+
79124
if (!NXPConfig::ConfigValueExists(NXPConfig::kCounterKey_BootReason))
80125
{
81126
err = StoreBootReason(to_underlying(BootReasonType::kUnspecified));
82127
SuccessOrExit(err);
83128
}
84129

85-
// Initialize the generic implementation base class.
86-
err = Internal::GenericConfigurationManagerImpl<NXPConfig>::Init();
87-
SuccessOrExit(err);
88-
89130
// TODO: Initialize the global GroupKeyStore object here
90131

91132
err = CHIP_NO_ERROR;
@@ -94,61 +135,34 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
94135
return err;
95136
}
96137

97-
CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareUpdateCompleted()
138+
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
98139
{
99-
/* Empty implementation*/
100-
return CHIP_NO_ERROR;
140+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
101141
}
102142

103-
CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount)
143+
CHIP_ERROR ConfigurationManagerImpl::GetUniqueId(char * buf, size_t bufSize)
104144
{
105-
return ReadConfigValue(NXPConfig::kCounterKey_RebootCount, rebootCount);
106-
}
145+
CHIP_ERROR err;
146+
size_t uniqueIdLen = 0; // without counting null-terminator
147+
err = ReadConfigValueStr(NXPConfig::kConfigKey_UniqueId, buf, bufSize, uniqueIdLen);
107148

108-
CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount)
109-
{
110-
return WriteConfigValue(NXPConfig::kCounterKey_RebootCount, rebootCount);
111-
}
149+
ReturnErrorOnFailure(err);
112150

113-
CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours)
114-
{
115-
return ReadConfigValue(NXPConfig::kCounterKey_TotalOperationalHours, totalOperationalHours);
116-
}
151+
VerifyOrReturnError(uniqueIdLen < bufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
152+
VerifyOrReturnError(buf[uniqueIdLen] == 0, CHIP_ERROR_INVALID_STRING_LENGTH);
117153

118-
CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
119-
{
120-
return WriteConfigValue(NXPConfig::kCounterKey_TotalOperationalHours, totalOperationalHours);
154+
return err;
121155
}
122156

123-
CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason)
157+
CHIP_ERROR ConfigurationManagerImpl::StoreUniqueId(const char * uniqueId, size_t uniqueIdLen)
124158
{
125-
bootReason = to_underlying(BootReasonType::kUnspecified);
126-
127-
uint32_t reason = CMC_GetSystemResetStatus(CMC0);
128-
129-
if ((reason & CMC_SRS_POR_MASK) || (reason & CMC_SRS_PIN_MASK))
130-
{
131-
bootReason = to_underlying(BootReasonType::kPowerOnReboot);
132-
}
133-
else if (reason & CMC_SRS_SW_MASK)
134-
{
135-
bootReason = to_underlying(BootReasonType::kSoftwareReset);
136-
}
137-
else if ((reason & CMC_SRS_WDOG0_MASK) || (reason & CMC_SRS_WDOG1_MASK))
138-
{
139-
bootReason = to_underlying(BootReasonType::kSoftwareWatchdogReset);
140-
}
141-
else
142-
{
143-
bootReason = to_underlying(BootReasonType::kUnspecified);
144-
}
145-
146-
return CHIP_NO_ERROR;
159+
return WriteConfigValueStr(NXPConfig::kConfigKey_UniqueId, uniqueId, uniqueIdLen);
147160
}
148161

149-
CHIP_ERROR ConfigurationManagerImpl::StoreBootReason(uint32_t bootReason)
162+
CHIP_ERROR ConfigurationManagerImpl::GenerateUniqueId(char * buf, size_t bufSize)
150163
{
151-
return WriteConfigValue(NXPConfig::kCounterKey_BootReason, bootReason);
164+
uint64_t randomUniqueId = Crypto::GetRandU64();
165+
return Encoding::BytesToUppercaseHexString(reinterpret_cast<uint8_t *>(&randomUniqueId), sizeof(uint64_t), buf, bufSize);
152166
}
153167

154168
bool ConfigurationManagerImpl::CanFactoryReset()
@@ -280,11 +294,41 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
280294
// Restart the system.
281295
ChipLogProgress(DeviceLayer, "System restarting");
282296

283-
NVIC_SystemReset();
297+
#if CONFIG_CHIP_NXP_PLATFORM_MCXW71
298+
PlatformMgrImpl().Reset();
299+
#else
300+
PlatformMgrImpl().ScheduleResetInIdle();
301+
#endif
302+
}
284303

285-
while (1)
286-
{
287-
}
304+
CHIP_ERROR ConfigurationManagerImpl::GetRebootCount(uint32_t & rebootCount)
305+
{
306+
return ReadConfigValue(NXPConfig::kCounterKey_RebootCount, rebootCount);
307+
}
308+
309+
CHIP_ERROR ConfigurationManagerImpl::StoreRebootCount(uint32_t rebootCount)
310+
{
311+
return WriteConfigValue(NXPConfig::kCounterKey_RebootCount, rebootCount);
312+
}
313+
314+
CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason)
315+
{
316+
return ReadConfigValue(NXPConfig::kCounterKey_BootReason, bootReason);
317+
}
318+
319+
CHIP_ERROR ConfigurationManagerImpl::StoreBootReason(uint32_t bootReason)
320+
{
321+
return WriteConfigValue(NXPConfig::kCounterKey_BootReason, bootReason);
322+
}
323+
324+
CHIP_ERROR ConfigurationManagerImpl::GetTotalOperationalHours(uint32_t & totalOperationalHours)
325+
{
326+
return ReadConfigValue(NXPConfig::kCounterKey_TotalOperationalHours, totalOperationalHours);
327+
}
328+
329+
CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOperationalHours)
330+
{
331+
return WriteConfigValue(NXPConfig::kCounterKey_TotalOperationalHours, totalOperationalHours);
288332
}
289333

290334
ConfigurationManager & ConfigurationMgrImpl()

src/platform/nxp/mcxw71/ConfigurationManagerImpl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2020 Project CHIP Authors
3+
* Copyright (c) 2020, 2025 Project CHIP Authors
44
* Copyright (c) 2020 Nest Labs, Inc.
55
* All rights reserved.
66
*
@@ -20,7 +20,7 @@
2020
/**
2121
* @file
2222
* Provides an implementation of the ConfigurationManager object
23-
* for K32W platforms using the NXP SDK.
23+
* for NXP MCXW7X platforms using the NXP SDK.
2424
*/
2525

2626
#pragma once
@@ -36,7 +36,7 @@ namespace chip {
3636
namespace DeviceLayer {
3737

3838
/**
39-
* Concrete implementation of the ConfigurationManager singleton object for the K32W platform.
39+
* Concrete implementation of the ConfigurationManager singleton object for the NXP MCXW7X platform.
4040
*/
4141
class ConfigurationManagerImpl final : public Internal::GenericConfigurationManagerImpl<Internal::NXPConfig>
4242
{
@@ -54,6 +54,9 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana
5454
void InitiateFactoryReset(void) override;
5555
CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) override;
5656
CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override;
57+
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
58+
CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) override;
59+
CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) override;
5760
CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override;
5861
CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override;
5962
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
@@ -80,12 +83,9 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana
8083
// ===== Private members reserved for use by this class only.
8184

8285
static void DoFactoryReset(intptr_t arg);
83-
};
8486

85-
inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
86-
{
87-
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
88-
}
87+
CHIP_ERROR DetermineBootReason(uint32_t reason);
88+
};
8989

9090
/**
9191
* Returns the platform-specific implementation of the ConfigurationManager object.

src/platform/nxp/mcxw72/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static_library("nxp_platform") {
8181
"../../FreeRTOS/SystemTimeSupport.cpp",
8282
"../../SingletonConfigurationManager.cpp",
8383
"../common/CHIPDevicePlatformEvent.h",
84-
"../common/ConfigurationManagerImpl.cpp",
8584
"../common/ConfigurationManagerImpl.h",
8685
"../common/ConnectivityManagerImpl.cpp",
8786
"../common/ConnectivityManagerImpl.h",
@@ -94,6 +93,7 @@ static_library("nxp_platform") {
9493
"../common/NetworkProvisioningServerImpl.h",
9594
"../common/PlatformManagerImpl.h",
9695
"../common/SoftwareUpdateManagerImpl.h",
96+
"../mcxw71/ConfigurationManagerImpl.cpp",
9797
"CHIPDevicePlatformConfig.h",
9898
"PlatformManagerImpl.cpp",
9999
]

0 commit comments

Comments
 (0)