diff --git a/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h b/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h index 0c263fc6ae3cfa..c90619bdddc040 100644 --- a/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h +++ b/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h @@ -253,3 +253,8 @@ */ #define CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS 10 #endif + +#ifndef NXP_USE_MML +/* Do not use Memory Manager Light for dynamic memory allocation by default. */ +#define NXP_USE_MML 0 +#endif // NXP_USE_MML diff --git a/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp b/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp index dd102217482de3..09d8a7d266a8ca 100644 --- a/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp +++ b/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp @@ -42,6 +42,17 @@ extern "C" { } #endif +#if NXP_USE_MML +#include "fsl_component_mem_manager.h" +#define GetFreeHeapSize MEM_GetFreeHeapSize +#define HEAP_SIZE MinimalHeapSize_c +#define GetMinimumEverFreeHeapSize MEM_GetFreeHeapSizeLowWaterMark +#else +#define GetFreeHeapSize xPortGetFreeHeapSize +#define HEAP_SIZE configTOTAL_HEAP_SIZE +#define GetMinimumEverFreeHeapSize xPortGetMinimumEverFreeHeapSize +#endif // NXP_USE_MML + // Not implement into the SDK // extern "C" void xPortResetHeapMinimumEverFreeHeapSize(void); @@ -57,8 +68,8 @@ DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance() CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree) { size_t freeHeapSize; + freeHeapSize = GetFreeHeapSize(); - freeHeapSize = xPortGetFreeHeapSize(); currentHeapFree = static_cast(freeHeapSize); return CHIP_NO_ERROR; } @@ -68,8 +79,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeap size_t freeHeapSize; size_t usedHeapSize; - freeHeapSize = xPortGetFreeHeapSize(); - usedHeapSize = configTOTAL_HEAP_SIZE - freeHeapSize; + freeHeapSize = GetFreeHeapSize(); + usedHeapSize = HEAP_SIZE - freeHeapSize; currentHeapUsed = static_cast(usedHeapSize); return CHIP_NO_ERROR; @@ -79,7 +90,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & cu { size_t highWatermarkHeapSize; - highWatermarkHeapSize = configTOTAL_HEAP_SIZE - xPortGetMinimumEverFreeHeapSize(); + highWatermarkHeapSize = HEAP_SIZE - GetMinimumEverFreeHeapSize(); + currentHeapHighWatermark = static_cast(highWatermarkHeapSize); return CHIP_NO_ERROR; } @@ -89,12 +101,16 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks() // If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the // value of the CurrentHeapUsed. +#if NXP_USE_MML + MEM_ResetFreeHeapSizeLowWaterMark(); + + return CHIP_NO_ERROR; +#else // Not implement into the SDK // xPortResetHeapMinimumEverFreeHeapSize(); - // return CHIP_NO_ERROR; - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; +#endif } CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut) diff --git a/src/platform/nxp/common/DiagnosticDataProviderImpl.h b/src/platform/nxp/common/DiagnosticDataProviderImpl.h index 5b9fc4c9ae894b..27b2e35365a1c6 100644 --- a/src/platform/nxp/common/DiagnosticDataProviderImpl.h +++ b/src/platform/nxp/common/DiagnosticDataProviderImpl.h @@ -39,6 +39,10 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider static DiagnosticDataProviderImpl & GetDefaultInstance(); // ===== Methods that implement the PlatformManager abstract interface. + +#if NXP_USE_MML + bool SupportsWatermarks() override { return true; } +#endif CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override; CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override; CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override; diff --git a/src/platform/nxp/mcxw71_k32w1/BUILD.gn b/src/platform/nxp/mcxw71_k32w1/BUILD.gn index 253e21e4ef6a97..6b399a1c1dbf27 100644 --- a/src/platform/nxp/mcxw71_k32w1/BUILD.gn +++ b/src/platform/nxp/mcxw71_k32w1/BUILD.gn @@ -90,10 +90,15 @@ config("nxp_platform_config") { static_library("nxp_platform") { deps = [] - defines = [ "CHIP_DEVICE_K32W1=1" ] + defines = [ + "CHIP_DEVICE_K32W1=1", + "NXP_USE_MML=1", + ] sources = [ "../../SingletonConfigurationManager.cpp", + "../common/DiagnosticDataProviderImpl.cpp", + "../common/DiagnosticDataProviderImpl.h", "../common/ble/BLEManagerCommon.cpp", "../common/ble/BLEManagerCommon.h", "../common/ble/BLEManagerImpl.cpp", @@ -104,8 +109,6 @@ static_library("nxp_platform") { "ConfigurationManagerImpl.h", "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", - "DiagnosticDataProviderImpl.cpp", - "DiagnosticDataProviderImpl.h", "PlatformManagerImpl.cpp", "PlatformManagerImpl.h", "SystemTimeSupport.cpp",