Skip to content

Commit

Permalink
[NXP][common][mcxw71_k32w1] Add MML support to DiagnosticDataProvider…
Browse files Browse the repository at this point in the history
…Impl (#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>
  • Loading branch information
andrei-menzopol and restyled-commits authored Oct 10, 2024
1 parent 8a01f93 commit d3f33ba
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/platform/nxp/common/CHIPNXPPlatformDefaultConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 22 additions & 6 deletions src/platform/nxp/common/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -57,8 +68,8 @@ DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance()
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree)
{
size_t freeHeapSize;
freeHeapSize = GetFreeHeapSize();

freeHeapSize = xPortGetFreeHeapSize();
currentHeapFree = static_cast<uint64_t>(freeHeapSize);
return CHIP_NO_ERROR;
}
Expand All @@ -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<uint64_t>(usedHeapSize);
return CHIP_NO_ERROR;
Expand All @@ -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<uint64_t>(highWatermarkHeapSize);
return CHIP_NO_ERROR;
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/platform/nxp/common/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/platform/nxp/mcxw71_k32w1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -104,8 +109,6 @@ static_library("nxp_platform") {
"ConfigurationManagerImpl.h",
"ConnectivityManagerImpl.cpp",
"ConnectivityManagerImpl.h",
"DiagnosticDataProviderImpl.cpp",
"DiagnosticDataProviderImpl.h",
"PlatformManagerImpl.cpp",
"PlatformManagerImpl.h",
"SystemTimeSupport.cpp",
Expand Down

0 comments on commit d3f33ba

Please sign in to comment.