@@ -2274,7 +2274,6 @@ UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush)
2274
2274
return (num_left );
2275
2275
}
2276
2276
2277
-
2278
2277
/******************************************************************************
2279
2278
**
2280
2279
** Function update_acl_pkt_num
@@ -2284,54 +2283,66 @@ UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush)
2284
2283
** Returns None
2285
2284
**
2286
2285
*******************************************************************************/
2287
-
2288
2286
#if BLE_INCLUDED == TRUE
2289
2287
void l2ble_update_att_acl_pkt_num (UINT8 type , tl2c_buff_param_t * param )
2290
2288
{
2291
2289
static SemaphoreHandle_t buff_semaphore = NULL ;
2292
2290
static INT16 btc_buf ;
2293
2291
static INT16 btu_buf ;
2294
2292
2295
- if (buff_semaphore != NULL ){
2296
- xSemaphoreTake (buff_semaphore , 10 / portTICK_PERIOD_MS );
2293
+ if (buff_semaphore == NULL && type != L2CA_BUFF_INI ){
2294
+ L2CAP_TRACE_ERROR ("%s buff_semaphore not init" , __func__ );
2295
+ return ;
2297
2296
}
2298
2297
switch (type )
2299
2298
{
2300
2299
case L2CA_ADD_BTC_NUM :{
2300
+ xSemaphoreTake (buff_semaphore , portMAX_DELAY );
2301
2301
btc_buf ++ ;
2302
+ xSemaphoreGive (buff_semaphore );
2302
2303
break ;
2303
2304
}
2304
2305
case L2CA_DECREASE_BTC_NUM :{
2306
+ xSemaphoreTake (buff_semaphore , portMAX_DELAY );
2305
2307
btc_buf -- ;
2308
+ xSemaphoreGive (buff_semaphore );
2306
2309
break ;
2307
2310
}
2308
2311
case L2CA_ADD_BTU_NUM :{
2312
+ xSemaphoreTake (buff_semaphore , portMAX_DELAY );
2309
2313
btu_buf ++ ;
2314
+ xSemaphoreGive (buff_semaphore );
2310
2315
break ;
2311
2316
}
2312
2317
case L2CA_DECREASE_BTU_NUM :{
2318
+ xSemaphoreTake (buff_semaphore , portMAX_DELAY );
2313
2319
btu_buf -- ;
2320
+ xSemaphoreGive (buff_semaphore );
2314
2321
break ;
2315
2322
}
2316
2323
case L2CA_GET_ATT_NUM :{
2324
+ xSemaphoreTake (buff_semaphore , portMAX_DELAY );
2317
2325
INT16 att_acl_pkt_num = 0 ;
2318
2326
INT16 att_max_num = 0 ;
2319
2327
* (param -> get_num ) = 0 ;
2320
2328
UINT8 tcb_idx = param -> conn_id ;
2321
2329
tGATT_TCB * p_tcb = gatt_get_tcb_by_idx (tcb_idx );
2322
2330
if (p_tcb == NULL ){
2323
2331
L2CAP_TRACE_ERROR ("%s not found p_tcb" , __func__ );
2332
+ xSemaphoreGive (buff_semaphore );
2324
2333
break ;
2325
2334
}
2326
2335
tL2C_LCB * p_lcb = l2cu_find_lcb_by_bd_addr (p_tcb -> peer_bda , BT_TRANSPORT_LE );
2327
2336
if (p_lcb == NULL ){
2328
2337
L2CAP_TRACE_ERROR ("%s not found p_lcb" , __func__ );
2338
+ xSemaphoreGive (buff_semaphore );
2329
2339
break ;
2330
2340
}
2331
2341
fixed_queue_t * queue = p_lcb -> p_fixed_ccbs [L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL ]-> xmit_hold_q ;
2332
2342
att_max_num = MIN (p_lcb -> link_xmit_quota , L2CAP_CACHE_ATT_ACL_NUM );
2333
2343
if (queue == NULL ){
2334
2344
L2CAP_TRACE_ERROR ("%s not found queue" , __func__ );
2345
+ xSemaphoreGive (buff_semaphore );
2335
2346
break ;
2336
2347
}
2337
2348
att_acl_pkt_num = fixed_queue_length (queue );
@@ -2340,23 +2351,31 @@ void l2ble_update_att_acl_pkt_num(UINT8 type, tl2c_buff_param_t *param)
2340
2351
* (param -> get_num ) = att_max_num - att_acl_pkt_num - (btc_buf + btu_buf );
2341
2352
}
2342
2353
}
2354
+ xSemaphoreGive (buff_semaphore );
2343
2355
break ;
2344
2356
}
2345
2357
case L2CA_BUFF_INI :{
2346
2358
btc_buf = 0 ;
2347
2359
btu_buf = 0 ;
2348
2360
buff_semaphore = xSemaphoreCreateBinary ();
2361
+ if (buff_semaphore == NULL ) {
2362
+ L2CAP_TRACE_ERROR ("%s NO MEMORY" , __func__ );
2363
+ break ;
2364
+ }
2349
2365
xSemaphoreGive (buff_semaphore );
2350
2366
break ;
2351
2367
}
2352
2368
case L2CA_BUFF_DEINIT :{
2369
+ xSemaphoreTake (buff_semaphore , portMAX_DELAY );
2353
2370
btc_buf = 0 ;
2354
2371
btu_buf = 0 ;
2372
+ xSemaphoreGive (buff_semaphore );
2373
+ vSemaphoreDelete (buff_semaphore );
2374
+ buff_semaphore = NULL ;
2355
2375
break ;
2356
2376
}
2357
2377
default :
2358
2378
break ;
2359
2379
}
2360
- xSemaphoreGive (buff_semaphore );
2361
2380
}
2362
2381
#endif
0 commit comments