fix timer collision in role switch

Closes https://github.com/espressif/esp-idf/issues/7203
This commit is contained in:
jincheng
2021-07-29 16:56:24 +08:00
parent 2c49af9e75
commit a523dd3ede
5 changed files with 41 additions and 1 deletions

View File

@@ -3835,7 +3835,10 @@ static void bta_dm_adjust_roles(BOOLEAN delay_role_switch)
} else {
bta_dm_cb.switch_delay_timer[i].p_cback =
(TIMER_CBACK *)&bta_dm_delay_role_switch_cback;
bta_sys_start_timer(&bta_dm_cb.switch_delay_timer[i], 0, 500);
/* Start the timer if not active */
if (!bta_sys_timer_is_active(&bta_dm_cb.switch_delay_timer[i])) {
bta_sys_start_timer(&bta_dm_cb.switch_delay_timer[i], 0, 500);
}
}
}

View File

@@ -225,6 +225,7 @@ extern void bta_sys_sendmsg(void *p_msg);
extern void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms);
extern void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle);
extern void bta_sys_free_timer(TIMER_LIST_ENT *p_tle);
extern BOOLEAN bta_sys_timer_is_active(TIMER_LIST_ENT *p_tle);
extern void bta_sys_disable(tBTA_SYS_HW_MODULE module);
extern UINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle);

View File

@@ -638,6 +638,27 @@ UINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle)
}
/*******************************************************************************
**
** Function bta_sys_timer_is_active
**
** Description Get info of timer is active or not.
**
** Returns true if timer is exist and active, false otherwise.
**
*******************************************************************************/
BOOLEAN bta_sys_timer_is_active(TIMER_LIST_ENT *p_tle)
{
assert(p_tle != NULL);
osi_alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle);
if (alarm != NULL && osi_alarm_is_active(alarm)) {
return TRUE;
}
return FALSE;
}
/*******************************************************************************
**
** Function bta_sys_stop_timer