Skip to content

Commit a3f2ba1

Browse files
jrintahaMaureenHelm
authored andcommitted
drivers: bluetooth: silabs: move code from module to main tree
The code that handles passing events to and from the controller resided in the hal_silabs module. This is an integral part of the HCI driver that it can't work without, and logically belongs in the driver. Signed-off-by: Jori Rintahaka <jori.rintahaka@silabs.com>
1 parent 094b049 commit a3f2ba1

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

drivers/bluetooth/hci/slz_hci.c

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sl_btctrl_linklayer.h>
1010
#include <sl_hci_common_transport.h>
1111
#include <pa_conversions_efr32.h>
12-
#include <sl_bt_ll_zephyr.h>
1312
#include <rail.h>
1413

1514
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
@@ -34,6 +33,17 @@ struct hci_data {
3433
static K_KERNEL_STACK_DEFINE(slz_ll_stack, SL_BT_SILABS_LL_STACK_SIZE);
3534
static struct k_thread slz_ll_thread;
3635

36+
/* Semaphore for Link Layer */
37+
K_SEM_DEFINE(slz_ll_sem, 0, 1);
38+
39+
/* Events mask for Link Layer */
40+
static atomic_t sli_btctrl_events;
41+
42+
/* FIXME: these functions should come from the SiSDK headers! */
43+
void BTLE_LL_EventRaise(uint32_t events);
44+
void BTLE_LL_Process(uint32_t events);
45+
bool sli_pending_btctrl_events(void);
46+
3747
void rail_isr_installer(void)
3848
{
3949
#ifdef CONFIG_SOC_SERIES_EFR32MG24
@@ -72,11 +82,11 @@ uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len)
7282
len -= 1;
7383

7484
switch (packet_type) {
75-
case h4_event:
85+
case BT_HCI_H4_EVT:
7686
event_code = data[0];
7787
buf = bt_buf_get_evt(event_code, false, K_FOREVER);
7888
break;
79-
case h4_acl:
89+
case BT_HCI_H4_ACL:
8090
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
8191
break;
8292
default:
@@ -100,10 +110,10 @@ static int slz_bt_send(const struct device *dev, struct net_buf *buf)
100110

101111
switch (bt_buf_get_type(buf)) {
102112
case BT_BUF_ACL_OUT:
103-
net_buf_push_u8(buf, h4_acl);
113+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
104114
break;
105115
case BT_BUF_CMD:
106-
net_buf_push_u8(buf, h4_command);
116+
net_buf_push_u8(buf, BT_HCI_H4_CMD);
107117
break;
108118
default:
109119
rv = -EINVAL;
@@ -120,13 +130,25 @@ static int slz_bt_send(const struct device *dev, struct net_buf *buf)
120130
return rv;
121131
}
122132

133+
/**
134+
* The HCI driver thread simply waits for the LL semaphore to signal that
135+
* it has an event to handle, whether it's from the radio, its own scheduler,
136+
* or an HCI event to pass upstairs. The BTLE_LL_Process function call will
137+
* take care of all of them, and add HCI events to the HCI queue when applicable.
138+
*/
123139
static void slz_thread_func(void *p1, void *p2, void *p3)
124140
{
125141
ARG_UNUSED(p1);
126142
ARG_UNUSED(p2);
127143
ARG_UNUSED(p3);
128144

129-
slz_ll_thread_func();
145+
while (true) {
146+
uint32_t events;
147+
148+
k_sem_take(&slz_ll_sem, K_FOREVER);
149+
events = atomic_clear(&sli_btctrl_events);
150+
BTLE_LL_Process(events);
151+
}
130152
}
131153

132154
static int slz_bt_open(const struct device *dev, bt_hci_recv_t recv)
@@ -211,6 +233,23 @@ static int slz_bt_open(const struct device *dev, bt_hci_recv_t recv)
211233
return ret;
212234
}
213235

236+
bool sli_pending_btctrl_events(void)
237+
{
238+
return false; /* TODO: check if this should really return false! */
239+
}
240+
241+
/* Store event flags and increment the LL semaphore */
242+
void BTLE_LL_EventRaise(uint32_t events)
243+
{
244+
atomic_or(&sli_btctrl_events, events);
245+
k_sem_give(&slz_ll_sem);
246+
}
247+
248+
void sl_bt_controller_init(void)
249+
{
250+
/* No extra initialization procedure required */
251+
}
252+
214253
static const struct bt_hci_driver_api drv = {
215254
.open = slz_bt_open,
216255
.send = slz_bt_send,

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ manifest:
223223
groups:
224224
- hal
225225
- name: hal_silabs
226-
revision: bb44c61d3f8b1e00d7b3d3804cfaf8df1e905d5d
226+
revision: d07d744a933bada3a87377dc46241960f620011f
227227
path: modules/hal/silabs
228228
groups:
229229
- hal

0 commit comments

Comments
 (0)