Skip to content

Commit

Permalink
Merge branch 'feature/separate_coex_lib_from_wifi_lib' into 'master'
Browse files Browse the repository at this point in the history
feature: separate coex lib from wifi lib

See merge request espressif/esp-idf!21791
  • Loading branch information
jack0c committed Feb 26, 2023
2 parents e8b38e1 + db11eae commit a9646eb
Show file tree
Hide file tree
Showing 51 changed files with 1,747 additions and 1,235 deletions.
1 change: 1 addition & 0 deletions .gitlab/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -80,6 +80,7 @@
/components/efuse/ @esp-idf-codeowners/system
/components/esp_adc/ @esp-idf-codeowners/peripherals
/components/esp_app_format/ @esp-idf-codeowners/system @esp-idf-codeowners/app-utilities
/components/esp_coex/ @esp-idf-codeowners/wifi @esp-idf-codeowners/bluetooth @esp-idf-codeowners/ieee802154
/components/esp_common/ @esp-idf-codeowners/system
/components/esp_eth/ @esp-idf-codeowners/network
/components/esp_event/ @esp-idf-codeowners/system
Expand Down
7 changes: 6 additions & 1 deletion .gitlab/ci/pre_check.yml
Expand Up @@ -77,13 +77,18 @@ test_check_kconfigs:
check_blobs:
extends: .pre_check_template
variables:
SUBMODULES_TO_FETCH: "components/esp_wifi/lib;components/esp_phy/lib"
SUBMODULES_TO_FETCH: "components/esp_wifi/lib;components/esp_phy/lib;components/esp_coex/lib"
script:
# Check if Wi-Fi library header files match between IDF and the version used when compiling the libraries
- IDF_TARGET=esp32 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh
- IDF_TARGET=esp32s2 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh
- IDF_TARGET=esp32s3 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh
- IDF_TARGET=esp32c3 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh
# Check if Coexistence library header files match between IDF and the version used when compiling the libraries
- IDF_TARGET=esp32 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh
- IDF_TARGET=esp32s2 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh
- IDF_TARGET=esp32s3 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh
- IDF_TARGET=esp32c3 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh
# Check if Wi-Fi, PHY, BT blobs contain references to specific symbols
- bash $IDF_PATH/tools/ci/check_blobs.sh

Expand Down
4 changes: 4 additions & 0 deletions .gitlab/ci/rules.yml
Expand Up @@ -86,6 +86,7 @@
.patterns-target_test-i154: &patterns-target_test-i154
- "components/esp_phy/**/*"
- "components/ieee802154/**/*"
- "components/esp_coex/**/*"

.patterns-example_test-i154: &patterns-example_test-i154
- "components/esp_netif/**/*"
Expand All @@ -100,6 +101,7 @@
- "components/esp_wifi/**/*"
- "components/esp_phy/**/*"
- "components/wpa_supplicant/**/*"
- "components/esp_coex/**/*"

.patterns-integration_test-ble: &patterns-integration_test-ble
- "tools/ci/python_packages/gitlab_api.py"
Expand All @@ -109,6 +111,7 @@
- "components/bt/controller/lib_esp32h2/esp32h2-bt-lib"
- "components/bt/host/nimble/nimble"
- "components/esp_phy/lib"
- "components/esp_coex/**/*"

.patterns-integration_test-wifi: &patterns-integration_test-wifi
- "tools/ci/python_packages/gitlab_api.py"
Expand Down Expand Up @@ -183,6 +186,7 @@
- "components/cmock/CMock"
- "components/esp_phy/lib"
- "components/esp_wifi/lib"
- "components/esp_coex/lib"
- "components/ieee802154/lib"
- "components/json/cJSON"
- "components/lwip/lwip"
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Expand Up @@ -86,3 +86,7 @@
[submodule "components/heap/tlsf"]
path = components/heap/tlsf
url = ../../espressif/tlsf.git

[submodule "components/esp_coex/lib"]
path = components/esp_coex/lib
url = ../../espressif/esp-coex-lib.git
2 changes: 1 addition & 1 deletion components/bt/CMakeLists.txt
Expand Up @@ -692,7 +692,7 @@ idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
REQUIRES esp_timer esp_wifi
PRIV_REQUIRES nvs_flash soc esp_pm esp_phy mbedtls driver vfs
PRIV_REQUIRES nvs_flash soc esp_pm esp_phy esp_coex mbedtls driver vfs
LDFRAGMENTS "linker.lf")

if(CONFIG_BT_ENABLED)
Expand Down
45 changes: 29 additions & 16 deletions components/bt/controller/esp32/bt.c
Expand Up @@ -89,7 +89,7 @@ do{\
} while(0)

#define OSI_FUNCS_TIME_BLOCKING 0xffffffff
#define OSI_VERSION 0x00010003
#define OSI_VERSION 0x00010004
#define OSI_MAGIC_VALUE 0xFADEBEAD

