From 6ad01e7218ca2c47f8cd94b7ee8b0228e82cbde3 Mon Sep 17 00:00:00 2001 From: Tibor Laczko Date: Thu, 19 Sep 2024 13:27:08 +0200 Subject: [PATCH] drivers: bluetooth: siwx917: Add Bluetooth HCI driver PR finding fixes Lower tickrate because of timeout errors --- .github/workflows/build.yml | 1 + .github/workflows/upstream-build.yml | 1 + .../siwx917_rb4338a/siwx917_rb4338a.dts | 5 + .../siwx917_rb4338a/siwx917_rb4338a.yaml | 1 + drivers/CMakeLists.txt | 1 + drivers/bluetooth/CMakeLists.txt | 4 + drivers/bluetooth/Kconfig | 8 ++ drivers/bluetooth/hci/CMakeLists.txt | 4 + drivers/bluetooth/hci/Kconfig.siwx917 | 10 ++ drivers/bluetooth/hci/siwx917_hci.c | 118 ++++++++++++++++++ drivers/wifi/siwx917/Kconfig.siwx917 | 21 +--- drivers/wifi/siwx917/siwx917_wifi.c | 10 +- dts/arm/silabs/siwg917.dtsi | 5 + .../bluetooth/silabs,siwx917-bt-hci.yaml | 13 ++ .../silabs_siwx917/siwg917/CMakeLists.txt | 1 + soc/silabs/silabs_siwx917/siwg917/Kconfig.soc | 31 +++++ soc/silabs/silabs_siwx917/siwg917/nwp_init.c | 118 ++++++++++++++++++ soc/silabs/silabs_siwx917/siwg917/soc.c | 13 -- west.yml | 2 +- 19 files changed, 328 insertions(+), 39 deletions(-) create mode 100644 drivers/bluetooth/CMakeLists.txt create mode 100644 drivers/bluetooth/Kconfig create mode 100644 drivers/bluetooth/hci/CMakeLists.txt create mode 100644 drivers/bluetooth/hci/Kconfig.siwx917 create mode 100644 drivers/bluetooth/hci/siwx917_hci.c create mode 100644 dts/bindings/bluetooth/silabs,siwx917-bt-hci.yaml create mode 100644 soc/silabs/silabs_siwx917/siwg917/nwp_init.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3fe9c14..eb0f464 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,3 +45,4 @@ jobs: fi west twister --test sample.basic.helloworld -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS west twister --test sample.net.wifi -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS + west twister -K --test sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS diff --git a/.github/workflows/upstream-build.yml b/.github/workflows/upstream-build.yml index fb49d13..35d0929 100644 --- a/.github/workflows/upstream-build.yml +++ b/.github/workflows/upstream-build.yml @@ -58,3 +58,4 @@ jobs: fi west twister -T ../zephyr/samples -s sample.basic.helloworld -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS west twister -T ../zephyr/samples -s sample.net.wifi -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS + west twister -K -T ../zephyr/samples -s sample.bluetooth.peripheral_hr -p siwx917_rb4338a -v --inline-logs $EXTRA_TWISTER_FLAGS diff --git a/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.dts b/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.dts index b50d750..5b24c5f 100644 --- a/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.dts +++ b/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.dts @@ -20,6 +20,7 @@ zephyr,flash = &flash0; zephyr,console = &ulpuart0; zephyr,shell-uart = &ulpuart0; + zephyr,bt-hci = &bt_hci_silabs_siwx917; }; aliases { @@ -58,6 +59,10 @@ status = "okay"; }; +&bt_hci_silabs_siwx917 { + status = "okay"; +}; + &ulpuart0 { status = "okay"; pinctrl-0 = <&ulpuart0_default>; diff --git a/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.yaml b/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.yaml index 45ea1e5..d589c17 100644 --- a/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.yaml +++ b/boards/silabs/radio_boards/siwx917_rb4338a/siwx917_rb4338a.yaml @@ -11,4 +11,5 @@ toolchain: supported: - gpio - i2c + - bluetooth vendor: silabs diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 90b743b..1e2076c 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright (c) 2024 Silicon Laboratories Inc. # SPDX-License-Identifier: Apache-2.0 +add_subdirectory(bluetooth) add_subdirectory(gpio) add_subdirectory(pinctrl) add_subdirectory(wifi) diff --git a/drivers/bluetooth/CMakeLists.txt b/drivers/bluetooth/CMakeLists.txt new file mode 100644 index 0000000..054016a --- /dev/null +++ b/drivers/bluetooth/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(hci) diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig new file mode 100644 index 0000000..fa0e433 --- /dev/null +++ b/drivers/bluetooth/Kconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +if BT_HCI + +rsource "hci/Kconfig.siwx917" + +endif diff --git a/drivers/bluetooth/hci/CMakeLists.txt b/drivers/bluetooth/hci/CMakeLists.txt new file mode 100644 index 0000000..5f5ff38 --- /dev/null +++ b/drivers/bluetooth/hci/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library_sources_ifdef(CONFIG_BT_SIWX917 siwx917_hci.c) diff --git a/drivers/bluetooth/hci/Kconfig.siwx917 b/drivers/bluetooth/hci/Kconfig.siwx917 new file mode 100644 index 0000000..4ef7971 --- /dev/null +++ b/drivers/bluetooth/hci/Kconfig.siwx917 @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Silicon Laboratories Inc. +# SPDX-License-Identifier: Apache-2.0 + +config BT_SIWX917 + bool "Silabs SiWx917 Bluetooth interface" + default y + depends on DT_HAS_SILABS_SIWX917_BT_HCI_ENABLED + select SIWX917_NWP_NETWORK_STACK + help + Use Silicon Labs Wiseconnect 3.x Bluetooth library to connect to the controller. diff --git a/drivers/bluetooth/hci/siwx917_hci.c b/drivers/bluetooth/hci/siwx917_hci.c new file mode 100644 index 0000000..e2e3675 --- /dev/null +++ b/drivers/bluetooth/hci/siwx917_hci.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 Silicon Laboratories Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#define DT_DRV_COMPAT silabs_siwx917_bt_hci +#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL +#include +LOG_MODULE_REGISTER(bt_hci_driver_siwg917); + +#include "rsi_ble.h" + +static void bt_siwg917_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf); + +struct hci_data { + bt_hci_recv_t recv; + rsi_data_packet_t rsi_data_packet; +}; + +static int bt_siwg917_open(const struct device *dev, bt_hci_recv_t recv) +{ + struct hci_data *hci = dev->data; + int status = rsi_ble_enhanced_gap_extended_register_callbacks(RSI_BLE_ON_RCP_EVENT, + (void *)bt_siwg917_resp_rcvd); + + if (!status) { + hci->recv = recv; + } + return status ? -EIO : 0; +} + +static int bt_siwg917_send(const struct device *dev, struct net_buf *buf) +{ + struct hci_data *hci = dev->data; + int sc = -EOVERFLOW; + uint8_t packet_type = BT_HCI_H4_NONE; + + switch (bt_buf_get_type(buf)) { + case BT_BUF_ACL_OUT: + packet_type = BT_HCI_H4_ACL; + break; + case BT_BUF_CMD: + packet_type = BT_HCI_H4_CMD; + break; + default: + sc = -EINVAL; + break; + } + + if ((packet_type != BT_HCI_H4_NONE) && (buf->len < sizeof(hci->rsi_data_packet.data))) { + net_buf_push_u8(buf, packet_type); + memcpy(&hci->rsi_data_packet, buf->data, buf->len); + sc = rsi_bt_driver_send_cmd(RSI_BLE_REQ_HCI_RAW, &hci->rsi_data_packet, NULL); + /* TODO SILABS ZEPHYR Convert to errno. A common function from rsi/sl_status should + * be introduced + */ + if (sc) { + LOG_ERR("BT command send failure: %d", sc); + sc = -EIO; + } + } + net_buf_unref(buf); + return sc; +} + +static void bt_siwg917_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf) +{ + const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); + struct hci_data *hci = dev->data; + uint8_t packet_type = BT_HCI_H4_NONE; + size_t len = 0; + struct net_buf *buf = NULL; + + /* TODO SILABS ZEPHYR This horror expression is from the WiseConnect from the HCI example... + * No workaround have been found until now. + */ + memcpy(&packet_type, (resp_buf->data - 12), 1); + switch (packet_type) { + case BT_HCI_H4_EVT: { + struct bt_hci_evt_hdr *hdr = (void *)resp_buf->data; + + len = hdr->len + sizeof(*hdr); + buf = bt_buf_get_evt(hdr->evt, false, K_FOREVER); + break; + } + case BT_HCI_H4_ACL: { + struct bt_hci_acl_hdr *hdr = (void *)resp_buf->data; + + len = hdr->len + sizeof(*hdr); + buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER); + break; + } + default: + LOG_ERR("Unknown/Unhandled HCI type: %d", packet_type); + break; + } + + if (buf && (len <= net_buf_tailroom(buf))) { + net_buf_add_mem(buf, resp_buf->data, len); + hci->recv(dev, buf); + } +} + +static const struct bt_hci_driver_api drv = { + .open = bt_siwg917_open, + .send = bt_siwg917_send, +}; + +#define HCI_DEVICE_INIT(inst) \ + static struct hci_data hci_data_##inst; \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, POST_KERNEL, \ + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) + +/* Only one instance supported right now */ +HCI_DEVICE_INIT(0) diff --git a/drivers/wifi/siwx917/Kconfig.siwx917 b/drivers/wifi/siwx917/Kconfig.siwx917 index 1555f91..297b97c 100644 --- a/drivers/wifi/siwx917/Kconfig.siwx917 +++ b/drivers/wifi/siwx917/Kconfig.siwx917 @@ -5,34 +5,15 @@ config WIFI_SIWX917 bool "Silabs SiWx917 SoC series WiFi driver" default y depends on DT_HAS_SILABS_SIWX917_WIFI_ENABLED + select SIWX917_NWP_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 -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 diff --git a/drivers/wifi/siwx917/siwx917_wifi.c b/drivers/wifi/siwx917/siwx917_wifi.c index 43283ad..3b1c00e 100644 --- a/drivers/wifi/siwx917/siwx917_wifi.c +++ b/drivers/wifi/siwx917/siwx917_wifi.c @@ -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); @@ -609,9 +610,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; @@ -643,6 +646,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); diff --git a/dts/arm/silabs/siwg917.dtsi b/dts/arm/silabs/siwg917.dtsi index f07a943..c8e26b2 100644 --- a/dts/arm/silabs/siwg917.dtsi +++ b/dts/arm/silabs/siwg917.dtsi @@ -24,6 +24,11 @@ reg = <0x00000000 DT_SIZE_K(191)>; }; + bt_hci_silabs_siwx917: bt_hci_silabs_siwx917 { + compatible = "silabs,siwx917-bt-hci"; + status = "disabled"; + }; + flash0: flash@8202000 { compatible = "soc-nv-flash"; reg = <0x8202000 DT_SIZE_K(2040)>; diff --git a/dts/bindings/bluetooth/silabs,siwx917-bt-hci.yaml b/dts/bindings/bluetooth/silabs,siwx917-bt-hci.yaml new file mode 100644 index 0000000..ab23280 --- /dev/null +++ b/dts/bindings/bluetooth/silabs,siwx917-bt-hci.yaml @@ -0,0 +1,13 @@ +description: Bluetooth HCI on Silabs boards + +compatible: "silabs,siwx917-bt-hci" + +include: bt-hci.yaml + +properties: + bt-hci-name: + default: "sl:siwx917:bt" + bt-hci-bus: + default: "BT_HCI_BUS_VIRTUAL" + bt-hci-quirks: + default: ["BT_HCI_QUIRK_NO_RESET"] diff --git a/soc/silabs/silabs_siwx917/siwg917/CMakeLists.txt b/soc/silabs/silabs_siwx917/siwg917/CMakeLists.txt index f8e2896..c1078a4 100644 --- a/soc/silabs/silabs_siwx917/siwg917/CMakeLists.txt +++ b/soc/silabs/silabs_siwx917/siwg917/CMakeLists.txt @@ -4,5 +4,6 @@ zephyr_include_directories(.) zephyr_sources_ifdef(CONFIG_SOC_SERIES_SIWG917 soc.c) +zephyr_sources_ifdef(CONFIG_SIWX917_NWP_NETWORK_STACK nwp_init.c) set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "") diff --git a/soc/silabs/silabs_siwx917/siwg917/Kconfig.soc b/soc/silabs/silabs_siwx917/siwg917/Kconfig.soc index 0e14e36..64cb632 100644 --- a/soc/silabs/silabs_siwx917/siwg917/Kconfig.soc +++ b/soc/silabs/silabs_siwx917/siwg917/Kconfig.soc @@ -19,3 +19,34 @@ config SOC config SOC_PART_NUMBER default "SIWG917M111MGTBA" if SOC_PART_NUMBER_SIWG917M111MGTBA + +config SIWX917_NWP_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 SIWX917_NWP_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 100 + +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 #SIWX917_NWP_NETWORK_STACK diff --git a/soc/silabs/silabs_siwx917/siwg917/nwp_init.c b/soc/silabs/silabs_siwx917/siwg917/nwp_init.c new file mode 100644 index 0000000..fd839c6 --- /dev/null +++ b/soc/silabs/silabs_siwx917/siwg917/nwp_init.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 Silicon Laboratories Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "sl_wifi.h" +#include "sl_wifi_callback_framework.h" +#if 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} + +/* TODO SILABS ZEPHYR: Make these configs accessible via Kconfig */ +#define NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP_WIFI \ + (SL_SI91X_EXT_TCP_IP_WINDOW_SCALING | SL_SI91X_EXT_TCP_IP_TOTAL_SELECTS(10) | \ + SL_SI91X_CONFIG_FEAT_EXTENTION_VALID) + +#ifdef SLI_SI91X_ENABLE_IPV6 +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP_WIFI_IPV6 \ + (SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT | SL_SI91X_TCP_IP_FEAT_IPV6) +#else +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP_WIFI_IPV6 0 +#endif +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP_WIFI \ + (SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | NWP_INIT_TCP_IP_FEATURE_BIT_MAP_WIFI_IPV6 | \ + 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 | SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID) +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP_BLE \ + (SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID) + +#define NWP_INIT_BT_FEATURE_BIT_MAP_BLE (SL_SI91X_BT_RF_TYPE | SL_SI91X_ENABLE_BLE_PROTOCOL) + +#define NWP_INIT_BLE_FEATURE_BIT_MAP_BLE \ + (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_EXTENTION_VALID) + +#define NWP_INIT_BLE_EXT_FEATURE_BIT_MAP_BLE \ + (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)) + +#define NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP_COMMON \ + (MEMORY_CONFIG | SL_SI91X_EXT_FEAT_XTAL_CLK | \ + SL_SI91X_EXT_FEAT_FRONT_END_SWITCH_PINS_ULP_GPIO_4_5_0) + +#if CONFIG_WIFI_SIWX917 && CONFIG_BT_SIWX917 +#define NWP_INIT_COEX_MODE SL_SI91X_WLAN_BLE_MODE +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP \ + (NWP_INIT_TCP_IP_FEATURE_BIT_MAP_WIFI | NWP_INIT_TCP_IP_FEATURE_BIT_MAP_BLE) +#define NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP \ + (NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP_COMMON | SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE) +#define NWP_INIT_BT_FEATURE_BIT_MAP NWP_INIT_BT_FEATURE_BIT_MAP_BLE +#define NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP_WIFI +#define NWP_INIT_BLE_FEATURE_BIT_MAP NWP_INIT_BLE_FEATURE_BIT_MAP_BLE +#define NWP_INIT_BLE_EXT_FEATURE_BIT_MAP NWP_INIT_BLE_EXT_FEATURE_BIT_MAP_BLE +#elif CONFIG_WIFI_SIWX917 +#define NWP_INIT_COEX_MODE SL_SI91X_WLAN_ONLY_MODE +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP NWP_INIT_TCP_IP_FEATURE_BIT_MAP_WIFI +#define NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP_COMMON +#define NWP_INIT_BT_FEATURE_BIT_MAP 0 +#define NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP_WIFI +#define NWP_INIT_BLE_FEATURE_BIT_MAP 0 +#define NWP_INIT_BLE_EXT_FEATURE_BIT_MAP 0 +#elif CONFIG_BT_SIWX917 +#define NWP_INIT_COEX_MODE SL_SI91X_BLE_MODE +#define NWP_INIT_TCP_IP_FEATURE_BIT_MAP NWP_INIT_TCP_IP_FEATURE_BIT_MAP_BLE +#define NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP \ + (NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP_COMMON | SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE) +#define NWP_INIT_BT_FEATURE_BIT_MAP NWP_INIT_BT_FEATURE_BIT_MAP_BLE +#define NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP SL_SI91X_CONFIG_FEAT_EXTENTION_VALID +#define NWP_INIT_BLE_FEATURE_BIT_MAP NWP_INIT_BLE_FEATURE_BIT_MAP_BLE +#define NWP_INIT_BLE_EXT_FEATURE_BIT_MAP NWP_INIT_BLE_EXT_FEATURE_BIT_MAP_BLE +#else +#error "No configuration selected" +#endif + +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 = NWP_INIT_COEX_MODE, + .feature_bit_map = SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_WPS_DISABLE, + .tcp_ip_feature_bit_map = NWP_INIT_TCP_IP_FEATURE_BIT_MAP, + .ext_tcp_ip_feature_bit_map = NWP_INIT_EXT_TCP_IP_FEATURE_BIT_MAP, + .custom_feature_bit_map = SL_SI91X_CUSTOM_FEAT_EXTENTION_VALID, + .ext_custom_feature_bit_map = NWP_INIT_EXT_CUSTOM_FEATURE_BIT_MAP, + .bt_feature_bit_map = NWP_INIT_BT_FEATURE_BIT_MAP, + .ble_feature_bit_map = NWP_INIT_BLE_FEATURE_BIT_MAP, + .ble_ext_feature_bit_map = NWP_INIT_BLE_EXT_FEATURE_BIT_MAP, + .config_feature_bit_map = SL_SI91X_ENABLE_ENHANCED_MAX_PSP, + }}; + +static int silabs_siwx917_nwp_init(void) +{ + return sl_wifi_init(&network_config, NULL, sl_wifi_default_event_handler); +} +SYS_INIT(silabs_siwx917_nwp_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); + +/* IRQn 74 is used for communication with co-processor */ +Z_ISR_DECLARE(74, ISR_FLAG_DIRECT, IRQ074_Handler, 0); + +/* TODO SILABS ZEPHYR: CONFIG macro for the NWP stack size */ +static uint8_t __aligned(8) nwp_stack[10 * 1024]; +NWP_ADD_TO_VECTOR_TABLE(30, ISR_FLAG_DIRECT, &nwp_stack[sizeof(nwp_stack) - 1], 0, nwp_stack); diff --git a/soc/silabs/silabs_siwx917/siwg917/soc.c b/soc/silabs/silabs_siwx917/siwg917/soc.c index 520ced7..dcac51d 100644 --- a/soc/silabs/silabs_siwx917/siwg917/soc.c +++ b/soc/silabs/silabs_siwx917/siwg917/soc.c @@ -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); diff --git a/west.yml b/west.yml index 09157ef..5e3b6aa 100644 --- a/west.yml +++ b/west.yml @@ -11,7 +11,7 @@ manifest: projects: - name: hal_silabs remote: silabs - revision: 3febda5e93f51324961a7e374321d10d6b2688f3 + revision: pull/6/head path: modules/hal/silabs - name: zephyr remote: zephyrproject-rtos