Skip to content

Commit

Permalink
Merge branch 'master' into chef-robotic-vacuum-cleaner-326681447
Browse files Browse the repository at this point in the history
  • Loading branch information
stingchang authored May 3, 2024
2 parents 4ffc4a9 + fcfc9bc commit 2f49442
Show file tree
Hide file tree
Showing 41 changed files with 1,013 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ jobs:
-enableUndefinedBehaviorSanitizer YES
- flavor: tsan
arguments: -enableThreadSanitizer YES
# "leaks" does not seem to be very compatible with asan or tsan
- flavor: leaks
defines: ENABLE_LEAK_DETECTION=1
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
9 changes: 9 additions & 0 deletions examples/air-purifier-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#if CONFIG_ENABLE_AMEBA_CRYPTO
#include <platform/Ameba/crypto/AmebaPersistentStorageOperationalKeystore.h>
#endif

#include <lwip_netconf.h>

Expand Down Expand Up @@ -130,6 +133,12 @@ static void InitServer(intptr_t context)
// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
#if CONFIG_ENABLE_AMEBA_CRYPTO
ChipLogProgress(DeviceLayer, "platform crypto enabled!");
static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore;
VerifyOrDie((sAmebaPersistentStorageOpKeystore.Init(initParams.persistentStorageDelegate)) == CHIP_NO_ERROR);
initParams.operationalKeystore = &sAmebaPersistentStorageOpKeystore;
#endif
chip::Server::GetInstance().Init(initParams);
gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
Expand Down
10 changes: 10 additions & 0 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <microwave-oven-device.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#if CONFIG_ENABLE_AMEBA_CRYPTO
#include <platform/Ameba/crypto/AmebaPersistentStorageOperationalKeystore.h>
#endif
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
Expand Down Expand Up @@ -153,6 +156,13 @@ static void InitServer(intptr_t context)

initParams.InitializeStaticResourcesBeforeServerInit();

#if CONFIG_ENABLE_AMEBA_CRYPTO
ChipLogProgress(DeviceLayer, "platform crypto enabled!");
static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore;
VerifyOrDie((sAmebaPersistentStorageOpKeystore.Init(initParams.persistentStorageDelegate)) == CHIP_NO_ERROR);
initParams.operationalKeystore = &sAmebaPersistentStorageOpKeystore;
#endif

