Skip to content

Commit

Permalink
drivers: bluetooth and wifi: siwx917: Introducing NWP init
Browse files Browse the repository at this point in the history
WiFi and Bluetooth HCI driver was changed to use the nwp_init component.
This component initializes the NWP
based on the project configuration (BLE and/or WiFi).
Later on the component can be modified
to support common flash mode read/write/erase without BLE and WiFi.

Coprocessor stack moved to a more suitable place (nwp_init).

WiFi and Bluetooth advertising sample apps were tried to verify the change.

Signed-off-by: Tibor Laczko <[email protected]>
  • Loading branch information
silabs-TiborL committed Sep 26, 2024
1 parent 34597f8 commit 383cd8f
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 122 deletions.
29 changes: 1 addition & 28 deletions drivers/bluetooth/hci/Kconfig.siwx917
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,6 @@ config BT_SIWX917
bool "Silabs SiWx917 Bluetooth interface"
default y
depends on DT_HAS_SILABS_SIWX917_BT_HCI_ENABLED
select CMSIS_RTOS_V2
select POLL
select DYNAMIC_THREAD
select THREAD_NAME
select THREAD_STACK_INFO
select THREAD_MONITOR
select INIT_STACKS
select WISECONNECT_NETWORK_STACK
help
Use Silicon Labs Wiseconnect 3.x Bluetooth library to connect to the controller.

if BT_SIWX917

# WiseConnect create threads with realtime priority. Default (10kHz) clock tick
# prevent proper use of the system with these threads.
config SYS_CLOCK_TICKS_PER_SEC
default 1024

config NUM_PREEMPT_PRIORITIES
default 56

config CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT
default 2

config CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE
default 1024

config CMSIS_V2_THREAD_MAX_STACK_SIZE
default 2048

endif #BT_SIWX917
53 changes: 2 additions & 51 deletions drivers/bluetooth/hci/siwx917_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_hci_driver_siwg917);

#include "sl_wifi.h"
#include "sl_wifi_callback_framework.h"
#include "rsi_ble_common_config.h"
#include "rsi_ble.h"

static void bt_siwg917_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf);
Expand All @@ -23,54 +20,11 @@ struct hci_data {
rsi_data_packet_t rsi_data_packet;
};

static const sl_wifi_device_configuration_t network_config = {
.boot_option = LOAD_NWP_FW,
.mac_address = NULL,
.band = SL_SI91X_WIFI_BAND_2_4GHZ,
.region_code = DEFAULT_REGION,
.boot_config = {
.oper_mode = SL_SI91X_CLIENT_MODE,
.coex_mode = SL_SI91X_BLE_MODE,
.feature_bit_map =
SL_SI91X_FEAT_SECURITY_OPEN |
SL_SI91X_FEAT_WPS_DISABLE,
.tcp_ip_feature_bit_map =
SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT |
SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID,
.ext_tcp_ip_feature_bit_map = SL_SI91X_CONFIG_FEAT_EXTENSION_VALID,
.custom_feature_bit_map = SL_SI91X_CUSTOM_FEAT_EXTENSION_VALID,
.ext_custom_feature_bit_map =
MEMORY_CONFIG |
SL_SI91X_EXT_FEAT_XTAL_CLK |
SL_SI91X_EXT_FEAT_FRONT_END_SWITCH_PINS_ULP_GPIO_4_5_0 |
SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE,
.config_feature_bit_map = SL_SI91X_ENABLE_ENHANCED_MAX_PSP,
.bt_feature_bit_map =
SL_SI91X_BT_RF_TYPE |
SL_SI91X_ENABLE_BLE_PROTOCOL,
.ble_feature_bit_map =
SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) |
SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) |
SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) |
SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC) |
SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) |
SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) |
SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE |
SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENSION_VALID,
.ble_ext_feature_bit_map =
SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) |
SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES) |
SL_SI91X_BLE_ENABLE_ADV_EXTN |
SL_SI91X_BLE_AE_MAX_ADV_SETS(RSI_BLE_AE_MAX_ADV_SETS),
}};

