Skip to content

Commit

Permalink
[Silabs] Refactor RCP WiFi initialization to remove platform-specific…
Browse files Browse the repository at this point in the history
… dependencies and unify initialization function (#37135)

* Changes the WiFi initialization and adds it to platfrom init flow

* Rename API based on refactor

* Add debug log for failed sl_matter_wifi_init

* Refactor platform-specific includes in MatterConfig.cpp

* Refactor WiFi initialization to remove platform-specific dependencies and unify initialization function

* Refactor InitWiFiStack to return CHIP_ERROR and improve error handling across implementations

* Improve documentation for wfx_bus_start function

* Remove error log from wfx_bus_start and update documentation for memory allocation failure

* Apply suggestions from code review

Co-authored-by: Mathieu Kardous <[email protected]>

* Refactor InitWiFiStack error handling to use appropriate CHIP_ERROR codes and update documentation

* Update src/platform/silabs/wifi/WifiInterface.h

Co-authored-by: Mathieu Kardous <[email protected]>

---------

Co-authored-by: Mathieu Kardous <[email protected]>
  • Loading branch information
rosahay-silabs and mkardous-silabs authored Jan 28, 2025
1 parent dcf7e0d commit a3561e1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 81 deletions.
28 changes: 4 additions & 24 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include <platform/silabs/wifi/WifiInterface.h>

// TODO: We shouldn't need any platform specific includes in this file
#ifdef WF200_WIFI
#include <platform/silabs/wifi/wf200/ncp/sl_wfx_task.h>
#endif // WF200_WIFI
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
#include <platform/silabs/SiWx917/SiWxPlatformInterface.h>
#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
#endif // SL_WIFI

#if PW_RPC_ENABLED
Expand All @@ -45,15 +45,6 @@
#include "MemMonitoring.h"
#endif

// TODO: We shouldn't need any platform specific includes in this file
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
#include <platform/silabs/SiWx917/SiWxPlatformInterface.h>
#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 )

#if ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
#include <platform/silabs/wifi/wiseconnect-interface/WiseconnectWifiInterface.h>
#endif // ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))

#include <crypto/CHIPCryptoPAL.h>
// If building with the EFR32-provided crypto backend, we can use the
// opaque keystore
Expand Down Expand Up @@ -317,18 +308,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
#ifdef SL_WIFI
CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
{
// TODO: Platform specific init should not be required here
#ifdef WF200_WIFI
// Start wfx bus communication task.
wfx_bus_start();
#endif // WF200_WIFI

// TODO: Platform specific init should not be required here
#if ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
VerifyOrReturnError(InitSiWxWifi() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
#endif //((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) || defined(EXP_BOARD))

return CHIP_NO_ERROR;
return InitWiFiStack();
}
#endif // SL_WIFI

Expand Down
7 changes: 0 additions & 7 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ extern "C" {
#define BLE_TIMEOUT_MS 400
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (5000)

osSemaphoreId_t sl_rs_ble_init_sem;

using namespace ::chip;
using namespace ::chip::Ble;
using namespace ::chip::DeviceLayer::Internal;
Expand Down Expand Up @@ -234,9 +232,6 @@ void BLEManagerImpl::sl_ble_event_handling_task(void * args)
sl_status_t status;
SilabsBleWrapper::BleEvent_t bleEvent;

//! This semaphore is waiting for wifi module initialization.
osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever);

// This function initialize BLE and start BLE advertisement.
sInstance.sl_ble_init();

Expand Down Expand Up @@ -288,8 +283,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
{
CHIP_ERROR err;

sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL);

sBleThread = osThreadNew(sInstance.sl_ble_event_handling_task, NULL, &kBleTaskAttr);

VerifyOrReturnError(sBleThread != nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand Down
17 changes: 8 additions & 9 deletions src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ extern "C" {
#endif

WfxRsi_t wfx_rsi;
extern osSemaphoreId_t sl_rs_ble_init_sem;

namespace {

Expand Down Expand Up @@ -310,7 +309,6 @@ sl_status_t sl_wifi_siwx917_init(void)
#endif // SL_MBEDTLS_USE_TINYCRYPT

wfx_rsi.dev_state.Set(WifiState::kStationInit);
osSemaphoreRelease(sl_rs_ble_init_sem);
return status;
}

Expand Down Expand Up @@ -555,29 +553,30 @@ CHIP_ERROR ResetCounters()
return CHIP_NO_ERROR;
}

sl_status_t InitSiWxWifi(void)
CHIP_ERROR InitWiFiStack(void)
{
sl_status_t status = SL_STATUS_OK;

status = sl_net_init((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr);
VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status));
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status));

// Create Sempaphore for scan completion
sScanCompleteSemaphore = osSemaphoreNew(1, 0, nullptr);
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED);
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, CHIP_ERROR_NO_MEMORY);

// Create Semaphore for scan in-progress protection
sScanInProgressSemaphore = osSemaphoreNew(1, 1, nullptr);
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED);
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, CHIP_ERROR_NO_MEMORY);

// Create the message queue
sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiPlatformEvent), nullptr);
VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED);
VerifyOrReturnError(sWifiEventQueue != nullptr, CHIP_ERROR_NO_MEMORY);

status = CreateDHCPTimer();
VerifyOrReturnError(status == SL_STATUS_OK, status);
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_NO_MEMORY,
ChipLogError(DeviceLayer, "CreateDHCPTimer failed: %lx", status));

