Add bt alive Checker.

This commit is contained in:
gengyuchao 2020-04-09 13:53:58 +08:00 committed by maojianxin
parent 9958b41cab
commit 2f911d84db
3 changed files with 67 additions and 1 deletions

View File

@ -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

View File

@ -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 */
#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 */

View File

@ -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