From 99951fbcf8df25bab57fc6e5db9e4ad9b87c9d68 Mon Sep 17 00:00:00 2001 From: baohongde Date: Tue, 10 Dec 2019 23:00:44 +0800 Subject: [PATCH] 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 --- components/bt/Kconfig | 4 +- components/bt/bluedroid/bta/av/bta_av_aact.c | 14 ++++ components/bt/bluedroid/bta/dm/bta_dm_act.c | 8 +++ components/bt/bluedroid/bta/dm/bta_dm_main.c | 65 +++++++++++++++++++ components/bt/bluedroid/bta/dm/bta_dm_pm.c | 3 + .../bt/bluedroid/bta/dm/include/bta_dm_int.h | 5 +- .../bt/bluedroid/bta/include/bta/bta_api.h | 14 ++++ .../bt/bluedroid/osi/include/osi/thread.h | 2 +- .../stack/include/stack/btm_ble_api.h | 2 +- components/bt/lib | 2 +- components/esp32/coexist.c | 5 ++ components/esp32/cpu_start.c | 4 ++ components/esp32/include/esp_coexist.h | 9 +++ .../esp32/include/esp_coexist_internal.h | 48 +++++++++++++- components/esp32/lib | 2 +- components/esp32/phy_init.c | 1 - 16 files changed, 178 insertions(+), 10 deletions(-) diff --git a/components/bt/Kconfig b/components/bt/Kconfig index da2a31ead0..0f61ba352f 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -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. diff --git a/components/bt/bluedroid/bta/av/bta_av_aact.c b/components/bt/bluedroid/bta/av/bta_av_aact.c index 27970a990a..88cb8e4426 100644 --- a/components/bt/bluedroid/bta/av/bta_av_aact.c +++ b/components/bt/bluedroid/bta/av/bta_av_aact.c @@ -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; diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index caa6f98047..b54f353dab 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -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; diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index fbc876a6ba..a47ab7b8d3 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -28,6 +28,7 @@ #include "osi/allocator.h" #include +#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); +} diff --git a/components/bt/bluedroid/bta/dm/bta_dm_pm.c b/components/bt/bluedroid/bta/dm/bta_dm_pm.c index cf55b1c341..335095a531 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_pm.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_pm.c @@ -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); diff --git a/components/bt/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/bluedroid/bta/dm/include/bta_dm_int.h index e29b579ef3..d1b524bd35 100644 --- a/components/bt/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/include/bta_dm_int.h @@ -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 diff --git a/components/bt/bluedroid/bta/include/bta/bta_api.h b/components/bt/bluedroid/bta/include/bta/bta_api.h index 36b26d0589..a72bc1251f 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta/bta_api.h @@ -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 diff --git a/components/bt/bluedroid/osi/include/osi/thread.h b/components/bt/bluedroid/osi/include/osi/thread.h index a8e0773b90..044aacb6a5 100644 --- a/components/bt/bluedroid/osi/include/osi/thread.h +++ b/components/bt/bluedroid/osi/include/osi/thread.h @@ -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 diff --git a/components/bt/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/bluedroid/stack/include/stack/btm_ble_api.h index 7e6feb39bd..6ac146a38e 100644 --- a/components/bt/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/stack/btm_ble_api.h @@ -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 */ diff --git a/components/bt/lib b/components/bt/lib index bd605c2000..d8c93bd62b 160000 --- a/components/bt/lib +++ b/components/bt/lib @@ -1 +1 @@ -Subproject commit bd605c2000afbc9b15be92de35ec20bcd8c47fcf +Subproject commit d8c93bd62b820dd2441b2352c9b4ca9ff46ebcd0 diff --git a/components/esp32/coexist.c b/components/esp32/coexist.c index 6282699427..1172f23e42 100644 --- a/components/esp32/coexist.c +++ b/components/esp32/coexist.c @@ -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); +} diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 3267166466..9720050ab4 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -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(); diff --git a/components/esp32/include/esp_coexist.h b/components/esp32/include/esp_coexist.h index c9b241d3dc..d8b3c62f84 100644 --- a/components/esp32/include/esp_coexist.h +++ b/components/esp32/include/esp_coexist.h @@ -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 diff --git a/components/esp32/include/esp_coexist_internal.h b/components/esp32/include/esp_coexist_internal.h index bdd023a93d..d33390b41c 100644 --- a/components/esp32/include/esp_coexist_internal.h +++ b/components/esp32/include/esp_coexist_internal.h @@ -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 diff --git a/components/esp32/lib b/components/esp32/lib index f50b25d69a..21f3b49129 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit f50b25d69a3b04d70acf249705382a6b57f81954 +Subproject commit 21f3b49129798f1542cc7cca9f5f4022c80c71f4 diff --git a/components/esp32/phy_init.c b/components/esp32/phy_init.c index dc80971b8e..967b4d02d1 100644 --- a/components/esp32/phy_init.c +++ b/components/esp32/phy_init.c @@ -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(); } }