From 2f40c4449fdd5c11000a0a48fbf7f1f2f43b38ad Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 30 Mar 2020 19:33:25 +0800 Subject: [PATCH] ble_mesh: Split mesh os related into a separate file --- components/bt/CMakeLists.txt | 1 + .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 4 +- .../mesh_common/include/mesh_kernel.h | 54 +++++++++++++++++++ .../mesh_common/include/mesh_mutex.h | 7 +-- .../mesh_common/include/mesh_timer.h | 12 ----- .../bt/esp_ble_mesh/mesh_common/mesh_kernel.c | 14 +++++ .../bt/esp_ble_mesh/mesh_common/mesh_timer.c | 6 --- components/bt/esp_ble_mesh/mesh_core/adv.c | 7 +-- .../mesh_core/include/mesh_bearer_adapt.h | 14 +---- 9 files changed, 74 insertions(+), 45 deletions(-) create mode 100644 components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h create mode 100644 components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 5f515562e..1e6ca4c99 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -347,6 +347,7 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/mesh_common/mesh_atomic.c" "esp_ble_mesh/mesh_common/mesh_buf.c" "esp_ble_mesh/mesh_common/mesh_common.c" + "esp_ble_mesh/mesh_common/mesh_kernel.c" "esp_ble_mesh/mesh_common/mesh_mutex.c" "esp_ble_mesh/mesh_common/mesh_timer.c" "esp_ble_mesh/mesh_common/mesh_util.c" diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 704a18f03..bd9311269 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -15,10 +15,8 @@ #include #include -#include "freertos/FreeRTOS.h" -#include "freertos/semphr.h" - #include "adv.h" +#include "mesh_kernel.h" #include "mesh_proxy.h" #include "mesh.h" #include "access.h" diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h new file mode 100644 index 000000000..e443dc373 --- /dev/null +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016, Wind River Systems, Inc. + * Additional Copyright (c) 2020 Espressif Systems (Shanghai) PTE LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _BLE_MESH_KERNEL_H_ +#define _BLE_MESH_KERNEL_H_ + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" + +#include "mesh_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef CONFIG_BT_BLUEDROID_ENABLED +#define BLE_MESH_ADV_TASK_CORE TASK_PINNED_TO_CORE +#endif + +#ifdef CONFIG_BT_NIMBLE_ENABLED +#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) +#else +#define BLE_MESH_ADV_TASK_CORE (0) +#endif + +#endif + +#define BLE_MESH_ADV_TASK_STACK_SIZE 3072 + +/** + * @brief Put the current thread to sleep. + * + * This routine puts the current thread to sleep for @a duration + * milliseconds. + * + * @param duration Number of milliseconds to sleep. + * + * @return N/A + */ +void k_sleep(s32_t duration); + +#ifdef __cplusplus +} +#endif + +#endif /* _BLE_MESH_KERNEL_H_ */ + diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h index 00287d0ec..488e010fa 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h @@ -15,12 +15,7 @@ #ifndef _BLE_MESH_MUTEX_H_ #define _BLE_MESH_MUTEX_H_ -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" - -#include "mesh_types.h" +#include "mesh_kernel.h" #include "mesh_slist.h" #include "mesh_atomic.h" diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_timer.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_timer.h index 6a9a2089a..7d753a21a 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_timer.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_timer.h @@ -256,18 +256,6 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler); */ s64_t k_uptime_get(void); -/** - * @brief Put the current thread to sleep. - * - * This routine puts the current thread to sleep for @a duration - * milliseconds. - * - * @param duration Number of milliseconds to sleep. - * - * @return N/A - */ -void k_sleep(s32_t duration); - void bt_mesh_timer_init(void); void bt_mesh_timer_deinit(void); diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c b/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c new file mode 100644 index 000000000..b288f6500 --- /dev/null +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2016 Intel Corporation + * Copyright (c) 2016 Wind River Systems, Inc. + * Additional Copyright (c) 2020 Espressif Systems (Shanghai) PTE LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mesh_kernel.h" + +void k_sleep(s32_t duration) +{ + vTaskDelay(duration / portTICK_PERIOD_MS); +} diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c b/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c index b9df23563..76b7ac2a9 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c @@ -43,12 +43,6 @@ u32_t k_uptime_get_32(void) return (u32_t)(esp_timer_get_time() / 1000); } -void k_sleep(s32_t duration) -{ - vTaskDelay(duration / portTICK_PERIOD_MS); - return; -} - void bt_mesh_timer_init(void) { bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE, diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 1986f1fba..6fa2291ec 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -11,14 +11,11 @@ #include #include -#include "freertos/FreeRTOS.h" -#include "freertos/queue.h" -#include "freertos/task.h" - -#include "osi/thread.h" +#include "bt_common.h" #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_ADV) +#include "mesh_kernel.h" #include "mesh.h" #include "mesh_hci.h" #include "mesh_common.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 13e344edb..e9fbeb54e 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 @@ -21,25 +21,13 @@ extern "C" { /* BLE Mesh Max Connection Count */ #ifdef CONFIG_BT_BLUEDROID_ENABLED -#define BLE_MESH_MAX_CONN \ - MIN(CONFIG_BT_ACL_CONNECTIONS, CONFIG_BTDM_CTRL_BLE_MAX_CONN) - -#define BLE_MESH_ADV_TASK_CORE TASK_PINNED_TO_CORE +#define BLE_MESH_MAX_CONN MIN(CONFIG_BT_ACL_CONNECTIONS, CONFIG_BTDM_CTRL_BLE_MAX_CONN) #endif #ifdef CONFIG_BT_NIMBLE_ENABLED #define BLE_MESH_MAX_CONN CONFIG_BT_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) -#else -#define BLE_MESH_ADV_TASK_CORE (0) #endif -#endif - -#define BLE_MESH_ADV_TASK_STACK_SIZE 3072 - #define BLE_MESH_GAP_ADV_MAX_LEN 31 #define BLE_MESH_GATT_DEF_MTU_SIZE 23