Skip to content

Commit

Permalink
Merge branch 'feature/ble_mesh_multi_adv_instance_support' into 'master'
Browse files Browse the repository at this point in the history
Feature/ble mesh multi adv instance support

Closes BLERP-1282

See merge request espressif/esp-idf!35208
  • Loading branch information
Isl2017 committed Dec 27, 2024
2 parents 4e2dad6 + 689b10e commit 305f1c1
Show file tree
Hide file tree
Showing 22 changed files with 2,135 additions and 899 deletions.
9 changes: 8 additions & 1 deletion components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,15 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/common/common.c"
"esp_ble_mesh/common/kernel.c"
"esp_ble_mesh/common/mutex.c"
"esp_ble_mesh/common/queue.c"
"esp_ble_mesh/common/timer.c"
"esp_ble_mesh/common/utils.c"
"esp_ble_mesh/core/storage/settings_nvs.c"
"esp_ble_mesh/core/storage/settings_uid.c"
"esp_ble_mesh/core/storage/settings.c"
"esp_ble_mesh/core/access.c"
"esp_ble_mesh/core/adv.c"
"esp_ble_mesh/core/adv_common.c"
"esp_ble_mesh/core/ble_adv.c"
"esp_ble_mesh/core/beacon.c"
"esp_ble_mesh/core/cfg_cli.c"
"esp_ble_mesh/core/cfg_srv.c"
Expand Down Expand Up @@ -579,6 +581,11 @@ if(CONFIG_BT_ENABLED)
list(APPEND srcs
"esp_ble_mesh/core/transport.c")
endif()
if(CONFIG_BLE_MESH_SUPPORT_MULTI_ADV)
list(APPEND srcs "esp_ble_mesh/core/ext_adv.c")
else()
list(APPEND srcs "esp_ble_mesh/core/adv.c")
endif()
endif()


Expand Down
57 changes: 57 additions & 0 deletions components/bt/esp_ble_mesh/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,63 @@ if BLE_MESH
help
This option to enable BLE Mesh using some BLE 5.0 APIs.

config BLE_MESH_ADV_INST_ID
depends on BLE_MESH_USE_BLE_50
int "Extended adv instance for Mesh normal packets"
default 0
range 0 3
help
Extended ADV instance used by Mesh normal advertising packets.

menuconfig BLE_MESH_SUPPORT_MULTI_ADV
bool "Support using multiple adv instance for BLE Mesh"
depends on BLE_MESH_USE_BLE_50
default n
help
Enable this option to support using multiple adv instance while running BLE Mesh.

config BLE_MESH_PROXY_ADV_INST_ID
int "Extended adv instance for Mesh proxy packets"
depends on BLE_MESH_PROXY
depends on (BLE_MESH_PB_GATT || BLE_MESH_GATT_PROXY_SERVER)
depends on BLE_MESH_SUPPORT_MULTI_ADV
default 1
range 0 3
help
Extended ADV instance used by Mesh proxy advertising packets.

menuconfig BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE
bool "Use separate extended adv instance for Mesh relay packets"
depends on BLE_MESH_SUPPORT_MULTI_ADV
depends on BLE_MESH_RELAY_ADV_BUF
default n
help
Enable this option to support using a separate extended ADV instance for Mesh relay packets.

config BLE_MESH_RELAY_ADV_INST_ID
int "Extended adv instance for Mesh relay packets"
depends on BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE
default 2
range 0 3
help
Extended ADV instance used by Mesh relay advertising packets.

menuconfig BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
bool "Use separate extended adv instance for BLE normal packets"
depends on BLE_MESH_SUPPORT_MULTI_ADV
depends on BLE_MESH_SUPPORT_BLE_ADV
default n
help
Enable this option to support using a separate extended ADV instance for normal BLE advertising packets.

config BLE_MESH_BLE_ADV_INST_ID
int "Extended adv instance for normal BLE packets"
depends on BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
default 3
range 0 3
help
Extended ADV instance used by normal BLE advertising packets.

config BLE_MESH_USE_DUPLICATE_SCAN
bool "Support Duplicate Scan in BLE Mesh"
select BTDM_BLE_SCAN_DUPL if IDF_TARGET_ESP32
Expand Down
7 changes: 6 additions & 1 deletion components/bt/esp_ble_mesh/common/include/mesh/mutex.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -32,6 +32,11 @@ void bt_mesh_r_mutex_free(bt_mesh_mutex_t *mutex);
void bt_mesh_r_mutex_lock(bt_mesh_mutex_t *mutex);
void bt_mesh_r_mutex_unlock(bt_mesh_mutex_t *mutex);