/* Types definition
Expand Down Expand Up @@ -176,6 +176,7 @@ struct osi_funcs_t {
void (*_interrupt_l3_disable)(void);
void (*_interrupt_l3_restore)(void);
void *(* _customer_queue_create)(uint32_t queue_len, uint32_t item_size);
int (* _coex_version_get)(unsigned int *major, unsigned int *minor, unsigned int *patch);
uint32_t _magic;
};

Expand Down Expand Up @@ -218,20 +219,6 @@ extern int bredr_txpwr_set(int min_power_level, int max_power_level);
extern int bredr_txpwr_get(int *min_power_level, int *max_power_level);
extern void bredr_sco_datapath_set(uint8_t data_path);
extern void btdm_controller_scan_duplicate_list_clear(void);
/* Coexistence */
extern int coex_bt_request(uint32_t event, uint32_t latency, uint32_t duration);
extern int coex_bt_release(uint32_t event);
extern int coex_register_bt_cb(coex_func_cb_t cb);
extern uint32_t coex_bb_reset_lock(void);
extern void coex_bb_reset_unlock(uint32_t restore);
extern int coex_schm_register_btdm_callback(void *callback);
extern void coex_schm_status_bit_clear(uint32_t type, uint32_t status);
extern void coex_schm_status_bit_set(uint32_t type, uint32_t status);
extern uint32_t coex_schm_interval_get(void);
extern uint8_t coex_schm_curr_period_get(void);
extern void * coex_schm_curr_phase_get(void);
extern int coex_wifi_channel_get(uint8_t *primary, uint8_t *secondary);
extern int coex_register_wifi_channel_change_callback(void *cb);
/* Shutdown */
extern void esp_bt_controller_shutdown(void);

Expand Down Expand Up @@ -320,6 +307,7 @@ static uint8_t coex_schm_curr_period_get_wrapper(void);
static void * coex_schm_curr_phase_get_wrapper(void);
static int coex_wifi_channel_get_wrapper(uint8_t *primary, uint8_t *secondary);
static int coex_register_wifi_channel_change_callback_wrapper(void *cb);
static int coex_version_get_wrapper(unsigned int *major, unsigned int *minor, unsigned int *patch);
#if CONFIG_BTDM_CTRL_HLI
static void *customer_queue_create_hlevel_wrapper(uint32_t queue_len, uint32_t item_size);
#endif /* CONFIG_BTDM_CTRL_HLI */
Expand Down Expand Up @@ -412,6 +400,7 @@ static const struct osi_funcs_t osi_funcs_ro = {
#else
._customer_queue_create = NULL,
#endif /* CONFIG_BTDM_CTRL_HLI */
._coex_version_get = coex_version_get_wrapper,
._magic = OSI_MAGIC_VALUE,
};

Expand Down Expand Up @@ -1165,7 +1154,7 @@ static void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore)
static int coex_schm_register_btdm_callback_wrapper(void *callback)
{
#if CONFIG_SW_COEXIST_ENABLE
return coex_schm_register_btdm_callback(callback);
return coex_schm_register_callback(COEX_SCHM_CALLBACK_TYPE_BT, callback);
#else
return 0;
#endif
Expand Down Expand Up @@ -1230,6 +1219,30 @@ static int coex_register_wifi_channel_change_callback_wrapper(void *cb)
#endif
}

static int coex_version_get_wrapper(unsigned int *major, unsigned int *minor, unsigned int *patch)
{
#if CONFIG_SW_COEXIST_ENABLE
const char *ver_str = esp_coex_version_get();
if (ver_str != NULL) {
unsigned int _major = 0, _minor = 0, _patch = 0;
if (sscanf(ver_str, "%u.%u.%u", &_major, &_minor, &_patch) != 3) {
return -1;
}
if (major != NULL) {
*major = _major;
}
if (minor != NULL) {
*minor = _minor;
}
if (patch != NULL) {
*patch = _patch;
}
return 0;
}
#endif
return -1;
}

bool esp_vhci_host_check_send_available(void)
{
return API_vhci_host_check_send_available();
Expand Down
1 change: 0 additions & 1 deletion components/bt/controller/esp32c2/bt.c
Expand Up @@ -114,7 +114,6 @@ struct ext_funcs_t {
*/

extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs);
extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high);
extern int ble_controller_init(esp_bt_controller_config_t *cfg);
extern int ble_controller_deinit(void);
extern int ble_controller_enable(uint8_t mode);
Expand Down
3 changes: 1 addition & 2 deletions components/bt/controller/esp32c3/bt.c
Expand Up @@ -235,7 +235,6 @@ extern int ble_txpwr_set(int power_type, int power_level);
extern int ble_txpwr_get(int power_type);

extern uint16_t l2c_ble_link_get_tx_buf_num(void);
extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high);
extern void coex_pti_v2(void);

