Skip to content

Commit a92f4ed

Browse files
committed
change(ble): Supported cuttable architecture for ble
1 parent a03b8e1 commit a92f4ed

File tree

13 files changed

+667
-243
lines changed

13 files changed

+667
-243
lines changed

components/bt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ if(CONFIG_BT_ENABLED)
9191
endif()
9292
set(ldscripts "linker_esp32c2.lf")
9393
else()
94+
list(APPEND srcs "controller/${target_name}/ble.c")
9495
list(APPEND ldscripts "linker_esp_ble_controller.lf")
9596
endif()
9697

components/bt/controller/esp32c5/Kconfig.in

Lines changed: 86 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -283,110 +283,116 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE
283283
help
284284
This configures stack size of NimBLE controller task
285285

286-
menuconfig BT_LE_CONTROLLER_LOG_ENABLED
287-
bool "Controller log enable"
288-
default n
289-
help
290-
Enable controller log
286+
menu "Controller debug features"
287+
menuconfig BT_LE_CONTROLLER_LOG_ENABLED
288+
bool "Controller log enable"
289+
default n
290+
help
291+
Enable controller log
291292

292-
config BT_LE_CONTROLLER_LOG_CTRL_ENABLED
293-
bool "enable controller log module"
294-
depends on BT_LE_CONTROLLER_LOG_ENABLED
295-
default y
296-
help
293+
config BT_LE_CONTROLLER_LOG_CTRL_ENABLED
294+
bool "enable controller log module"
295+
depends on BT_LE_CONTROLLER_LOG_ENABLED
296+
default y
297+
help
297298
Enable controller log module
298299

299-
config BT_LE_CONTROLLER_LOG_HCI_ENABLED
300-
bool "enable HCI log module"
301-
depends on BT_LE_CONTROLLER_LOG_ENABLED
302-
default y
303-
help
300+
config BT_LE_CONTROLLER_LOG_HCI_ENABLED
301+
bool "enable HCI log module"
302+
depends on BT_LE_CONTROLLER_LOG_ENABLED
303+
default y
304+
help
304305
Enable hci log module
305306

306-
config BT_LE_CONTROLLER_LOG_DUMP_ONLY
307-
bool "Controller log dump mode only"
308-
depends on BT_LE_CONTROLLER_LOG_ENABLED
309-
default y
310-
help
307+
config BT_LE_CONTROLLER_LOG_DUMP_ONLY
308+
bool "Controller log dump mode only"
309+
depends on BT_LE_CONTROLLER_LOG_ENABLED
310+
default y
311+
help
311312
Only operate in dump mode
312313

313-
config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED
314-
bool "Output ble controller logs to SPI bus (Experimental)"
315-
depends on BT_LE_CONTROLLER_LOG_ENABLED
316-
depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY
317-
select BT_BLE_LOG_SPI_OUT_ENABLED
318-
default n
319-
help
320-
Output ble controller logs to SPI bus
314+
config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED
315+
bool "Output ble controller logs to SPI bus (Experimental)"
316+
depends on BT_LE_CONTROLLER_LOG_ENABLED
317+
depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY
318+
select BT_BLE_LOG_SPI_OUT_ENABLED
319+
default n
320+
help
321+
Output ble controller logs to SPI bus
321322

322-
config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
323-
bool "Store ble controller logs to flash(Experimental)"
324-
depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY
325-
depends on BT_LE_CONTROLLER_LOG_ENABLED
326-
default n
327-
help
323+
config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
324+
bool "Store ble controller logs to flash(Experimental)"
325+
depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY
326+
depends on BT_LE_CONTROLLER_LOG_ENABLED
327+
default n
328+
help
328329
Store ble controller logs to flash memory.
329330

330-
config BT_LE_CONTROLLER_LOG_PARTITION_SIZE
331-
int "size of ble controller log partition(Multiples of 4K)"
332-
depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
333-
default 65536
334-
help
331+
config BT_LE_CONTROLLER_LOG_PARTITION_SIZE
332+
int "size of ble controller log partition(Multiples of 4K)"
333+
depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
334+
default 65536
335+
help
335336
The size of ble controller log partition shall be a multiples of 4K.
336337
The name of log partition shall be "bt_ctrl_log".
337338
The partition type shall be ESP_PARTITION_TYPE_DATA.
338339
The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY.
339340

340-
config BT_LE_LOG_CTRL_BUF1_SIZE
341-
int "size of the first BLE controller LOG buffer"
342-
depends on BT_LE_CONTROLLER_LOG_ENABLED
343-
default 4096
344-
help
341+
config BT_LE_LOG_CTRL_BUF1_SIZE
342+
int "size of the first BLE controller LOG buffer"
343+
depends on BT_LE_CONTROLLER_LOG_ENABLED
344+
default 4096
345+
help
345346
Configure the size of the first BLE controller LOG buffer.
346347

