Skip to content

Commit a3561e1

Browse files
[Silabs] Refactor RCP WiFi initialization to remove platform-specific 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 <84793247+mkardous-silabs@users.noreply.github.com> * 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 <84793247+mkardous-silabs@users.noreply.github.com> --------- Co-authored-by: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com>
1 parent dcf7e0d commit a3561e1

File tree

9 files changed

+51
-81
lines changed

9 files changed

+51
-81
lines changed

examples/platform/silabs/MatterConfig.cpp

+4-24
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include <platform/silabs/wifi/WifiInterface.h>
2929

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

3636
#if PW_RPC_ENABLED
@@ -45,15 +45,6 @@
4545
#include "MemMonitoring.h"
4646
#endif
4747

48-
// TODO: We shouldn't need any platform specific includes in this file
49-
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
50-
#include <platform/silabs/SiWx917/SiWxPlatformInterface.h>
51-
#endif // (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 )
52-
53-
#if ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
54-
#include <platform/silabs/wifi/wiseconnect-interface/WiseconnectWifiInterface.h>
55-
#endif // ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
56-
5748
#include <crypto/CHIPCryptoPAL.h>
5849
// If building with the EFR32-provided crypto backend, we can use the
5950
// opaque keystore
@@ -317,18 +308,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
317308
#ifdef SL_WIFI
318309
CHIP_ERROR SilabsMatterConfig::InitWiFi(void)
319310
{
320-
// TODO: Platform specific init should not be required here
321-
#ifdef WF200_WIFI
322-
// Start wfx bus communication task.
323-
wfx_bus_start();
324-
#endif // WF200_WIFI
325-
326-
// TODO: Platform specific init should not be required here
327-
#if ((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1) || defined(EXP_BOARD))
328-
VerifyOrReturnError(InitSiWxWifi() == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
329-
#endif //((defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1 ) || defined(EXP_BOARD))
330-
331-
return CHIP_NO_ERROR;
311+
return InitWiFiStack();
332312
}
333313
#endif // SL_WIFI
334314

src/platform/silabs/rs911x/BLEManagerImpl.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ extern "C" {
5252
#define BLE_TIMEOUT_MS 400
5353
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (5000)
5454

55-
osSemaphoreId_t sl_rs_ble_init_sem;
56-
5755
using namespace ::chip;
5856
using namespace ::chip::Ble;
5957
using namespace ::chip::DeviceLayer::Internal;
@@ -234,9 +232,6 @@ void BLEManagerImpl::sl_ble_event_handling_task(void * args)
234232
sl_status_t status;
235233
SilabsBleWrapper::BleEvent_t bleEvent;
236234

237-
//! This semaphore is waiting for wifi module initialization.
238-
osSemaphoreAcquire(sl_rs_ble_init_sem, osWaitForever);
239-
240235
// This function initialize BLE and start BLE advertisement.
241236
sInstance.sl_ble_init();
242237

@@ -288,8 +283,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
288283
{
289284
CHIP_ERROR err;
290285

291-
sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL);
292-
293286
sBleThread = osThreadNew(sInstance.sl_ble_event_handling_task, NULL, &kBleTaskAttr);
294287

295288
VerifyOrReturnError(sBleThread != nullptr, CHIP_ERROR_INCORRECT_STATE);

src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ extern "C" {
8686
#endif
8787

8888
WfxRsi_t wfx_rsi;
89-
extern osSemaphoreId_t sl_rs_ble_init_sem;
9089

9190
namespace {
9291

@@ -310,7 +309,6 @@ sl_status_t sl_wifi_siwx917_init(void)
310309
#endif // SL_MBEDTLS_USE_TINYCRYPT
311310

312311
wfx_rsi.dev_state.Set(WifiState::kStationInit);
313-
osSemaphoreRelease(sl_rs_ble_init_sem);
314312
return status;
315313
}
316314

@@ -555,29 +553,30 @@ CHIP_ERROR ResetCounters()
555553
return CHIP_NO_ERROR;
556554
}
557555

558-
sl_status_t InitSiWxWifi(void)
556+
CHIP_ERROR InitWiFiStack(void)
559557
{
560558
sl_status_t status = SL_STATUS_OK;
561559

562560
status = sl_net_init((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, &config, &wifi_client_context, nullptr);
563-
VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status));
561+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "sl_net_init failed: %lx", status));
564562