static int bt_siwg917_open(const struct device *dev, bt_hci_recv_t recv)
{
struct hci_data *hci = dev->data;

int status = sl_wifi_init(&network_config, NULL, sl_wifi_default_event_handler);
status |= rsi_ble_enhanced_gap_extended_register_callbacks(RSI_BLE_ON_RCP_EVENT,
(void *)bt_siwg917_resp_rcvd);
int status = rsi_ble_enhanced_gap_extended_register_callbacks(RSI_BLE_ON_RCP_EVENT,
(void *)bt_siwg917_resp_rcvd);

if (!status) {
hci->recv = recv;
Expand Down Expand Up @@ -162,6 +116,3 @@ static const struct bt_hci_driver_api drv = {

/* Only one instance supported right now */
HCI_DEVICE_INIT(0)

/* IRQn 74 is used for communication with co-processor */
Z_ISR_DECLARE(74, ISR_FLAG_DIRECT, IRQ074_Handler, 0);
26 changes: 1 addition & 25 deletions drivers/wifi/siwx917/Kconfig.siwx917
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,15 @@ config WIFI_SIWX917
bool "Silabs SiWx917 SoC series WiFi driver"
default y
depends on DT_HAS_SILABS_SIWX917_WIFI_ENABLED
select WISECONNECT_NETWORK_STACK
select EVENTS
select WIFI_OFFLOAD
select NET_L2_WIFI_MGMT
select CMSIS_RTOS_V2
# Also select CMSIS-RTOS v2 dependencies
select POLL
select DYNAMIC_THREAD
select THREAD_NAME
select THREAD_STACK_INFO
select THREAD_MONITOR
select INIT_STACKS
help
Enable WiFi driver for the Silabs SiWx917 SoC series.

if WIFI_SIWX917

# WiseConnect create threads with realtime priority. Default (10kHz) clock tick
# prevent proper use of the system with these threads.
config SYS_CLOCK_TICKS_PER_SEC
default 1024

config NUM_PREEMPT_PRIORITIES
default 56

config CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT
default 2

config CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE
default 1024

config CMSIS_V2_THREAD_MAX_STACK_SIZE
default 2048

config NET_TCP_WORKQ_STACK_SIZE
default 2048

Expand Down
10 changes: 5 additions & 5 deletions drivers/wifi/siwx917/siwx917_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sl_wifi.h"
#include "sl_net_si91x.h"
#include "sl_net.h"
#include "sl_net_default_values.h"

BUILD_ASSERT(NUMBER_OF_BSD_SOCKETS < sizeof(uint32_t) * 8);
BUILD_ASSERT(NUMBER_OF_BSD_SOCKETS < SIZEOF_FIELD(sl_si91x_fd_set, __fds_bits) * 8);
Expand Down Expand Up @@ -632,9 +633,11 @@ static void siwx917_iface_init(struct net_if *iface)
sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, &mac_addr);
net_if_set_link_addr(iface, mac_addr.octet, sizeof(mac_addr.octet), NET_LINK_ETHERNET);

status = sl_net_init(SL_NET_WIFI_CLIENT_INTERFACE, NULL, NULL, NULL);
status = sl_net_set_profile(SL_NET_WIFI_CLIENT_INTERFACE,
SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID,
&DEFAULT_WIFI_CLIENT_PROFILE);
if (status) {
LOG_ERR("sl_net_init(): %#04x", status);
LOG_ERR("sl_net_set_profile(): %#04x", status);
return;
}
sidev->state = WIFI_STATE_INACTIVE;
Expand Down Expand Up @@ -666,6 +669,3 @@ static const struct net_wifi_mgmt_offload siwx917_api = {
static struct siwx917_dev siwx917_dev;
NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, siwx917_dev_init, NULL, &siwx917_dev, NULL,
CONFIG_WIFI_INIT_PRIORITY, &siwx917_api, NET_ETH_MTU);

/* IRQn 74 is used for communication with co-processor */
Z_ISR_DECLARE(74, ISR_FLAG_DIRECT, IRQ074_Handler, 0);
1 change: 1 addition & 0 deletions soc/silabs/silabs_siwx917/siwg917/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
zephyr_include_directories(.)

zephyr_sources_ifdef(CONFIG_SOC_SERIES_SIWG917 soc.c)
zephyr_sources_ifdef(CONFIG_WISECONNECT_NETWORK_STACK nwp_init.c)

set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "")
31 changes: 31 additions & 0 deletions soc/silabs/silabs_siwx917/siwg917/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,34 @@ config SIWX917_FLASH_MODE_DUAL
bool "Dual Flash"

endchoice

config WISECONNECT_NETWORK_STACK
bool
select CMSIS_RTOS_V2
select POLL
select DYNAMIC_THREAD
select THREAD_NAME
select THREAD_STACK_INFO
select THREAD_MONITOR
select INIT_STACKS

if WISECONNECT_NETWORK_STACK

# WiseConnect create threads with realtime priority. Default (10kHz) clock tick
# prevent proper use of the system with these threads.
config SYS_CLOCK_TICKS_PER_SEC
default 1024

config NUM_PREEMPT_PRIORITIES
default 56

config CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT
default 2

config CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE
default 1024

config CMSIS_V2_THREAD_MAX_STACK_SIZE
default 2048

endif #WISECONNECT_NETWORK_STACK
96 changes: 96 additions & 0 deletions soc/silabs/silabs_siwx917/siwg917/nwp_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2024 Silicon Laboratories Inc.
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>

#include "sl_wifi.h"
#include "sl_wifi_callback_framework.h"
#if IS_ENABLED(CONFIG_BT_SIWX917)
#include "rsi_ble_common_config.h"
#endif

/* TODO SILABS ZEPHYR: Check how to add constants to the vector table */
#define NWP_ADD_TO_VECTOR_TABLE(irq, flags, expression, arg, name) \
static Z_DECL_ALIGN(struct _isr_list) Z_GENERIC_SECTION(.intList) \
__used __isr_##name = {irq, flags, expression, arg}

#if IS_ENABLED(CONFIG_WIFI_SIWX917) && IS_ENABLED(CONFIG_BT_SIWX917)
#define NWP_INIT_COEX_MODE SL_SI91X_WLAN_BLE_MODE
#elif IS_ENABLED(CONFIG_WIFI_SIWX917)
#define NWP_INIT_COEX_MODE SL_SI91X_WLAN_ONLY_MODE
#elif IS_ENABLED(CONFIG_BT_SIWX917)
#define NWP_INIT_COEX_MODE SL_SI91X_BLE_MODE
#else
#error "Not supported configuration!"
#endif

static int silabs_siwx917_nwp_init(void)
{
sl_wifi_device_configuration_t network_config = {
.boot_option = LOAD_NWP_FW,
.mac_address = NULL,
.band = SL_SI91X_WIFI_BAND_2_4GHZ,
.region_code = DEFAULT_REGION,
.boot_config = {
.oper_mode = SL_SI91X_CLIENT_MODE,
.coex_mode = NWP_INIT_COEX_MODE,
.feature_bit_map = SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_WPS_DISABLE,
.tcp_ip_feature_bit_map = SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID,
.ext_tcp_ip_feature_bit_map = SL_SI91X_CONFIG_FEAT_EXTENSION_VALID,
.config_feature_bit_map = SL_SI91X_ENABLE_ENHANCED_MAX_PSP,
.custom_feature_bit_map = SL_SI91X_CUSTOM_FEAT_EXTENSION_VALID,
.ext_custom_feature_bit_map =
MEMORY_CONFIG | SL_SI91X_EXT_FEAT_XTAL_CLK |
SL_SI91X_EXT_FEAT_FRONT_END_SWITCH_PINS_ULP_GPIO_4_5_0,
}};
sl_si91x_boot_configuration_t *cfg = &network_config.boot_config;

#if IS_ENABLED(CONFIG_WIFI_SIWX917)
cfg->tcp_ip_feature_bit_map |=
#if IS_ENABLED(CONFIG_NET_IPV6)
SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT | SL_SI91X_TCP_IP_FEAT_IPV6 |
#endif
SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_DNS_CLIENT |
SL_SI91X_TCP_IP_FEAT_SSL | SL_SI91X_TCP_IP_FEAT_MDNSD | SL_SI91X_TCP_IP_FEAT_ICMP;
cfg->ext_tcp_ip_feature_bit_map |=
SL_SI91X_EXT_TCP_IP_WINDOW_SCALING | SL_SI91X_EXT_TCP_IP_TOTAL_SELECTS(10);
#endif

#if IS_ENABLED(CONFIG_BT_SIWX917)
cfg->ext_custom_feature_bit_map |= SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE;
cfg->bt_feature_bit_map |= SL_SI91X_BT_RF_TYPE | SL_SI91X_ENABLE_BLE_PROTOCOL;
cfg->ble_feature_bit_map |= SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) |
SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) |
SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) |
SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC) |
SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) |
SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) |
SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE |
SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENSION_VALID;
cfg->ble_ext_feature_bit_map |= SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) |
SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES) |
SL_SI91X_BLE_ENABLE_ADV_EXTN |
SL_SI91X_BLE_AE_MAX_ADV_SETS(RSI_BLE_AE_MAX_ADV_SETS);
#endif

