support coex scheme

1. add bugfix of ble and add api to set max adv delay time
2. open full scan and change adv interval check in bluedroid
This commit is contained in:
baohongde 2019-12-10 23:00:44 +08:00 committed by Tian Hao
parent 3b704d2f3a
commit 99951fbcf8
16 changed files with 178 additions and 10 deletions

View File

@ -275,8 +275,8 @@ menu Bluetooth
config BTDM_CONTROLLER_FULL_SCAN_SUPPORTED
bool "BLE full scan feature supported"
depends on BTDM_CONTROLLER_MODE_BLE_ONLY
default n
depends on BTDM_CONTROLLER_MODE_BLE_ONLY || BTDM_CONTROLLER_MODE_BTDM
default y
help
The full scan function is mainly used to provide BLE scan performance.
This is required for scenes with high scan performance requirements, such as BLE Mesh scenes.

View File

@ -41,6 +41,7 @@
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
#include "bta/bta_ar_api.h"
#endif
#include "bta/bta_api.h"
/*****************************************************************************
** Constants
@ -528,8 +529,21 @@ static void bta_av_proc_stream_evt(UINT8 handle, BD_ADDR bd_addr, UINT8 event, t
/* look up application event */
if ((p_data == NULL) || (p_data->hdr.err_code == 0)) {
p_msg->hdr.event = bta_av_stream_evt_ok[event];
if (p_msg->hdr.event == BTA_AV_STR_START_OK_EVT) {
BTA_DmCoexEventTrigger(BTA_COEX_EVT_STREAMING_STARTED);
} else if (p_msg->hdr.event == BTA_AV_STR_START_FAIL_EVT ||
p_msg->hdr.event == BTA_AV_STR_SUSPEND_CFM_EVT ||
p_msg->hdr.event == BTA_AV_STR_CLOSE_EVT) {
BTA_DmCoexEventTrigger(BTA_COEX_EVT_STREAMING_STOPPED);
}
} else {
p_msg->hdr.event = bta_av_stream_evt_fail[event];
if (p_msg->hdr.event == BTA_AV_STR_START_FAIL_EVT ||
p_msg->hdr.event == BTA_AV_STR_START_OK_EVT ||
p_msg->hdr.event == BTA_AV_STR_SUSPEND_CFM_EVT ||
p_msg->hdr.event == BTA_AV_STR_CLOSE_EVT) {
BTA_DmCoexEventTrigger(BTA_COEX_EVT_STREAMING_STOPPED);
}
}
p_msg->initiator = FALSE;

View File

