Skip to content

Commit

Permalink
drivers: bluetooth: siwx917: Add Bluetooth HCI driver
Browse files Browse the repository at this point in the history
PR finding fixes
Lower tickrate because of timeout errors
  • Loading branch information
silabs-TiborL committed Sep 20, 2024
1 parent 892c436 commit 6ad01e7
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/upstream-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
zephyr,flash = &flash0;
zephyr,console = &ulpuart0;
zephyr,shell-uart = &ulpuart0;
zephyr,bt-hci = &bt_hci_silabs_siwx917;
};

aliases {
Expand Down Expand Up @@ -58,6 +59,10 @@
status = "okay";
};

&bt_hci_silabs_siwx917 {
status = "okay";
};

&ulpuart0 {
status = "okay";
pinctrl-0 = <&ulpuart0_default>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ toolchain:
supported:
- gpio
- i2c
- bluetooth
vendor: silabs
1 change: 1 addition & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions drivers/bluetooth/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) 2024 Silicon Laboratories Inc.
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(hci)
8 changes: 8 additions & 0 deletions drivers/bluetooth/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Silicon Laboratories Inc.
# SPDX-License-Identifier: Apache-2.0

if BT_HCI

rsource "hci/Kconfig.siwx917"

endif
4 changes: 4 additions & 0 deletions drivers/bluetooth/hci/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions drivers/bluetooth/hci/Kconfig.siwx917
Original file line number Diff line number Diff line change
@@ -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.
118 changes: 118 additions & 0 deletions drivers/bluetooth/hci/siwx917_hci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2024 Silicon Laboratories Inc.
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/bluetooth.h>

#define DT_DRV_COMPAT silabs_siwx917_bt_hci
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
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)
21 changes: 1 addition & 20 deletions drivers/wifi/siwx917/Kconfig.siwx917
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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;
Expand Down Expand Up @@ -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);
5 changes: 5 additions & 0 deletions dts/arm/silabs/siwg917.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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)>;
Expand Down
13 changes: 13 additions & 0 deletions dts/bindings/bluetooth/silabs,siwx917-bt-hci.yaml
Original file line number Diff line number Diff line change
@@ -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"]
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_SIWX917_NWP_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.soc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 6ad01e7

Please sign in to comment.