From a692abd423dc9a9babb8a51f7f2f797e40771c70 Mon Sep 17 00:00:00 2001 From: Geng Yuchao Date: Fri, 3 Jun 2022 21:57:44 +0800 Subject: [PATCH] Optimize the Cmake file structure, support esp32c2. Follow Kconfig to update the nimble config macro name. --- components/bt/CMakeLists.txt | 177 ++++++++++-------- .../host/nimble/esp-hci/src/esp_nimble_hci.c | 2 + .../host/nimble/port/include/esp_nimble_cfg.h | 39 +--- 3 files changed, 112 insertions(+), 106 deletions(-) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 6b1391be50..b6f73e0ced 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -1,45 +1,34 @@ if(CONFIG_BT_ENABLED) - if(CONFIG_IDF_TARGET_ESP32) - set(srcs "controller/esp32/bt.c" - "controller/esp32/hli_api.c" - "controller/esp32/hli_vectors.S") - elseif(CONFIG_IDF_TARGET_ESP32C3) - set(srcs "controller/esp32c3/bt.c") - elseif(CONFIG_IDF_TARGET_ESP32S3) - set(srcs "controller/esp32s3/bt.c") - elseif(CONFIG_IDF_TARGET_ESP32H2) - set(srcs "controller/esp32h2/bt.c") - endif() - if(CONFIG_NIMBLE_USE_UART_HCI) - set(srcs - "porting/nimble/src/hal_uart.c" - ) - else() - endif() - - set(include_dirs common/osi/include) + set(srcs "") + set(include_dirs "") if(CONFIG_IDF_TARGET_ESP32) - list(APPEND include_dirs include/esp32/include) + list(APPEND srcs "controller/esp32/bt.c" + "controller/esp32/hli_api.c" + "controller/esp32/hli_vectors.S") + list(APPEND include_dirs include/esp32/include) + elseif(CONFIG_IDF_TARGET_ESP32C3) - list(APPEND include_dirs include/esp32c3/include) + list(APPEND srcs "controller/esp32c3/bt.c") + list(APPEND include_dirs include/esp32c3/include) + elseif(CONFIG_IDF_TARGET_ESP32S3) - list(APPEND include_dirs include/esp32s3/include) + list(APPEND srcs "controller/esp32s3/bt.c") + list(APPEND include_dirs include/esp32s3/include) + elseif(CONFIG_IDF_TARGET_ESP32H2) - if(CONFIG_BT_BLUEDROID_ENABLED) - list(APPEND include_dirs - host/nimble/nimble/porting/nimble/include - host/nimble/nimble/nimble/include - host/nimble/nimble/porting/npl/freertos/include - host/nimble/nimble/nimble/transport/ram/include - host/nimble/port/include - include/esp32h2/include) - else() - list(APPEND include_dirs include/esp32h2/include) - endif() + list(APPEND srcs "controller/esp32h2/bt.c") + list(APPEND include_dirs include/esp32h2/include) + + elseif(CONFIG_IDF_TARGET_ESP32C2) + list(APPEND srcs "controller/esp32c2/bt.c") + list(APPEND include_dirs include/esp32c2/include) endif() + # Common + list(APPEND include_dirs common/osi/include) + list(APPEND priv_include_dirs common/btc/include common/include) @@ -48,6 +37,7 @@ if(CONFIG_BT_ENABLED) common/btc/profile/esp/blufi/include common/btc/profile/esp/include) + list(APPEND srcs "common/btc/core/btc_alarm.c" "common/api/esp_blufi_api.c" "common/btc/core/btc_manage.c" @@ -68,6 +58,7 @@ if(CONFIG_BT_ENABLED) "common/osi/osi.c" "common/osi/semaphore.c") + # Host Bluedroid if(CONFIG_BT_BLUEDROID_ENABLED) list(APPEND priv_include_dirs @@ -361,16 +352,15 @@ if(CONFIG_BT_ENABLED) "host/bluedroid/stack/smp/smp_l2c.c" "host/bluedroid/stack/smp/smp_main.c" "host/bluedroid/stack/smp/smp_utils.c") -if(CONFIG_IDF_TARGET_ESP32H2) - if(CONFIG_BT_BLUEDROID_ENABLED) + if(CONFIG_IDF_TARGET_ESP32H2 OR CONFIG_IDF_TARGET_ESP32C2) list(APPEND srcs "host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c" "host/nimble/nimble/porting/nimble/src/os_msys_init.c" "host/nimble/port/src/esp_nimble_mem.c") - endif() -endif() + endif() + + list(APPEND srcs "common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c") - list(APPEND srcs "common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c") if(CONFIG_BLE_MESH) list(APPEND srcs "esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c") endif() @@ -475,12 +465,73 @@ endif() "esp_ble_mesh/mesh_models/server/time_scene_server.c") endif() + + # Nimble + # Nimble common + if(CONFIG_BT_NIMBLE_ENABLED OR + (CONFIG_BT_CONTROLLER_ENABLED AND (CONFIG_IDF_TARGET_ESP32C2 OR CONFIG_IDF_TARGET_ESP32H2))) + list(APPEND srcs + "host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c" + "host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c" + "host/nimble/nimble/porting/nimble/src/os_cputime_pwr2.c" + "host/nimble/nimble/porting/nimble/src/hal_timer.c" + "host/nimble/nimble/porting/nimble/src/os_msys_init.c" + "host/nimble/nimble/porting/nimble/src/nimble_port.c" + "host/nimble/port/src/esp_nimble_mem.c" + "host/nimble/esp-hci/src/esp_nimble_hci.c" + "host/nimble/nimble/porting/nimble/src/os_cputime.c" + ) + + list(APPEND include_dirs + host/nimble/nimble/porting/nimble/include + host/nimble/port/include + host/nimble/nimble/nimble/include + host/nimble/nimble/porting/npl/freertos/include + host/nimble/esp-hci/include + ) + + if(NOT CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS) + + list(APPEND include_dirs + host/nimble/nimble/ext/tinycrypt/include) + + list(APPEND srcs "host/nimble/nimble/ext/tinycrypt/src/utils.c" + "host/nimble/nimble/ext/tinycrypt/src/sha256.c" + "host/nimble/nimble/ext/tinycrypt/src/ecc.c" + "host/nimble/nimble/ext/tinycrypt/src/ctr_prng.c" + "host/nimble/nimble/ext/tinycrypt/src/ctr_mode.c" + "host/nimble/nimble/ext/tinycrypt/src/aes_decrypt.c" + "host/nimble/nimble/ext/tinycrypt/src/aes_encrypt.c" + "host/nimble/nimble/ext/tinycrypt/src/ccm_mode.c" + "host/nimble/nimble/ext/tinycrypt/src/ecc_dsa.c" + "host/nimble/nimble/ext/tinycrypt/src/cmac_mode.c" + "host/nimble/nimble/ext/tinycrypt/src/ecc_dh.c" + "host/nimble/nimble/ext/tinycrypt/src/hmac_prng.c" + "host/nimble/nimble/ext/tinycrypt/src/ecc_platform_specific.c" + "host/nimble/nimble/ext/tinycrypt/src/hmac.c" + "host/nimble/nimble/ext/tinycrypt/src/cbc_mode.c") + endif() + + if(CONFIG_BT_LE_HCI_INTERFACE_USE_UART) + list(APPEND srcs + "host/nimble/nimble/porting/nimble/src/hal_uart.c" + ) + list(APPEND include_dirs + host/nimble/nimble/nimble/transport/uart/include + ) + else() + list(APPEND include_dirs + host/nimble/nimble/nimble/transport/ram/include + ) + endif() + endif() + + + if(CONFIG_BT_NIMBLE_ENABLED) list(APPEND include_dirs - host/nimble/nimble/porting/nimble/include - host/nimble/port/include - host/nimble/nimble/nimble/include + host/nimble/nimble/nimble/host/include host/nimble/nimble/nimble/host/services/ans/include host/nimble/nimble/nimble/host/services/bas/include @@ -494,31 +545,7 @@ endif() host/nimble/nimble/nimble/host/util/include host/nimble/nimble/nimble/host/store/ram/include host/nimble/nimble/nimble/host/store/config/include - host/nimble/nimble/porting/npl/freertos/include - host/nimble/nimble/nimble/transport/ram/include - host/nimble/esp-hci/include) - - if(NOT CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS) - - list(APPEND include_dirs - host/nimble/nimble/ext/tinycrypt/include) - - list(APPEND srcs "host/nimble/nimble/ext/tinycrypt/src/utils.c" - "host/nimble/nimble/ext/tinycrypt/src/sha256.c" - "host/nimble/nimble/ext/tinycrypt/src/ecc.c" - "host/nimble/nimble/ext/tinycrypt/src/ctr_prng.c" - "host/nimble/nimble/ext/tinycrypt/src/ctr_mode.c" - "host/nimble/nimble/ext/tinycrypt/src/aes_decrypt.c" - "host/nimble/nimble/ext/tinycrypt/src/aes_encrypt.c" - "host/nimble/nimble/ext/tinycrypt/src/ccm_mode.c" - "host/nimble/nimble/ext/tinycrypt/src/ecc_dsa.c" - "host/nimble/nimble/ext/tinycrypt/src/cmac_mode.c" - "host/nimble/nimble/ext/tinycrypt/src/ecc_dh.c" - "host/nimble/nimble/ext/tinycrypt/src/hmac_prng.c" - "host/nimble/nimble/ext/tinycrypt/src/ecc_platform_specific.c" - "host/nimble/nimble/ext/tinycrypt/src/hmac.c" - "host/nimble/nimble/ext/tinycrypt/src/cbc_mode.c") - endif() + ) list(APPEND srcs "host/nimble/nimble/nimble/host/util/src/addr.c" "host/nimble/nimble/nimble/host/services/gatt/src/ble_svc_gatt.c" @@ -577,15 +604,7 @@ endif() "host/nimble/nimble/nimble/host/store/ram/src/ble_store_ram.c" "host/nimble/nimble/nimble/host/store/config/src/ble_store_config.c" "host/nimble/nimble/nimble/host/store/config/src/ble_store_nvs.c" - "host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c" - "host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c" - "host/nimble/nimble/porting/nimble/src/os_cputime_pwr2.c" - "host/nimble/nimble/porting/nimble/src/hal_timer.c" - "host/nimble/nimble/porting/nimble/src/os_msys_init.c" - "host/nimble/nimble/porting/nimble/src/nimble_port.c" - "host/nimble/port/src/esp_nimble_mem.c" - "host/nimble/esp-hci/src/esp_nimble_hci.c" - "host/nimble/nimble/porting/nimble/src/os_cputime.c") + ) if(CONFIG_IDF_TARGET_ESP32) list(APPEND srcs @@ -608,8 +627,9 @@ endif() endif() - list(APPEND srcs + list(APPEND srcs "common/btc/profile/esp/blufi/nimble_host/esp_blufi.c") + if(CONFIG_BLE_MESH) list(APPEND srcs "esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c") endif() @@ -681,7 +701,10 @@ if(CONFIG_BT_ENABLED) "-L${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32s3") target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app) elseif(CONFIG_IDF_TARGET_ESP32H2) - add_prebuilt_library(nimblelib "controller/lib_esp32h2/esp32h2-bt-lib/libcontroller_5p0_seq.a") + add_prebuilt_library(nimblelib "controller/lib_esp32h2/esp32h2-bt-lib/libble_app.a") + target_link_libraries(${COMPONENT_LIB} PRIVATE nimblelib) + elseif(CONFIG_IDF_TARGET_ESP32C2) + add_prebuilt_library(nimblelib "controller/lib_esp32c2/esp32c2-bt-lib/libble_app.a") target_link_libraries(${COMPONENT_LIB} PRIVATE nimblelib) endif() diff --git a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c index bfbfb09a62..f96f435142 100644 --- a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c +++ b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c @@ -7,7 +7,9 @@ #include #include "sysinit/sysinit.h" #include "nimble/hci_common.h" +#if CONFIG_BT_NIMBLE_ENABLED #include "host/ble_hs.h" +#endif //CONFIG_BT_NIMBLE_ENABLED #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" #include "esp_nimble_hci.h" diff --git a/components/bt/host/nimble/port/include/esp_nimble_cfg.h b/components/bt/host/nimble/port/include/esp_nimble_cfg.h index 0261d59f1e..095b044819 100644 --- a/components/bt/host/nimble/port/include/esp_nimble_cfg.h +++ b/components/bt/host/nimble/port/include/esp_nimble_cfg.h @@ -22,12 +22,6 @@ #define IRAM_ATTR_64MCPU IRAM_ATTR #endif -#ifdef CONFIG_BT_NIMBLE_RUN_QA_TEST -#define RUN_QA_TEST_N (CONFIG_BT_NIMBLE_RUN_QA_TEST) -#else -#define RUN_QA_TEST_N (0) -#endif - #define BLE_LL_CTRL_PROC_TIMEOUT_MS_N (40000) /* ms */ #define BLE_LL_CFG_NUM_HCI_CMD_PKTS_N (1) @@ -54,14 +48,10 @@ #define BLE_LL_TX_PWR_DBM_N (0) -#define BLE_LL_SYNC_CNT_N (7) - -#define BLE_LL_SYNC_LIST_CNT_N (7) - -#ifndef CONFIG_BT_NIMBLE_CONTROLLER_ENABLED +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #define NIMBLE_CFG_CONTROLLER 0 #else -#define NIMBLE_CFG_CONTROLLER CONFIG_BT_NIMBLE_CONTROLLER_ENABLED +#define NIMBLE_CFG_CONTROLLER CONFIG_BT_CONTROLLER_ENABLED #endif /*** kernel/os */ @@ -144,6 +134,11 @@ #define MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS (CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS) #endif +#ifndef CONFIG_BT_NIMBLE_MAX_PERIODIC_ADVERTISER_LIST +#define MYNEWT_VAL_BLE_MAX_PERIODIC_ADVERTISER_LIST (0) +#else +#define MYNEWT_VAL_BLE_MAX_PERIODIC_ADVERTISER_LIST (CONFIG_BT_NIMBLE_MAX_PERIODIC_ADVERTISER_LIST) +#endif #ifndef CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES #define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (1) @@ -193,7 +188,7 @@ /*** @apache-mynewt-nimble/nimble/controller */ /*** @apache-mynewt-nimble/nimble/controller */ #ifndef MYNEWT_VAL_BLE_CONTROLLER -#if CONFIG_IDF_TARGET_ESP32H2 +#if NIMBLE_CFG_CONTROLLER #define MYNEWT_VAL_BLE_CONTROLLER (1) #else #define MYNEWT_VAL_BLE_CONTROLLER (0) @@ -284,10 +279,6 @@ #define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION (CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION) #endif -#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_PING -#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_PING (MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION) -#endif - /* Value copied from BLE_LL_OUR_SCA */ #ifndef MYNEWT_VAL_BLE_LL_SCA #define MYNEWT_VAL_BLE_LL_SCA (60) @@ -330,11 +321,7 @@ #endif #ifndef MYNEWT_VAL_BLE_HCI_UART_PARITY -#if CONFIG_IDF_TARGET_ESP32H2 -#define MYNEWT_VAL_BLE_HCI_UART_PARITY 0 -#else -#define MYNEWT_VAL_BLE_HCI_UART_PARITY (HAL_UART_PARITY_NONE) -#endif +#define MYNEWT_VAL_BLE_HCI_UART_PARITY (0) // HAL_UART_PARITY_NONE #endif #ifndef CONFIG_BT_NIMBLE_HCI_UART_PORT @@ -360,12 +347,6 @@ #define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV (MYNEWT_VAL_BLE_EXT_ADV) #endif -#if MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV -#define BLE_LL_SCAN_PHY_NUMBER_N (2) -#else -#define BLE_LL_SCAN_PHY_NUMBER_N (1) -#endif - /* Value copied from BLE_PERIODIC_ADV */ #ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV #define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV (CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV) @@ -431,7 +412,7 @@ #endif #ifndef MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE -#define MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE (CONFIG_BT_NIMBLE_LL_RESOLV_LIST_SIZE) +#define MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE (4) #endif #ifndef MYNEWT_VAL_BLE_LL_RNG_BUFSIZE