@ -711,6 +711,12 @@ void bta_dm_set_visibility(tBTA_DM_MSG *p_data)
BTM_SetPairableMode((BOOLEAN)(!(bta_dm_cb.disable_pair_mode)), bta_dm_cb.conn_paired_only);
}
if (((p_data->set_visibility.conn_mode & BTA_DM_IGNORE) == BTA_DM_NON_CONN) &&
((p_data->set_visibility.disc_mode & BTA_DM_IGNORE) == BTA_DM_NON_DISC)) {
BTA_DmCoexEventTrigger(BTA_COEX_EVT_SCAN_STOPPED);
} else {
BTA_DmCoexEventTrigger(BTA_COEX_EVT_SCAN_STARTED);
}
}
/*******************************************************************************
@ -3111,6 +3117,7 @@ static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data)
p_msg->transport = p_data->conn.transport;
p_msg->handle = p_data->conn.handle;
#endif
BTA_DmCoexEventTrigger(BTA_COEX_EVT_ACL_CONNECTED);
break;
case BTM_BL_DISCN_EVT:
bdcpy(p_msg->bd_addr, p_data->discn.p_bda);
@ -3118,6 +3125,7 @@ static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data)
p_msg->transport = p_data->discn.transport;
p_msg->handle = p_data->discn.handle;
#endif
BTA_DmCoexEventTrigger(BTA_COEX_EVT_ACL_DISCONNECTED);
break;
case BTM_BL_UPDATE_EVT:
p_msg->busy_level = p_data->update.busy_level;

View File

@ -28,6 +28,7 @@
#include "osi/allocator.h"
#include <string.h>
#include "esp_coexist_internal.h"
/*****************************************************************************
** Constants and types
@ -453,3 +454,67 @@ BOOLEAN bta_dm_search_sm_execute(BT_HDR *p_msg)
return TRUE;
}
void BTA_DmCoexEventTrigger(uint32_t event)
{
uint8_t bt_status = 0;
switch(event) {
case BTA_COEX_EVT_SCAN_STARTED:
bta_dm_cb.coex_scan_st = true;
break;
case BTA_COEX_EVT_SCAN_STOPPED:
bta_dm_cb.coex_scan_st = false;
break;
case BTA_COEX_EVT_ACL_CONNECTED:
bta_dm_cb.coex_acl_st = true;
// clear streaming state and sniff state;
bta_dm_cb.coex_streaming_st = false;
bta_dm_cb.coex_sniff_st = false;
break;
case BTA_COEX_EVT_ACL_DISCONNECTED:
bta_dm_cb.coex_acl_st = false;
// clear streaming state and sniff state;
bta_dm_cb.coex_streaming_st = false;
bta_dm_cb.coex_sniff_st = false;
break;
case BTA_COEX_EVT_STREAMING_STARTED:
bta_dm_cb.coex_streaming_st = true;
break;
case BTA_COEX_EVT_STREAMING_STOPPED:
bta_dm_cb.coex_streaming_st = false;
break;
case BTA_COEX_EVT_SNIFF_ENTER:
bta_dm_cb.coex_sniff_st = true;
break;
case BTA_COEX_EVT_SNIFF_EXIT:
bta_dm_cb.coex_sniff_st = false;
break;
default:
break;
}
if (bta_dm_cb.coex_scan_st) {
bt_status = coex_schm_status_get(COEX_SCHM_ST_TYPE_BT) | COEX_SCHM_BT_ST_ISCAN;
} else {
bt_status = coex_schm_status_get(COEX_SCHM_ST_TYPE_BT) & (~COEX_SCHM_BT_ST_ISCAN);
}
// acl st may overwrite the wifi_percent set by coex_scan_st
if (bta_dm_cb.coex_acl_st) {
bt_status = bt_status | COEX_SCHM_BT_ST_ACL_CONNECTED;
if (bta_dm_cb.coex_streaming_st) {
bt_status = bt_status | COEX_SCHM_BT_ST_A2DP_STREAMING;
} else if (bta_dm_cb.coex_sniff_st) {
bt_status = (bt_status & (~COEX_SCHM_BT_ST_A2DP_STREAMING)) | COEX_SCHM_BT_ST_SNIFF;
} else {
// not streaming, not sniff, acl connected
bt_status = bt_status & (~(COEX_SCHM_BT_ST_A2DP_STREAMING | COEX_SCHM_BT_ST_SNIFF));
}
} else {
bt_status = (bt_status & ~(COEX_SCHM_BT_ST_A2DP_STREAMING | COEX_SCHM_BT_ST_ACL_CONNECTED | COEX_SCHM_BT_ST_SNIFF));
}
coex_schm_status_set(COEX_SCHM_ST_TYPE_BT, bt_status);
APPL_TRACE_EVENT("bt_status %02x", bt_status);
}

View File

@ -910,6 +910,7 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data)
bta_dm_pm_stop_timer_by_mode(p_data->pm_status.bd_addr, p_dev->pm_mode_attempted);
bta_dm_pm_set_mode(p_data->pm_status.bd_addr, BTA_DM_PM_NO_ACTION, BTA_DM_PM_RESTART);
}
BTA_DmCoexEventTrigger(BTA_COEX_EVT_SNIFF_EXIT);
} else {
#if (BTM_SSR_INCLUDED == TRUE)
if (p_dev->prev_low) {
@ -921,6 +922,7 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data)
/* link to active mode, need to restart the timer for next low power mode if needed */
bta_dm_pm_stop_timer(p_data->pm_status.bd_addr);
bta_dm_pm_set_mode(p_data->pm_status.bd_addr, BTA_DM_PM_NO_ACTION, BTA_DM_PM_RESTART);
BTA_DmCoexEventTrigger(BTA_COEX_EVT_SNIFF_EXIT);
}
break;
@ -951,6 +953,7 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data)
* PM timer sole purpose is to put the link
* in sniff mode from host side.
*/
BTA_DmCoexEventTrigger(BTA_COEX_EVT_SNIFF_ENTER);
bta_dm_pm_stop_timer(p_data->pm_status.bd_addr);
} else {
p_dev->info &= ~(BTA_DM_DI_SET_SNIFF | BTA_DM_DI_INT_SNIFF | BTA_DM_DI_ACP_SNIFF);

View File

@ -1049,7 +1049,10 @@ typedef struct {
tBTA_DM_ENCRYPT_CBACK *p_encrypt_cback;
TIMER_LIST_ENT switch_delay_timer;
bool coex_scan_st;
bool coex_acl_st;
bool coex_streaming_st;
bool coex_sniff_st;
} tBTA_DM_CB;
#ifndef BTA_DM_SDP_DB_SIZE

View File

@ -1377,6 +1377,7 @@ typedef UINT8 tBTA_DM_LINK_TYPE;
#define ALLOW_ALL_FILTER 0x00
#define LOWEST_RSSI_VALUE 129
/*****************************************************************************
** External Function Declarations
*****************************************************************************/
@ -2615,6 +2616,19 @@ extern void BTA_VendorInit (void);
*******************************************************************************/
extern void BTA_VendorCleanup (void);
enum {
BTA_COEX_EVT_SCAN_STARTED = 1,
BTA_COEX_EVT_SCAN_STOPPED,
BTA_COEX_EVT_ACL_CONNECTED,
BTA_COEX_EVT_ACL_DISCONNECTED,
BTA_COEX_EVT_STREAMING_STARTED,
BTA_COEX_EVT_STREAMING_STOPPED,
BTA_COEX_EVT_SNIFF_ENTER,
BTA_COEX_EVT_SNIFF_EXIT,
};
extern void BTA_DmCoexEventTrigger(uint32_t event);
#endif
#ifdef __cplusplus

View File

@ -66,7 +66,7 @@ typedef enum {
#define HCI_HOST_QUEUE_LEN 40
#define HCI_H4_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE)
#define HCI_H4_TASK_STACK_SIZE (4096 + BT_TASK_EXTRA_STACK_SIZE)
#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 4)
#define HCI_H4_TASK_NAME "hciH4T"
#define HCI_H4_QUEUE_LEN 1

View File

@ -105,7 +105,7 @@ typedef UINT8 tBTM_BLE_SFP;
#endif
/* adv parameter boundary values */
#define BTM_BLE_ADV_INT_MIN 0x0020
#define BTM_BLE_ADV_INT_MIN 0x0010
#define BTM_BLE_ADV_INT_MAX 0x4000
/* Full scan boundary values */

@ -1 +1 @@
Subproject commit bd605c2000afbc9b15be92de35ec20bcd8c47fcf
Subproject commit d8c93bd62b820dd2441b2352c9b4ca9ff46ebcd0

View File

@ -24,3 +24,8 @@ esp_err_t esp_coex_preference_set(esp_coex_prefer_t prefer)
{
return coex_preference_set((coex_prefer_t)prefer);
}
esp_err_t esp_coex_wifi_percent_set(int wifi_percent)
{
return coex_wifi_percent_set(wifi_percent);
}

View File

@ -422,6 +422,10 @@ void start_cpu0_default(void)
#if CONFIG_SW_COEXIST_ENABLE
esp_coex_adapter_register(&g_coex_adapter_funcs);
coex_pre_init();
coex_preference_set(CONFIG_SW_COEXIST_PREFERENCE_VALUE);
extern esp_err_t coex_schm_init(void);
coex_schm_init();
#endif
bootloader_flash_update_id();

View File

@ -51,6 +51,15 @@ const char *esp_coex_version_get(void);
*/
esp_err_t esp_coex_preference_set(esp_coex_prefer_t prefer);
/**
* @brief Set coexist wifi_percent
* Default is 50%. The range is 10% <= wifi_percent <= 90%.
*
* @param prefer : percent without %. Eg: 70 means 70%
* @return : ESP_OK - success, other - failed
*/
esp_err_t esp_coex_wifi_percent_set(int wifi_percent);
#ifdef __cplusplus
}
#endif

View File

@ -31,6 +31,27 @@ typedef enum {
typedef void (* coex_func_cb_t)(uint32_t event, int sched_cnt);
typedef enum {
COEX_SCHM_ST_TYPE_WIFI = 0,
COEX_SCHM_ST_TYPE_BLE,
COEX_SCHM_ST_TYPE_BT,
} coex_schm_st_type_t;
#define COEX_SCHM_BLE_ST_IDLE 0x0
#define COEX_SCHM_BLE_ST_ADV 0x01
#define COEX_SCHM_BLE_ST_SCAN 0x02
#define COEX_SCHM_BLE_ST_CONNECTED 0x04
#define COEX_SCHM_BLE_ST_MESH_CONFIG 0x08
#define COEX_SCHM_BLE_ST_MESH_TRAFFIC 0x10
#define COEX_SCHM_BLE_ST_MESH_STANDBY 0x20
#define COEX_SCHM_BT_ST_IDLE 0x0
#define COEX_SCHM_BT_ST_ISCAN 0x01
#define COEX_SCHM_BT_ST_INQ 0x02
#define COEX_SCHM_BT_ST_ACL_CONNECTED 0x04
#define COEX_SCHM_BT_ST_SNIFF 0x08
#define COEX_SCHM_BT_ST_A2DP_STREAMING 0x10
/**
* @brief Pre-Init software coexist
* extern function for internal use.
@ -65,8 +86,7 @@ void coex_pause(void);
*/
void coex_resume(void);
/**
* @brief Get software coexist version string
/** * @brief Get software coexist version string
* extern function for internal use.
* @return : version string
*/
@ -81,12 +101,36 @@ const char *coex_version_get(void);
*/
esp_err_t coex_preference_set(coex_prefer_t prefer);
/**
* @brief Set coexist wifi_percent for internal
* Default is 50%. The range is 10% <= wifi_percent <= 90%.
*
* @param prefer : percent without %. Eg: 70 means 70%
* @return : ESP_OK - success, other - failed
*/
esp_err_t coex_wifi_percent_set(int wifi_percent);
/**
* @brief Get software coexist status.
* @return : software coexist status
*/
uint32_t coex_status_get(void);
/**
* @brief Set coex schm status
* @param type : WIFI/BLE/BT
* @param status : WIFI/BLE/BT STATUS
* @return : ESP_OK - success, other - failed
*/
esp_err_t coex_schm_status_set(coex_schm_st_type_t type, uint32_t status);
/**
* @brief Get coex schm status
* @param type : WIFI/BLE/BT
* @return : status
*/
uint32_t coex_schm_status_get(coex_schm_st_type_t type);
/**
* @brief Set software coexist condition.
* @return : software coexist condition

@ -1 +1 @@
Subproject commit f50b25d69a3b04d70acf249705382a6b57f81954
Subproject commit 21f3b49129798f1542cc7cca9f5f4022c80c71f4

View File

@ -184,7 +184,6 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibrat
uint32_t phy_bt_wifi_mask = BIT(PHY_BT_MODULE) | BIT(PHY_WIFI_MODULE);
if ((s_module_phy_rf_init & phy_bt_wifi_mask) == phy_bt_wifi_mask) { //both wifi & bt enabled
coex_init();
coex_preference_set(CONFIG_SW_COEXIST_PREFERENCE_VALUE);
coex_resume();
}
}