9
9
#include <sl_btctrl_linklayer.h>
10
10
#include <sl_hci_common_transport.h>
11
11
#include <pa_conversions_efr32.h>
12
- #include <sl_bt_ll_zephyr.h>
13
12
#include <rail.h>
14
13
15
14
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
@@ -34,6 +33,17 @@ struct hci_data {
34
33
static K_KERNEL_STACK_DEFINE (slz_ll_stack , SL_BT_SILABS_LL_STACK_SIZE ) ;
35
34
static struct k_thread slz_ll_thread ;
36
35
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
+
37
47
void rail_isr_installer (void )
38
48
{
39
49
#ifdef CONFIG_SOC_SERIES_EFR32MG24
@@ -72,11 +82,11 @@ uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len)
72
82
len -= 1 ;
73
83
74
84
switch (packet_type ) {
75
- case h4_event :
85
+ case BT_HCI_H4_EVT :
76
86
event_code = data [0 ];
77
87
buf = bt_buf_get_evt (event_code , false, K_FOREVER );
78
88
break ;
79
- case h4_acl :
89
+ case BT_HCI_H4_ACL :
80
90
buf = bt_buf_get_rx (BT_BUF_ACL_IN , K_FOREVER );
81
91
break ;
82
92
default :
@@ -100,10 +110,10 @@ static int slz_bt_send(const struct device *dev, struct net_buf *buf)
100
110
101
111
switch (bt_buf_get_type (buf )) {
102
112
case BT_BUF_ACL_OUT :
103
- net_buf_push_u8 (buf , h4_acl );
113
+ net_buf_push_u8 (buf , BT_HCI_H4_ACL );
104
114
break ;
105
115
case BT_BUF_CMD :
106
- net_buf_push_u8 (buf , h4_command );
116
+ net_buf_push_u8 (buf , BT_HCI_H4_CMD );
107
117
break ;
108
118
default :
109
119
rv = - EINVAL ;
@@ -120,13 +130,25 @@ static int slz_bt_send(const struct device *dev, struct net_buf *buf)
120
130
return rv ;
121
131
}
122
132
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
+ */
123
139
static void slz_thread_func (void * p1 , void * p2 , void * p3 )
124
140
{
125
141
ARG_UNUSED (p1 );
126
142
ARG_UNUSED (p2 );
127
143
ARG_UNUSED (p3 );
128
144
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
+ }
130
152
}
131
153
132
154
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)
211
233
return ret ;
212
234
}
213
235
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
+
214
253
static const struct bt_hci_driver_api drv = {
215
254
.open = slz_bt_open ,
216
255
.send = slz_bt_send ,
0 commit comments