[Silabs] Moving to CMSIS OS and fixing task priorities (#35289)
* moving to cmsis os and correcting the priority of all tasks
* fixing the build for rs9116
* merging the wfx_rsi_host.cpp files
* fixing the build of efr32
* fixing the build for the rs9116
* removing commented code and adding comments
* Restyled by whitespace
* Restyled by clang-format
* fixing rs9116 and removing the unused code
* Restyled by clang-format
* renaming drv_task to drv_thread
* Update src/platform/silabs/rs911x/BLEManagerImpl.cpp
Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com>
* Update src/platform/silabs/efr32/BLEManagerImpl.cpp
Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com>
* moving rsi_if.c to cpp
* removing the osThread from the struct and adding them to there owner file
* Restyled by clang-format
* adding a length check compare for the scan
* Restyled by clang-format
* fixing the build
---------
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com>
diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn
index 2780e2e..f2ddfd5 100644
--- a/examples/platform/silabs/SiWx917/BUILD.gn
+++ b/examples/platform/silabs/SiWx917/BUILD.gn
@@ -192,11 +192,11 @@
"${silabs_common_plat_dir}/silabs_utils.cpp",
"${silabs_common_plat_dir}/syscalls_stubs.cpp",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
+ "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp",
"${silabs_plat_si91x_wifi_dir}/dhcp_client.cpp",
"${silabs_plat_si91x_wifi_dir}/ethernetif.cpp",
"${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp",
"SiWx917/sl_wifi_if.cpp",
- "SiWx917/wfx_rsi_host.cpp",
]
if (chip_enable_pw_rpc || chip_build_libshell || sl_uart_log_output) {
diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
index 92d5ca4..ad3e15f 100644
--- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
+++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
@@ -90,10 +90,11 @@
// TODO: Figure out why we actually need this, we are already handling failure and retries somewhere else.
#define WIFI_SCAN_TIMEOUT_TICK 10000
-WfxRsi_t wfx_rsi;
+#if !defined(MIN)
+#define MIN(A, B) ((A) < (B) ? (A) : (B))
+#endif
-/* Declare a variable to hold the data associated with the created event group. */
-StaticEventGroup_t rsiDriverEventGroup;
+WfxRsi_t wfx_rsi;
bool hasNotifiedIPV6 = false;
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
@@ -451,7 +452,6 @@
}
#endif // SL_MBEDTLS_USE_TINYCRYPT
- wfx_rsi.events = xEventGroupCreateStatic(&rsiDriverEventGroup);
wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY;
osSemaphoreRelease(sl_rs_ble_init_sem);
return status;
@@ -537,7 +537,9 @@
strncpy(cur_scan_result.ssid, (char *) &scan_result->scan_info[idx].ssid, WFX_MAX_SSID_LENGTH);
// if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
- if (wfx_rsi.scan_ssid != NULL && strcmp(wfx_rsi.scan_ssid, cur_scan_result.ssid) != CMP_SUCCESS)
+ if (wfx_rsi.scan_ssid != NULL &&
+ (strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) ==
+ CMP_SUCCESS))
{
continue;
}
diff --git a/examples/platform/silabs/efr32/rs911x/rs9117.gni b/examples/platform/silabs/efr32/rs911x/rs9117.gni
index 356b72f..cff3e3d 100644
--- a/examples/platform/silabs/efr32/rs911x/rs9117.gni
+++ b/examples/platform/silabs/efr32/rs911x/rs9117.gni
@@ -4,11 +4,11 @@
rs911x_src_plat = [
"${examples_plat_dir}/rs911x/sl_wifi_if.cpp",
- "${examples_plat_dir}/rs911x/wfx_rsi_host.cpp",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c",
"${examples_plat_dir}/rs911x/hal/sl_si91x_ncp_utility.c",
"${examples_plat_dir}/rs911x/hal/efx32_ncp_host.c",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
+ "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp",
]
rs9117_inc_plat = [
diff --git a/examples/platform/silabs/efr32/rs911x/rs911x.gni b/examples/platform/silabs/efr32/rs911x/rs911x.gni
index 54507de..b25fbef 100644
--- a/examples/platform/silabs/efr32/rs911x/rs911x.gni
+++ b/examples/platform/silabs/efr32/rs911x/rs911x.gni
@@ -3,13 +3,13 @@
import("${efr32_sdk_build_root}/efr32_sdk.gni")
rs911x_src_plat = [
- "${examples_plat_dir}/rs911x/rsi_if.c",
- "${examples_plat_dir}/rs911x/wfx_rsi_host.cpp",
+ "${examples_plat_dir}/rs911x/rsi_if.cpp",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_ioports.c",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c",
"${examples_plat_dir}/rs911x/hal/efx_spi.c",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
+ "${silabs_common_plat_dir}/wifi/wfx_rsi_host.cpp",
]
#
diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.c b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp
similarity index 93%
rename from examples/platform/silabs/efr32/rs911x/rsi_if.c
rename to examples/platform/silabs/efr32/rs911x/rsi_if.cpp
index f012128..d5560d6 100644
--- a/examples/platform/silabs/efr32/rs911x/rsi_if.c
+++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp
@@ -30,6 +30,9 @@
// TODO Fix include order issue #33120
#include "wfx_host_events.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
#include "rsi_bootup_config.h"
#include "rsi_common_apis.h"
#include "rsi_data_types.h"
@@ -42,10 +45,13 @@
#include "rsi_wlan_apis.h"
#include "rsi_wlan_config.h"
#include "rsi_wlan_non_rom.h"
-#include "silabs_utils.h"
+#ifdef __cplusplus
+}
+#endif
#include "dhcp_client.h"
#include "lwip/nd6.h"
+#include "silabs_utils.h"
#include "wfx_rsi.h"
// TODO convert this file to cpp and use CodeUtils.h
@@ -55,14 +61,17 @@
#define WFX_QUEUE_SIZE 10
-/* Rsi driver Task will use as its stack */
-StackType_t driverRsiTaskStack[WFX_RSI_WLAN_TASK_SZ] = { 0 };
-
-/* Structure that will hold the TCB of the wfxRsi Task being created. */
-StaticTask_t driverRsiTaskBuffer;
-
-/* Declare a variable to hold the data associated with the created event group. */
-StaticEventGroup_t rsiDriverEventGroup;
+static osThreadId_t sDrvThread;
+constexpr uint32_t kDrvTaskSize = 1792;
+static uint8_t drvStack[kDrvTaskSize];
+static osThread_t sDrvTaskControlBlock;
+osThreadAttr_t kDrvTaskAttr = { .name = "drv_rsi",
+ .attr_bits = osThreadDetached,
+ .cb_mem = &sDrvTaskControlBlock,
+ .cb_size = osThreadCbSize,
+ .stack_mem = drvStack,
+ .stack_size = kDrvTaskSize,
+ .priority = osPriorityHigh };
bool hasNotifiedIPV6 = false;
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
@@ -83,6 +92,19 @@
static uint8_t wfx_rsi_drv_buf[WFX_RSI_BUF_SZ];
static wfx_wifi_scan_ext_t temp_reset;
+/******************************************************************
+ * @fn void rsi_wireless_driver_task_wrapper(void * argument)
+ * @brief
+ * wrapper thread for the driver task
+ * @param[in] argument: argument
+ * @return
+ * None
+ *********************************************************************/
+static void rsi_wireless_driver_task_wrapper(void * argument)
+{
+ rsi_wireless_driver_task();
+}
+
static void DHCPTimerEventHandler(void * arg)
{
WfxEvent_t event;
@@ -359,11 +381,10 @@
}
SILABS_LOG("wfx_rsi_init: start wireless drv task", __func__);
/*
- * Create the driver task
+ * Create the driver wrapper thread
*/
- wfx_rsi.drv_task = xTaskCreateStatic((TaskFunction_t) rsi_wireless_driver_task, "rsi_drv", WFX_RSI_WLAN_TASK_SZ, NULL,
- WLAN_TASK_PRIORITY, driverRsiTaskStack, &driverRsiTaskBuffer);
- if (NULL == wfx_rsi.drv_task)
+ sDrvThread = osThreadNew(rsi_wireless_driver_task_wrapper, NULL, &kDrvTaskAttr);
+ if (NULL == sDrvThread)
{
SILABS_LOG("wfx_rsi_init: error: rsi_wireless_driver_task failed", __func__);
return RSI_ERROR_INVALID_PARAM;
@@ -605,7 +626,8 @@
sta_netif = wfx_get_netif(SL_WFX_STA_INTERFACE);
if (sta_netif == NULL)
{
- // TODO: Notify the application that the interface is not set up or Chipdie here because we are in an unkonwn state
+ // TODO: Notify the application that the interface is not set up or Chipdie here because we
+ // are in an unkonwn state
SILABS_LOG("HandleDHCPPolling: failed to get STA netif");
return;
}
@@ -664,7 +686,8 @@
if (status != osOK)
{
SILABS_LOG("WfxPostEvent: failed to post event with status: %d", status);
- // TODO: Handle error, requeue event depending on queue size or notify relevant task, Chipdie, etc.
+ // TODO: Handle error, requeue event depending on queue size or notify relevant task,
+ // Chipdie, etc.
}
}
@@ -673,7 +696,7 @@
// Process event
switch (inEvent.eventType)
{
- case WFX_EVT_STA_CONN:
+ case WFX_EVT_STA_CONN: {
SILABS_LOG("Starting LwIP STA");
wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTED;
ResetDHCPNotificationFlags();
@@ -683,8 +706,9 @@
// of AP connectivity.
// wfx_connected_notify(0, &wfx_rsi.ap_mac); // This
// is independant of IP connectivity.
- break;
- case WFX_EVT_STA_DISCONN:
+ }
+ break;
+ case WFX_EVT_STA_DISCONN: {
// TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something
wfx_rsi.dev_state &=
~(WFX_RSI_ST_STA_READY | WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE);
@@ -697,14 +721,15 @@
wfx_ip_changed_notify(IP_STATUS_FAIL);
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
wfx_ipv6_notify(GET_IPV6_FAIL);
- break;
+ }
+ break;
case WFX_EVT_AP_START:
// TODO: Currently unimplemented
break;
case WFX_EVT_AP_STOP:
// TODO: Currently unimplemented
break;
- case WFX_EVT_SCAN:
+ case WFX_EVT_SCAN: {
#ifdef SL_WFX_CONFIG_SCAN
rsi_rsp_scan_t scan_rsp = { 0 };
int32_t status = rsi_wlan_bgscan_profile(1, &scan_rsp, sizeof(scan_rsp));
@@ -721,10 +746,12 @@
{
scan = &scan_rsp.scan_info[x];
// is it a scan all or target scan
- if (!wfx_rsi.scan_ssid || (wfx_rsi.scan_ssid && strcmp(wfx_rsi.scan_ssid, (char *) scan->ssid) == CMP_SUCCESS))
+ if (wfx_rsi.scan_ssid != NULL &&
+ (strncmp(wfx_rsi.scan_ssid, (char *) scan->ssid, MIN(strlen(wfx_rsi.scan_ssid), sizeof(scan->ssid))) ==
+ CMP_SUCCESS))
{
strncpy(ap.ssid, (char *) scan->ssid, MIN(sizeof(ap.ssid), sizeof(scan->ssid)));
- ap.security = scan->security_mode;
+ ap.security = static_cast<wfx_sec_t>(scan->security_mode);
ap.rssi = (-1) * scan->rssi_val;
configASSERT(sizeof(ap.bssid) >= BSSID_LEN);
configASSERT(sizeof(scan->bssid) >= BSSID_LEN);
@@ -748,22 +775,28 @@
vPortFree(wfx_rsi.scan_ssid);
wfx_rsi.scan_ssid = (char *) 0;
}
- break;
#endif /* SL_WFX_CONFIG_SCAN */
- case WFX_EVT_STA_START_JOIN:
+ }
+ break;
+ case WFX_EVT_STA_START_JOIN: {
// saving the AP related info
wfx_rsi_save_ap_info();
// Joining to the network
wfx_rsi_do_join();
- break;
- case WFX_EVT_STA_DO_DHCP:
+ }
+ break;
+ case WFX_EVT_STA_DO_DHCP: {
StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL);
- break;
- case WFX_EVT_STA_DHCP_DONE:
+ }
+ break;
+ case WFX_EVT_STA_DHCP_DONE: {
CancelDHCPTimer();
- break;
- case WFX_EVT_DHCP_POLL:
+ }
+ break;
+ case WFX_EVT_DHCP_POLL: {
HandleDHCPPolling();
+ }
+ break;
default:
break;
}
@@ -893,7 +926,7 @@
int32_t wfx_rsi_send_data(void * p, uint16_t len)
{
int32_t status;
- register uint8_t * host_desc;
+ uint8_t * host_desc;
rsi_pkt_t * pkt;
pkt = (rsi_pkt_t *) p;
diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.cpp b/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.cpp
deleted file mode 100644
index 8d92c0e..0000000
--- a/examples/platform/silabs/efr32/rs911x/wfx_rsi_host.cpp
+++ /dev/null
@@ -1,429 +0,0 @@
-/*
- *
- * Copyright (c) 2022 Project CHIP Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "em_bus.h"
-#include "em_cmu.h"
-#include "em_gpio.h"
-#include "em_ldma.h"
-#include "em_usart.h"
-#include "sl_status.h"
-
-#include "silabs_utils.h"
-
-#include "FreeRTOS.h"
-#include "event_groups.h"
-#include "task.h"
-
-#include "wfx_host_events.h"
-#include "wfx_rsi.h"
-
-/* wfxRsi Task will use as its stack */
-StackType_t wfxRsiTaskStack[WFX_RSI_TASK_SZ] = { 0 };
-
-/* Structure that will hold the TCB of the wfxRsi Task being created. */
-StaticTask_t wfxRsiTaskBuffer;
-
-/*********************************************************************
- * @fn sl_status_t wfx_wifi_start(void)
- * @brief
- * Called from ConnectivityManagerImpl.cpp - to enable the device
- * Create the RSI task and let it deal with life.
- * @param[in] None
- * @return Returns SL_STATUS_OK if successful,
- * SL_STATUS_FAIL otherwise
- ***********************************************************************/
-sl_status_t wfx_wifi_start(void)
-{
- if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED)
- {
- return SL_STATUS_OK;
- }
- wfx_rsi.dev_state |= WFX_RSI_ST_STARTED;
- /*
- * Create the Wifi driver task
- */
- wfx_rsi.wlan_task = xTaskCreateStatic(wfx_rsi_task, "wfx_rsi", WFX_RSI_TASK_SZ, NULL, WLAN_DRIVER_TASK_PRIORITY,
- wfxRsiTaskStack, &wfxRsiTaskBuffer);
-
- if (NULL == wfx_rsi.wlan_task)
- {
- return SL_STATUS_FAIL;
- }
- return SL_STATUS_OK;
-}
-
-/*********************************************************************
- * @fn void wfx_enable_sta_mode(void)
- * @brief
- * driver enable the STA mode
- * @param[in] None
- * @return None
- ***********************************************************************/
-void wfx_enable_sta_mode(void)
-{
- wfx_rsi.dev_state |= WFX_RSI_ST_STA_MODE;
-}
-
-/*********************************************************************
- * @fn bool wfx_is_sta_mode_enabled(void)
- * @brief
- * driver enabled the STA mode
- * @param[in] None
- * @return mode
- ***********************************************************************/
-bool wfx_is_sta_mode_enabled(void)
-{
- bool mode;
- mode = !!(wfx_rsi.dev_state & WFX_RSI_ST_STA_MODE);
- return mode;
-}
-
-/*********************************************************************
- * @fn wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr)
- * @brief
- * get the wifi mac address
- * @param[in] Interface:
- * @param[in] addr : address
- * @return
- * None
- ***********************************************************************/
-void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr)
-{
- if (addr)
- {
-#ifdef SL_WFX_CONFIG_SOFTAP
- *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac;
-#else
- *addr = wfx_rsi.sta_mac;
-#endif
- }
-}
-
-/*********************************************************************
- * @fn void wfx_set_wifi_provision(wfx_wifi_provision_t *cfg)
- * @brief
- * Driver set the wifi provision
- * @param[in] cfg: wifi configuration
- * @return
- * None
- ***********************************************************************/
-void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg)
-{
- if (cfg)
- {
- wfx_rsi.sec = *cfg;
- wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED;
- }
-}
-
-/*********************************************************************
- * @fn bool wfx_get_wifi_provision(wfx_wifi_provision_t *wifiConfig)
- * @brief
- * Driver get the wifi provision
- * @param[in] wifiConfig: wifi configuration
- * @return return false if successful,
- * true otherwise
- ***********************************************************************/
-bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig)
-{
- if (wifiConfig != NULL)
- {
- if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED)
- {
- *wifiConfig = wfx_rsi.sec;
- return true;
- }
- }
- return false;
-}
-
-/*********************************************************************
- * @fn void wfx_clear_wifi_provision(void)
- * @brief
- * Driver is clear the wifi provision
- * @param[in] None
- * @return None
- ***********************************************************************/
-void wfx_clear_wifi_provision(void)
-{
- memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec));
- wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED;
-}
-
-/*************************************************************************
- * @fn sl_status_t wfx_connect_to_ap(void)
- * @brief
- * Start a JOIN command to the AP - Done by the wfx_rsi task
- * @param[in] None
- * @return returns SL_STATUS_OK if successful,
- * SL_STATUS_INVALID_CONFIGURATION otherwise
- ****************************************************************************/
-sl_status_t wfx_connect_to_ap(void)
-{
- WfxEvent_t event;
- if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED)
- {
- SILABS_LOG("Connecting to access point -> SSID: %s", &wfx_rsi.sec.ssid[0]);
- event.eventType = WFX_EVT_STA_START_JOIN;
- WfxPostEvent(&event);
- }
- else
- {
- SILABS_LOG("Error: access point not provisioned.");
- return SL_STATUS_INVALID_CONFIGURATION;
- }
- return SL_STATUS_OK;
-}
-
-#if SL_ICD_ENABLED
-#if SLI_SI917
-/*********************************************************************
- * @fn sl_status_t wfx_power_save()
- * @brief
- * Implements the power save in sleepy application
- * @param[in] sl_si91x_ble_state : State to set for the BLE
- sl_si91x_wifi_state : State to set for the WiFi
- * @return SL_STATUS_OK if successful,
- * SL_STATUS_FAIL otherwise
- ***********************************************************************/
-sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state)
-{
- return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK);
-}
-#else // For RS9116
-/*********************************************************************
- * @fn sl_status_t wfx_power_save()
- * @brief
- * Implements the power save in sleepy application
- * @param[in] None
- * @return SL_STATUS_OK if successful,
- * SL_STATUS_FAIL otherwise
- ***********************************************************************/
-sl_status_t wfx_power_save()
-{
- return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK);
-}
-#endif /* SLI_SI917 */
-#endif /* SL_ICD_ENABLED */
-
-/*********************************************************************
- * @fn void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
- * @brief
- * Implement the ipv6 setup
- * @param[in] whichif:
- * @return None
- ***********************************************************************/
-void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
-{
- /*
- * TODO: Implement IPV6 setup, currently in wfx_rsi_task()
- * This is hooked with MATTER code.
- */
-}
-
-/*********************************************************************
- * @fn bool wfx_is_sta_connected(void)
- * @brief
- * called fuction when driver is connected to STA
- * @param[in] None
- * @return returns ture if successful,
- * false otherwise
- ***********************************************************************/
-bool wfx_is_sta_connected(void)
-{
- bool status;
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) ? true : false;
- return status;
-}
-
-/*********************************************************************
- * @fn wifi_mode_t wfx_get_wifi_mode()
- * @brief
- * get the wifi mode
- * @param[in] None
- * @return return WIFI_MODE_NULL if successful,
- * WIFI_MODE_STA otherwise
- ***********************************************************************/
-wifi_mode_t wfx_get_wifi_mode()
-{
- if (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY)
- return WIFI_MODE_STA;
- return WIFI_MODE_NULL;
-}
-
-/*********************************************************************
- * @fn sl_status_t wfx_sta_discon(void)
- * @brief
- * called fuction when STA disconnected
- * @param[in] None
- * @return return SL_STATUS_OK if successful,
- * SL_STATUS_FAIL otherwise
- ***********************************************************************/
-sl_status_t wfx_sta_discon(void)
-{
- int32_t status;
- status = wfx_rsi_disconnect();
- wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED;
- return status;
-}
-#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
-/*********************************************************************
- * @fn bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if)
- * @brief
- * called fuction when driver have ipv4 address
- * @param[in] which_if:
- * @return returns ture if successful,
- * false otherwise
- ***********************************************************************/
-bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if)
-{
- bool status = false;
- if (which_if == SL_WFX_STA_INTERFACE)
- {
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) ? true : false;
- }
- else
- {
- status = false; /* TODO */
- }
- return status;
-}
-#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
-
-/*********************************************************************
- * @fn bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if)
- * @brief
- * called fuction when driver have ipv6 address
- * @param[in] which_if:
- * @return returns ture if successful,
- * false otherwise
- ***********************************************************************/
-bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if)
-{
- bool status = false;
- if (which_if == SL_WFX_STA_INTERFACE)
- {
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) ? true : false;
- }
- else
- {
- status = false; /* TODO */
- }
- return status;
-}
-
-/*********************************************************************
- * @fn bool wfx_hw_ready(void)
- * @brief
- * called fuction when driver ready
- * @param[in] None
- * @return returns ture if successful,
- * false otherwise
- ***********************************************************************/
-bool wfx_hw_ready(void)
-{
- return (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) ? true : false;
-}
-
-/*********************************************************************
- * @fn int32_t wfx_get_ap_info(wfx_wifi_scan_result_t *ap)
- * @brief
- * get the access point information
- * @param[in] ap: access point
- * @return
- * access point information
- ***********************************************************************/
-int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap)
-{
- return wfx_rsi_get_ap_info(ap);
-}
-
-/*********************************************************************
- * @fn int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t *extra_info)
- * @brief
- * get the access point extra information
- * @param[in] extra_info:access point extra information
- * @return
- * access point extra information
- ***********************************************************************/
-int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info)
-{
- return wfx_rsi_get_ap_ext(extra_info);
-}
-
-/***************************************************************************
- * @fn int32_t wfx_reset_counts(){
- * @brief
- * get the driver reset count
- * @param[in] None
- * @return
- * reset count
- *****************************************************************************/
-int32_t wfx_reset_counts()
-{
- return wfx_rsi_reset_count();
-}
-
-#ifdef SL_WFX_CONFIG_SCAN
-/*******************************************************************************
- * @fn bool wfx_start_scan(char *ssid, void (*callback)(wfx_wifi_scan_result_t *))
- * @brief
- * called fuction when driver start scaning
- * @param[in] ssid:
- * @return returns ture if successful,
- * false otherwise
- *******************************************************************************/
-bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
-{
- int sz;
- WfxEvent_t event;
- if (wfx_rsi.scan_cb)
- return false; /* Already in progress */
- if (ssid)
- {
- sz = strlen(ssid);
- if ((wfx_rsi.scan_ssid = (char *) pvPortMalloc(sz + 1)) == (char *) 0)
- {
- return false;
- }
- strcpy(wfx_rsi.scan_ssid, ssid);
- }
- wfx_rsi.scan_cb = callback;
-
- event.eventType = WFX_EVT_SCAN;
- WfxPostEvent(&event);
-
- return true;
-}
-
-/***************************************************************************
- * @fn void wfx_cancel_scan(void)
- * @brief
- * called function when driver cancel scaning
- * @param[in] None
- * @return
- * None
- *****************************************************************************/
-void wfx_cancel_scan(void)
-{
- /* Not possible */
-}
-#endif /* SL_WFX_CONFIG_SCAN */
diff --git a/examples/platform/silabs/uart.cpp b/examples/platform/silabs/uart.cpp
index 7d6dad9..a05dd70 100644
--- a/examples/platform/silabs/uart.cpp
+++ b/examples/platform/silabs/uart.cpp
@@ -138,7 +138,13 @@
.cb_size = osThreadCbSize,
.stack_mem = uartStack,
.stack_size = kUartTaskSize,
- .priority = osPriorityRealtime };
+#if SLI_SI91X_MCU_INTERFACE
+ // Reducing the priority of the UART task to avoid priority inversion
+ .priority = osPriorityNormal
+#else
+ .priority = osPriorityRealtime
+#endif // SLI_SI91X_MCU_INTERFACE
+};
typedef struct
{
diff --git a/examples/platform/silabs/wfx_rsi.h b/examples/platform/silabs/wfx_rsi.h
index 502dd1a..5e7358e 100644
--- a/examples/platform/silabs/wfx_rsi.h
+++ b/examples/platform/silabs/wfx_rsi.h
@@ -17,7 +17,9 @@
#pragma once
#include <app/icd/server/ICDServerConfig.h>
+#include <cmsis_os2.h>
#include <event_groups.h>
+#include <sl_cmsis_os2_common.h>
#include <wfx_host_events.h>
#ifndef RSI_BLE_ENABLE
@@ -28,10 +30,8 @@
* Interface to RSI Sapis
*/
-#define WFX_RSI_WLAN_TASK_SZ (1024 + 512 + 256) /* Stack for the WLAN task */
-#define WFX_RSI_TASK_SZ (1024 + 1024) /* Stack for the WFX/RSI task */
-#define WFX_RSI_BUF_SZ (1024 * 10) /* May need tweak */
-// TODO: Default values are usually in minutes, but this is in ms. Confirm if this is correct
+#define WFX_RSI_WLAN_TASK_SZ (1024 + 512 + 256) /* Stack for the WLAN task */ // TODO: For rs9116
+#define WFX_RSI_BUF_SZ (1024 * 10)
#define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */
#define WFX_RSI_NUM_TIMERS (2) /* Number of RSI timers to alloc */
@@ -71,14 +71,6 @@
typedef struct wfx_rsi_s
{
- // TODO: Change tp WfxEventType_e once the event queue is implemented
- EventGroupHandle_t events;
- TaskHandle_t drv_task;
- TaskHandle_t wlan_task;
- TaskHandle_t init_task;
-#ifdef RSI_BLE_ENABLE
- TaskHandle_t ble_task;
-#endif
uint16_t dev_state;
uint16_t ap_chan; /* The chan our STA is using */
wfx_wifi_provision_t sec;
diff --git a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp
similarity index 89%
rename from examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp
rename to examples/platform/silabs/wifi/wfx_rsi_host.cpp
index 83c3a95..921ec82 100644
--- a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp
+++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp
@@ -28,11 +28,20 @@
#include "wfx_host_events.h"
#include "wfx_rsi.h"
-/* wfxRsi Task will use as its stack */
-StackType_t wfxRsiTaskStack[WFX_RSI_TASK_SZ] = { 0 };
+#include <platform/CHIPDeviceLayer.h>
-/* Structure that will hold the TCB of the wfxRsi Task being created. */
-StaticTask_t wfxRsiTaskBuffer;
+// Thread for the WLAN RSI
+static osThreadId_t sWlanThread;
+constexpr uint32_t kWlanTaskSize = 2048;
+static uint8_t wlanStack[kWlanTaskSize];
+static osThread_t sWlanTaskControlBlock;
+constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi",
+ .attr_bits = osThreadDetached,
+ .cb_mem = &sWlanTaskControlBlock,
+ .cb_size = osThreadCbSize,
+ .stack_mem = wlanStack,
+ .stack_size = kWlanTaskSize,
+ .priority = osPriorityAboveNormal7 };
/*********************************************************************
* @fn sl_status_t wfx_wifi_start(void)
@@ -47,22 +56,20 @@
{
if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED)
{
- SILABS_LOG("%s: already started.", __func__);
return SL_STATUS_OK;
}
+
wfx_rsi.dev_state |= WFX_RSI_ST_STARTED;
SILABS_LOG("%s: starting..", __func__);
+
/*
* Create the Wifi driver task
*/
- wfx_rsi.wlan_task = xTaskCreateStatic(wfx_rsi_task, "wfx_rsi", WFX_RSI_TASK_SZ, NULL, WLAN_DRIVER_TASK_PRIORITY,
- wfxRsiTaskStack, &wfxRsiTaskBuffer);
+ // Creating a Wi-Fi driver thread
+ sWlanThread = osThreadNew(wfx_rsi_task, NULL, &kWlanTaskAttr);
- if (NULL == wfx_rsi.wlan_task)
- {
- SILABS_LOG("%s: error: failed to create task.", __func__);
- return SL_STATUS_FAIL;
- }
+ VerifyOrReturnError(sWlanThread != NULL, SL_STATUS_FAIL);
+
return SL_STATUS_OK;
}
@@ -191,6 +198,7 @@
}
#if SL_ICD_ENABLED
+#if SLI_SI917
/*********************************************************************
* @fn sl_status_t wfx_power_save()
* @brief
@@ -202,12 +210,22 @@
***********************************************************************/
sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state)
{
- if (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) != SL_STATUS_OK)
- {
- return SL_STATUS_FAIL;
- }
- return SL_STATUS_OK;
+ return (wfx_rsi_power_save(sl_si91x_ble_state, sl_si91x_wifi_state) ? SL_STATUS_FAIL : SL_STATUS_OK);
}
+#else // For RS9116
+/*********************************************************************
+ * @fn sl_status_t wfx_power_save()
+ * @brief
+ * Implements the power save in sleepy application
+ * @param[in] None
+ * @return SL_STATUS_OK if successful,
+ * SL_STATUS_FAIL otherwise
+ ***********************************************************************/
+sl_status_t wfx_power_save()
+{
+ return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK);
+}
+#endif /* SLI_SI917 */
#endif /* SL_ICD_ENABLED */
/*********************************************************************
diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h
index 86d1b05..4ff6d9d 100644
--- a/src/platform/silabs/BLEManagerImpl.h
+++ b/src/platform/silabs/BLEManagerImpl.h
@@ -196,7 +196,7 @@
void CancelBleAdvTimeoutTimer(void);
CHIPoBLEConState * GetConnectionState(uint8_t conId, bool allocate = false);
static void DriveBLEState(intptr_t arg);
- static void BleAdvTimeoutHandler(TimerHandle_t xTimer);
+ static void BleAdvTimeoutHandler(void * arg);
uint8_t GetTimerHandle(uint8_t connectionHandle, bool allocate);
#if (SLI_SI91X_ENABLE_BLE || RSI_BLE_ENABLE)
diff --git a/src/platform/silabs/efr32/BLEManagerImpl.cpp b/src/platform/silabs/efr32/BLEManagerImpl.cpp
index 2fcceef..e29e34e 100644
--- a/src/platform/silabs/efr32/BLEManagerImpl.cpp
+++ b/src/platform/silabs/efr32/BLEManagerImpl.cpp
@@ -101,7 +101,7 @@
#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value
#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value
-TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
+osTimerId_t sbleAdvTimeoutTimer; // SW timer
const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 };
@@ -122,13 +122,8 @@
memset(mIndConfId, kUnusedIndex, sizeof(mIndConfId));
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
- // Create FreeRTOS sw timer for BLE timeouts and interval change.
- sbleAdvTimeoutTimer = xTimerCreate("BleAdvTimer", // Just a text name, not used by the RTOS kernel
- pdMS_TO_TICKS(1), // == default timer period
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = ble obj context
- BleAdvTimeoutHandler // timer callback handler
- );
+ // SW timer for BLE timeouts and interval change.
+ sbleAdvTimeoutTimer = osTimerNew(BleAdvTimeoutHandler, osTimerOnce, NULL, NULL);
mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
@@ -991,7 +986,7 @@
return freeIndex;
}
-void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
+void BLEManagerImpl::BleAdvTimeoutHandler(void * arg)
{
if (BLEMgrImpl().mFlags.Has(Flags::kFastAdvertisingEnabled))
{
@@ -1016,7 +1011,7 @@
void BLEManagerImpl::CancelBleAdvTimeoutTimer(void)
{
- if (xTimerStop(sbleAdvTimeoutTimer, pdMS_TO_TICKS(0)) == pdFAIL)
+ if (osTimerStop(sbleAdvTimeoutTimer) != osOK)
{
ChipLogError(DeviceLayer, "Failed to stop BledAdv timeout timer");
}
@@ -1024,15 +1019,7 @@
void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
{
- if (xTimerIsTimerActive(sbleAdvTimeoutTimer))
- {
- CancelBleAdvTimeoutTimer();
- }
-
- // timer is not active, change its period to required value (== restart).
- // FreeRTOS- Block for a maximum of 100 ticks if the change period command
- // cannot immediately be sent to the timer command queue.
- if (xTimerChangePeriod(sbleAdvTimeoutTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS)
+ if (osTimerStart(sbleAdvTimeoutTimer, pdMS_TO_TICKS(aTimeoutInMs)) != osOK)
{
ChipLogError(DeviceLayer, "Failed to start BledAdv timeout timer");
}
diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp
index 75853c8..6fea061 100644
--- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp
+++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp
@@ -71,13 +71,22 @@
extern sl_wfx_msg_t event_msg;
-StaticTask_t rsiBLETaskStruct;
-
osSemaphoreId_t sl_ble_event_sem;
osSemaphoreId_t sl_rs_ble_init_sem;
-/* wfxRsi Task will use as its stack */
-StackType_t wfxBLETaskStack[WFX_RSI_TASK_SZ] = { 0 };
+osTimerId_t sbleAdvTimeoutTimer;
+
+static osThreadId_t sBleThread;
+constexpr uint32_t kBleTaskSize = 2048;
+static uint8_t bleStack[kBleTaskSize];
+static osThread_t sBleTaskControlBlock;
+constexpr osThreadAttr_t kBleTaskAttr = { .name = "rsi_ble",
+ .attr_bits = osThreadDetached,
+ .cb_mem = &sBleTaskControlBlock,
+ .cb_size = osThreadCbSize,
+ .stack_mem = bleStack,
+ .stack_size = kBleTaskSize,
+ .priority = osPriorityHigh };
using namespace ::chip;
using namespace ::chip::Ble;
@@ -110,7 +119,7 @@
chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
}
-void sl_ble_event_handling_task(void)
+void sl_ble_event_handling_task(void * args)
{
int32_t event_id;
@@ -236,8 +245,6 @@
#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value
#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value
-TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
-
const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00 };
const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6, 0xFF };
@@ -253,13 +260,9 @@
sl_rs_ble_init_sem = osSemaphoreNew(1, 0, NULL);
sl_ble_event_sem = osSemaphoreNew(1, 0, NULL);
- wfx_rsi.ble_task = xTaskCreateStatic((TaskFunction_t) sl_ble_event_handling_task, "rsi_ble", WFX_RSI_TASK_SZ, NULL,
- BLE_DRIVER_TASK_PRIORITY, wfxBLETaskStack, &rsiBLETaskStruct);
+ sBleThread = osThreadNew(sl_ble_event_handling_task, NULL, &kBleTaskAttr);
- if (wfx_rsi.ble_task == NULL)
- {
- ChipLogError(DeviceLayer, "%s: error: failed to create ble task.", __func__);
- }
+ VerifyOrReturnError(sBleThread != nullptr, CHIP_ERROR_INCORRECT_STATE);
// Initialize the CHIP BleLayer.
err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer());
@@ -269,13 +272,8 @@
memset(mIndConfId, kUnusedIndex, sizeof(mIndConfId));
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
- // Create FreeRTOS sw timer for BLE timeouts and interval change.
- sbleAdvTimeoutTimer = xTimerCreate("BleAdvTimer", // Just a text name, not used by the RTOS kernel
- pdMS_TO_TICKS(BLE_DEFAULT_TIMER_PERIOD_MS), // == default timer period
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = ble obj context
- BleAdvTimeoutHandler // timer callback handler
- );
+ // SW timer for BLE timeouts and interval change.
+ sbleAdvTimeoutTimer = osTimerNew(BleAdvTimeoutHandler, osTimerOnce, NULL, NULL);
mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
@@ -1070,7 +1068,7 @@
return freeIndex;
}
-void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
+void BLEManagerImpl::BleAdvTimeoutHandler(void * arg)
{
if (BLEMgrImpl().mFlags.Has(Flags::kFastAdvertisingEnabled))
{
@@ -1081,7 +1079,7 @@
void BLEManagerImpl::CancelBleAdvTimeoutTimer(void)
{
- if (xTimerStop(sbleAdvTimeoutTimer, pdMS_TO_TICKS(0)) == pdFAIL)
+ if (osTimerStop(sbleAdvTimeoutTimer) != osOK)
{
ChipLogError(DeviceLayer, "Failed to stop BledAdv timeout timer");
}
@@ -1089,15 +1087,7 @@
void BLEManagerImpl::StartBleAdvTimeoutTimer(uint32_t aTimeoutInMs)
{
- if (xTimerIsTimerActive(sbleAdvTimeoutTimer))
- {
- CancelBleAdvTimeoutTimer();
- }
-
- // timer is not active, change its period to required value (== restart).
- // FreeRTOS- Block for a maximum of 100 ticks if the change period command
- // cannot immediately be sent to the timer command queue.
- if (xTimerChangePeriod(sbleAdvTimeoutTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS)
+ if (osTimerStart(sbleAdvTimeoutTimer, pdMS_TO_TICKS(aTimeoutInMs)) != osOK)
{
ChipLogError(DeviceLayer, "Failed to start BledAdv timeout timer");
}