Skip to content

Commit

Permalink
[NXP][Zephyr] Use common wifi port for Zephyr (#32143)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Axel Le Bourhis <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 23, 2024
1 parent d2afc4d commit 1966322
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "NxpWifiDriver.h"
#include "ZephyrWifiDriver.h"

#include <platform/KeyValueStoreManager.h>

Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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));

Expand All @@ -95,7 +95,7 @@ void NxpWifiScanResponseIterator::Add(const WiFiScanResponse & result)
}
}

CHIP_ERROR NxpWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
CHIP_ERROR ZephyrWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
{
mpNetworkStatusChangeCallback = networkStatusChangeCallback;

Expand All @@ -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)
{
Expand All @@ -132,20 +132,20 @@ 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));

return CHIP_NO_ERROR;
}

CHIP_ERROR NxpWifiDriver::RevertConfiguration()
CHIP_ERROR ZephyrWifiDriver::RevertConfiguration()
{
LoadFromStorage();

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 = {};

Expand All @@ -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;
Expand Down Expand Up @@ -252,7 +252,7 @@ void NxpWifiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callbac
}
}

void NxpWifiDriver::LoadFromStorage()
void ZephyrWifiDriver::LoadFromStorage()
{
WiFiManager::WiFiNetwork network;

Expand All @@ -262,20 +262,20 @@ 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,
CharSpan(), &mScanResponseIterator);
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ constexpr uint8_t kMaxWiFiNetworks = 1;
constexpr uint8_t kWiFiScanNetworksTimeOutSeconds = 10;
constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 35;

class NxpWifiScanResponseIterator : public Iterator<WiFiScanResponse>
class ZephyrWifiScanResponseIterator : public Iterator<WiFiScanResponse>
{
public:
size_t Count() override { return mResultCount; }
Expand All @@ -43,7 +43,7 @@ class NxpWifiScanResponseIterator : public Iterator<WiFiScanResponse>
WiFiScanResponse * mResults = nullptr;
};

class NxpWifiDriver final : public WiFiDriver
class ZephyrWifiDriver final : public WiFiDriver
{
public:
// Define non-volatile storage keys for SSID and password.
Expand All @@ -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 };
};

Expand All @@ -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;
}

Expand All @@ -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 };
};

Expand Down
12 changes: 6 additions & 6 deletions src/platform/nxp/zephyr/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/zephyr/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include "wifi/ConnectivityManagerImplWiFi.h"
#include <platform/Zephyr/wifi/ConnectivityManagerImplWiFi.h>
#else
#include <platform/internal/GenericConnectivityManagerImpl_NoWiFi.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "DiagnosticDataProviderImplNxp.h"

#ifdef CONFIG_WIFI_NXP
#include <platform/nxp/zephyr/wifi/WiFiManager.h>
#include <platform/Zephyr/wifi/WiFiManager.h>
#endif

namespace chip {
Expand Down

0 comments on commit 1966322

Please sign in to comment.