Skip to content

Commit

Permalink
Update EFR32 Thread Stack Manager Impl (#17111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored Apr 6, 2022
1 parent cd29bba commit 5601756
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/platform/EFR32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
#if defined(EFR32MG21)
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (2 * 1024)
#else
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (4 * 1024)
#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (8 * 1024)
#endif
#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE

Expand Down
5 changes: 0 additions & 5 deletions src/platform/EFR32/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>

#include <lwip/dns.h>
#include <lwip/ip_addr.h>
#include <lwip/nd6.h>
#include <lwip/netif.h>

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>
#endif
Expand Down
1 change: 0 additions & 1 deletion src/platform/EFR32/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
#endif
#include <lwip/tcpip.h>

#include "AppConfig.h"
#include "FreeRTOS.h"
Expand Down
10 changes: 9 additions & 1 deletion src/platform/EFR32/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@
#define LOG_WARN "<warn > "
#define LOG_INFO "<info > "
#define LOG_DETAIL "<detail> "
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#define LOG_LWIP "<lwip > "
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
#define LOG_EFR32 "<efr32 > "
// If a new category string LOG_* is created, add it in the MaxStringLength arguments below
#if CHIP_SYSTEM_CONFIG_USE_LWIP
static constexpr size_t kMaxCategoryStrLen = chip::MaxStringLength(LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DETAIL, LOG_LWIP, LOG_EFR32);
#else
static constexpr size_t kMaxCategoryStrLen = chip::MaxStringLength(LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DETAIL, LOG_EFR32);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if EFR32_LOG_ENABLED
static bool sLogInitialized = false;
Expand Down Expand Up @@ -218,6 +224,8 @@ void LogV(const char * module, uint8_t category, const char * aFormat, va_list v
} // namespace Logging
} // namespace chip

#if CHIP_SYSTEM_CONFIG_USE_LWIP

/**
* LwIP log output function.
*/
Expand Down Expand Up @@ -251,7 +259,7 @@ extern "C" void LwIPLog(const char * aFormat, ...)
#endif // EFR32_LOG_ENABLED
va_end(v);
}

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
/**
* Platform logging function for OpenThread
*/
Expand Down
4 changes: 4 additions & 0 deletions src/platform/EFR32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/tcpip.h>
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#include "AppConfig.h"
#include "FreeRTOS.h"
Expand All @@ -51,8 +53,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance());
SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance());

#if CHIP_SYSTEM_CONFIG_USE_LWIP
// Initialize LwIP.
tcpip_init(NULL, NULL);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

ReturnErrorOnFailure(System::Clock::InitClock_RealTime());

Expand Down
1 change: 1 addition & 0 deletions src/platform/EFR32/SystemPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ChipDeviceEvent;
// ==================== Platform Adaptations ====================
#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1
#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent *
#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 8

// ========== Platform-specific Configuration Overrides =========

Expand Down
4 changes: 2 additions & 2 deletions src/platform/EFR32/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp>
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>

Expand All @@ -54,7 +54,7 @@ CHIP_ERROR ThreadStackManagerImpl::InitThreadStack(otInstance * otInst)
// Initialize the generic implementation base classes.
err = GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>::DoInit();
SuccessOrExit(err);
err = GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>::DoInit(otInst);
err = GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::DoInit(otInst);
SuccessOrExit(err);

exit:
Expand Down
6 changes: 3 additions & 3 deletions src/platform/EFR32/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#pragma once

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>

#include <openthread/tasklet.h>
#include <openthread/thread.h>
Expand All @@ -47,7 +47,7 @@ extern int GetEntropy_EFR32(uint8_t * buf, size_t bufSize);
* using the Silicon Labs SDK and the OpenThread stack.
*/
class ThreadStackManagerImpl final : public ThreadStackManager,
public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
public Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>,
public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
{
// Allow the ThreadStackManager interface class to delegate method calls to
Expand All @@ -58,7 +58,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
// this class.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
#endif

Expand Down
5 changes: 2 additions & 3 deletions src/platform/EFR32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ mbedtls_target = "${efr32_sdk_build_root}:efr32_sdk"
openthread_external_mbedtls = mbedtls_target

chip_device_platform = "efr32"
chip_mdns = "platform"

#Net work configuration OpenThread
lwip_platform = "efr32"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
#include <app/data-model/Encode.h>

#include <limits>

#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
#include <app/server/Server.h>
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
extern "C" void otSysProcessDrivers(otInstance * aInstance);

#if CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
Expand Down Expand Up @@ -215,6 +217,32 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnPlatformEvent(const

#endif // CHIP_DETAIL_LOGGING

#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
if (event->ThreadStateChange.RoleChanged || event->ThreadStateChange.AddressChanged)
{
bool isInterfaceUp;
isInterfaceUp = GenericThreadStackManagerImpl_OpenThread<ImplClass>::IsThreadInterfaceUpNoLock();
// Post an event signaling the change in Thread interface connectivity state.
{
ChipDeviceEvent event;
event.Clear();
event.Type = DeviceEventType::kThreadConnectivityChange;
event.ThreadConnectivityChange.Result = (isInterfaceUp) ? kConnectivity_Established : kConnectivity_Lost;
CHIP_ERROR status = PlatformMgr().PostEvent(&event);
if (status != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to post Thread connectivity change: %" CHIP_ERROR_FORMAT, status.Format());
}
}

// Refresh Multicast listening
if (GenericThreadStackManagerImpl_OpenThread<ImplClass>::IsThreadAttachedNoLock())
{
ChipLogDetail(DeviceLayer, "Thread Attached updating Multicast address");
Server::GetInstance().RejoinExistingMulticastGroups();
}
}
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
Impl()->UnlockThreadStack();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@

#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp>

#include <app/server/Server.h>
#include <transport/raw/PeerAddress.h>

#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
#error "When using OpenThread Endpoints, one should also use GenericThreadStackManagerImpl_OpenThread"
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT

namespace chip {
namespace DeviceLayer {
namespace Internal {
Expand Down Expand Up @@ -230,17 +233,6 @@ void GenericThreadStackManagerImpl_OpenThread_LwIP<ImplClass>::UpdateThreadInter
addrAssigned[addrIdx] = true;
}
}

// Multicast won't work with LWIP on top of OT
// Duplication of listeners, unecessary timers, buffer duplication, hardfault etc...
#if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
// Refresh Multicast listening
if (GenericThreadStackManagerImpl_OpenThread<ImplClass>::IsThreadAttachedNoLock())
{
ChipLogDetail(DeviceLayer, "Thread Attached updating Multicast address");
Server::GetInstance().RejoinExistingMulticastGroups();
}
#endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT
}

ChipLogDetail(DeviceLayer, "LwIP Thread interface addresses %s", isInterfaceUp ? "updated" : "cleared");
Expand Down

0 comments on commit 5601756

Please sign in to comment.