@@ -38,13 +38,16 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_BRIDGE_BLE_LOG_LEVEL);
38
38
#define ATT_MIN_PAYLOAD 20 /* Minimum L2CAP MTU minus ATT header */
39
39
40
40
static void bt_send_work_handler (struct k_work * work );
41
+ static void bt_adv_resume_work_handler (struct k_work * work );
42
+ static void adv_start (bool resume );
41
43
42
44
K_MEM_SLAB_DEFINE (ble_rx_slab , BLE_RX_BLOCK_SIZE , BLE_RX_BUF_COUNT , BLE_SLAB_ALIGNMENT );
43
45
RING_BUF_DECLARE (ble_tx_ring_buf , BLE_TX_BUF_SIZE );
44
46
45
47
static K_SEM_DEFINE (ble_tx_sem , 0 , 1 ) ;
46
48
47
49
static K_WORK_DEFINE (bt_send_work , bt_send_work_handler ) ;
50
+ static K_WORK_DEFINE (bt_adv_resume_work , bt_adv_resume_work_handler ) ;
48
51
49
52
static struct bt_conn * current_conn ;
50
53
static struct bt_gatt_exchange_params exchange_params ;
@@ -130,9 +133,18 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
130
133
APP_EVENT_SUBMIT (event );
131
134
}
132
135
136
+ static void recycled (void )
137
+ {
138
+ if (atomic_get (& active )) {
139
+ /* Resume advertising outside of ISR context */
140
+ k_work_submit (& bt_adv_resume_work );
141
+ }
142
+ }
143
+
133
144
static struct bt_conn_cb conn_callbacks = {
134
145
.connected = connected ,
135
146
.disconnected = disconnected ,
147
+ .recycled = recycled ,
136
148
};
137
149
138
150
static void bt_send_work_handler (struct k_work * work )
@@ -166,6 +178,11 @@ static void bt_send_work_handler(struct k_work *work)
166
178
}
167
179
}
168
180
181
+ static void bt_adv_resume_work_handler (struct k_work * work )
182
+ {
183
+ adv_start (true);
184
+ }
185
+
169
186
static void bt_receive_cb (struct bt_conn * conn , const uint8_t * const data ,
170
187
uint16_t len )
171
188
{
@@ -211,7 +228,7 @@ static struct bt_nus_cb nus_cb = {
211
228
.sent = bt_sent_cb ,
212
229
};
213
230
214
- static void adv_start (void )
231
+ static void adv_start (bool resume )
215
232
{
216
233
int err ;
217
234
@@ -229,7 +246,7 @@ static void adv_start(void)
229
246
ad , ARRAY_SIZE (ad ), sd , ARRAY_SIZE (sd ));
230
247
if (err ) {
231
248
LOG_ERR ("bt_le_adv_start: %d" , err );
232
- } else {
249
+ } else if (! resume ) {
233
250
module_set_state (MODULE_STATE_READY );
234
251
}
235
252
}
@@ -287,7 +304,7 @@ static void bt_ready(int err)
287
304
#endif
288
305
289
306
if (atomic_get (& active )) {
290
- adv_start ();
307
+ adv_start (false );
291
308
}
292
309
}
293
310
@@ -377,7 +394,7 @@ static bool app_event_handler(const struct app_event_header *aeh)
377
394
case BLE_CTRL_ENABLE :
378
395
if (!atomic_set (& active , true)) {
379
396
short_range_rf_front_end_enable ();
380
- adv_start ();
397
+ adv_start (false );
381
398
}
382
399
break ;
383
400
case BLE_CTRL_DISABLE :
0 commit comments