[NXP][common][mcxw71_k32w1] Add MML support to DiagnosticDataProviderImpl (#35990)
* [nxp][platform][common] Add MML suppport for heap diagnostics
* add SupportsWatermarks
* add NXP_USE_MML define
* add MML support for heap diagnostics
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
* [nxp][platform][mcxw71_k32w1] Use MML support for heap diagnostics
* switch to common DiagnosticDataProviderImpl
* enable MML support for heap diagnostics
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
* Restyled by whitespace
* Restyled by clang-format
* Restyled by gn
---------
Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h b/src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h
index 0c263fc..c90619b 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 dd10221..09d8a7d 100644
--- a/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp
+++ b/src/platform/nxp/common/DiagnosticDataProviderImpl.cpp
@@ -42,6 +42,17 @@
}
#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 @@
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree)
{
size_t freeHeapSize;
+ freeHeapSize = GetFreeHeapSize();
- freeHeapSize = xPortGetFreeHeapSize();
currentHeapFree = static_cast<uint64_t>(freeHeapSize);
return CHIP_NO_ERROR;
}
@@ -68,8 +79,8 @@
size_t freeHeapSize;
size_t usedHeapSize;
- freeHeapSize = xPortGetFreeHeapSize();
- usedHeapSize = configTOTAL_HEAP_SIZE - freeHeapSize;
+ freeHeapSize = GetFreeHeapSize();
+ usedHeapSize = HEAP_SIZE - freeHeapSize;
currentHeapUsed = static_cast<uint64_t>(usedHeapSize);
return CHIP_NO_ERROR;
@@ -79,7 +90,8 @@
{
size_t highWatermarkHeapSize;
- highWatermarkHeapSize = configTOTAL_HEAP_SIZE - xPortGetMinimumEverFreeHeapSize();
+ highWatermarkHeapSize = HEAP_SIZE - GetMinimumEverFreeHeapSize();
+
currentHeapHighWatermark = static_cast<uint64_t>(highWatermarkHeapSize);
return CHIP_NO_ERROR;
}
@@ -89,12 +101,16 @@
// 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 5b9fc4c..27b2e35 100644
--- a/src/platform/nxp/common/DiagnosticDataProviderImpl.h
+++ b/src/platform/nxp/common/DiagnosticDataProviderImpl.h
@@ -39,6 +39,10 @@
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 253e21e..6b399a1 100644
--- a/src/platform/nxp/mcxw71_k32w1/BUILD.gn
+++ b/src/platform/nxp/mcxw71_k32w1/BUILD.gn
@@ -90,10 +90,15 @@
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 @@
"ConfigurationManagerImpl.h",
"ConnectivityManagerImpl.cpp",
"ConnectivityManagerImpl.h",
- "DiagnosticDataProviderImpl.cpp",
- "DiagnosticDataProviderImpl.h",
"PlatformManagerImpl.cpp",
"PlatformManagerImpl.h",
"SystemTimeSupport.cpp",