From 19663228016c2c0cdde6bf01f0b5c9be1323f5a6 Mon Sep 17 00:00:00 2001 From: Axel Le Bourhis <45206070+axelnxp@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:59:20 +0100 Subject: [PATCH] [NXP][Zephyr] Use common wifi port for Zephyr (#32143) * [NXP][Zephyr] Use common wifi port for Zephyr Move current NXP Zephyr wifi port to a common place, to be shared with other zephyr platforms. Signed-off-by: Axel Le Bourhis * Restyled by gn * [NXP][platform][zephyr] Lower CHIP task priority Lower CHIP task priority to give margin for higher priority system tasks. Signed-off-by: Axel Le Bourhis --------- Signed-off-by: Axel Le Bourhis Co-authored-by: Restyled.io --- .../wifi/ConnectivityManagerImplWiFi.cpp | 0 .../wifi/ConnectivityManagerImplWiFi.h | 0 .../zephyr => Zephyr}/wifi/WiFiManager.cpp | 0 .../{nxp/zephyr => Zephyr}/wifi/WiFiManager.h | 0 .../wifi/ZephyrWifiDriver.cpp} | 40 +++++++++---------- .../wifi/ZephyrWifiDriver.h} | 14 +++---- src/platform/nxp/zephyr/BUILD.gn | 12 +++--- .../nxp/zephyr/CHIPDevicePlatformConfig.h | 2 +- .../nxp/zephyr/ConnectivityManagerImpl.h | 2 +- .../zephyr/DiagnosticDataProviderImplNxp.cpp | 2 +- 10 files changed, 36 insertions(+), 36 deletions(-) rename src/platform/{nxp/zephyr => Zephyr}/wifi/ConnectivityManagerImplWiFi.cpp (100%) rename src/platform/{nxp/zephyr => Zephyr}/wifi/ConnectivityManagerImplWiFi.h (100%) rename src/platform/{nxp/zephyr => Zephyr}/wifi/WiFiManager.cpp (100%) rename src/platform/{nxp/zephyr => Zephyr}/wifi/WiFiManager.h (100%) rename src/platform/{nxp/zephyr/wifi/NxpWifiDriver.cpp => Zephyr/wifi/ZephyrWifiDriver.cpp} (86%) rename src/platform/{nxp/zephyr/wifi/NxpWifiDriver.h => Zephyr/wifi/ZephyrWifiDriver.h} (90%) diff --git a/src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.cpp b/src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.cpp similarity index 100% rename from src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.cpp rename to src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.cpp diff --git a/src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.h b/src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.h similarity index 100% rename from src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.h rename to src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.h diff --git a/src/platform/nxp/zephyr/wifi/WiFiManager.cpp b/src/platform/Zephyr/wifi/WiFiManager.cpp similarity index 100% rename from src/platform/nxp/zephyr/wifi/WiFiManager.cpp rename to src/platform/Zephyr/wifi/WiFiManager.cpp diff --git a/src/platform/nxp/zephyr/wifi/WiFiManager.h b/src/platform/Zephyr/wifi/WiFiManager.h similarity index 100% rename from src/platform/nxp/zephyr/wifi/WiFiManager.h rename to src/platform/Zephyr/wifi/WiFiManager.h diff --git a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.cpp b/src/platform/Zephyr/wifi/ZephyrWifiDriver.cpp similarity index 86% rename from src/platform/nxp/zephyr/wifi/NxpWifiDriver.cpp rename to src/platform/Zephyr/wifi/ZephyrWifiDriver.cpp index f3969a583221e6..53b7fa684a2213 100644 --- a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.cpp +++ b/src/platform/Zephyr/wifi/ZephyrWifiDriver.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "NxpWifiDriver.h" +#include "ZephyrWifiDriver.h" #include @@ -32,13 +32,13 @@ namespace chip { namespace DeviceLayer { namespace NetworkCommissioning { -size_t NxpWifiDriver::WiFiNetworkIterator::Count() +size_t ZephyrWifiDriver::WiFiNetworkIterator::Count() { VerifyOrReturnValue(mDriver != nullptr, 0); return mDriver->mStagingNetwork.IsConfigured() ? 1 : 0; } -bool NxpWifiDriver::WiFiNetworkIterator::Next(Network & item) +bool ZephyrWifiDriver::WiFiNetworkIterator::Next(Network & item) { // we assume only one network is actually supported // TODO: verify if this can be extended @@ -67,7 +67,7 @@ bool NxpWifiDriver::WiFiNetworkIterator::Next(Network & item) return true; } -bool NxpWifiScanResponseIterator::Next(WiFiScanResponse & item) +bool ZephyrWifiScanResponseIterator::Next(WiFiScanResponse & item) { if (mResultId < mResultCount) { @@ -77,14 +77,14 @@ bool NxpWifiScanResponseIterator::Next(WiFiScanResponse & item) return false; } -void NxpWifiScanResponseIterator::Release() +void ZephyrWifiScanResponseIterator::Release() { mResultId = mResultCount = 0; Platform::MemoryFree(mResults); mResults = nullptr; } -void NxpWifiScanResponseIterator::Add(const WiFiScanResponse & result) +void ZephyrWifiScanResponseIterator::Add(const WiFiScanResponse & result) { void * newResults = Platform::MemoryRealloc(mResults, (mResultCount + 1) * sizeof(WiFiScanResponse)); @@ -95,7 +95,7 @@ void NxpWifiScanResponseIterator::Add(const WiFiScanResponse & result) } } -CHIP_ERROR NxpWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback) +CHIP_ERROR ZephyrWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback) { mpNetworkStatusChangeCallback = networkStatusChangeCallback; @@ -113,7 +113,7 @@ CHIP_ERROR NxpWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChange return CHIP_NO_ERROR; } -void NxpWifiDriver::OnNetworkStatusChanged(Status status) +void ZephyrWifiDriver::OnNetworkStatusChanged(Status status) { if (status == Status::kSuccess) { @@ -132,12 +132,12 @@ void NxpWifiDriver::OnNetworkStatusChanged(Status status) } } -void NxpWifiDriver::Shutdown() +void ZephyrWifiDriver::Shutdown() { mpNetworkStatusChangeCallback = nullptr; } -CHIP_ERROR NxpWifiDriver::CommitConfiguration() +CHIP_ERROR ZephyrWifiDriver::CommitConfiguration() { ReturnErrorOnFailure(KeyValueStoreMgr().Put(kPassKey, mStagingNetwork.pass, mStagingNetwork.passLen)); ReturnErrorOnFailure(KeyValueStoreMgr().Put(kSsidKey, mStagingNetwork.ssid, mStagingNetwork.ssidLen)); @@ -145,7 +145,7 @@ CHIP_ERROR NxpWifiDriver::CommitConfiguration() return CHIP_NO_ERROR; } -CHIP_ERROR NxpWifiDriver::RevertConfiguration() +CHIP_ERROR ZephyrWifiDriver::RevertConfiguration() { LoadFromStorage(); @@ -172,8 +172,8 @@ CHIP_ERROR NxpWifiDriver::RevertConfiguration() return CHIP_NO_ERROR; } -Status NxpWifiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, - uint8_t & outNetworkIndex) +Status ZephyrWifiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { outDebugText = {}; outNetworkIndex = 0; @@ -191,7 +191,7 @@ Status NxpWifiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mu return Status::kSuccess; } -Status NxpWifiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) +Status ZephyrWifiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { outDebugText = {}; outNetworkIndex = 0; @@ -202,7 +202,7 @@ Status NxpWifiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDeb return Status::kSuccess; } -Status NxpWifiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) +Status ZephyrWifiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { outDebugText = {}; @@ -213,7 +213,7 @@ Status NxpWifiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableC return Status::kSuccess; } -void NxpWifiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) +void ZephyrWifiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) { Status status = Status::kSuccess; WiFiManager::StationStatus stationStatus; @@ -252,7 +252,7 @@ void NxpWifiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callbac } } -void NxpWifiDriver::LoadFromStorage() +void ZephyrWifiDriver::LoadFromStorage() { WiFiManager::WiFiNetwork network; @@ -262,7 +262,7 @@ void NxpWifiDriver::LoadFromStorage() mStagingNetwork = network; } -void NxpWifiDriver::OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status) +void ZephyrWifiDriver::OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status) { VerifyOrReturn(mScanCallback != nullptr); mScanCallback->OnFinished(status == WiFiManager::WiFiRequestStatus::SUCCESS ? Status::kSuccess : Status::kUnknownError, @@ -270,12 +270,12 @@ void NxpWifiDriver::OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status) mScanCallback = nullptr; } -void NxpWifiDriver::OnScanWiFiNetworkResult(const WiFiScanResponse & response) +void ZephyrWifiDriver::OnScanWiFiNetworkResult(const WiFiScanResponse & response) { mScanResponseIterator.Add(response); } -void NxpWifiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callback) +void ZephyrWifiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callback) { mScanCallback = callback; CHIP_ERROR error = WiFiManager::Instance().Scan( diff --git a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.h b/src/platform/Zephyr/wifi/ZephyrWifiDriver.h similarity index 90% rename from src/platform/nxp/zephyr/wifi/NxpWifiDriver.h rename to src/platform/Zephyr/wifi/ZephyrWifiDriver.h index 01e4964e2ea046..9096aa408b69bd 100644 --- a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.h +++ b/src/platform/Zephyr/wifi/ZephyrWifiDriver.h @@ -29,7 +29,7 @@ constexpr uint8_t kMaxWiFiNetworks = 1; constexpr uint8_t kWiFiScanNetworksTimeOutSeconds = 10; constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 35; -class NxpWifiScanResponseIterator : public Iterator +class ZephyrWifiScanResponseIterator : public Iterator { public: size_t Count() override { return mResultCount; } @@ -43,7 +43,7 @@ class NxpWifiScanResponseIterator : public Iterator WiFiScanResponse * mResults = nullptr; }; -class NxpWifiDriver final : public WiFiDriver +class ZephyrWifiDriver final : public WiFiDriver { public: // Define non-volatile storage keys for SSID and password. @@ -54,14 +54,14 @@ class NxpWifiDriver final : public WiFiDriver class WiFiNetworkIterator final : public NetworkIterator { public: - WiFiNetworkIterator(NxpWifiDriver * aDriver) : mDriver(aDriver) {} + WiFiNetworkIterator(ZephyrWifiDriver * aDriver) : mDriver(aDriver) {} size_t Count() override; bool Next(Network & item) override; void Release() override { delete this; } ~WiFiNetworkIterator() = default; private: - NxpWifiDriver * mDriver; + ZephyrWifiDriver * mDriver; bool mExhausted{ false }; }; @@ -87,9 +87,9 @@ class NxpWifiDriver final : public WiFiDriver uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; - static NxpWifiDriver & Instance() + static ZephyrWifiDriver & Instance() { - static NxpWifiDriver sInstance; + static ZephyrWifiDriver sInstance; return sInstance; } @@ -103,7 +103,7 @@ class NxpWifiDriver final : public WiFiDriver ConnectCallback * mpConnectCallback{ nullptr }; NetworkStatusChangeCallback * mpNetworkStatusChangeCallback{ nullptr }; WiFiManager::WiFiNetwork mStagingNetwork; - NxpWifiScanResponseIterator mScanResponseIterator; + ZephyrWifiScanResponseIterator mScanResponseIterator; ScanCallback * mScanCallback{ nullptr }; }; diff --git a/src/platform/nxp/zephyr/BUILD.gn b/src/platform/nxp/zephyr/BUILD.gn index 1c370750d911a6..bdf1f2bba9d324 100644 --- a/src/platform/nxp/zephyr/BUILD.gn +++ b/src/platform/nxp/zephyr/BUILD.gn @@ -87,12 +87,12 @@ static_library("nxp_zephyr") { sources += [ "../../Zephyr/InetUtils.cpp", "../../Zephyr/InetUtils.h", - "wifi/ConnectivityManagerImplWiFi.cpp", - "wifi/ConnectivityManagerImplWiFi.h", - "wifi/NxpWifiDriver.cpp", - "wifi/NxpWifiDriver.h", - "wifi/WiFiManager.cpp", - "wifi/WiFiManager.h", + "../../Zephyr/wifi/ConnectivityManagerImplWiFi.cpp", + "../../Zephyr/wifi/ConnectivityManagerImplWiFi.h", + "../../Zephyr/wifi/WiFiManager.cpp", + "../../Zephyr/wifi/WiFiManager.h", + "../../Zephyr/wifi/ZephyrWifiDriver.cpp", + "../../Zephyr/wifi/ZephyrWifiDriver.h", ] } diff --git a/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h b/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h index 7a80a39a3f77b2..900aa846e49d5c 100644 --- a/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h +++ b/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h @@ -105,7 +105,7 @@ // ========== Platform-specific Configuration Overrides ========= #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY -#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY (K_PRIO_PREEMPT(1)) +#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY (K_PRIO_PREEMPT(5)) #endif // CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE diff --git a/src/platform/nxp/zephyr/ConnectivityManagerImpl.h b/src/platform/nxp/zephyr/ConnectivityManagerImpl.h index 6d7a717886a7eb..c43d6a35dcb841 100644 --- a/src/platform/nxp/zephyr/ConnectivityManagerImpl.h +++ b/src/platform/nxp/zephyr/ConnectivityManagerImpl.h @@ -36,7 +36,7 @@ #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI -#include "wifi/ConnectivityManagerImplWiFi.h" +#include #else #include #endif diff --git a/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp b/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp index b7f0e2523610a5..6c3481da234719 100644 --- a/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp +++ b/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp @@ -24,7 +24,7 @@ #include "DiagnosticDataProviderImplNxp.h" #ifdef CONFIG_WIFI_NXP -#include +#include #endif namespace chip {