347-
config BT_LE_LOG_CTRL_BUF2_SIZE
348-
int "size of the second BLE controller LOG buffer"
349-
depends on BT_LE_CONTROLLER_LOG_ENABLED
350-
default 1024
351-
help
348+
config BT_LE_LOG_CTRL_BUF2_SIZE
349+
int "size of the second BLE controller LOG buffer"
350+
depends on BT_LE_CONTROLLER_LOG_ENABLED
351+
default 1024
352+
help
352353
Configure the size of the second BLE controller LOG buffer.
353354

354-
config BT_LE_LOG_HCI_BUF_SIZE
355-
int "size of the BLE HCI LOG buffer"
356-
depends on BT_LE_CONTROLLER_LOG_ENABLED
357-
default 4096
358-
help
355+
config BT_LE_LOG_HCI_BUF_SIZE
356+
int "size of the BLE HCI LOG buffer"
357+
depends on BT_LE_CONTROLLER_LOG_ENABLED
358+
default 4096
359+
help
359360
Configure the size of the BLE HCI LOG buffer.
360361

361-
config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
362-
bool "Enable wrap panic handler"
363-
depends on BT_LE_CONTROLLER_LOG_ENABLED
364-
default n
365-
help
366-
Wrap esp_panic_handler to get controller logs when PC pointer exception crashes.
362+
config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
363+
bool "Enable wrap panic handler"
364+
depends on BT_LE_CONTROLLER_LOG_ENABLED
365+
default n
366+
help
367+
Wrap esp_panic_handler to get controller logs when PC pointer exception crashes.
367368

368-
config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
369-
bool "Enable esp_task_wdt_isr_user_handler implementation"
370-
depends on BT_LE_CONTROLLER_LOG_ENABLED
371-
default n
372-
help
373-
Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered.
369+
config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
370+
bool "Enable esp_task_wdt_isr_user_handler implementation"
371+
depends on BT_LE_CONTROLLER_LOG_ENABLED
372+
default n
373+
help
374+
Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered.
374375

375-
config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL
376-
int "The output level of controller log"
377-
depends on BT_LE_CONTROLLER_LOG_ENABLED
378-
range 0 5
379-
default 1
380-
help
381-
The output level of controller log.
376+
config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL
377+
int "The output level of controller log"
378+
depends on BT_LE_CONTROLLER_LOG_ENABLED
379+
range 0 5
380+
default 1
381+
help
382+
The output level of controller log.
382383

383-
config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH
384-
hex "The switch of module log output"
385-
depends on BT_LE_CONTROLLER_LOG_ENABLED
386-
range 0 0xFFFFFFFF
387-
default 0xFFFFFFFF
388-
help
389-
The switch of module log output, this is an unsigned 32-bit hexadecimal value.
384+
config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH
385+
hex "The switch of module log output"
386+
depends on BT_LE_CONTROLLER_LOG_ENABLED
387+
range 0 0xFFFFFFFF
388+
default 0xFFFFFFFF
389+
help
390+
The switch of module log output, this is an unsigned 32-bit hexadecimal value.
391+
392+
config BT_LE_ERROR_SIM_ENABLED
393+
bool "Enable controller features for internal testing"
394+
default n
395+
endmenu
390396