return status;
return CHIP_NO_ERROR;
}

void HandleDHCPPolling(void)
Expand Down
10 changes: 10 additions & 0 deletions src/platform/silabs/wifi/WifiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ extern WfxRsi_t wfx_rsi;

/* Updated functions */

/**
* @brief Function initalizes the WiFi module before starting WiFi task.
*
* @return CHIP_ERROR CHIP_NO_ERROR, if the initialization succeeded
* CHIP_ERROR_INTERNAL, if sequence failed due to internal API error
* CHIP_ERROR_NO_MEMORY, if sequence failed due to unavaliablility of memory
*/

CHIP_ERROR InitWiFiStack(void);

/**
* @brief Function notifies the PlatformManager that an IPv6 event occured on the WiFi interface.
*
Expand Down
22 changes: 8 additions & 14 deletions src/platform/silabs/wifi/rs911x/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ osThreadAttr_t kDrvTaskAttr = { .name = "drv_rsi",
.stack_size = kDrvTaskSize,
.priority = osPriorityHigh };

#if (RSI_BLE_ENABLE)
extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
#endif

static osMessageQueueId_t sWifiEventQueue = NULL;
/*
* This file implements the interface to the RSI SAPIs
Expand Down Expand Up @@ -331,10 +327,6 @@ static int32_t sl_matter_wifi_init(void)
return status;
}

#if (RSI_BLE_ENABLE)
rsi_semaphore_post(&sl_rs_ble_init_sem);
#endif

wfx_rsi.dev_state.Set(WifiState::kStationInit);
return RSI_SUCCESS;
}
Expand Down Expand Up @@ -646,15 +638,17 @@ void ProcessEvent(WifiPlatformEvent event)
}
}

CHIP_ERROR InitWiFiStack(void)
{
int32_t status = sl_matter_wifi_init();
VerifyOrReturnError(status == RSI_SUCCESS, CHIP_ERROR_INTERNAL,
ChipLogError(DeviceLayer, "sl_matter_wifi_init failed: %lx", status));
return CHIP_NO_ERROR;
}

void MatterWifiTask(void * arg)
{
(void) arg;
uint32_t rsi_status = sl_matter_wifi_init();
if (rsi_status != RSI_SUCCESS)
{
ChipLogError(DeviceLayer, "MatterWifiTask: sl_matter_wifi_init failed: %ld", rsi_status);
return;
}
WifiPlatformEvent event;
sl_matter_lwip_start();
sl_matter_wifi_task_started();
Expand Down
11 changes: 11 additions & 0 deletions src/platform/silabs/wifi/wf200/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,3 +1185,14 @@ void wfx_cancel_scan(void)
}
scan_cb = nullptr;
}

CHIP_ERROR InitWiFiStack(void)
{
// TODO: This function should include sl_wfx_hw_init() and sl_wfx_init() functions. Only done now to make MatterConfig platform
// agnostic. (MATTER-4680)
// Start wfx bus communication task.
sl_status_t status = wfx_bus_start();
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_NO_MEMORY,
ChipLogError(DeviceLayer, "wfx_bus_start failed: %lx", status));
return CHIP_NO_ERROR;
}
12 changes: 3 additions & 9 deletions src/platform/silabs/wifi/wf200/ncp/sl_wfx_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,13 @@ static void wfx_bus_task(void * p_arg)
}
}

/***************************************************************************
* @fn void wfx_bus_start()
* @brief
* Creates WFX bus communication task.
* @param[in] None
* @return None
******************************************************************************/
void wfx_bus_start()
sl_status_t wfx_bus_start(void)
{
wfx_bus_task_handle =
xTaskCreateStatic(wfx_bus_task, "wfxbus", BUS_TASK_STACK_SIZE, NULL, WFX_BUS_TASK_PRIORITY, busStack, &busTaskStruct);
if (wfx_bus_task_handle == NULL)
{
SILABS_LOG("*ERR*WFX BusTask");
return SL_STATUS_ALLOCATION_FAILED;
}
return SL_STATUS_OK;
}
13 changes: 7 additions & 6 deletions src/platform/silabs/wifi/wf200/ncp/sl_wfx_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ extern TaskHandle_t wfx_bus_task_handle;
extern "C" {
#endif

/****************************************************************************
* @fn void wfx_bus_start(void)
* @brief
* Start wfx bus communication task.
*****************************************************************************/
void wfx_bus_start(void);
/**
* @brief Start WFX bus communication task.
*
* @return sl_status_t SL_STATUS_OK, if the initialization succeeded
* SL_STATUS_ALLOCATION_FAILED, if there are a memory allocation failure.
*/
sl_status_t wfx_bus_start(void);

/****************************************************************************
* @fn bool wfx_bus_is_receive_processing(void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,3 @@ void PostWifiPlatformEvent(WifiPlatformEvent event);
* @param[in] arg context pointer
*/
void MatterWifiTask(void * arg);

/**
* @brief Function initializes SiWx Wi-Fi interface
*
* TODO: This function is specific to the SiWx platform and should not be present in the WiseconnectWifiInterface.
* Once the SoC and NCP init sequence are harmonised, remove this API.
*
* @return sl_status_t SL_STATUS_OK, if the initialization succeeded
* SL_STATUS_ALLOCATION_FAILED, if there are a memory allocation failure,
* SL_STATUS_FAILURE, otherwise
*/
sl_status_t InitSiWxWifi();

0 comments on commit a3561e1

Please sign in to comment.