From ff32d56805487471a8bc8ebf3d06be83c81e3b45 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Tue, 19 Apr 2022 15:07:06 -0400 Subject: [PATCH] [System] Remove LwIP from EFR32 OpenThread implementation (#17512) * Remove LwIP from EFR32 OpenThread platform impl --- src/inet/UDPEndPointImplOpenThread.cpp | 2 +- src/platform/EFR32/args.gni | 1 + src/system/BUILD.gn | 20 ++++++++++++++++++++ src/system/SystemConfig.h | 9 ++++++++- src/system/SystemLayer.h | 2 +- src/system/SystemLayerImplLwIP.cpp | 2 ++ src/system/SystemMutex.h | 5 ++++- src/system/SystemPacketBuffer.cpp | 7 ++++++- src/system/SystemPacketBuffer.h | 19 ++----------------- src/system/system.gni | 3 ++- src/test_driver/efr32/args.gni | 1 + 11 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/inet/UDPEndPointImplOpenThread.cpp b/src/inet/UDPEndPointImplOpenThread.cpp index 9dfe8ebd63db41..c7dc23c47dd8d6 100644 --- a/src/inet/UDPEndPointImplOpenThread.cpp +++ b/src/inet/UDPEndPointImplOpenThread.cpp @@ -82,7 +82,7 @@ void UDPEndPointImplOT::handleUdpReceive(void * aContext, otMessage * aMessage, payload->SetDataLength(static_cast(msgLen + sizeof(IPPacketInfo))); ep->Retain(); - CHIP_ERROR err = ep->GetSystemLayer().ScheduleLambda([ep, p = System::LwIPPacketBufferView::UnsafeGetLwIPpbuf(payload)] { + CHIP_ERROR err = ep->GetSystemLayer().ScheduleLambda([ep, p = payload.Get()] { ep->HandleDataReceived(System::PacketBufferHandle::Adopt(p)); ep->Release(); }); diff --git a/src/platform/EFR32/args.gni b/src/platform/EFR32/args.gni index 83dd799d85b075..616e14bc97922c 100644 --- a/src/platform/EFR32/args.gni +++ b/src/platform/EFR32/args.gni @@ -33,6 +33,7 @@ chip_mdns = "platform" chip_inet_config_enable_ipv4 = false chip_inet_config_enable_tcp_endpoint = false chip_system_config_use_open_thread_inet_endpoints = true +chip_with_lwip = false chip_build_tests = false diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn index acfa246b029b5e..75fc92b0f42924 100644 --- a/src/system/BUILD.gn +++ b/src/system/BUILD.gn @@ -40,6 +40,21 @@ if (chip_project_config_include_dirs == [] && chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] } +if (chip_device_platform == "cc13x2_26x2") { + import("//build_overrides/ti_simplelink_sdk.gni") +} else if (chip_device_platform == "efr32") { + import("//build_overrides/efr32_sdk.gni") +} else if (chip_device_platform == "qpg") { + import("//build_overrides/qpg_sdk.gni") + import("${qpg_sdk_build_root}/qpg_sdk.gni") +} else if (chip_device_platform == "k32w0") { + import("//build_overrides/k32w0_sdk.gni") +} else if (chip_device_platform == "p6") { + import("//build_overrides/p6.gni") +} else if (chip_device_platform == "cyw30739") { + import("//build_overrides/cyw30739_sdk.gni") +} + buildconfig_header("system_buildconfig") { header = "SystemBuildConfig.h" header_dir = "system" @@ -123,6 +138,11 @@ source_set("system_config_header") { if (target_cpu != "esp32") { if (chip_system_config_use_lwip) { public_deps += [ "${chip_root}/src/lwip" ] + } else { + if (chip_device_platform == "efr32") { + public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ] + } + # Add platform here as needed. } } } diff --git a/src/system/SystemConfig.h b/src/system/SystemConfig.h index dc5ddf22ea460f..de7c7eae28c628 100644 --- a/src/system/SystemConfig.h +++ b/src/system/SystemConfig.h @@ -94,7 +94,8 @@ /*--- Sanity check on the build configuration logic. ---*/ -#if !(CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) +#if !(CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK || \ + CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT) #error "REQUIRED: CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK" #endif // !(CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_USE_NETWORK_FRAMEWORK) @@ -110,6 +111,12 @@ #error "FORBIDDEN: CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK && CHIP_SYSTEM_CONFIG_USE_SOCKETS" #endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK && CHIP_SYSTEM_CONFIG_USE_SOCKETS +#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT && \ + (CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_LWIP) +#error \ + "FORBIDDEN: CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT && ( CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK || CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_LWIP )" +#endif + // clang-format off /** diff --git a/src/system/SystemLayer.h b/src/system/SystemLayer.h index d1635f113989a1..0d4554c3dc6124 100644 --- a/src/system/SystemLayer.h +++ b/src/system/SystemLayer.h @@ -172,7 +172,7 @@ class DLL_EXPORT Layer Layer & operator=(const Layer &) = delete; }; -#if CHIP_SYSTEM_CONFIG_USE_LWIP +#if CHIP_SYSTEM_CONFIG_USE_LWIP || CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT class LayerLwIP : public Layer { diff --git a/src/system/SystemLayerImplLwIP.cpp b/src/system/SystemLayerImplLwIP.cpp index 605f78daaa46bd..cac7b1faa4679c 100644 --- a/src/system/SystemLayerImplLwIP.cpp +++ b/src/system/SystemLayerImplLwIP.cpp @@ -36,7 +36,9 @@ CHIP_ERROR LayerImplLwIP::Init() { VerifyOrReturnError(mLayerState.SetInitializing(), CHIP_ERROR_INCORRECT_STATE); +#if CHIP_SYSTEM_CONFIG_USE_LWIP RegisterLwIPErrorFormatter(); +#endif // CHIP_SYSTEM_CONFIG_USE_LWIP VerifyOrReturnError(mLayerState.SetInitialized(), CHIP_ERROR_INCORRECT_STATE); return CHIP_NO_ERROR; diff --git a/src/system/SystemMutex.h b/src/system/SystemMutex.h index c9c6dab21c5c0d..09470b4d66df8b 100644 --- a/src/system/SystemMutex.h +++ b/src/system/SystemMutex.h @@ -73,6 +73,9 @@ class DLL_EXPORT Mutex ~Mutex(); static CHIP_ERROR Init(Mutex & aMutex); +#if CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING + inline bool isInitialized() { return mInitialized; } +#endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING void Lock(); /**< Acquire the mutual exclusion lock, blocking the current thread indefinitely if necessary. */ void Unlock(); /**< Release the mutual exclusion lock (can block on some systems until scheduler completes). */ @@ -91,7 +94,7 @@ class DLL_EXPORT Mutex StaticSemaphore_t mFreeRTOSSemaphoreObj; #endif // (configSUPPORT_STATIC_ALLOCATION == 1) volatile SemaphoreHandle_t mFreeRTOSSemaphore = nullptr; - volatile int mInitialized = 0; + volatile bool mInitialized = 0; #endif // CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING #if CHIP_SYSTEM_CONFIG_MBED_LOCKING diff --git a/src/system/SystemPacketBuffer.cpp b/src/system/SystemPacketBuffer.cpp index 55fd5fe593338e..3f6c136bcb152b 100644 --- a/src/system/SystemPacketBuffer.cpp +++ b/src/system/SystemPacketBuffer.cpp @@ -470,7 +470,12 @@ PacketBufferHandle PacketBufferHandle::New(size_t aAvailableSize, uint16_t aRese #elif CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL static_cast(lBlockSize); - +#if !CHIP_SYSTEM_CONFIG_NO_LOCKING && CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING + if (!sBufferPoolMutex.isInitialized()) + { + Mutex::Init(sBufferPoolMutex); + } +#endif LOCK_BUF_POOL(); lPacket = PacketBuffer::sFreeList; diff --git a/src/system/SystemPacketBuffer.h b/src/system/SystemPacketBuffer.h index b576eb03fb1043..a7ee5e472c1cd7 100644 --- a/src/system/SystemPacketBuffer.h +++ b/src/system/SystemPacketBuffer.h @@ -651,6 +651,8 @@ class DLL_EXPORT PacketBufferHandle #endif } + PacketBuffer * Get() const { return mBuffer; } + protected: #if CHIP_SYSTEM_CONFIG_USE_LWIP // For use via LwIPPacketBufferView only. @@ -677,8 +679,6 @@ class DLL_EXPORT PacketBufferHandle return PacketBufferHandle(buffer); } - PacketBuffer * Get() const { return mBuffer; } - bool operator==(const PacketBufferHandle & aOther) { return mBuffer == aOther.mBuffer; } #if CHIP_SYSTEM_PACKETBUFFER_HAS_RIGHTSIZE @@ -809,15 +809,6 @@ namespace Inet { class UDPEndPointImplLwIP; } // namespace Inet -#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT -// TODO : Temp Implementation issue : 13085 -// Still use LwIP buffer even if using OpenThread UDP implementation -// since decoupling of LwIP from OpenThread is still in progress -namespace Inet { -class UDPEndPointImplOT; -} // namespace Inet -#endif - namespace System { /** @@ -835,12 +826,6 @@ class LwIPPacketBufferView : public PacketBufferHandle */ static struct pbuf * UnsafeGetLwIPpbuf(const PacketBufferHandle & handle) { return PacketBufferHandle::GetLwIPpbuf(handle); } friend class Inet::UDPEndPointImplLwIP; -#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT - // TODO : Temp Implementation issue : 13085 - // Still use LwIP buffer even if using OpenThread UDP implementation - // since decoupling of LwIP from OpenThread is still in progress - friend class Inet::UDPEndPointImplOT; -#endif }; } // namespace System diff --git a/src/system/system.gni b/src/system/system.gni index e2a3de5eef181c..15aeead0a94c27 100644 --- a/src/system/system.gni +++ b/src/system/system.gni @@ -44,7 +44,8 @@ declare_args() { declare_args() { # Event loop type. - if (chip_system_config_use_lwip) { + if (chip_system_config_use_lwip || + chip_system_config_use_open_thread_inet_endpoints) { chip_system_config_event_loop = "LwIP" } else { chip_system_config_event_loop = "Select" diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index 8e2506c8afb694..45e18a61dd1d37 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -30,3 +30,4 @@ chip_monolithic_tests = true #Fix me : Test driver should use same config as examples # Problem : Linker issue if set to true chip_system_config_use_open_thread_inet_endpoints = false +chip_with_lwip = true