return sl_wifi_init(&network_config, NULL, sl_wifi_default_event_handler);
}
SYS_INIT(silabs_siwx917_nwp_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

/* IRQn 74 is used for communication with co-processor */
Z_ISR_DECLARE(74, ISR_FLAG_DIRECT, IRQ074_Handler, 0);

/* Co-processor will use value stored in IVT to store its stack.
*
* FIXME: We can't use Z_ISR_DECLARE() to declare this entry
* FIXME: Allow to configure size of buffer
*/
static uint8_t __aligned(8) nwp_stack[10 * 1024];
static Z_DECL_ALIGN(struct _isr_list) Z_GENERIC_SECTION(.intList)
__used __isr_siwx917_coprocessor_stack_irq = {
.irq = 30,
.flags = ISR_FLAG_DIRECT,
.func = &nwp_stack[sizeof(nwp_stack) - 1],
};
13 changes: 0 additions & 13 deletions soc/silabs/silabs_siwx917/siwg917/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ int silabs_siwx917_init(void)
}
SYS_INIT(silabs_siwx917_init, PRE_KERNEL_1, 0);

/* Co-processor will use value stored in IVT to store its stack.
*
* FIXME: We can't use Z_ISR_DECLARE() to declare this entry
* FIXME: Allow to configure size of buffer
*/
uint8_t __aligned(4) siwx917_coprocessor_stack[10 * 1024];
static Z_DECL_ALIGN(struct _isr_list) Z_GENERIC_SECTION(.intList)
__used __isr_siwx917_coprocessor_stack_irq = {
.irq = 30,
.flags = ISR_FLAG_DIRECT,
.func = siwx917_coprocessor_stack + sizeof(siwx917_coprocessor_stack),
};

/* SiWx917's bootloader requires IRQn 32 to hold payload's entry point address. */
extern void z_arm_reset(void);
Z_ISR_DECLARE(32, ISR_FLAG_DIRECT, z_arm_reset, 0);

0 comments on commit 383cd8f

Please sign in to comment.