diff --git a/components/bt/bluedroid/stack/btm/btm_acl.c b/components/bt/bluedroid/stack/btm/btm_acl.c index e42724f235..bb9154ba48 100644 --- a/components/bt/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/bluedroid/stack/btm/btm_acl.c @@ -135,6 +135,28 @@ UINT8 btm_handle_to_acl_index (UINT16 hci_handle) return (xx); } +uint32_t connection_LinkSuperTimeout = HCI_DEFAULT_INACT_TOUT; + +bool connection_is_alive () +{ +#if BTM_DYNAMIC_MEMORY == TRUE + if(&btm_cb==NULL) + return false; +#endif + tACL_CONN *p = &btm_cb.acl_db[0]; + UINT8 xx; + BTM_TRACE_DEBUG ("test connection_is_alive.\n"); + for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) { + if ((p->in_use) && p->transport == BT_TRANSPORT_BR_EDR) { + connection_LinkSuperTimeout = p->link_super_tout; + BTM_TRACE_WARNING("conn index:%d,timeout:%d\n",xx,connection_LinkSuperTimeout*625); + return true; + } + } + + /* If here, no BD Addr found */ + return false; +} /******************************************************************************* ** ** Function btm_handle_to_acl diff --git a/components/bt/bt.c b/components/bt/bt.c index ed5e5d1b8e..b0c9127416 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -1369,4 +1369,46 @@ esp_err_t esp_ble_scan_dupilcate_list_flush(void) btdm_controller_scan_duplicate_list_clear(); return ESP_OK; } -#endif /* CONFIG_BT_ENABLED */ \ No newline at end of file + +#define BT_IS_ALIVE true +#define BT_NOT_ALIVE false + +extern bool connection_is_alive(); +extern uint32_t real_bt_isr_count ; +extern uint32_t connection_LinkSuperTimeout; +extern uint32_t bt_isr_count_arry[16]; + + +static bool check_bt_is_alive() +{ + static int stop_times = 0; + static int64_t last_time = 0; + static int last_clk_ts = -1; + int stop_timeout = (connection_LinkSuperTimeout*625+5000000); + stop_timeout = (stop_timeout > 20000000) ? stop_timeout : 20000000; + int currect_clkint_ts = real_bt_isr_count; + if(last_clk_ts == currect_clkint_ts) { + if(stop_times==0) { + last_time = esp_timer_get_time(); + } else if(esp_timer_get_time() - last_time > stop_timeout) { + return BT_NOT_ALIVE; + } + stop_times++; + } else { + stop_times = 0; + } + + last_clk_ts = currect_clkint_ts; + return BT_IS_ALIVE; +} + +void esp_bt_check_need_restart() +{ + if(connection_is_alive() && (check_bt_is_alive()==false)) + { + ets_printf("!! Check BT is not alive. Abort !!"); + abort(); + } +} + +#endif /* CONFIG_BT_ENABLED */ diff --git a/components/bt/include/esp_bt.h b/components/bt/include/esp_bt.h index c119e98b2a..0af9d5f470 100644 --- a/components/bt/include/esp_bt.h +++ b/components/bt/include/esp_bt.h @@ -481,6 +481,8 @@ void esp_bt_controller_wakeup_request(void); */ esp_err_t esp_ble_scan_dupilcate_list_flush(void); +void esp_bt_check_need_restart(); + #ifdef __cplusplus } #endif