void bt_mesh_c_semaphore_create(bt_mesh_mutex_t *mutex, int max, int init);
void bt_mesh_c_semaphore_free(bt_mesh_mutex_t *mutex);
void bt_mesh_c_semaphore_give(bt_mesh_mutex_t *mutex);
void bt_mesh_c_semaphore_take(bt_mesh_mutex_t *mutex, uint32_t timeout);

void bt_mesh_alarm_lock(void);
void bt_mesh_alarm_unlock(void);

Expand Down
33 changes: 33 additions & 0 deletions components/bt/esp_ble_mesh/common/include/mesh/queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef _BLE_MESH_QUEUE_H_
#define _BLE_MESH_QUEUE_H_

#include "mesh/kernel.h"
#include "mesh/slist.h"
#include "mesh/atomic.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
QueueHandle_t handle;
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
StaticQueue_t *buffer;
uint8_t *storage;
#endif
} bt_mesh_queue_t;

int bt_mesh_queue_init(bt_mesh_queue_t *queue, uint8_t queue_size, uint8_t item_size);
int bt_mesh_queue_deinit(bt_mesh_queue_t *queue);

#ifdef __cplusplus
}
#endif

#endif /* _BLE_MESH_QUEUE_H_ */
53 changes: 52 additions & 1 deletion components/bt/esp_ble_mesh/common/mutex.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -125,6 +125,57 @@ void bt_mesh_r_mutex_unlock(bt_mesh_mutex_t *mutex)
}
}

void bt_mesh_c_semaphore_free(bt_mesh_mutex_t *mutex)
{
bt_mesh_mutex_free(mutex);
}

void bt_mesh_c_semaphore_create(bt_mesh_mutex_t *mutex, int max, int init)
{
if (!mutex) {
BT_ERR("Create, invalid mutex");
return;
}

#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#endif
__ASSERT(mutex->buffer, "Failed to create counting semaphore buffer");
mutex->mutex = xSemaphoreCreateCountingStatic(max, init, mutex->buffer);
__ASSERT(mutex->mutex, "Failed to create static counting semaphore");
#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
mutex->mutex = xSemaphoreCreateCounting(max, init);
__ASSERT(mutex->mutex, "Failed to create counting semaphore");
#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
}

void bt_mesh_c_semaphore_take(bt_mesh_mutex_t *mutex, uint32_t timeout)
{
if (!mutex) {
BT_ERR("Lock, invalid counting semaphore");
return;
}

if (mutex->mutex) {
xSemaphoreTake(mutex->mutex, timeout / portTICK_PERIOD_MS);
}
}

void bt_mesh_c_semaphore_give(bt_mesh_mutex_t *mutex)
{
if (!mutex) {
BT_ERR("Unlock, invalid counting semaphore");
return;
}

if (mutex->mutex) {
xSemaphoreGive(mutex->mutex);
}
}

void bt_mesh_alarm_lock(void)
{
bt_mesh_mutex_lock(&alarm_lock);
Expand Down
48 changes: 48 additions & 0 deletions components/bt/esp_ble_mesh/common/queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "mesh/common.h"
#include "mesh/queue.h"

int bt_mesh_queue_init(bt_mesh_queue_t *queue, uint8_t queue_size, uint8_t item_size)
{
__ASSERT(queue && queue_size && item_size, "Invalid queue init parameters");

#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
queue->handle = xQueueCreate(queue_size, item_size);
__ASSERT(queue->handle, "Failed to create queue");
#else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
queue->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
queue->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#endif
__ASSERT(queue->buffer, "Failed to create queue buffer");
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
queue->storage = heap_caps_calloc_prefer(1, (queue_size * item_size), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
queue->storage = heap_caps_calloc_prefer(1, (queue_size * item_size), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#endif
__ASSERT(queue->storage, "Failed to create queue storage");
queue->handle = xQueueCreateStatic(queue_size, item_size, (uint8_t*)queue->storage, queue->buffer);
__ASSERT(queue->handle, "Failed to create static queue");
#endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
return 0;
}

int bt_mesh_queue_deinit(bt_mesh_queue_t *queue)
{
__ASSERT(queue, "Invalid queue init parameters");
vQueueDelete(queue->handle);
queue->handle = NULL;
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
heap_caps_free(queue->buffer);
queue->buffer = NULL;
heap_caps_free(queue->storage);
queue->storage = NULL;
#endif
return 0;
}
Loading

0 comments on commit 305f1c1

Please sign in to comment.