extern bool btdm_deep_sleep_mem_init(void);
Expand Down Expand Up @@ -365,7 +364,7 @@ static const struct osi_funcs_t osi_funcs_ro = {
._btdm_sleep_exit_phase2 = NULL,
._btdm_sleep_exit_phase3 = btdm_sleep_exit_phase3_wrapper,
._coex_wifi_sleep_set = coex_wifi_sleep_set_hook,
._coex_core_ble_conn_dyn_prio_get = coex_core_ble_conn_dyn_prio_get,
._coex_core_ble_conn_dyn_prio_get = NULL,
._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper,
._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper,
._interrupt_on = interrupt_on_wrapper,
Expand Down
1 change: 0 additions & 1 deletion components/bt/controller/esp32c6/bt.c
Expand Up @@ -110,7 +110,6 @@ struct ext_funcs_t {
************************************************************************
*/
extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs);
extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high);
extern int ble_controller_init(esp_bt_controller_config_t *cfg);
extern int ble_controller_deinit(void);
extern int ble_controller_enable(uint8_t mode);
Expand Down
1 change: 0 additions & 1 deletion components/bt/controller/esp32h4/bt.c
Expand Up @@ -113,7 +113,6 @@ struct ext_funcs_t {

extern int ble_plf_set_log_level(int level);
extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs);
extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high);
extern int ble_controller_init(esp_bt_controller_config_t *cfg);
extern int ble_controller_deinit(void);
extern int ble_controller_enable(uint8_t mode);
Expand Down
3 changes: 1 addition & 2 deletions components/bt/controller/esp32s3/bt.c
Expand Up @@ -240,7 +240,6 @@ extern int ble_txpwr_set(int power_type, int power_level);
extern int ble_txpwr_get(int power_type);

extern uint16_t l2c_ble_link_get_tx_buf_num(void);
extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high);
extern void coex_pti_v2(void);

extern bool btdm_deep_sleep_mem_init(void);
Expand Down Expand Up @@ -369,7 +368,7 @@ static const struct osi_funcs_t osi_funcs_ro = {
._btdm_sleep_exit_phase2 = NULL,
._btdm_sleep_exit_phase3 = btdm_sleep_exit_phase3_wrapper,
._coex_wifi_sleep_set = coex_wifi_sleep_set_hook,
._coex_core_ble_conn_dyn_prio_get = coex_core_ble_conn_dyn_prio_get,
._coex_core_ble_conn_dyn_prio_get = NULL,
._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper,
._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper,
._interrupt_on = interrupt_on_wrapper,
Expand Down
2 changes: 1 addition & 1 deletion components/bt/controller/lib_esp32
41 changes: 41 additions & 0 deletions components/esp_coex/CMakeLists.txt
@@ -0,0 +1,41 @@
idf_build_get_property(idf_target IDF_TARGET)

if(CONFIG_ESP_COEX_SW_COEXIST_ENABLE OR CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE)
if(CONFIG_APP_NO_BLOBS)
set(link_binary_libs 0)
set(ldfragments)
else()
set(link_binary_libs 1)
set(ldfragments "linker.lf")
endif()

set(srcs
"src/coexist.c"
"${idf_target}/esp_coex_adapter.c")
endif()

if(CONFIG_ESP_WIFI_ENABLED)
list(APPEND srcs "${idf_target}/esp_coex_adapter.c")
endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include"
PRIV_REQUIRES esp_timer driver esp_event
LDFRAGMENTS "${ldfragments}")

if(CONFIG_ESP_COEX_SW_COEXIST_ENABLE OR CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE)
idf_build_get_property(build_dir BUILD_DIR)

set(target_name "${idf_target}")
target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}")

if(link_binary_libs)
set(blob coexist)

add_prebuilt_library(${blob} "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib${blob}.a"
REQUIRES ${COMPONENT_NAME})
target_link_libraries(${COMPONENT_LIB} PUBLIC ${blob})
endif()

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
endif()
28 changes: 28 additions & 0 deletions components/esp_coex/Kconfig
@@ -0,0 +1,28 @@

menu "Wireless Coexistence"
config ESP_COEX_SW_COEXIST_ENABLE
bool "Software controls WiFi/Bluetooth coexistence"
depends on (ESP_WIFI_ENABLED && BT_ENABLED) || \
(ESP_WIFI_ENABLED && IEEE802154_ENABLED)
default y
select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE
help
If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware.
Recommended for heavy traffic scenarios. Both coexistence configuration options are
automatically managed, no user intervention is required.
If only Bluetooth is used, it is recommended to disable this option to reduce binary file
size.

config ESP_COEX_EXTERNAL_COEXIST_ENABLE
bool "External Coexistence"
default n
depends on (!(BT_ENABLED||NIMBLE_ENABLED)&&(!IDF_TARGET_ESP32))
help
If enabled, HW External coexistence arbitration is managed by GPIO pins.
It can support three types of wired combinations so far which are 1-wired/2-wired/3-wired.
User can select GPIO pins in application code with configure interfaces.

This function depends on BT-off
because currently we do not support external coex and internal coex simultaneously.

endmenu # Wi-Fi

0 comments on commit a9646eb

Please sign in to comment.