565563
// Create Sempaphore for scan completion
566564
sScanCompleteSemaphore = osSemaphoreNew(1, 0, nullptr);
567-
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED);
565+
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, CHIP_ERROR_NO_MEMORY);
568566

569567
// Create Semaphore for scan in-progress protection
570568
sScanInProgressSemaphore = osSemaphoreNew(1, 1, nullptr);
571-
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED);
569+
VerifyOrReturnError(sScanCompleteSemaphore != nullptr, CHIP_ERROR_NO_MEMORY);
572570

573571
// Create the message queue
574572
sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiPlatformEvent), nullptr);
575-
VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED);
573+
VerifyOrReturnError(sWifiEventQueue != nullptr, CHIP_ERROR_NO_MEMORY);
576574

577575
status = CreateDHCPTimer();
578-
VerifyOrReturnError(status == SL_STATUS_OK, status);
576+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_NO_MEMORY,
577+
ChipLogError(DeviceLayer, "CreateDHCPTimer failed: %lx", status));
579578

580-
return status;
579+
return CHIP_NO_ERROR;
581580
}
582581

583582
void HandleDHCPPolling(void)

src/platform/silabs/wifi/WifiInterface.h

+10
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ extern WfxRsi_t wfx_rsi;
177177

178178
/* Updated functions */
179179

180+
/**
181+
* @brief Function initalizes the WiFi module before starting WiFi task.
182+
*
183+
* @return CHIP_ERROR CHIP_NO_ERROR, if the initialization succeeded
184+
* CHIP_ERROR_INTERNAL, if sequence failed due to internal API error
185+
* CHIP_ERROR_NO_MEMORY, if sequence failed due to unavaliablility of memory
186+
*/
187+
188+
CHIP_ERROR InitWiFiStack(void);
189+
180190
/**
181191
* @brief Function notifies the PlatformManager that an IPv6 event occured on the WiFi interface.
182192
*

src/platform/silabs/wifi/rs911x/WifiInterfaceImpl.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ osThreadAttr_t kDrvTaskAttr = { .name = "drv_rsi",
7171
.stack_size = kDrvTaskSize,
7272
.priority = osPriorityHigh };
7373

74-
#if (RSI_BLE_ENABLE)
75-
extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
76-
#endif
77-
7874
static osMessageQueueId_t sWifiEventQueue = NULL;
7975
/*
8076
* This file implements the interface to the RSI SAPIs
@@ -331,10 +327,6 @@ static int32_t sl_matter_wifi_init(void)
331327
return status;
332328
}
333329

334-
#if (RSI_BLE_ENABLE)
335-
rsi_semaphore_post(&sl_rs_ble_init_sem);
336-
#endif
337-
338330
wfx_rsi.dev_state.Set(WifiState::kStationInit);
339331
return RSI_SUCCESS;
340332
}
@@ -646,15 +638,17 @@ void ProcessEvent(WifiPlatformEvent event)
646638
}
647639
}
648640

641+
CHIP_ERROR InitWiFiStack(void)
642+
{
643+
int32_t status = sl_matter_wifi_init();
644+
VerifyOrReturnError(status == RSI_SUCCESS, CHIP_ERROR_INTERNAL,
645+
ChipLogError(DeviceLayer, "sl_matter_wifi_init failed: %lx", status));
646+
return CHIP_NO_ERROR;
647+
}
648+
649649
void MatterWifiTask(void * arg)
650650
{
651651
(void) arg;
652-
uint32_t rsi_status = sl_matter_wifi_init();
653-
if (rsi_status != RSI_SUCCESS)
654-
{
655-
ChipLogError(DeviceLayer, "MatterWifiTask: sl_matter_wifi_init failed: %ld", rsi_status);
656-
return;
657-
}
658652
WifiPlatformEvent event;
659653
sl_matter_lwip_start();
660654
sl_matter_wifi_task_started();

src/platform/silabs/wifi/wf200/WifiInterfaceImpl.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1185,3 +1185,14 @@ void wfx_cancel_scan(void)
11851185
}
11861186
scan_cb = nullptr;
11871187
}
1188+
1189+
CHIP_ERROR InitWiFiStack(void)
1190+
{
1191+
// TODO: This function should include sl_wfx_hw_init() and sl_wfx_init() functions. Only done now to make MatterConfig platform
1192+
// agnostic. (MATTER-4680)
1193+
// Start wfx bus communication task.
1194+
sl_status_t status = wfx_bus_start();
1195+
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_NO_MEMORY,
1196+
ChipLogError(DeviceLayer, "wfx_bus_start failed: %lx", status));
1197+
return CHIP_NO_ERROR;
1198+
}

src/platform/silabs/wifi/wf200/ncp/sl_wfx_task.c

+3-9
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,13 @@ static void wfx_bus_task(void * p_arg)
110110
}
111111
}
112112

113-
/***************************************************************************
114-
* @fn void wfx_bus_start()
115-
* @brief
116-
* Creates WFX bus communication task.
117-
* @param[in] None
118-
* @return None
119-
******************************************************************************/
120-
void wfx_bus_start()
113+
sl_status_t wfx_bus_start(void)
121114
{
122115
wfx_bus_task_handle =
123116
xTaskCreateStatic(wfx_bus_task, "wfxbus", BUS_TASK_STACK_SIZE, NULL, WFX_BUS_TASK_PRIORITY, busStack, &busTaskStruct);
124117
if (wfx_bus_task_handle == NULL)
125118
{
126-
SILABS_LOG("*ERR*WFX BusTask");
119+
return SL_STATUS_ALLOCATION_FAILED;
127120
}
121+
return SL_STATUS_OK;
128122
}