391397
config BT_LE_LL_RESOLV_LIST_SIZE
392398
int "BLE LL Resolving list size"
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <stdlib.h>
7+
8+
#include "sdkconfig.h"
9+
#include "esp_bt_cfg.h"
10+
11+
/* External functions or variables
12+
************************************************************************
13+
*/
14+
int base_stack_initEnv(void);
15+
void base_stack_deinitEnv(void);
16+
int base_stack_enable(void);
17+
void base_stack_disable(void);
18+
19+
int conn_stack_initEnv(void);
20+
void conn_stack_deinitEnv(void);
21+
int conn_stack_enable(void);
22+
void conn_stack_disable(void);
23+
24+
#if CONFIG_BT_LE_ERROR_SIM_ENABLED
25+
int conn_errorSim_initEnv(void);
26+
void conn_errorSim_deinitEnv(void);
27+
int conn_errorSim_enable(void);
28+
void conn_errorSim_disable(void);
29+
#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED
30+
31+
/* Local functions definition
32+
***************************************************************************
33+
*/
34+
int ble_stack_initEnv(void)
35+
{
36+
int rc;
37+
38+
rc = base_stack_initEnv();
39+
if (rc) {
40+
return rc;
41+
}
42+
43+
#if DEFAULT_BT_LE_MAX_CONNECTIONS
44+
rc = conn_stack_initEnv();
45+
if (rc) {
46+
return rc;
47+
}
48+
#if CONFIG_BT_LE_ERROR_SIM_ENABLED
49+
rc = conn_errorSim_initEnv();
50+
if (rc) {
51+
return rc;
52+
}
53+
#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED
54+
#endif // DEFAULT_BT_LE_MAX_CONNECTIONS
55+
56+
return 0;
57+
}
58+
59+
void ble_stack_deinitEnv(void)
60+
{
61+
#if DEFAULT_BT_LE_MAX_CONNECTIONS
62+
#if CONFIG_BT_LE_ERROR_SIM_ENABLED
63+
conn_errorSim_deinitEnv();
64+
#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED
65+
conn_stack_deinitEnv();
66+
#endif // DEFAULT_BT_LE_MAX_CONNECTIONS
67+
68+
base_stack_deinitEnv();
69+
}
70+
71+
int ble_stack_enable(void)
72+
{
73+
int rc;
74+
75+
rc = base_stack_enable();
76+
if (rc) {
77+
return rc;
78+
}
79+
80+
#if DEFAULT_BT_LE_MAX_CONNECTIONS
81+
rc = conn_stack_enable();
82+
if (rc) {
83+
return rc;
84+
}
85+
#if CONFIG_BT_LE_ERROR_SIM_ENABLED
86+
rc = conn_errorSim_enable();
87+
if (rc) {
88+
return rc;
89+
}
90+
#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED
91+
#endif // DEFAULT_BT_LE_MAX_CONNECTIONS
92+
93+
return 0;
94+
}
95+
96+
void ble_stack_disable(void)
97+
{
98+
#if DEFAULT_BT_LE_MAX_CONNECTIONS
99+
#if CONFIG_BT_LE_ERROR_SIM_ENABLED
100+
conn_errorSim_disable();
101+
#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED
102+
conn_stack_disable();
103+
#endif // DEFAULT_BT_LE_MAX_CONNECTIONS
104+
105+
base_stack_disable();
106+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
int ble_stack_initEnv(void);
7+
8+
void ble_stack_deinitEnv(void);
9+
10+
int ble_stack_enable(void);
11+
12+
void ble_stack_disable(void);

components/bt/controller/esp32c5/bt.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "os/endian.h"
3535

3636
#include "esp_bt.h"
37+
#include "ble_priv.h"
3738
#include "esp_intr_alloc.h"
3839
#include "esp_sleep.h"
3940
#include "esp_pm.h"
@@ -925,13 +926,19 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
925926
goto modem_deint;
926927
}
927928

929+
ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version());
930+
928931
ret = r_ble_controller_init(cfg);
929932
if (ret != ESP_OK) {
930933
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "r_ble_controller_init failed %d", ret);
931934
goto modem_deint;
932935
}
933936

934-
ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version());
937+
ret = ble_stack_initEnv();
938+
if (ret != ESP_OK) {
939+
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_stack_initEnv failed %d", ret);
940+
goto free_controller;
941+
}
935942

936943
ble_controller_scan_duplicate_config();
937944

@@ -971,6 +978,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
971978
hci_transport_deinit();
972979
controller_sleep_deinit();
973980
os_msys_deinit();
981+
ble_stack_deinitEnv();
974982
r_ble_controller_deinit();
975983
modem_deint:
976984
esp_ble_unregister_bb_funcs();
@@ -1008,6 +1016,7 @@ esp_err_t esp_bt_controller_deinit(void)
10081016
// modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE);
10091017
modem_clock_module_disable(PERIPH_BT_MODULE);
10101018

1019+
ble_stack_deinitEnv();
10111020
r_ble_controller_deinit();
10121021
esp_ble_unregister_bb_funcs();
10131022
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
@@ -1061,6 +1070,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
10611070
r_ble_ll_scan_start_time_init_compensation(500);
10621071
r_priv_sdk_config_insert_proc_time_set(500);
10631072
#endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
1073+
1074+
if (ble_stack_enable() != 0) {
1075+
ret = ESP_FAIL;
1076+
goto error;
1077+
}
1078+
10641079
if (r_ble_controller_enable(mode) != 0) {
10651080
ret = ESP_FAIL;
10661081
goto error;
@@ -1069,6 +1084,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
10691084
return ESP_OK;
10701085

10711086
error:
1087+
ble_stack_disable();
10721088
#if CONFIG_SW_COEXIST_ENABLE
10731089
coex_disable();
10741090
#endif
@@ -1092,6 +1108,7 @@ esp_err_t esp_bt_controller_disable(void)
10921108
if (r_ble_controller_disable() != 0) {
10931109
return ESP_FAIL;
10941110
}
1111+
ble_stack_disable();
10951112
#if CONFIG_SW_COEXIST_ENABLE
10961113
coex_disable();
10971114
#endif

0 commit comments

Comments
 (0)