From 58599691d133c09d2538da4f86ed6efee6f752e8 Mon Sep 17 00:00:00 2001 From: Thirupathi S <108743108+Thirsrin@users.noreply.github.com> Date: Fri, 18 Aug 2023 23:12:06 +0530 Subject: [PATCH] [Silabs]DIC refactor changes (#27340) * DIC refactor changes * Restyled by clang-format * Restyled by gn * removed windows src changes in DIC refactor * removed windows src changes in DIC refactor * Refactor changes for DIC * DIC changes for light app * Restyled by clang-format * Restyled by gn * build gn file related changes for DIC * DIC BUILD gn changes for 917 soc * 917 soc dic changes * Addressed review comments * Restyled by gn * DIC refactor changes * Restyled by clang-format * Restyled by gn * removed windows src changes in DIC refactor * removed windows src changes in DIC refactor * Refactor changes for DIC * DIC changes for light app * Restyled by clang-format * Restyled by gn * build gn file related changes for DIC * DIC BUILD gn changes for 917 soc * 917 soc dic changes * Addressed review comments * Restyled by gn * Added changes with respect to aws ota * Restyled by gn * Added DIC AWS OTA Changes --------- Co-authored-by: Restyled.io Co-authored-by: KishorSilabs --- .../lighting-app/silabs/src/ZclCallbacks.cpp | 7 ++++ examples/lock-app/silabs/src/ZclCallbacks.cpp | 7 ++++ examples/platform/silabs/BaseApplication.cpp | 25 ++++++++++++ examples/platform/silabs/FreeRTOSConfig.h | 2 +- examples/platform/silabs/SiWx917/BUILD.gn | 40 ++++++------------- examples/platform/silabs/efr32/BUILD.gn | 39 +++++------------- src/lwip/silabs/lwipopts-wf200.h | 7 ++-- third_party/silabs/efr32_sdk.gni | 3 ++ third_party/silabs/silabs_board.gni | 3 ++ 9 files changed, 73 insertions(+), 60 deletions(-) diff --git a/examples/lighting-app/silabs/src/ZclCallbacks.cpp b/examples/lighting-app/silabs/src/ZclCallbacks.cpp index cfbcbc8a191411..1a27a20da15a63 100644 --- a/examples/lighting-app/silabs/src/ZclCallbacks.cpp +++ b/examples/lighting-app/silabs/src/ZclCallbacks.cpp @@ -28,6 +28,10 @@ #include #include +#ifdef DIC_ENABLE +#include "dic.h" +#endif // DIC_ENABLE + using namespace ::chip; using namespace ::chip::app::Clusters; @@ -40,6 +44,9 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id) { +#ifdef DIC_ENABLE + dic_sendmsg("light/state", (const char *) (value ? (*value ? "on" : "off") : "invalid")); +#endif // DIC_ENABLE LightMgr().InitiateAction(AppEvent::kEventType_Light, *value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION); } else if (clusterId == LevelControl::Id) diff --git a/examples/lock-app/silabs/src/ZclCallbacks.cpp b/examples/lock-app/silabs/src/ZclCallbacks.cpp index 12649100df5737..1c0c1efab19dde 100644 --- a/examples/lock-app/silabs/src/ZclCallbacks.cpp +++ b/examples/lock-app/silabs/src/ZclCallbacks.cpp @@ -31,6 +31,10 @@ #include #include +#ifdef DIC_ENABLE +#include "dic.h" +#endif // DIC_ENABLE + using namespace ::chip::app::Clusters; using namespace ::chip::DeviceLayer::Internal; using ::chip::app::DataModel::Nullable; @@ -47,6 +51,9 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & DoorLock::DlLockState lockState = *(reinterpret_cast(value)); ChipLogProgress(Zcl, "Door lock cluster: " ChipLogFormatMEI " state %d", ChipLogValueMEI(clusterId), to_underlying(lockState)); +#ifdef DIC_ENABLE + dic_sendmsg("lock/state", (const char *) (lockState == DoorLock::DlLockState::kLocked ? "lock" : "unlock")); +#endif // DIC_ENABLE } } diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index cd37c4615fa4bb..78d31c8acd4b61 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -61,6 +61,11 @@ #include #endif // SL_WIFI +#ifdef DIC_ENABLE +#include "dic.h" +#include "dic_control.h" +#endif // DIC_ENABLE + /********************************************************** * Defines and Constants *********************************************************/ @@ -140,6 +145,22 @@ Identify gIdentify = { #endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER } // namespace +#ifdef DIC_ENABLE +namespace { +void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_t arg) +{ + SILABS_LOG("AppSpecificConnectivityEventCallback: call back for IPV4"); + if ((event->Type == DeviceEventType::kInternetConnectivityChange) && + (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)) + { + SILABS_LOG("Got IPv4 Address! Starting DIC module\n"); + if (DIC_OK != dic_init(dic::control::subscribeCB)) + SILABS_LOG("Failed to initialize DIC module\n"); + } +} +} // namespace +#endif // DIC_ENABLE + /********************************************************** * AppTask Definitions *********************************************************/ @@ -220,6 +241,10 @@ CHIP_ERROR BaseApplication::Init() sStatusLED.Init(SYSTEM_STATE_LED); #endif // ENABLE_WSTK_LEDS +#ifdef DIC_ENABLE + chip::DeviceLayer::PlatformMgr().AddEventHandler(AppSpecificConnectivityEventCallback, reinterpret_cast(nullptr)); +#endif // DIC_ENABLE + ConfigurationMgr().LogDeviceConfig(); OutputQrCode(true /*refreshLCD at init*/); diff --git a/examples/platform/silabs/FreeRTOSConfig.h b/examples/platform/silabs/FreeRTOSConfig.h index 8d3236763f35e6..4c1d29f015eb9c 100644 --- a/examples/platform/silabs/FreeRTOSConfig.h +++ b/examples/platform/silabs/FreeRTOSConfig.h @@ -213,7 +213,7 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ #ifndef configTOTAL_HEAP_SIZE #ifdef SL_WIFI #ifdef DIC_ENABLE -#define configTOTAL_HEAP_SIZE ((size_t)(56 * 1024)) +#define configTOTAL_HEAP_SIZE ((size_t)(68 * 1024)) #else #define configTOTAL_HEAP_SIZE ((size_t)(34 * 1024)) #endif // DIC diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index f0600f012e19e7..f18e89d1beb21e 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -83,33 +83,6 @@ config("chip_examples_project_config") { ] } -if (enable_dic) { - config("efr32_dic_config") { - include_dirs = [ - "${chip_root}/third_party/silabs/mqtt/stack", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/include", - "${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/include", - ] - } - - source_set("efr32-dic") { - sources = [ - "${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/src/dic.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/MQTT_transport.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_alloc.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_tcp.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_tls_mbedtls.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_tls_mbedtls_mem.c", - ] - public_deps = [ - "${chip_root}/src/inet", - "${chip_root}/src/lwip", - ] - public_configs = [ ":efr32_dic_config" ] - } -} - source_set("siwx917-matter-shell") { if (chip_build_libshell) { defines = [ "ENABLE_CHIP_SHELL" ] @@ -293,6 +266,19 @@ source_set("siwx917-common") { deps += [ ":siwx917-matter-shell" ] } + # DIC + if (enable_dic) { + public_deps += + [ "${silabs_common_plat_dir}/DIC/matter_abs_interface:silabs-dic" ] + } + + # AWS SDK OTA + if (aws_sdk_ota) { + public_deps += [ + "${silabs_common_plat_dir}/DIC/matter_abs_interface:silabs-aws-sdk-ota", + ] + } + # Attestation Credentials if (chip_build_platform_attestation_credentials_provider) { deps += [ ":siwx917-attestation-credentials" ] diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 5bb628ad4f99e6..4ae40522fe4ccc 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -97,33 +97,6 @@ config("chip_examples_project_config") { ] } -if (enable_dic) { - config("efr32_dic_config") { - include_dirs = [ - "${chip_root}/third_party/silabs/mqtt/stack", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/include", - "${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/include", - ] - } - - source_set("efr32-dic") { - sources = [ - "${chip_root}/examples/platform/silabs/DIC/matter_abs_interface/src/dic.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/MQTT_transport.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_alloc.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_tcp.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_tls_mbedtls.c", - "${chip_root}/third_party/silabs/mqtt/mqtt_transport_interface/src/altcp_tls_mbedtls_mem.c", - ] - public_deps = [ - "${chip_root}/src/inet", - "${chip_root}/src/lwip", - ] - public_configs = [ ":efr32_dic_config" ] - } -} - source_set("openthread_core_config_efr32_chip_examples") { if (chip_enable_openthread) { sources = [ "project_include/OpenThreadConfig.h" ] @@ -259,9 +232,17 @@ source_set("efr32-common") { "${efr32_sdk_build_root}:silabs_config", ] - # MQTT + # DIC if (enable_dic) { - deps += [ "${examples_plat_dir}:efr32-dic" ] + public_deps += + [ "${silabs_common_plat_dir}/DIC/matter_abs_interface:silabs-dic" ] + } + + # AWS SDK OTA + if (aws_sdk_ota) { + public_deps += [ + "${silabs_common_plat_dir}/DIC/matter_abs_interface:silabs-aws-sdk-ota", + ] } include_dirs = [ "." ] diff --git a/src/lwip/silabs/lwipopts-wf200.h b/src/lwip/silabs/lwipopts-wf200.h index 681ef9accb32f8..bbb30012cc6366 100644 --- a/src/lwip/silabs/lwipopts-wf200.h +++ b/src/lwip/silabs/lwipopts-wf200.h @@ -70,9 +70,13 @@ #define DNS_RAND_TXID() ((u32_t) rand()) #define MEM_SIZE 5632 #define MEMP_NUM_UDP_PCB (6) +#define TCP_MSS (4 * 1152) +#define TCPIP_THREAD_PRIO (3) #else #define LWIP_DNS 0 #define MEMP_NUM_UDP_PCB (5) +#define TCP_MSS (1152) +#define TCPIP_THREAD_PRIO (2) #endif // DIC_ENABLE #define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 1 @@ -131,7 +135,6 @@ #define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL) #define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE) -#define TCP_MSS (1152) #define TCP_SND_BUF (2 * TCP_MSS) #define TCP_LISTEN_BACKLOG (1) @@ -141,8 +144,6 @@ #define TCPIP_THREAD_STACKSIZE (2048) -#define TCPIP_THREAD_PRIO (2) - #define NETIF_MAX_HWADDR_LEN 8U #define LWIP_IPV6_NUM_ADDRESSES 5 diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 9c64cd951cd5d9..84e9d8a24b5432 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -252,6 +252,9 @@ template("efr32_sdk") { assert(chip_enable_wifi_ipv4, "enable chip_enable_wifi_ipv4") defines += [ "DIC_ENABLE=1" ] } + if (aws_sdk_ota) { + defines += [ "ENABLE_AWS_OTA_FEAT=1" ] + } if (chip_enable_wifi_ipv4) { defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4=1" ] } diff --git a/third_party/silabs/silabs_board.gni b/third_party/silabs/silabs_board.gni index bba3f060f8898d..2d25ac2b54e3f4 100644 --- a/third_party/silabs/silabs_board.gni +++ b/third_party/silabs/silabs_board.gni @@ -41,6 +41,9 @@ declare_args() { #Disable MQTT by default enable_dic = false + # Disable AWS SDK OTA by default + aws_sdk_ota = false + # Disable UART log forwarding by default sl_uart_log_output = false }