src/platform/silabs/wifi/wf200/ncp/sl_wfx_task.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ extern TaskHandle_t wfx_bus_task_handle;
3838
extern "C" {
3939
#endif
4040

41-
/****************************************************************************
42-
* @fn void wfx_bus_start(void)
43-
* @brief
44-
* Start wfx bus communication task.
45-
*****************************************************************************/
46-
void wfx_bus_start(void);
41+
/**
42+
* @brief Start WFX bus communication task.
43+
*
44+
* @return sl_status_t SL_STATUS_OK, if the initialization succeeded
45+
* SL_STATUS_ALLOCATION_FAILED, if there are a memory allocation failure.
46+
*/
47+
sl_status_t wfx_bus_start(void);
4748

4849
/****************************************************************************
4950
* @fn bool wfx_bus_is_receive_processing(void)

src/platform/silabs/wifi/wiseconnect-interface/WiseconnectWifiInterface.h

-12
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,3 @@ void PostWifiPlatformEvent(WifiPlatformEvent event);
112112
* @param[in] arg context pointer
113113
*/
114114
void MatterWifiTask(void * arg);
115-
116-
/**
117-
* @brief Function initializes SiWx Wi-Fi interface
118-
*
119-
* TODO: This function is specific to the SiWx platform and should not be present in the WiseconnectWifiInterface.
120-
* Once the SoC and NCP init sequence are harmonised, remove this API.
121-
*
122-
* @return sl_status_t SL_STATUS_OK, if the initialization succeeded
123-
* SL_STATUS_ALLOCATION_FAILED, if there are a memory allocation failure,
124-
* SL_STATUS_FAILURE, otherwise
125-
*/
126-
sl_status_t InitSiWxWifi();

0 commit comments

Comments
 (0)