5
5
*/
6
6
7
7
#include <zephyr/drivers/bluetooth.h>
8
+ #include <zephyr/kernel.h>
8
9
9
10
#include <sl_btctrl_linklayer.h>
10
11
#include <sl_hci_common_transport.h>
@@ -36,12 +37,18 @@ struct hci_data {
36
37
static K_KERNEL_STACK_DEFINE (slz_ll_stack , CONFIG_BT_SILABS_EFR32_ACCEPT_LINK_LAYER_STACK_SIZE ) ;
37
38
static struct k_thread slz_ll_thread ;
38
39
40
+ static K_KERNEL_STACK_DEFINE (slz_rx_stack , CONFIG_BT_DRV_RX_STACK_SIZE ) ;
41
+ static struct k_thread slz_rx_thread ;
42
+
39
43
/* Semaphore for Link Layer */
40
44
K_SEM_DEFINE (slz_ll_sem , 0 , 1 );
41
45
42
46
/* Events mask for Link Layer */
43
47
static atomic_t sli_btctrl_events ;
44
48
49
+ /* FIFO for received HCI packets */
50
+ static struct k_fifo slz_rx_fifo ;
51
+
45
52
/* FIXME: these functions should come from the SiSDK headers! */
46
53
void BTLE_LL_EventRaise (uint32_t events );
47
54
void BTLE_LL_Process (uint32_t events );
@@ -73,8 +80,6 @@ void rail_isr_installer(void)
73
80
*/
74
81
uint32_t hci_common_transport_transmit (uint8_t * data , int16_t len )
75
82
{
76
- const struct device * dev = DEVICE_DT_GET (DT_DRV_INST (0 ));
77
- struct hci_data * hci = dev -> data ;
78
83
struct net_buf * buf ;
79
84
uint8_t packet_type = data [0 ];
80
85
uint8_t event_code ;
@@ -99,7 +104,7 @@ uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len)
99
104
}
100
105
101
106
net_buf_add_mem (buf , data , len );
102
- hci -> recv ( dev , buf );
107
+ k_fifo_put ( & slz_rx_fifo , buf );
103
108
104
109
sl_btctrl_hci_transmit_complete (0 );
105
110
@@ -140,7 +145,7 @@ static int slz_bt_send(const struct device *dev, struct net_buf *buf)
140
145
* or an HCI event to pass upstairs. The BTLE_LL_Process function call will
141
146
* take care of all of them, and add HCI events to the HCI queue when applicable.
142
147
*/
143
- static void slz_thread_func (void * p1 , void * p2 , void * p3 )
148
+ static void slz_ll_thread_func (void * p1 , void * p2 , void * p3 )
144
149
{
145
150
ARG_UNUSED (p1 );
146
151
ARG_UNUSED (p2 );
@@ -155,17 +160,40 @@ static void slz_thread_func(void *p1, void *p2, void *p3)
155
160
}
156
161
}
157
162
163
+ static void slz_rx_thread_func (void * p1 , void * p2 , void * p3 )
164
+ {
165
+ const struct device * dev = p1 ;
166
+ struct hci_data * hci = dev -> data ;
167
+
168
+ ARG_UNUSED (p2 );
169
+ ARG_UNUSED (p3 );
170
+
171
+ while (true) {
172
+ struct net_buf * buf = k_fifo_get (& slz_rx_fifo , K_FOREVER );
173
+
174
+ hci -> recv (dev , buf );
175
+ }
176
+ }
177
+
158
178
static int slz_bt_open (const struct device * dev , bt_hci_recv_t recv )
159
179
{
160
180
struct hci_data * hci = dev -> data ;
161
181
int ret ;
162
182
163
- /* Start RX thread */
164
- k_thread_create (& slz_ll_thread , slz_ll_stack ,
165
- K_KERNEL_STACK_SIZEOF (slz_ll_stack ),
166
- slz_thread_func , NULL , NULL , NULL ,
167
- K_PRIO_COOP (CONFIG_BT_DRIVER_RX_HIGH_PRIO ), 0 ,
168
- K_NO_WAIT );
183
+ BUILD_ASSERT (CONFIG_NUM_METAIRQ_PRIORITIES > 0 ,
184
+ "Config NUM_METAIRQ_PRIORITIES must be greater than 0" );
185
+ BUILD_ASSERT (CONFIG_BT_SILABS_EFR32_LL_THREAD_PRIO < CONFIG_NUM_METAIRQ_PRIORITIES ,
186
+ "Config BT_SILABS_EFR32_LL_THREAD_PRIO must be a meta-IRQ priority" );
187
+
188
+ k_fifo_init (& slz_rx_fifo );
189
+
190
+ k_thread_create (& slz_ll_thread , slz_ll_stack , K_KERNEL_STACK_SIZEOF (slz_ll_stack ),
191
+ slz_ll_thread_func , NULL , NULL , NULL ,
192
+ K_PRIO_COOP (CONFIG_BT_SILABS_EFR32_LL_THREAD_PRIO ), 0 , K_NO_WAIT );
193
+
194
+ k_thread_create (& slz_rx_thread , slz_rx_stack , K_KERNEL_STACK_SIZEOF (slz_rx_stack ),
195
+ slz_rx_thread_func , (void * )dev , NULL , NULL ,
196
+ K_PRIO_COOP (CONFIG_BT_DRIVER_RX_HIGH_PRIO ), 0 , K_NO_WAIT );
169
197
170
198
rail_isr_installer ();
171
199
sl_rail_util_pa_init ();
0 commit comments