Skip to content

Commit 689b10e

Browse files
committed
feat(ble_mesh): multi adv instance support
1 parent 30b257c commit 689b10e

File tree

20 files changed

+2054
-899
lines changed

20 files changed

+2054
-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

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);

0 commit comments

Comments
 (0)