Skip to content

Commit 305f1c1

Browse files
committed
Merge branch 'feature/ble_mesh_multi_adv_instance_support' into 'master'
Feature/ble mesh multi adv instance support Closes BLERP-1282 See merge request espressif/esp-idf!35208
2 parents 4e2dad6 + 689b10e commit 305f1c1

File tree

22 files changed

+2135
-899
lines changed

22 files changed

+2135
-899
lines changed

components/bt/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,15 @@ if(CONFIG_BT_ENABLED)
501501
"esp_ble_mesh/common/common.c"
502502
"esp_ble_mesh/common/kernel.c"
503503
"esp_ble_mesh/common/mutex.c"
504+
"esp_ble_mesh/common/queue.c"
504505
"esp_ble_mesh/common/timer.c"
505506
"esp_ble_mesh/common/utils.c"
506507
"esp_ble_mesh/core/storage/settings_nvs.c"
507508
"esp_ble_mesh/core/storage/settings_uid.c"
508509
"esp_ble_mesh/core/storage/settings.c"
509510
"esp_ble_mesh/core/access.c"
510-
"esp_ble_mesh/core/adv.c"
511+
"esp_ble_mesh/core/adv_common.c"
512+
"esp_ble_mesh/core/ble_adv.c"
511513
"esp_ble_mesh/core/beacon.c"
512514
"esp_ble_mesh/core/cfg_cli.c"
513515
"esp_ble_mesh/core/cfg_srv.c"
@@ -579,6 +581,11 @@ if(CONFIG_BT_ENABLED)
579581
list(APPEND srcs
580582
"esp_ble_mesh/core/transport.c")
581583
endif()
584+
if(CONFIG_BLE_MESH_SUPPORT_MULTI_ADV)
585+
list(APPEND srcs "esp_ble_mesh/core/ext_adv.c")
586+
else()
587+
list(APPEND srcs "esp_ble_mesh/core/adv.c")
588+
endif()
582589
endif()
583590

584591

components/bt/esp_ble_mesh/Kconfig.in

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,63 @@ if BLE_MESH
3434
help
3535
This option to enable BLE Mesh using some BLE 5.0 APIs.
3636

37+
config BLE_MESH_ADV_INST_ID
38+
depends on BLE_MESH_USE_BLE_50
39+
int "Extended adv instance for Mesh normal packets"
40+
default 0
41+
range 0 3
42+
help
43+
Extended ADV instance used by Mesh normal advertising packets.
44+
45+
menuconfig BLE_MESH_SUPPORT_MULTI_ADV
46+
bool "Support using multiple adv instance for BLE Mesh"
47+
depends on BLE_MESH_USE_BLE_50
48+
default n
49+
help
50+
Enable this option to support using multiple adv instance while running BLE Mesh.
51+
52+
config BLE_MESH_PROXY_ADV_INST_ID
53+
int "Extended adv instance for Mesh proxy packets"
54+
depends on BLE_MESH_PROXY
55+
depends on (BLE_MESH_PB_GATT || BLE_MESH_GATT_PROXY_SERVER)
56+
depends on BLE_MESH_SUPPORT_MULTI_ADV
57+
default 1
58+
range 0 3
59+
help
60+
Extended ADV instance used by Mesh proxy advertising packets.
61+
62+
menuconfig BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE
63+
bool "Use separate extended adv instance for Mesh relay packets"
64+
depends on BLE_MESH_SUPPORT_MULTI_ADV
65+
depends on BLE_MESH_RELAY_ADV_BUF
66+
default n
67+
help
68+
Enable this option to support using a separate extended ADV instance for Mesh relay packets.
69+
70+
config BLE_MESH_RELAY_ADV_INST_ID
71+
int "Extended adv instance for Mesh relay packets"
72+
depends on BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE
73+
default 2
74+
range 0 3
75+
help
76+
Extended ADV instance used by Mesh relay advertising packets.
77+
78+
menuconfig BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
79+
bool "Use separate extended adv instance for BLE normal packets"
80+
depends on BLE_MESH_SUPPORT_MULTI_ADV
81+
depends on BLE_MESH_SUPPORT_BLE_ADV
82+
default n
83+
help
84+
Enable this option to support using a separate extended ADV instance for normal BLE advertising packets.
85+
86+
config BLE_MESH_BLE_ADV_INST_ID
87+
int "Extended adv instance for normal BLE packets"
88+
depends on BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
89+
default 3
90+
range 0 3
91+
help
92+
Extended ADV instance used by normal BLE advertising packets.
93+
3794
config BLE_MESH_USE_DUPLICATE_SCAN
3895
bool "Support Duplicate Scan in BLE Mesh"
3996
select BTDM_BLE_SCAN_DUPL if IDF_TARGET_ESP32

components/bt/esp_ble_mesh/common/include/mesh/mutex.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -32,6 +32,11 @@ void bt_mesh_r_mutex_free(bt_mesh_mutex_t *mutex);
3232
void bt_mesh_r_mutex_lock(bt_mesh_mutex_t *mutex);
3333
void bt_mesh_r_mutex_unlock(bt_mesh_mutex_t *mutex);
3434

