From cb26afad1f2abca511db779d17bd7bec47c368fd Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Thu, 1 Feb 2024 14:59:30 -0500 Subject: [PATCH] Clean up CSL support --- .../light-switch-app/silabs/src/AppTask.cpp | 5 - examples/platform/silabs/MatterConfig.cpp | 207 ++++++++---------- .../efr32/project_include/OpenThreadConfig.h | 45 ++-- scripts/examples/gn_silabs_example.sh | 4 + third_party/silabs/efr32_sdk.gni | 17 +- 5 files changed, 124 insertions(+), 154 deletions(-) diff --git a/examples/light-switch-app/silabs/src/AppTask.cpp b/examples/light-switch-app/silabs/src/AppTask.cpp index 2083a6a885c577..25ea90e670e607 100644 --- a/examples/light-switch-app/silabs/src/AppTask.cpp +++ b/examples/light-switch-app/silabs/src/AppTask.cpp @@ -129,11 +129,6 @@ void AppTask::AppTaskMain(void * pvParameter) SILABS_LOG("App Task started"); -#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) - SILABS_LOG("----------------------------------------------- ADING EM1 requirement ---------------------------------"); - sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); -#endif - while (true) { BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 3356e5b8f2f262..c9bc96a96a5673 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -152,179 +152,164 @@ void SilabsMatterConfig::ConnectivityEventCallback(const ChipDeviceEvent * event chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); #endif - - SILABS_LOG("------------------------------------ Send Data Request -------------------------------------") - otLinkSendDataRequest(chip::DeviceLayer::ThreadStackMgrImpl().OTInstance()); - } - if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete) - { -#if CHIP_ENABLE_OPENTHREAD -#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) - SILABS_LOG("------------------------------------ REMOVE EM 1 REQUIREMENT -------------------------------------") - sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); -#endif -#endif // CHIP_ENABLE_OPENTHREAD - } -} - #if SILABS_TEST_EVENT_TRIGGER_ENABLED -static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, - 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, - 0xcc, 0xdd, 0xee, 0xff }; + static uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, + 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0xcc, 0xdd, 0xee, 0xff }; #endif // SILABS_TEST_EVENT_TRIGGER_ENABLED -CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) -{ - CHIP_ERROR err; + CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) + { + CHIP_ERROR err; - mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); + mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); - SILABS_LOG("=================================================="); - SILABS_LOG("%s starting", appName); - SILABS_LOG("=================================================="); + SILABS_LOG("=================================================="); + SILABS_LOG("%s starting", appName); + SILABS_LOG("=================================================="); #if PW_RPC_ENABLED - chip::rpc::Init(); + chip::rpc::Init(); #endif #ifdef HEAP_MONITORING - MemMonitoring::startHeapMonitoring(); + MemMonitoring::startHeapMonitoring(); #endif - //============================================== - // Init Matter Stack - //============================================== - SILABS_LOG("Init CHIP Stack"); - // Init Chip memory management before the stack - ReturnErrorOnFailure(chip::Platform::MemoryInit()); + //============================================== + // Init Matter Stack + //============================================== + SILABS_LOG("Init CHIP Stack"); + // Init Chip memory management before the stack + ReturnErrorOnFailure(chip::Platform::MemoryInit()); // WiFi needs to be initialized after Memory Init for some reason #ifdef SL_WIFI - ReturnErrorOnFailure(InitWiFi()); + ReturnErrorOnFailure(InitWiFi()); #endif - ReturnErrorOnFailure(PlatformMgr().InitChipStack()); + ReturnErrorOnFailure(PlatformMgr().InitChipStack()); - SetDeviceInstanceInfoProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider()); - SetCommissionableDataProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider()); + SetDeviceInstanceInfoProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider()); + SetCommissionableDataProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider()); - chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(appName); + chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName(appName); #if CHIP_ENABLE_OPENTHREAD - ReturnErrorOnFailure(InitOpenThread()); + ReturnErrorOnFailure(InitOpenThread()); #endif - // Stop Matter event handling while setting up resources - chip::DeviceLayer::PlatformMgr().LockChipStack(); + // Stop Matter event handling while setting up resources + chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Create initParams with SDK example defaults here - // TODO: replace with our own init param to avoid double allocation in examples - static chip::CommonCaseDeviceServerInitParams initParams; + // Create initParams with SDK example defaults here + // TODO: replace with our own init param to avoid double allocation in examples + static chip::CommonCaseDeviceServerInitParams initParams; - // Report scheduler and timer delegate instance - static chip::app::DefaultTimerDelegate sTimerDelegate; + // Report scheduler and timer delegate instance + static chip::app::DefaultTimerDelegate sTimerDelegate; #if CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED - static chip::app::reporting::SynchronizedReportSchedulerImpl sReportScheduler(&sTimerDelegate); + static chip::app::reporting::SynchronizedReportSchedulerImpl sReportScheduler(&sTimerDelegate); #else - static chip::app::reporting::ReportSchedulerImpl sReportScheduler(&sTimerDelegate); + static chip::app::reporting::ReportSchedulerImpl sReportScheduler(&sTimerDelegate); #endif - initParams.reportScheduler = &sReportScheduler; + initParams.reportScheduler = &sReportScheduler; #if SILABS_TEST_EVENT_TRIGGER_ENABLED - if (Encoding::HexToBytes(SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY, strlen(SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY), - sTestEventTriggerEnableKey, - TestEventTriggerDelegate::kEnableKeyLength) != TestEventTriggerDelegate::kEnableKeyLength) - { - SILABS_LOG("Failed to convert the EnableKey string to octstr type value"); - memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey)); - } - // TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler()` - static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) }; - initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; + if (Encoding::HexToBytes(SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY, strlen(SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY), + sTestEventTriggerEnableKey, + TestEventTriggerDelegate::kEnableKeyLength) != TestEventTriggerDelegate::kEnableKeyLength) + { + SILABS_LOG("Failed to convert the EnableKey string to octstr type value"); + memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey)); + } + // TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler()` + static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) }; + initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; #endif // SILABS_TEST_EVENT_TRIGGER_ENABLED #if CHIP_CRYPTO_PLATFORM && !(defined(SIWX_917)) - // When building with EFR32 crypto, use the opaque key store - // instead of the default (insecure) one. - gOperationalKeystore.Init(); - initParams.operationalKeystore = &gOperationalKeystore; + // When building with EFR32 crypto, use the opaque key store + // instead of the default (insecure) one. + gOperationalKeystore.Init(); + initParams.operationalKeystore = &gOperationalKeystore; #endif #ifdef PERFORMANCE_TEST_ENABLED - // Set up Test Event Trigger command of the General Diagnostics cluster. Used only in performance testing - // TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler()` - static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; - initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; + // Set up Test Event Trigger command of the General Diagnostics cluster. Used only in performance testing + // TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler()` + static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) }; + initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; #endif - // Initialize the remaining (not overridden) providers to the SDK example defaults - (void) initParams.InitializeStaticResourcesBeforeServerInit(); + // Initialize the remaining (not overridden) providers to the SDK example defaults + (void) initParams.InitializeStaticResourcesBeforeServerInit(); #if CHIP_ENABLE_OPENTHREAD - // Set up OpenThread configuration when OpenThread is included - chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams; - nativeParams.lockCb = LockOpenThreadTask; - nativeParams.unlockCb = UnlockOpenThreadTask; - nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance(); - initParams.endpointNativeParams = static_cast(&nativeParams); + // Set up OpenThread configuration when OpenThread is included + chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams; + nativeParams.lockCb = LockOpenThreadTask; + nativeParams.unlockCb = UnlockOpenThreadTask; + nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance(); + initParams.endpointNativeParams = static_cast(&nativeParams); #endif - // Init Matter Server and Start Event Loop - err = chip::Server::GetInstance().Init(initParams); + // Init Matter Server and Start Event Loop + err = chip::Server::GetInstance().Init(initParams); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - ReturnErrorOnFailure(err); + ReturnErrorOnFailure(err); - // OTA Requestor initialization will be triggered by the connectivity events - PlatformMgr().AddEventHandler(ConnectivityEventCallback, reinterpret_cast(nullptr)); + // OTA Requestor initialization will be triggered by the connectivity events + PlatformMgr().AddEventHandler(ConnectivityEventCallback, reinterpret_cast(nullptr)); - SILABS_LOG("Starting Platform Manager Event Loop"); - ReturnErrorOnFailure(PlatformMgr().StartEventLoopTask()); + SILABS_LOG("Starting Platform Manager Event Loop"); + ReturnErrorOnFailure(PlatformMgr().StartEventLoopTask()); #ifdef ENABLE_CHIP_SHELL - chip::startShellTask(); + chip::startShellTask(); #endif - return CHIP_NO_ERROR; -} + return CHIP_NO_ERROR; + } #ifdef SL_WIFI -CHIP_ERROR SilabsMatterConfig::InitWiFi(void) -{ + CHIP_ERROR SilabsMatterConfig::InitWiFi(void) + { #ifdef WF200_WIFI - // Start wfx bus communication task. - wfx_bus_start(); + // Start wfx bus communication task. + wfx_bus_start(); #ifdef SL_WFX_USE_SECURE_LINK - wfx_securelink_task_start(); // start securelink key renegotiation task -#endif // SL_WFX_USE_SECURE_LINK -#endif /* WF200_WIFI */ + wfx_securelink_task_start(); // start securelink key renegotiation task +#endif // SL_WFX_USE_SECURE_LINK +#endif /* WF200_WIFI */ #ifdef SIWX_917 - sl_status_t status; - if ((status = wfx_wifi_rsi_init()) != SL_STATUS_OK) - { - ReturnErrorOnFailure((CHIP_ERROR) status); - } + sl_status_t status; + if ((status = wfx_wifi_rsi_init()) != SL_STATUS_OK) + { + ReturnErrorOnFailure((CHIP_ERROR) status); + } #endif // SIWX_917 - return CHIP_NO_ERROR; -} + return CHIP_NO_ERROR; + } #endif // SL_WIFI -// ================================================================================ -// FreeRTOS Callbacks -// ================================================================================ -extern "C" void vApplicationIdleHook(void) -{ -#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER - if (ConnectivityMgr().IsWiFiStationConnected()) + // ================================================================================ + // FreeRTOS Callbacks + // ================================================================================ + extern "C" void vApplicationIdleHook(void) { - // Let the M4 sleep once commissioning is done and device is in idle state - sl_wfx_host_si91x_sleep_wakeup(); - } +#if SIWX_917 && CHIP_CONFIG_ENABLE_ICD_SERVER + if (ConnectivityMgr().IsWiFiStationConnected()) + { + // Let the M4 sleep once commissioning is done and device is in idle state + sl_wfx_host_si91x_sleep_wakeup(); + } #endif -} + } diff --git a/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h b/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h index 56fc6ea87d8be8..ff62b620191d8b 100644 --- a/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h +++ b/examples/platform/silabs/efr32/project_include/OpenThreadConfig.h @@ -45,40 +45,37 @@ // Timeout after 2 missed checkin or 4 mins if sleep interval is too short. #define OPENTHREAD_CONFIG_MLE_CHILD_TIMEOUT_DEFAULT ((SL_MLE_TIMEOUT_s < 120) ? 240 : ((SL_MLE_TIMEOUT_s * 2) + 1)) +#if defined(SL_CSL_ENABLE) && SL_CSL_ENABLE #define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 1 #define OPENTHREAD_CONFIG_MAC_CSL_AUTO_SYNC_ENABLE 1 #define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 #define OPENTHREAD_CONFIG_CHILD_SUPERVISION_CHECK_TIMEOUT 0 +#define OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD 700 +#define OPENTHREAD_CONFIG_CSL_TIMEOUT SL_CSL_TIMEOUT #define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 200 +#endif // SL_CSL_ENABLE + #endif // SL_ICD_ENABLED /****Uncomment below section for OpenThread Debug logs*/ -// #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG - -// #ifndef OPENTHREAD_CONFIG_LOG_CLI -// #define OPENTHREAD_CONFIG_LOG_CLI 1 -// #endif - -// #ifndef OPENTHREAD_CONFIG_LOG_PKT_DUMP -// #define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1 -// #endif - -// #ifndef OPENTHREAD_CONFIG_LOG_PLATFORM -// #define OPENTHREAD_CONFIG_LOG_PLATFORM 1 -// #endif - -// #ifndef OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL -// #define OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL 1 -// #endif - -// EFR32MG21A020F1024IM32 has 96k of RAM. Reduce the number of buffers to -// conserve RAM for this Series 2 part. -#if defined(EFR32MG21) -#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 -#define OPENTHREAD_CONFIG_CLI_UART_TX_BUFFER_SIZE 512 -#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 512 +#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG + +#ifndef OPENTHREAD_CONFIG_LOG_CLI +#define OPENTHREAD_CONFIG_LOG_CLI 1 +#endif + +#ifndef OPENTHREAD_CONFIG_LOG_PKT_DUMP +#define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1 +#endif + +#ifndef OPENTHREAD_CONFIG_LOG_PLATFORM +#define OPENTHREAD_CONFIG_LOG_PLATFORM 1 +#endif + +#ifndef OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL +#define OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL 1 #endif #define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1 diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 2042dc11876db7..54a2d614f13eb7 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -198,6 +198,10 @@ else optArgs+="chip_enable_icd_server=true chip_openthread_ftd=false " shift ;; + --ssed) + optArgs+="enable_synchronized_sed=true " + shift + ;; --low-power) optArgs+="chip_build_libshell=false enable_openthread_cli=false show_qr_code=false disable_lcd=true " shift diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index a81760b8239f43..415f89b4db04fb 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -49,7 +49,7 @@ declare_args() { # ICD Openthread Configuration flags sl_ot_idle_interval_ms = 15000 # 15s Idle Intervals sl_ot_active_interval_ms = 200 # 200ms Active Intervals - + # SSED Specific configurations sl_ot_csl_timeout_sec = 30 # 30s CSL timeout @@ -301,13 +301,6 @@ template("efr32_sdk") { #"__STACK_SIZE=0", ] - if (!(use_silabs_thread_lib || use_silabs_thread_lib)) { - #Enabling this config temporarly to fix a build issue until - #official fix is pushed - - defines += [ "OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE=1" ] - } - # Temporary configuration to enable COAP specific configurations if (use_thread_coap_lib) { defines += [ "SL_USE_COAP_CONFIG=1" ] @@ -442,12 +435,8 @@ template("efr32_sdk") { if (enable_synchronized_sed) { defines += [ "CHIP_DEVICE_CONFIG_THREAD_SSED=1", - "OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE=1", - "OPENTHREAD_CONFIG_MAC_CSL_AUTO_SYNC_ENABLE=1", - "OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE=1", - "OPENTHREAD_CONFIG_CHILD_SUPERVISION_CHECK_TIMEOUT=0", - "SL_OPENTHREAD_CSL_TX_UNCERTAINTY=200", - "OPENTHREAD_CONFIG_CSL_TIMEOUT=${sl_ot_csl_timeout_sec}", + "SL_CSL_ENABLE=1", + "SL_CSL_TIMEOUT=${sl_ot_csl_timeout_sec}", ] } }