From cf6f1e82462d665a6894d6a98f7987ae66715b92 Mon Sep 17 00:00:00 2001 From: Hrishikesh Dhayagude Date: Wed, 5 Feb 2020 13:38:29 +0530 Subject: [PATCH] Add support of NimBLE host in ESP-BLE-Mesh - v3.3 --- components/bt/CMakeLists.txt | 72 +++++--- components/bt/Kconfig | 3 +- components/bt/bluedroid/api/esp_gap_bt_api.c | 1 + .../btc/profile/std/include/btc_gap_bt.h | 1 + .../bluedroid/common/include/common/bt_defs.h | 27 +-- .../common/include/common/bt_target.h | 6 +- .../common/include/common/bt_trace.h | 77 +------- components/bt/bluedroid/stack/btu/btu_init.c | 2 +- .../bluedroid/stack/include/stack/bt_types.h | 22 +-- .../btc/core/btc_alarm.c | 1 + .../btc/core/btc_manage.c | 3 - .../{bluedroid => common}/btc/core/btc_task.c | 19 +- .../btc/include/btc/btc_alarm.h | 0 .../btc/include/btc/btc_manage.h | 2 - .../btc/include/btc/btc_task.h | 7 +- components/bt/common/include/bt_common.h | 169 ++++++++++++++++++ .../bt/{bluedroid => common}/osi/alarm.c | 7 +- .../bt/{bluedroid => common}/osi/allocator.c | 2 +- .../bt/{bluedroid => common}/osi/buffer.c | 4 +- .../bt/{bluedroid => common}/osi/config.c | 2 +- .../{bluedroid => common}/osi/fixed_queue.c | 2 - .../bt/{bluedroid => common}/osi/future.c | 3 +- .../osi/hash_functions.c | 0 .../bt/{bluedroid => common}/osi/hash_map.c | 3 +- .../osi/include/osi/alarm.h | 0 .../osi/include/osi/allocator.h | 0 .../osi/include/osi/buffer.h | 0 .../osi/include/osi/config.h | 0 .../osi/include/osi/fixed_queue.h | 0 .../osi/include/osi/future.h | 0 .../osi/include/osi/hash_functions.h | 0 .../osi/include/osi/hash_map.h | 0 .../osi/include/osi/list.h | 0 .../osi/include/osi/mutex.h | 0 .../osi/include/osi/osi.h | 0 .../osi/include/osi/semaphore.h | 0 .../osi/include/osi/thread.h | 10 +- .../bt/{bluedroid => common}/osi/list.c | 3 +- .../bt/{bluedroid => common}/osi/mutex.c | 0 components/bt/{bluedroid => common}/osi/osi.c | 0 .../bt/{bluedroid => common}/osi/semaphore.c | 0 components/bt/component.mk | 31 +++- .../bt/esp_ble_mesh/mesh_common/mesh_kernel.c | 1 + .../bluedroid_host/mesh_bearer_adapt.c | 1 + .../mesh_core/include/mesh_bearer_adapt.h | 8 +- components/nimble/nimble | 2 +- .../nimble/port/include/esp_nimble_cfg.h | 8 + .../main/ble_mesh_demo_init.c | 4 +- .../main/ble_mesh_demo_init.c | 4 +- .../onoff_client/main/ble_mesh_demo_init.c | 4 +- .../onoff_server/main/ble_mesh_demo_init.c | 4 +- .../main/ble_mesh_demo_init.c | 4 +- .../main/ble_mesh_demo_init.c | 4 +- 53 files changed, 312 insertions(+), 211 deletions(-) rename components/bt/{bluedroid => common}/btc/core/btc_alarm.c (97%) rename components/bt/{bluedroid => common}/btc/core/btc_manage.c (93%) rename components/bt/{bluedroid => common}/btc/core/btc_task.c (97%) rename components/bt/{bluedroid => common}/btc/include/btc/btc_alarm.h (100%) rename components/bt/{bluedroid => common}/btc/include/btc/btc_manage.h (94%) rename components/bt/{bluedroid => common}/btc/include/btc/btc_task.h (97%) create mode 100644 components/bt/common/include/bt_common.h rename components/bt/{bluedroid => common}/osi/alarm.c (98%) rename components/bt/{bluedroid => common}/osi/allocator.c (99%) rename components/bt/{bluedroid => common}/osi/buffer.c (96%) rename components/bt/{bluedroid => common}/osi/config.c (99%) rename components/bt/{bluedroid => common}/osi/fixed_queue.c (99%) rename components/bt/{bluedroid => common}/osi/future.c (98%) rename components/bt/{bluedroid => common}/osi/hash_functions.c (100%) rename components/bt/{bluedroid => common}/osi/hash_map.c (99%) rename components/bt/{bluedroid => common}/osi/include/osi/alarm.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/allocator.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/buffer.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/config.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/fixed_queue.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/future.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/hash_functions.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/hash_map.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/list.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/mutex.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/osi.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/semaphore.h (100%) rename components/bt/{bluedroid => common}/osi/include/osi/thread.h (88%) rename components/bt/{bluedroid => common}/osi/list.c (99%) rename components/bt/{bluedroid => common}/osi/mutex.c (100%) rename components/bt/{bluedroid => common}/osi/osi.c (100%) rename components/bt/{bluedroid => common}/osi/semaphore.c (100%) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 337fcfe977..7de6b2f907 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -6,6 +6,8 @@ if(CONFIG_BT_ENABLED) if(CONFIG_BLUEDROID_ENABLED) list(APPEND COMPONENT_PRIV_INCLUDEDIRS + common/btc/include + common/include bluedroid/bta/include bluedroid/bta/ar/include bluedroid/bta/av/include @@ -18,7 +20,6 @@ if(CONFIG_BT_ENABLED) bluedroid/bta/sys/include bluedroid/device/include bluedroid/hci/include - bluedroid/osi/include bluedroid/external/sbc/decoder/include bluedroid/external/sbc/encoder/include bluedroid/btc/profile/esp/blufi/include @@ -38,11 +39,29 @@ if(CONFIG_BT_ENABLED) bluedroid/stack/a2dp/include bluedroid/stack/rfcomm/include bluedroid/stack/include - bluedroid/common/include) + bluedroid/common/include + common/btc/include + common/include) - list(APPEND COMPONENT_ADD_INCLUDEDIRS bluedroid/api/include/api) + list(APPEND COMPONENT_ADD_INCLUDEDIRS bluedroid/api/include/api + common/osi/include) - list(APPEND COMPONENT_SRCS "bluedroid/api/esp_a2dp_api.c" + list(APPEND COMPONENT_SRCS "common/btc/core/btc_alarm.c" + "common/btc/core/btc_manage.c" + "common/btc/core/btc_task.c" + "common/osi/alarm.c" + "common/osi/allocator.c" + "common/osi/buffer.c" + "common/osi/config.c" + "common/osi/fixed_queue.c" + "common/osi/future.c" + "common/osi/hash_functions.c" + "common/osi/hash_map.c" + "common/osi/list.c" + "common/osi/mutex.c" + "common/osi/osi.c" + "common/osi/semaphore.c" + "bluedroid/api/esp_a2dp_api.c" "bluedroid/api/esp_avrc_api.c" "bluedroid/api/esp_blufi_api.c" "bluedroid/api/esp_bt_device.c" @@ -109,18 +128,15 @@ if(CONFIG_BT_ENABLED) "bluedroid/bta/sys/bta_sys_conn.c" "bluedroid/bta/sys/bta_sys_main.c" "bluedroid/bta/sys/utl.c" - "bluedroid/btc/core/btc_alarm.c" "bluedroid/btc/core/btc_ble_storage.c" "bluedroid/btc/core/btc_config.c" "bluedroid/btc/core/btc_dev.c" "bluedroid/btc/core/btc_dm.c" "bluedroid/btc/core/btc_main.c" - "bluedroid/btc/core/btc_manage.c" "bluedroid/btc/core/btc_profile_queue.c" "bluedroid/btc/core/btc_sec.c" "bluedroid/btc/core/btc_sm.c" "bluedroid/btc/core/btc_storage.c" - "bluedroid/btc/core/btc_task.c" "bluedroid/btc/core/btc_util.c" "bluedroid/btc/profile/esp/blufi/blufi_prf.c" "bluedroid/btc/profile/esp/blufi/blufi_protocol.c" @@ -173,18 +189,6 @@ if(CONFIG_BT_ENABLED) "bluedroid/hci/packet_fragmenter.c" "bluedroid/main/bte_init.c" "bluedroid/main/bte_main.c" - "bluedroid/osi/alarm.c" - "bluedroid/osi/allocator.c" - "bluedroid/osi/buffer.c" - "bluedroid/osi/config.c" - "bluedroid/osi/fixed_queue.c" - "bluedroid/osi/future.c" - "bluedroid/osi/hash_functions.c" - "bluedroid/osi/hash_map.c" - "bluedroid/osi/list.c" - "bluedroid/osi/mutex.c" - "bluedroid/osi/osi.c" - "bluedroid/osi/semaphore.c" "bluedroid/stack/a2dp/a2d_api.c" "bluedroid/stack/a2dp/a2d_sbc.c" "bluedroid/stack/avct/avct_api.c" @@ -281,7 +285,6 @@ if(CONFIG_BT_ENABLED) "bluedroid/stack/smp/smp_utils.c") if(CONFIG_BLE_MESH) - list(APPEND COMPONENT_ADD_INCLUDEDIRS bluedroid/osi/include) list(APPEND COMPONENT_SRCS "esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c") endif() @@ -362,6 +365,35 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/mesh_models/server/state_transition.c" "esp_ble_mesh/mesh_models/server/time_scene_server.c") endif() + + if(CONFIG_NIMBLE_ENABLED) + + if (CONFIG_BLE_MESH) + list(APPEND COMPONENT_PRIV_INCLUDEDIRS + common/btc/include + common/include) + + list(APPEND COMPONENT_ADD_INCLUDEDIRS common/osi/include) + + list(APPEND COMPONENT_SRCS "esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c" + "common/btc/core/btc_alarm.c" + "common/btc/core/btc_manage.c" + "common/btc/core/btc_task.c" + "common/osi/alarm.c" + "common/osi/allocator.c" + "common/osi/buffer.c" + "common/osi/config.c" + "common/osi/fixed_queue.c" + "common/osi/future.c" + "common/osi/hash_functions.c" + "common/osi/hash_map.c" + "common/osi/list.c" + "common/osi/mutex.c" + "common/osi/osi.c" + "common/osi/semaphore.c") + endif() + + endif() endif() # requirements can't depend on config diff --git a/components/bt/Kconfig b/components/bt/Kconfig index ec8c20317b..9ee47b45e5 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1341,7 +1341,7 @@ menu Bluetooth config NIMBLE_MAX_CONNECTIONS int "Maximum number of concurrent connections" range 1 9 - default 1 + default BTDM_CONTROLLER_BLE_MAX_CONN depends on NIMBLE_ENABLED help Defines maximum number of concurrent BLE connections @@ -1392,6 +1392,7 @@ menu Bluetooth config NIMBLE_TASK_STACK_SIZE int "NimBLE Host task stack size" depends on NIMBLE_ENABLED + default 5120 if BLE_MESH default 4096 help This configures stack size of NimBLE host task diff --git a/components/bt/bluedroid/api/esp_gap_bt_api.c b/components/bt/bluedroid/api/esp_gap_bt_api.c index ac0326e11f..89e1df33fa 100644 --- a/components/bt/bluedroid/api/esp_gap_bt_api.c +++ b/components/bt/bluedroid/api/esp_gap_bt_api.c @@ -17,6 +17,7 @@ #include "esp_bt_main.h" #include "esp_gap_bt_api.h" #include "common/bt_trace.h" +#include "bta/bta_api.h" #include "btc/btc_manage.h" #include "btc_gap_bt.h" #include "btc/btc_storage.h" diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gap_bt.h b/components/bt/bluedroid/btc/profile/std/include/btc_gap_bt.h index 67e03cb3f9..847b938194 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gap_bt.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gap_bt.h @@ -16,6 +16,7 @@ #define __BTC_GAP_BT_H__ #include "common/bt_target.h" +#include "common/bt_defs.h" #include "esp_bt_defs.h" #include "esp_gap_bt_api.h" #include "btc/btc_task.h" diff --git a/components/bt/bluedroid/common/include/common/bt_defs.h b/components/bt/bluedroid/common/include/common/bt_defs.h index 77719bc847..7421e7b147 100644 --- a/components/bt/bluedroid/common/include/common/bt_defs.h +++ b/components/bt/bluedroid/common/include/common/bt_defs.h @@ -21,7 +21,7 @@ #include #include -#include "common/bt_trace.h" +#include "bt_common.h" #include "common/bt_target.h" #define UNUSED(x) (void)(x) @@ -65,31 +65,6 @@ typedef struct { uint8_t uu[16]; } bt_uuid_t; -/** Bluetooth Error Status */ -/** We need to build on this */ - -/* relate to ESP_BT_STATUS_xxx in esp_bt_defs.h */ -typedef enum { - BT_STATUS_SUCCESS = 0, - BT_STATUS_FAIL, - BT_STATUS_NOT_READY, - BT_STATUS_NOMEM, - BT_STATUS_BUSY, - BT_STATUS_DONE, /* request already completed */ - BT_STATUS_UNSUPPORTED, - BT_STATUS_PARM_INVALID, - BT_STATUS_UNHANDLED, - BT_STATUS_AUTH_FAILURE, - BT_STATUS_RMT_DEV_DOWN, - BT_STATUS_AUTH_REJECTED, - BT_STATUS_INVALID_STATIC_RAND_ADDR, - BT_STATUS_PENDING, - BT_STATUS_UNACCEPT_CONN_INTERVAL, - BT_STATUS_PARAM_OUT_OF_RANGE, - BT_STATUS_TIMEOUT, - BT_STATUS_MEMORY_FULL, -} bt_status_t; - #ifndef CPU_LITTLE_ENDIAN #define CPU_LITTLE_ENDIAN #endif diff --git a/components/bt/bluedroid/common/include/common/bt_target.h b/components/bt/bluedroid/common/include/common/bt_target.h index f2c0d3c211..4504e0cd86 100644 --- a/components/bt/bluedroid/common/include/common/bt_target.h +++ b/components/bt/bluedroid/common/include/common/bt_target.h @@ -20,6 +20,8 @@ #ifndef BT_TARGET_H #define BT_TARGET_H +#include "bt_common.h" + #ifndef BUILDCFG #define BUILDCFG #endif @@ -349,10 +351,6 @@ #define BTA_AV_CO_CP_SCMS_T FALSE//FALSE #endif -#ifndef QUEUE_CONGEST_SIZE -#define QUEUE_CONGEST_SIZE 40 -#endif - #ifndef CONFIG_BLE_HOST_QUEUE_CONGESTION_CHECK #define SCAN_QUEUE_CONGEST_CHECK FALSE #else diff --git a/components/bt/bluedroid/common/include/common/bt_trace.h b/components/bt/bluedroid/common/include/common/bt_trace.h index 7583479b2b..780ff2d08c 100644 --- a/components/bt/bluedroid/common/include/common/bt_trace.h +++ b/components/bt/bluedroid/common/include/common/bt_trace.h @@ -23,38 +23,7 @@ #include #include "stack/bt_types.h" - -#ifndef LOG_LOCAL_LEVEL -#ifndef BOOTLOADER_BUILD -#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL -#else -#define LOG_LOCAL_LEVEL CONFIG_LOG_BOOTLOADER_LEVEL -#endif -#endif - -#include "esp_log.h" - -// Mapping between ESP_LOG_LEVEL and BT_TRACE_LEVEL -#if (LOG_LOCAL_LEVEL >= 4) -#define LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL+1) -#else -#define LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL -#endif - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define BT_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_INITIAL_TRACE_LEVEL, LOG_LOCAL_LEVEL_MAPPING) >= BT_TRACE_LEVEL_##LEVEL) - -//#define TAG "BT" - -#define BT_PRINT_E(tag, format, ...) {esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_PRINT_W(tag, format, ...) {esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_PRINT_I(tag, format, ...) {esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_PRINT_D(tag, format, ...) {esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_PRINT_V(tag, format, ...) {esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } - -#ifndef assert -#define assert(x) do { if (!(x)) BT_PRINT_E("bt host error %s %u\n", __FILE__, __LINE__); } while (0) -#endif +#include "bt_common.h" inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len) { @@ -324,18 +293,6 @@ inline void trc_dump_buffer(const char *prefix, uint8_t *data, uint16_t len) #define BTIF_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING #endif -#ifdef CONFIG_BTC_INITIAL_TRACE_LEVEL -#define BTC_INITIAL_TRACE_LEVEL CONFIG_BTC_INITIAL_TRACE_LEVEL -#else -#define BTC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - -#ifdef CONFIG_OSI_INITIAL_TRACE_LEVEL -#define OSI_INITIAL_TRACE_LEVEL CONFIG_OSI_INITIAL_TRACE_LEVEL -#else -#define OSI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING -#endif - #ifdef CONFIG_BLUFI_INITIAL_TRACE_LEVEL #define BLUFI_INITIAL_TRACE_LEVEL CONFIG_BLUFI_INITIAL_TRACE_LEVEL #else @@ -497,22 +454,6 @@ extern UINT8 btif_trace_level; #define HCI_TRACE_EVENT(fmt, args...) {if (HCI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(HCI,EVENT)) BT_PRINT_D("BT_HCI", fmt,## args);} #define HCI_TRACE_DEBUG(fmt, args...) {if (HCI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(HCI,DEBUG)) BT_PRINT_D("BT_HCI", fmt,## args);} -/* define traces for BTC */ -#define BTC_TRACE_ERROR(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(BTC, ERROR)) BT_PRINT_E("BT_BTC", fmt, ## args);} -#define BTC_TRACE_WARNING(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(BTC, WARNING)) BT_PRINT_W("BT_BTC", fmt, ## args);} -#define BTC_TRACE_API(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(BTC,API)) BT_PRINT_I("BT_BTC", fmt, ## args);} -#define BTC_TRACE_EVENT(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(BTC,EVENT)) BT_PRINT_D("BT_BTC", fmt, ## args);} -#define BTC_TRACE_DEBUG(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(BTC,DEBUG)) BT_PRINT_D("BT_BTC", fmt, ## args);} -#define BTC_TRACE_VERBOSE(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_VERBOSE && BT_LOG_LEVEL_CHECK(BTC,VERBOSE)) BT_PRINT_V("BT_BTC", fmt, ## args);} - -/* define traces for OSI */ -#define OSI_TRACE_ERROR(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(OSI, ERROR)) BT_PRINT_E("BT_OSI", fmt, ## args);} -#define OSI_TRACE_WARNING(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(OSI, WARNING)) BT_PRINT_W("BT_OSI", fmt, ## args);} -#define OSI_TRACE_API(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(OSI,API)) BT_PRINT_I("BT_OSI", fmt, ## args);} -#define OSI_TRACE_EVENT(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(OSI,EVENT)) BT_PRINT_D("BT_OSI", fmt, ## args);} -#define OSI_TRACE_DEBUG(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(OSI,DEBUG)) BT_PRINT_D("BT_OSI", fmt, ## args);} -#define OSI_TRACE_VERBOSE(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_VERBOSE && BT_LOG_LEVEL_CHECK(OSI,VERBOSE)) BT_PRINT_V("BT_OSI", fmt, ## args);} - /* define traces for BLUFI */ #define BLUFI_TRACE_ERROR(fmt, args...) {if (BLUFI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(BLUFI, ERROR)) BT_PRINT_E("BT_BLUFI", fmt, ## args);} #define BLUFI_TRACE_WARNING(fmt, args...) {if (BLUFI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(BLUFI, WARNING)) BT_PRINT_W("BT_BLUFI", fmt, ## args);} @@ -671,22 +612,6 @@ extern UINT8 btif_trace_level; #define APPL_TRACE_DEBUG(fmt, args...) #define APPL_TRACE_VERBOSE(fmt, args...) -/* define traces for BTC */ -#define BTC_TRACE_ERROR(fmt, args...) -#define BTC_TRACE_WARNING(fmt, args...) -#define BTC_TRACE_API(fmt, args...) -#define BTC_TRACE_EVENT(fmt, args...) -#define BTC_TRACE_DEBUG(fmt, args...) -#define BTC_TRACE_VERBOSE(fmt, args...) - -/* define traces for OSI */ -#define OSI_TRACE_ERROR(fmt, args...) -#define OSI_TRACE_WARNING(fmt, args...) -#define OSI_TRACE_API(fmt, args...) -#define OSI_TRACE_EVENT(fmt, args...) -#define OSI_TRACE_DEBUG(fmt, args...) -#define OSI_TRACE_VERBOSE(fmt, args...) - /* define traces for BLUFI */ #define BLUFI_TRACE_ERROR(fmt, args...) #define BLUFI_TRACE_WARNING(fmt, args...) diff --git a/components/bt/bluedroid/stack/btu/btu_init.c b/components/bt/bluedroid/stack/btu/btu_init.c index 7014cfde00..f9c3d12c3d 100644 --- a/components/bt/bluedroid/stack/btu/btu_init.c +++ b/components/bt/bluedroid/stack/btu/btu_init.c @@ -240,7 +240,7 @@ UINT16 BTU_BleAclPktSize(void) bool BTU_check_queue_is_congest(void) { UBaseType_t wait_size = uxQueueMessagesWaiting(xBtuQueue); - if(wait_size >= QUEUE_CONGEST_SIZE ) { + if(wait_size >= BT_QUEUE_CONGEST_SIZE ) { return true; } return false; diff --git a/components/bt/bluedroid/stack/include/stack/bt_types.h b/components/bt/bluedroid/stack/include/stack/bt_types.h index 52385cb513..b331125f35 100644 --- a/components/bt/bluedroid/stack/include/stack/bt_types.h +++ b/components/bt/bluedroid/stack/include/stack/bt_types.h @@ -21,14 +21,7 @@ #include #include - -#ifndef FALSE -# define FALSE false -#endif - -#ifndef TRUE -# define TRUE true -#endif +#include "bt_common.h" typedef uint8_t UINT8; typedef uint16_t UINT16; @@ -524,19 +517,6 @@ typedef struct { typedef UINT8 tBT_DEVICE_TYPE; /*****************************************************************************/ - -/* Define trace levels */ -#define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ -#define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ -#define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ -#define BT_TRACE_LEVEL_API 3 /* API traces */ -#define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ -#define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ -#define BT_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ - -#define MAX_TRACE_LEVEL 6 - - /* Define New Trace Type Definition */ /* TRACE_CTRL_TYPE 0x^^000000*/ #define TRACE_CTRL_MASK 0xff000000 diff --git a/components/bt/bluedroid/btc/core/btc_alarm.c b/components/bt/common/btc/core/btc_alarm.c similarity index 97% rename from components/bt/bluedroid/btc/core/btc_alarm.c rename to components/bt/common/btc/core/btc_alarm.c index ade9f093ac..653f9826d2 100644 --- a/components/bt/bluedroid/btc/core/btc_alarm.c +++ b/components/bt/common/btc/core/btc_alarm.c @@ -14,6 +14,7 @@ #include "btc/btc_task.h" #include "btc/btc_alarm.h" +#include "esp_log.h" void btc_alarm_handler(btc_msg_t *msg) { diff --git a/components/bt/bluedroid/btc/core/btc_manage.c b/components/bt/common/btc/core/btc_manage.c similarity index 93% rename from components/bt/bluedroid/btc/core/btc_manage.c rename to components/bt/common/btc/core/btc_manage.c index 81ecad4103..037deee3a8 100644 --- a/components/bt/bluedroid/btc/core/btc_manage.c +++ b/components/bt/common/btc/core/btc_manage.c @@ -14,10 +14,7 @@ #include "btc/btc_task.h" -#include "common/bt_trace.h" #include "osi/thread.h" -#include "esp_bt_defs.h" -#include "esp_gatt_defs.h" static void *btc_profile_cb_tab[BTC_PID_NUM] = {}; diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/common/btc/core/btc_task.c similarity index 97% rename from components/bt/bluedroid/btc/core/btc_task.c rename to components/bt/common/btc/core/btc_task.c index 21726cf898..53f77629a9 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/common/btc/core/btc_task.c @@ -14,12 +14,14 @@ #include #include -#include "common/bt_target.h" #include "btc/btc_task.h" -#include "common/bt_trace.h" #include "osi/thread.h" -#include "common/bt_defs.h" +#include "esp_log.h" +#include "bt_common.h" #include "osi/allocator.h" +#include "btc/btc_alarm.h" +#ifdef CONFIG_BLUEDROID_ENABLED +#include "common/bt_target.h" #include "btc/btc_main.h" #include "btc/btc_dev.h" #include "btc_gatts.h" @@ -28,7 +30,6 @@ #include "btc_gap_ble.h" #include "btc_blufi_prf.h" #include "btc/btc_dm.h" -#include "btc/btc_alarm.h" #include "bta/bta_gatt_api.h" #if CONFIG_CLASSIC_BT_ENABLED #include "btc/btc_profile_queue.h" @@ -46,6 +47,7 @@ #include "btc_hf_client.h" #endif /* #if BTC_HF_CLIENT_INCLUDED */ #endif /* #if CONFIG_CLASSIC_BT_ENABLED */ +#endif #if CONFIG_BLE_MESH #include "btc_ble_mesh_prov.h" @@ -61,6 +63,7 @@ static xTaskHandle xBtcTaskHandle = NULL; static xQueueHandle xBtcQueue = 0; static btc_func_t profile_tab[BTC_PID_NUM] = { +#ifdef CONFIG_BLUEDROID_ENABLED [BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL }, [BTC_PID_DEV] = {btc_dev_call_handler, NULL }, #if (GATTS_INCLUDED == TRUE) @@ -79,7 +82,9 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { [BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler }, #endif ///GATTS_INCLUDED == TRUE [BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler }, +#endif [BTC_PID_ALARM] = {btc_alarm_handler, NULL }, +#ifdef CONFIG_BLUEDROID_ENABLED #if CONFIG_CLASSIC_BT_ENABLED #if (BTC_GAP_BT_INCLUDED == TRUE) [BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler }, @@ -96,6 +101,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { [BTC_PID_HF_CLIENT] = {btc_hf_client_call_handler, btc_hf_client_cb_handler}, #endif /* #if BTC_HF_CLIENT_INCLUDED */ #endif /* #if CONFIG_CLASSIC_BT_ENABLED */ +#endif #if CONFIG_BLE_MESH [BTC_PID_PROV] = {btc_ble_mesh_prov_call_handler, btc_ble_mesh_prov_cb_handler }, [BTC_PID_MODEL] = {btc_ble_mesh_model_call_handler, btc_ble_mesh_model_cb_handler }, @@ -194,7 +200,10 @@ int btc_init(void) if (xBtcTaskHandle == NULL || xBtcQueue == 0){ return BT_STATUS_NOMEM; } +#ifdef CONFIG_BLUEDROID_ENABLED btc_gap_callback_init(); +#endif + #if SCAN_QUEUE_CONGEST_CHECK btc_adv_list_init(); #endif @@ -216,7 +225,7 @@ void btc_deinit(void) bool btc_check_queue_is_congest(void) { UBaseType_t wait_size = uxQueueMessagesWaiting(xBtcQueue); - if(wait_size >= QUEUE_CONGEST_SIZE) { + if(wait_size >= BT_QUEUE_CONGEST_SIZE) { return true; } return false; diff --git a/components/bt/bluedroid/btc/include/btc/btc_alarm.h b/components/bt/common/btc/include/btc/btc_alarm.h similarity index 100% rename from components/bt/bluedroid/btc/include/btc/btc_alarm.h rename to components/bt/common/btc/include/btc/btc_alarm.h diff --git a/components/bt/bluedroid/btc/include/btc/btc_manage.h b/components/bt/common/btc/include/btc/btc_manage.h similarity index 94% rename from components/bt/bluedroid/btc/include/btc/btc_manage.h rename to components/bt/common/btc/include/btc/btc_manage.h index 46f746e8df..778786baaf 100644 --- a/components/bt/bluedroid/btc/include/btc/btc_manage.h +++ b/components/bt/common/btc/include/btc/btc_manage.h @@ -15,9 +15,7 @@ #ifndef __BTC_MANAGE_H__ #define __BTC_MANAGE_H__ -#include "bta/bta_api.h" #include "btc/btc_task.h" -#include "esp_bt_defs.h" /* reset gatt callback table */ void esp_profile_cb_reset(void); diff --git a/components/bt/bluedroid/btc/include/btc/btc_task.h b/components/bt/common/btc/include/btc/btc_task.h similarity index 97% rename from components/bt/bluedroid/btc/include/btc/btc_task.h rename to components/bt/common/btc/include/btc/btc_task.h index aa916d6f0e..00b63e55c0 100644 --- a/components/bt/bluedroid/btc/include/btc/btc_task.h +++ b/components/bt/common/btc/include/btc/btc_task.h @@ -16,10 +16,13 @@ #define __BTC_TASK_H__ #include -#include "common/bt_target.h" -#include "common/bt_defs.h" +#include "bt_common.h" #include "osi/thread.h" +#if CONFIG_BLUEDROID_ENABLED +#include "common/bt_target.h" +#endif + typedef struct btc_msg { uint8_t sig; //event signal uint8_t aid; //application id diff --git a/components/bt/common/include/bt_common.h b/components/bt/common/include/bt_common.h new file mode 100644 index 0000000000..32c7ce3485 --- /dev/null +++ b/components/bt/common/include/bt_common.h @@ -0,0 +1,169 @@ + +// Copyright 2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _BT_COMMON_H_ +#define _BT_COMMON_H_ + +#include "esp_log.h" + +#ifndef FALSE +#define FALSE false +#endif + +#ifndef TRUE +#define TRUE true +#endif + +#ifndef BT_QUEUE_CONGEST_SIZE +#define BT_QUEUE_CONGEST_SIZE 40 +#endif + +#ifdef CONFIG_BTC_INITIAL_TRACE_LEVEL +#define BTC_INITIAL_TRACE_LEVEL CONFIG_BTC_INITIAL_TRACE_LEVEL +#else +#define BTC_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#ifdef CONFIG_OSI_INITIAL_TRACE_LEVEL +#define OSI_INITIAL_TRACE_LEVEL CONFIG_OSI_INITIAL_TRACE_LEVEL +#else +#define OSI_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING +#endif + +#if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY +#define BT_BLE_DYNAMIC_ENV_MEMORY TRUE +#else +#define BT_BLE_DYNAMIC_ENV_MEMORY FALSE +#endif + +#ifdef CONFIG_BLUEDROID_PINNED_TO_CORE +#define TASK_PINNED_TO_CORE (CONFIG_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY) +#define BTC_TASK_STACK_SIZE (CONFIG_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig +#endif + +#ifdef CONFIG_NIMBLE_ENABLED +#define TASK_PINNED_TO_CORE (CONFIG_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY) +#define BTC_TASK_STACK_SIZE 4096 +#endif + +#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) +#define BTC_TASK_PRIO (configMAX_PRIORITIES - 6) +#define BTC_TASK_QUEUE_LEN 60 + +/* Define trace levels */ +#define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ +#define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ +#define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ +#define BT_TRACE_LEVEL_API 3 /* API traces */ +#define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ +#define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ +#define BT_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ + +#define MAX_TRACE_LEVEL 6 + +#ifndef LOG_LOCAL_LEVEL +#ifndef BOOTLOADER_BUILD +#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#else +#define LOG_LOCAL_LEVEL CONFIG_LOG_BOOTLOADER_LEVEL +#endif +#endif + +// Mapping between ESP_LOG_LEVEL and BT_TRACE_LEVEL +#if (LOG_LOCAL_LEVEL >= 4) +#define LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL+1) +#else +#define LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL +#endif + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + +#define BT_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_INITIAL_TRACE_LEVEL, LOG_LOCAL_LEVEL_MAPPING) >= BT_TRACE_LEVEL_##LEVEL) + +#define BT_PRINT_E(tag, format, ...) {esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BT_PRINT_W(tag, format, ...) {esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BT_PRINT_I(tag, format, ...) {esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BT_PRINT_D(tag, format, ...) {esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BT_PRINT_V(tag, format, ...) {esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } + +#ifndef assert +#define assert(x) do { if (!(x)) BT_PRINT_E("BT", "bt host error %s %u\n", __FILE__, __LINE__); } while (0) +#endif + + +#if !CONFIG_BT_STACK_NO_LOG +/* define traces for BTC */ +#define BTC_TRACE_ERROR(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(BTC, ERROR)) BT_PRINT_E("BT_BTC", fmt, ## args);} +#define BTC_TRACE_WARNING(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(BTC, WARNING)) BT_PRINT_W("BT_BTC", fmt, ## args);} +#define BTC_TRACE_API(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(BTC,API)) BT_PRINT_I("BT_BTC", fmt, ## args);} +#define BTC_TRACE_EVENT(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(BTC,EVENT)) BT_PRINT_D("BT_BTC", fmt, ## args);} +#define BTC_TRACE_DEBUG(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(BTC,DEBUG)) BT_PRINT_D("BT_BTC", fmt, ## args);} +#define BTC_TRACE_VERBOSE(fmt, args...) {if (BTC_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_VERBOSE && BT_LOG_LEVEL_CHECK(BTC,VERBOSE)) BT_PRINT_V("BT_BTC", fmt, ## args);} + +/* define traces for OSI */ +#define OSI_TRACE_ERROR(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_ERROR && BT_LOG_LEVEL_CHECK(OSI, ERROR)) BT_PRINT_E("BT_OSI", fmt, ## args);} +#define OSI_TRACE_WARNING(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_WARNING && BT_LOG_LEVEL_CHECK(OSI, WARNING)) BT_PRINT_W("BT_OSI", fmt, ## args);} +#define OSI_TRACE_API(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_API && BT_LOG_LEVEL_CHECK(OSI,API)) BT_PRINT_I("BT_OSI", fmt, ## args);} +#define OSI_TRACE_EVENT(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_EVENT && BT_LOG_LEVEL_CHECK(OSI,EVENT)) BT_PRINT_D("BT_OSI", fmt, ## args);} +#define OSI_TRACE_DEBUG(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_DEBUG && BT_LOG_LEVEL_CHECK(OSI,DEBUG)) BT_PRINT_D("BT_OSI", fmt, ## args);} +#define OSI_TRACE_VERBOSE(fmt, args...) {if (OSI_INITIAL_TRACE_LEVEL >= BT_TRACE_LEVEL_VERBOSE && BT_LOG_LEVEL_CHECK(OSI,VERBOSE)) BT_PRINT_V("BT_OSI", fmt, ## args);} + +#else + +/* define traces for BTC */ +#define BTC_TRACE_ERROR(fmt, args...) +#define BTC_TRACE_WARNING(fmt, args...) +#define BTC_TRACE_API(fmt, args...) +#define BTC_TRACE_EVENT(fmt, args...) +#define BTC_TRACE_DEBUG(fmt, args...) +#define BTC_TRACE_VERBOSE(fmt, args...) + +/* define traces for OSI */ +#define OSI_TRACE_ERROR(fmt, args...) +#define OSI_TRACE_WARNING(fmt, args...) +#define OSI_TRACE_API(fmt, args...) +#define OSI_TRACE_EVENT(fmt, args...) +#define OSI_TRACE_DEBUG(fmt, args...) +#define OSI_TRACE_VERBOSE(fmt, args...) + +#endif + +/** Bluetooth Error Status */ +/** We need to build on this */ + +/* relate to ESP_BT_STATUS_xxx in esp_bt_defs.h */ +typedef enum { + BT_STATUS_SUCCESS = 0, + BT_STATUS_FAIL, + BT_STATUS_NOT_READY, + BT_STATUS_NOMEM, + BT_STATUS_BUSY, + BT_STATUS_DONE, /* request already completed */ + BT_STATUS_UNSUPPORTED, + BT_STATUS_PARM_INVALID, + BT_STATUS_UNHANDLED, + BT_STATUS_AUTH_FAILURE, + BT_STATUS_RMT_DEV_DOWN, + BT_STATUS_AUTH_REJECTED, + BT_STATUS_INVALID_STATIC_RAND_ADDR, + BT_STATUS_PENDING, + BT_STATUS_UNACCEPT_CONN_INTERVAL, + BT_STATUS_PARAM_OUT_OF_RANGE, + BT_STATUS_TIMEOUT, + BT_STATUS_MEMORY_FULL, + BT_STATUS_EIR_TOO_LARGE, +} bt_status_t; + +#endif /* _BT_COMMON_H_ */ diff --git a/components/bt/bluedroid/osi/alarm.c b/components/bt/common/osi/alarm.c similarity index 98% rename from components/bt/bluedroid/osi/alarm.c rename to components/bt/common/osi/alarm.c index 5307010590..0a216a8dba 100644 --- a/components/bt/bluedroid/osi/alarm.c +++ b/components/bt/common/osi/alarm.c @@ -18,8 +18,6 @@ #include #include #include -#include "common/bt_defs.h" -#include "common/bt_trace.h" #include "osi/alarm.h" #include "osi/allocator.h" #include "osi/list.h" @@ -27,6 +25,7 @@ #include "btc/btc_task.h" #include "btc/btc_alarm.h" #include "osi/mutex.h" +#include "bt_common.h" typedef struct alarm_t { /* timer id point to here */ @@ -251,12 +250,12 @@ end: osi_alarm_err_t osi_alarm_set(osi_alarm_t *alarm, period_ms_t timeout) { - return alarm_set(alarm, timeout, false); + return alarm_set(alarm, timeout, FALSE); } osi_alarm_err_t osi_alarm_set_periodic(osi_alarm_t *alarm, period_ms_t period) { - return alarm_set(alarm, period, true); + return alarm_set(alarm, period, TRUE); } osi_alarm_err_t osi_alarm_cancel(osi_alarm_t *alarm) diff --git a/components/bt/bluedroid/osi/allocator.c b/components/bt/common/osi/allocator.c similarity index 99% rename from components/bt/bluedroid/osi/allocator.c rename to components/bt/common/osi/allocator.c index 7a06015e25..006f44209e 100644 --- a/components/bt/bluedroid/osi/allocator.c +++ b/components/bt/common/osi/allocator.c @@ -18,7 +18,7 @@ #include #include -#include "common/bt_defs.h" +#include "bt_common.h" #include "osi/allocator.h" extern void *pvPortZalloc(size_t size); diff --git a/components/bt/bluedroid/osi/buffer.c b/components/bt/common/osi/buffer.c similarity index 96% rename from components/bt/bluedroid/osi/buffer.c rename to components/bt/common/osi/buffer.c index 6b21ed8e28..5593675296 100644 --- a/components/bt/bluedroid/osi/buffer.c +++ b/components/bt/common/osi/buffer.c @@ -16,11 +16,9 @@ * ******************************************************************************/ #include -#include "common/bt_trace.h" +#include "bt_common.h" #include "osi/allocator.h" #include "osi/buffer.h" -#include "common/bt_defs.h" -#include "common/bt_trace.h" struct buffer_t { buffer_t *root; diff --git a/components/bt/bluedroid/osi/config.c b/components/bt/common/osi/config.c similarity index 99% rename from components/bt/bluedroid/osi/config.c rename to components/bt/common/osi/config.c index bd7307e8a3..75ec639679 100644 --- a/components/bt/bluedroid/osi/config.c +++ b/components/bt/common/osi/config.c @@ -23,10 +23,10 @@ #include #include +#include "bt_common.h" #include "osi/allocator.h" #include "osi/config.h" #include "osi/list.h" -#include "common/bt_trace.h" #define CONFIG_FILE_MAX_SIZE (1536)//1.5k #define CONFIG_FILE_DEFAULE_LENGTH (2048) diff --git a/components/bt/bluedroid/osi/fixed_queue.c b/components/bt/common/osi/fixed_queue.c similarity index 99% rename from components/bt/bluedroid/osi/fixed_queue.c rename to components/bt/common/osi/fixed_queue.c index 24442a0960..d0e68edb2c 100644 --- a/components/bt/bluedroid/osi/fixed_queue.c +++ b/components/bt/common/osi/fixed_queue.c @@ -16,12 +16,10 @@ * ******************************************************************************/ -#include "common/bt_defs.h" #include "osi/allocator.h" #include "osi/fixed_queue.h" #include "osi/list.h" #include "osi/osi.h" -#include "common/bt_trace.h" #include "osi/mutex.h" #include "osi/semaphore.h" diff --git a/components/bt/bluedroid/osi/future.c b/components/bt/common/osi/future.c similarity index 98% rename from components/bt/bluedroid/osi/future.c rename to components/bt/common/osi/future.c index 25eb5605e6..aee33b1c01 100644 --- a/components/bt/bluedroid/osi/future.c +++ b/components/bt/common/osi/future.c @@ -16,8 +16,7 @@ * ******************************************************************************/ -#include "common/bt_trace.h" - +#include "bt_common.h" #include "osi/allocator.h" #include "osi/future.h" #include "osi/osi.h" diff --git a/components/bt/bluedroid/osi/hash_functions.c b/components/bt/common/osi/hash_functions.c similarity index 100% rename from components/bt/bluedroid/osi/hash_functions.c rename to components/bt/common/osi/hash_functions.c diff --git a/components/bt/bluedroid/osi/hash_map.c b/components/bt/common/osi/hash_map.c similarity index 99% rename from components/bt/bluedroid/osi/hash_map.c rename to components/bt/common/osi/hash_map.c index 1487b07edc..bd7f67d00b 100644 --- a/components/bt/bluedroid/osi/hash_map.c +++ b/components/bt/common/osi/hash_map.c @@ -16,8 +16,7 @@ * ******************************************************************************/ -#include "common/bt_defs.h" -#include "common/bt_trace.h" +#include "bt_common.h" #include "osi/list.h" #include "osi/hash_map.h" #include "osi/allocator.h" diff --git a/components/bt/bluedroid/osi/include/osi/alarm.h b/components/bt/common/osi/include/osi/alarm.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/alarm.h rename to components/bt/common/osi/include/osi/alarm.h diff --git a/components/bt/bluedroid/osi/include/osi/allocator.h b/components/bt/common/osi/include/osi/allocator.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/allocator.h rename to components/bt/common/osi/include/osi/allocator.h diff --git a/components/bt/bluedroid/osi/include/osi/buffer.h b/components/bt/common/osi/include/osi/buffer.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/buffer.h rename to components/bt/common/osi/include/osi/buffer.h diff --git a/components/bt/bluedroid/osi/include/osi/config.h b/components/bt/common/osi/include/osi/config.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/config.h rename to components/bt/common/osi/include/osi/config.h diff --git a/components/bt/bluedroid/osi/include/osi/fixed_queue.h b/components/bt/common/osi/include/osi/fixed_queue.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/fixed_queue.h rename to components/bt/common/osi/include/osi/fixed_queue.h diff --git a/components/bt/bluedroid/osi/include/osi/future.h b/components/bt/common/osi/include/osi/future.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/future.h rename to components/bt/common/osi/include/osi/future.h diff --git a/components/bt/bluedroid/osi/include/osi/hash_functions.h b/components/bt/common/osi/include/osi/hash_functions.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/hash_functions.h rename to components/bt/common/osi/include/osi/hash_functions.h diff --git a/components/bt/bluedroid/osi/include/osi/hash_map.h b/components/bt/common/osi/include/osi/hash_map.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/hash_map.h rename to components/bt/common/osi/include/osi/hash_map.h diff --git a/components/bt/bluedroid/osi/include/osi/list.h b/components/bt/common/osi/include/osi/list.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/list.h rename to components/bt/common/osi/include/osi/list.h diff --git a/components/bt/bluedroid/osi/include/osi/mutex.h b/components/bt/common/osi/include/osi/mutex.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/mutex.h rename to components/bt/common/osi/include/osi/mutex.h diff --git a/components/bt/bluedroid/osi/include/osi/osi.h b/components/bt/common/osi/include/osi/osi.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/osi.h rename to components/bt/common/osi/include/osi/osi.h diff --git a/components/bt/bluedroid/osi/include/osi/semaphore.h b/components/bt/common/osi/include/osi/semaphore.h similarity index 100% rename from components/bt/bluedroid/osi/include/osi/semaphore.h rename to components/bt/common/osi/include/osi/semaphore.h diff --git a/components/bt/bluedroid/osi/include/osi/thread.h b/components/bt/common/osi/include/osi/thread.h similarity index 88% rename from components/bt/bluedroid/osi/include/osi/thread.h rename to components/bt/common/osi/include/osi/thread.h index a8e0773b90..cf7e7b01f9 100644 --- a/components/bt/bluedroid/osi/include/osi/thread.h +++ b/components/bt/common/osi/include/osi/thread.h @@ -21,7 +21,7 @@ #include "freertos/queue.h" #include "freertos/task.h" #include "esp_task.h" -#include "common/bt_defs.h" +#include "bt_common.h" #define portBASE_TYPE int @@ -57,8 +57,6 @@ typedef enum { SIG_BTU_NUM, } SIG_BTU_t; -#define TASK_PINNED_TO_CORE (CONFIG_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY) - #define HCI_HOST_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) #define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) #define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3) @@ -77,12 +75,6 @@ typedef enum { #define BTU_TASK_NAME "btuT" #define BTU_QUEUE_LEN 50 -#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) -#define BTC_TASK_STACK_SIZE (CONFIG_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig -#define BTC_TASK_NAME "btcT" -#define BTC_TASK_PRIO (configMAX_PRIORITIES - 6) -#define BTC_TASK_QUEUE_LEN 60 - #define BTC_A2DP_SINK_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE) #define BTC_A2DP_SINK_TASK_STACK_SIZE (CONFIG_A2DP_SINK_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig #define BTC_A2DP_SINK_TASK_NAME "BtA2dSinkT" diff --git a/components/bt/bluedroid/osi/list.c b/components/bt/common/osi/list.c similarity index 99% rename from components/bt/bluedroid/osi/list.c rename to components/bt/common/osi/list.c index 1a41873acf..730fe4e97a 100644 --- a/components/bt/bluedroid/osi/list.c +++ b/components/bt/common/osi/list.c @@ -1,6 +1,5 @@ -#include "common/bt_defs.h" - +#include "bt_common.h" #include "osi/allocator.h" #include "osi/list.h" #include "osi/osi.h" diff --git a/components/bt/bluedroid/osi/mutex.c b/components/bt/common/osi/mutex.c similarity index 100% rename from components/bt/bluedroid/osi/mutex.c rename to components/bt/common/osi/mutex.c diff --git a/components/bt/bluedroid/osi/osi.c b/components/bt/common/osi/osi.c similarity index 100% rename from components/bt/bluedroid/osi/osi.c rename to components/bt/common/osi/osi.c diff --git a/components/bt/bluedroid/osi/semaphore.c b/components/bt/common/osi/semaphore.c similarity index 100% rename from components/bt/bluedroid/osi/semaphore.c rename to components/bt/common/osi/semaphore.c diff --git a/components/bt/component.mk b/components/bt/component.mk index 73208b868c..04061b1605 100644 --- a/components/bt/component.mk +++ b/components/bt/component.mk @@ -22,11 +22,11 @@ ifeq ($(GCC_NOT_5_2_0), 1) CFLAGS += -Wno-implicit-fallthrough endif -endif - - ifdef CONFIG_BLUEDROID_ENABLED +COMPONENT_SRCDIRS += common/osi \ + common/btc/core + COMPONENT_PRIV_INCLUDEDIRS += bluedroid/bta/include \ bluedroid/bta/ar/include \ bluedroid/bta/av/include \ @@ -41,7 +41,6 @@ COMPONENT_PRIV_INCLUDEDIRS += bluedroid/bta/include \ bluedroid/device/include \ bluedroid/gki/include \ bluedroid/hci/include \ - bluedroid/osi/include \ bluedroid/utils/include \ bluedroid/external/sbc/decoder/include \ bluedroid/external/sbc/encoder/include \ @@ -69,7 +68,10 @@ COMPONENT_PRIV_INCLUDEDIRS += bluedroid/bta/include \ bluedroid/stack/rfcomm/include \ bluedroid/stack/include \ bluedroid/utils/include \ - bluedroid/common/include + bluedroid/common/include \ + common/btc/include \ + common/osi/include \ + common/include COMPONENT_ADD_INCLUDEDIRS += bluedroid/api/include/api @@ -128,11 +130,11 @@ bluedroid/stack/smp/smp_keys.o: CFLAGS += -Wno-unused-const-variable endif ifdef CONFIG_BLE_MESH -COMPONENT_ADD_INCLUDEDIRS += bluedroid/osi/include +COMPONENT_ADD_INCLUDEDIRS += common/osi/include COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core/bluedroid_host -endif +endif endif ifdef CONFIG_BLE_MESH @@ -157,3 +159,18 @@ COMPONENT_SRCDIRS += esp_ble_mesh/mesh_common \ esp_ble_mesh/api/core \ esp_ble_mesh/api/models endif + +ifdef CONFIG_NIMBLE_ENABLED +ifdef CONFIG_BLE_MESH +COMPONENT_PRIV_INCLUDEDIRS += common/btc/include \ + common/include + +COMPONENT_SRCDIRS += common/osi \ + common/btc/core \ + esp_ble_mesh/mesh_core/nimble_host + +COMPONENT_ADD_INCLUDEDIRS += common/osi/include +endif +endif + +endif diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c b/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c index d4597d8184..05607dcb94 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c @@ -14,6 +14,7 @@ #include "mesh_common.h" #include "provisioner_prov.h" +#include "bt_common.h" static bt_mesh_mutex_t bm_alarm_lock; static bt_mesh_mutex_t bm_list_lock; diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index 80998d2024..183c8d3fd4 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -19,6 +19,7 @@ #include "device/controller.h" #include "mbedtls/aes.h" +#include "bt_common.h" #include "mesh_hci.h" #include "mesh_aes_encrypt.h" diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h index 7c3ead1d0a..0ac2350d16 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -23,11 +23,11 @@ #define BLE_MESH_ADV_TASK_CORE TASK_PINNED_TO_CORE #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED -#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS +#ifdef CONFIG_NIMBLE_ENABLED +#define BLE_MESH_MAX_CONN CONFIG_NIMBLE_MAX_CONNECTIONS -#ifdef CONFIG_BT_NIMBLE_PINNED_TO_CORE -#define BLE_MESH_ADV_TASK_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY) +#ifdef CONFIG_NIMBLE_PINNED_TO_CORE +#define BLE_MESH_ADV_TASK_CORE (CONFIG_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY) #else #define BLE_MESH_ADV_TASK_CORE (0) #endif diff --git a/components/nimble/nimble b/components/nimble/nimble index 8326807c5e..5250d712a5 160000 --- a/components/nimble/nimble +++ b/components/nimble/nimble @@ -1 +1 @@ -Subproject commit 8326807c5e580c3bb8ad13d1e80819aa0029004e +Subproject commit 5250d712a5454b2623bf92343c027d77477ca804 diff --git a/components/nimble/port/include/esp_nimble_cfg.h b/components/nimble/port/include/esp_nimble_cfg.h index 86e483d93b..1298ec71b1 100644 --- a/components/nimble/port/include/esp_nimble_cfg.h +++ b/components/nimble/port/include/esp_nimble_cfg.h @@ -415,6 +415,14 @@ #define MYNEWT_VAL_BLE_HOST (1) #endif +#ifndef MYNEWT_VAL_ESP_BLE_MESH +#ifdef CONFIG_BLE_MESH_HCI_5_0 +#define MYNEWT_VAL_ESP_BLE_MESH (1) +#else +#define MYNEWT_VAL_ESP_BLE_MESH (0) +#endif +#endif + #ifndef MYNEWT_VAL_BLE_HS_DEBUG #ifdef CONFIG_NIMBLE_DEBUG #define MYNEWT_VAL_BLE_HS_DEBUG (1) diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_init.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_init.c index e0471fa185..2f6854eb61 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_init.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_init.c @@ -16,7 +16,7 @@ #include "esp_bt_device.h" #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED #include "esp_nimble_hci.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" @@ -71,7 +71,7 @@ esp_err_t bluetooth_init(void) #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED static SemaphoreHandle_t mesh_sem; static uint8_t own_addr_type; void ble_store_config_init(void); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_init.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_init.c index fb145ad2ca..a61f70e657 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_init.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_init.c @@ -16,7 +16,7 @@ #include "esp_bt_device.h" #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED #include "esp_nimble_hci.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" @@ -71,7 +71,7 @@ esp_err_t bluetooth_init(void) #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED static SemaphoreHandle_t mesh_sem; static uint8_t own_addr_type; void ble_store_config_init(void); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/ble_mesh_demo_init.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/ble_mesh_demo_init.c index fb145ad2ca..a61f70e657 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/ble_mesh_demo_init.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/ble_mesh_demo_init.c @@ -16,7 +16,7 @@ #include "esp_bt_device.h" #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED #include "esp_nimble_hci.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" @@ -71,7 +71,7 @@ esp_err_t bluetooth_init(void) #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED static SemaphoreHandle_t mesh_sem; static uint8_t own_addr_type; void ble_store_config_init(void); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/ble_mesh_demo_init.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/ble_mesh_demo_init.c index fb145ad2ca..a61f70e657 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/ble_mesh_demo_init.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/ble_mesh_demo_init.c @@ -16,7 +16,7 @@ #include "esp_bt_device.h" #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED #include "esp_nimble_hci.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" @@ -71,7 +71,7 @@ esp_err_t bluetooth_init(void) #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED static SemaphoreHandle_t mesh_sem; static uint8_t own_addr_type; void ble_store_config_init(void); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_init.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_init.c index fb145ad2ca..a61f70e657 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_init.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_init.c @@ -16,7 +16,7 @@ #include "esp_bt_device.h" #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED #include "esp_nimble_hci.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" @@ -71,7 +71,7 @@ esp_err_t bluetooth_init(void) #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED static SemaphoreHandle_t mesh_sem; static uint8_t own_addr_type; void ble_store_config_init(void); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_init.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_init.c index fb145ad2ca..a61f70e657 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_init.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_init.c @@ -16,7 +16,7 @@ #include "esp_bt_device.h" #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED #include "esp_nimble_hci.h" #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" @@ -71,7 +71,7 @@ esp_err_t bluetooth_init(void) #endif -#ifdef CONFIG_BT_NIMBLE_ENABLED +#ifdef CONFIG_NIMBLE_ENABLED static SemaphoreHandle_t mesh_sem; static uint8_t own_addr_type; void ble_store_config_init(void);