35+
void bt_mesh_c_semaphore_create(bt_mesh_mutex_t *mutex, int max, int init);
36+
void bt_mesh_c_semaphore_free(bt_mesh_mutex_t *mutex);
37+
void bt_mesh_c_semaphore_give(bt_mesh_mutex_t *mutex);
38+
void bt_mesh_c_semaphore_take(bt_mesh_mutex_t *mutex, uint32_t timeout);
39+
3540
void bt_mesh_alarm_lock(void);
3641
void bt_mesh_alarm_unlock(void);
3742

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _BLE_MESH_QUEUE_H_
8+
#define _BLE_MESH_QUEUE_H_
9+
10+
#include "mesh/kernel.h"
11+
#include "mesh/slist.h"
12+
#include "mesh/atomic.h"
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
typedef struct {
19+
QueueHandle_t handle;
20+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
21+
StaticQueue_t *buffer;
22+
uint8_t *storage;
23+
#endif
24+
} bt_mesh_queue_t;
25+
26+
int bt_mesh_queue_init(bt_mesh_queue_t *queue, uint8_t queue_size, uint8_t item_size);
27+
int bt_mesh_queue_deinit(bt_mesh_queue_t *queue);
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
#endif /* _BLE_MESH_QUEUE_H_ */

components/bt/esp_ble_mesh/common/mutex.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -125,6 +125,57 @@ void bt_mesh_r_mutex_unlock(bt_mesh_mutex_t *mutex)
125125
}
126126
}
127127

128+
void bt_mesh_c_semaphore_free(bt_mesh_mutex_t *mutex)
129+
{
130+
bt_mesh_mutex_free(mutex);
131+
}
132+
133+
void bt_mesh_c_semaphore_create(bt_mesh_mutex_t *mutex, int max, int init)
134+
{
135+
if (!mutex) {
136+
BT_ERR("Create, invalid mutex");
137+
return;
138+
}
139+
140+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
141+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
142+
mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
143+
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
144+
mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
145+
#endif
146+
__ASSERT(mutex->buffer, "Failed to create counting semaphore buffer");
147+
mutex->mutex = xSemaphoreCreateCountingStatic(max, init, mutex->buffer);
148+
__ASSERT(mutex->mutex, "Failed to create static counting semaphore");
149+
#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
150+
mutex->mutex = xSemaphoreCreateCounting(max, init);
151+
__ASSERT(mutex->mutex, "Failed to create counting semaphore");
152+
#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
153+
}
154+
155+
void bt_mesh_c_semaphore_take(bt_mesh_mutex_t *mutex, uint32_t timeout)
156+
{
157+
if (!mutex) {
158+
BT_ERR("Lock, invalid counting semaphore");
159+
return;
160+
}
161+
162+
if (mutex->mutex) {
163+
xSemaphoreTake(mutex->mutex, timeout / portTICK_PERIOD_MS);
164+
}
165+
}
166+
167+
void bt_mesh_c_semaphore_give(bt_mesh_mutex_t *mutex)
168+
{
169+
if (!mutex) {
170+
BT_ERR("Unlock, invalid counting semaphore");
171+
return;
172+
}
173+
174+
if (mutex->mutex) {
175+
xSemaphoreGive(mutex->mutex);
176+
}
177+
}
178+
128179
void bt_mesh_alarm_lock(void)
129180
{
130181
bt_mesh_mutex_lock(&alarm_lock);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "mesh/common.h"
8+
#include "mesh/queue.h"
9+
10+
int bt_mesh_queue_init(bt_mesh_queue_t *queue, uint8_t queue_size, uint8_t item_size)
11+
{
12+
__ASSERT(queue && queue_size && item_size, "Invalid queue init parameters");
13+
14+
#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
15+
queue->handle = xQueueCreate(queue_size, item_size);
16+
__ASSERT(queue->handle, "Failed to create queue");
17+
#else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
18+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
19+
queue->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
20+
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
21+
queue->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
22+
#endif
23+
__ASSERT(queue->buffer, "Failed to create queue buffer");
24+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
25+
queue->storage = heap_caps_calloc_prefer(1, (queue_size * item_size), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
26+
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
27+
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);
28+
#endif
29+
__ASSERT(queue->storage, "Failed to create queue storage");
30+
queue->handle = xQueueCreateStatic(queue_size, item_size, (uint8_t*)queue->storage, queue->buffer);
31+
__ASSERT(queue->handle, "Failed to create static queue");
32+
#endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
33+
return 0;
34+
}
35+
36+
int bt_mesh_queue_deinit(bt_mesh_queue_t *queue)
37+
{
38+
__ASSERT(queue, "Invalid queue init parameters");
39+
vQueueDelete(queue->handle);
40+
queue->handle = NULL;
41+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
42+
heap_caps_free(queue->buffer);
43+
queue->buffer = NULL;
44+
heap_caps_free(queue->storage);
45+
queue->storage = NULL;
46+
#endif
47+
return 0;
48+
}

0 commit comments

Comments
 (0)