chip::Server::GetInstance().Init(initParams);
gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
// TODO: Use our own DeviceInfoProvider
Expand Down
9 changes: 9 additions & 0 deletions examples/light-switch-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include <lib/core/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#if CONFIG_ENABLE_AMEBA_CRYPTO
#include <platform/Ameba/crypto/AmebaPersistentStorageOperationalKeystore.h>
#endif
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
Expand Down Expand Up @@ -100,6 +103,12 @@ static void InitServer(intptr_t context)
// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
initParams.InitializeStaticResourcesBeforeServerInit();
#if CONFIG_ENABLE_AMEBA_CRYPTO
ChipLogProgress(DeviceLayer, "platform crypto enabled!");
static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore;
VerifyOrDie((sAmebaPersistentStorageOpKeystore.Init(initParams.persistentStorageDelegate)) == CHIP_NO_ERROR);
initParams.operationalKeystore = &sAmebaPersistentStorageOpKeystore;
#endif
chip::Server::GetInstance().Init(initParams);
gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,7 @@ endpoint 0 {
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x0B;
ram attribute clusterRevision default = 1;
ram attribute clusterRevision default = 2;

handle command SetUTCTime;
handle command SetTrustedTimeSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3826,7 +3826,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"defaultValue": "2",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
12 changes: 10 additions & 2 deletions examples/lighting-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
#include <lib/core/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#if CONFIG_ENABLE_AMEBA_CRYPTO
#include <platform/Ameba/crypto/AmebaPersistentStorageOperationalKeystore.h>
#endif
#include <lwip_netconf.h>
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>

#include <lwip_netconf.h>

#if CONFIG_ENABLE_PW_RPC
#include "Rpc.h"
#endif
Expand Down Expand Up @@ -121,6 +123,12 @@ static void InitServer(intptr_t context)
// Init ZCL Data Model and CHIP App Server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
#if CONFIG_ENABLE_AMEBA_CRYPTO
ChipLogProgress(DeviceLayer, "platform crypto enabled!");
static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore;
VerifyOrDie((sAmebaPersistentStorageOpKeystore.Init(initParams.persistentStorageDelegate)) == CHIP_NO_ERROR);
initParams.operationalKeystore = &sAmebaPersistentStorageOpKeystore;
#endif
chip::Server::GetInstance().Init(initParams);
gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
#endif

#ifdef HEAP_MONITORING
MemMonitoring::startHeapMonitoring();
MemMonitoring::StartMonitor();
#endif

//==============================================
Expand Down
110 changes: 54 additions & 56 deletions examples/platform/silabs/MemMonitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,93 +19,91 @@
#include "MemMonitoring.h"

#include "AppConfig.h"
#include "FreeRTOS.h"
#include <cmsis_os2.h>
#include <platform/CHIPDeviceLayer.h>
#include <sl_cmsis_os2_common.h>

#define BLE_STACK_TASK_NAME "Bluetooth stack"
#define BLE_LINK_TASK_NAME "Bluetooth linklayer"
namespace chip {
namespace DeviceLayer {
namespace Silabs {

static StackType_t monitoringStack[MONITORING_STACK_SIZE_byte / sizeof(StackType_t)];
static StaticTask_t monitoringTaskStruct;
static osThreadId_t sMonitorThreadHandle;
constexpr uint32_t kMonitorTaskSize = 1024;
static uint8_t monitorStack[kMonitorTaskSize];
static osThread_t sMonitorTaskControlBlock;
constexpr osThreadAttr_t kMonitorTaskAttr = { .name = "MemMonitor",
.attr_bits = osThreadDetached,
.cb_mem = &sMonitorTaskControlBlock,
.cb_size = osThreadCbSize,
.stack_mem = monitorStack,
.stack_size = kMonitorTaskSize,
.priority = osPriorityLow };

size_t nbAllocSuccess = 0;
size_t nbFreeSuccess = 0;
size_t largestBlockAllocated = 0;

void MemMonitoring::startHeapMonitoring()
void MemMonitoring::StartMonitor()
{
xTaskCreateStatic(HeapMonitoring, "Monitoring", MONITORING_STACK_SIZE_byte / sizeof(StackType_t), NULL, 1, monitoringStack,
&monitoringTaskStruct);
sMonitorThreadHandle = osThreadNew(MonitorTask, nullptr, &kMonitorTaskAttr);
}

void MemMonitoring::HeapMonitoring(void * pvParameter)
void MemMonitoring::MonitorTask(void * pvParameter)
{
uint32_t threadCount = osThreadGetCount();

UBaseType_t appTaskValue;
UBaseType_t bleEventTaskValue;
UBaseType_t bleTaskValue;
UBaseType_t linkLayerTaskValue;
UBaseType_t openThreadTaskValue;
UBaseType_t eventLoopTaskValue;

TaskHandle_t eventLoopHandleStruct = xTaskGetHandle(CHIP_DEVICE_CONFIG_CHIP_TASK_NAME);
TaskHandle_t otTaskHandle = xTaskGetHandle(CHIP_DEVICE_CONFIG_THREAD_TASK_NAME);
TaskHandle_t appTaskHandle = xTaskGetHandle(APP_TASK_NAME);
TaskHandle_t bleStackTaskHandle = xTaskGetHandle(BLE_STACK_TASK_NAME);
TaskHandle_t bleLinkTaskHandle = xTaskGetHandle(BLE_LINK_TASK_NAME);
TaskHandle_t bleEventTaskHandle = xTaskGetHandle(CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME);

#if CHIP_SYSTEM_CONFIG_USE_LWIP
UBaseType_t lwipTaskValue;
TaskHandle_t lwipHandle = xTaskGetHandle(TCPIP_THREAD_NAME);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
osThreadId_t * threadIdTable = new osThreadId_t[threadCount];
// Forms a table of the active thread ids
osThreadEnumerate(threadIdTable, threadCount);

while (true)
{
appTaskValue = uxTaskGetStackHighWaterMark(appTaskHandle);
bleEventTaskValue = uxTaskGetStackHighWaterMark(bleEventTaskHandle);
bleTaskValue = uxTaskGetStackHighWaterMark(bleStackTaskHandle);
linkLayerTaskValue = uxTaskGetStackHighWaterMark(bleLinkTaskHandle);
openThreadTaskValue = uxTaskGetStackHighWaterMark(otTaskHandle);
eventLoopTaskValue = uxTaskGetStackHighWaterMark(eventLoopHandleStruct);
#if CHIP_SYSTEM_CONFIG_USE_LWIP
lwipTaskValue = uxTaskGetStackHighWaterMark(lwipHandle);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

SILABS_LOG("=============================");
SILABS_LOG(" ");
SILABS_LOG("Largest Block allocated 0x%x", largestBlockAllocated);
SILABS_LOG("Number Of Successful Alloc 0x%x", nbAllocSuccess);
SILABS_LOG("Number Of Successful Frees 0x%x", nbFreeSuccess);
SILABS_LOG(" ");
SILABS_LOG("App Task most bytes ever Free 0x%x", (appTaskValue * 4));
SILABS_LOG("BLE Event most bytes ever Free 0x%x", (bleEventTaskValue * 4));
SILABS_LOG("BLE Stack most bytes ever Free 0x%x", (bleTaskValue * 4));
SILABS_LOG("Link Layer Task most bytes ever Free 0x%x", (linkLayerTaskValue * 4));
SILABS_LOG("OpenThread Task most bytes ever Free 0x%x", (openThreadTaskValue * 4));
SILABS_LOG("Event Loop Task most bytes ever Free 0x%x", (eventLoopTaskValue * 4));
#if CHIP_SYSTEM_CONFIG_USE_LWIP
SILABS_LOG("LWIP Task most bytes ever Free 0x%x", (lwipTaskValue * 4));
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
SILABS_LOG(" ");
SILABS_LOG(" ");
SILABS_LOG("Largest Block allocated %lu B", largestBlockAllocated);
SILABS_LOG("Number Of Successful Alloc %lu", nbAllocSuccess);
SILABS_LOG("Number Of Successful Frees %lu", nbFreeSuccess);
SILABS_LOG(" ");

SILABS_LOG("Thread stack highwatermark ");
for (uint8_t tIdIndex = 0; tIdIndex < threadCount; tIdIndex++)
{
osThreadId_t tId = threadIdTable[tIdIndex];
if (tId != sMonitorThreadHandle) // don't print stats for this current debug thread.
{
// The smallest amount of free stack space there has been since the thread creation
SILABS_LOG("\t%-10s : %6lu B", osThreadGetName(tId), osThreadGetStackSpace(tId));
}
}

SILABS_LOG(" ");
SILABS_LOG("=============================");
vTaskDelay(pdMS_TO_TICKS(5000));
// run loop every 5 seconds
osDelay(osKernelGetTickFreq() * 5);
}

// will never get here. Still, free allocated memory before exiting
delete threadIdTable;
}

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip

extern "C" void memMonitoringTrackAlloc(void * ptr, size_t size)
{
if (ptr != NULL)
{
nbAllocSuccess++;
if (largestBlockAllocated < size)
chip::DeviceLayer::Silabs::nbAllocSuccess++;
if (chip::DeviceLayer::Silabs::largestBlockAllocated < size)
{
largestBlockAllocated = size;
chip::DeviceLayer::Silabs::largestBlockAllocated = size;
}
}
}

extern "C" void memMonitoringTrackFree(void * ptr, size_t size)
{
nbFreeSuccess++;
chip::DeviceLayer::Silabs::nbFreeSuccess++;
}
13 changes: 9 additions & 4 deletions examples/platform/silabs/MemMonitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@
#pragma once

#ifdef HEAP_MONITORING
#include "FreeRTOS.h"

#define MONITORING_STACK_SIZE_byte 1024
namespace chip {
namespace DeviceLayer {
namespace Silabs {

class MemMonitoring
{
public:
static void startHeapMonitoring();
static void StartMonitor();

private:
static void HeapMonitoring(void * pvParameter);
static void MonitorTask(void * pvParameter);
};

} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip

#endif
5 changes: 2 additions & 3 deletions scripts/setup/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ colorama==0.4.6
# west
coloredlogs==15.0.1
# via -r requirements.all.txt
construct==2.10.54
construct==2.10.70
# via
# -r requirements.esp32.txt
# esp-coredump
Expand Down Expand Up @@ -208,7 +208,7 @@ python-socketio==4.6.1
# via -r requirements.esp32.txt
pytz==2022.7.1
# via pandas
pyyaml==6.0
pyyaml==6.0.1
# via
# esptool
# idf-component-manager
Expand Down Expand Up @@ -296,4 +296,3 @@ setuptools==68.0.0
# Higher versions depend on proto-plus, which break
# nanopb code generation (due to name conflict of the 'proto' module)
google-api-core==2.17.0

2 changes: 1 addition & 1 deletion scripts/setup/requirements.esp32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ reedsolo>=1.5.3,<=1.5.4
bitarray==2.6.0
bitstring>=3.1.6,<4
ecdsa>=0.16.0
construct==2.10.54
construct>=2.10.70
python-socketio<5
itsdangerous<2.1 ; python_version < "3.11"
esp_idf_monitor==1.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
using chip::TimeSyncDataProvider;
using namespace chip::app::Clusters::TimeSynchronization;

void DefaultTimeSyncDelegate::TimeZoneListChanged(const Span<TimeSyncDataProvider::TimeZoneStore> timeZoneList)
{
// placeholder implementation
}

bool DefaultTimeSyncDelegate::HandleUpdateDSTOffset(chip::CharSpan name)
{
// placeholder implementation
return false;
}

bool DefaultTimeSyncDelegate::IsNTPAddressValid(chip::CharSpan ntp)
{
// placeholder implementation
Expand Down Expand Up @@ -67,14 +56,3 @@ CHIP_ERROR DefaultTimeSyncDelegate::UpdateTimeFromPlatformSource(chip::Callback:
}
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR DefaultTimeSyncDelegate::UpdateTimeUsingNTPFallback(const CharSpan & fallbackNTP,
chip::Callback::Callback<OnFallbackNTPCompletion> * callback)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

void DefaultTimeSyncDelegate::UTCTimeAvailabilityChanged(uint64_t time)
{
// placeholder implementation
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ class DefaultTimeSyncDelegate : public Delegate

public:
DefaultTimeSyncDelegate() : Delegate(){};
void TimeZoneListChanged(const Span<TimeSyncDataProvider::TimeZoneStore> timeZoneList) override;
bool HandleUpdateDSTOffset(CharSpan name) override;
bool IsNTPAddressValid(CharSpan ntp) override;
bool IsNTPAddressDomain(CharSpan ntp) override;
CHIP_ERROR UpdateTimeFromPlatformSource(chip::Callback::Callback<OnTimeSyncCompletion> * callback) override;
CHIP_ERROR UpdateTimeUsingNTPFallback(const CharSpan & fallbackNTP,
chip::Callback::Callback<OnFallbackNTPCompletion> * callback) override;
void UTCTimeAvailabilityChanged(uint64_t time) override;
};

} // namespace TimeSynchronization
Expand Down
Loading

0 comments on commit 2f49442

Please sign in to comment.