diff --git a/examples/bluetooth/nimble/blecent/main/Kconfig.projbuild b/examples/bluetooth/nimble/blecent/main/Kconfig.projbuild index dbfbdb1324..42a183a62d 100644 --- a/examples/bluetooth/nimble/blecent/main/Kconfig.projbuild +++ b/examples/bluetooth/nimble/blecent/main/Kconfig.projbuild @@ -6,4 +6,10 @@ menu "Example Configuration" help Enter the peer address in aa:bb:cc:dd:ee:ff form to connect to a specific peripheral + config EXAMPLE_INIT_DEINIT_LOOP + bool + prompt "Perform init deinit of nimble stack in a loop" + help + Enable this flag, to perform only stack Init and Deinit in a loop. + endmenu diff --git a/examples/bluetooth/nimble/blecent/main/main.c b/examples/bluetooth/nimble/blecent/main/main.c index 15102dda50..b8035125d2 100644 --- a/examples/bluetooth/nimble/blecent/main/main.c +++ b/examples/bluetooth/nimble/blecent/main/main.c @@ -510,8 +510,10 @@ blecent_on_sync(void) rc = ble_hs_util_ensure_addr(0); assert(rc == 0); +#if !CONFIG_EXAMPLE_INIT_DEINIT_LOOP /* Begin scanning for a peripheral to connect to. */ blecent_scan(); +#endif } void blecent_host_task(void *param) @@ -523,6 +525,37 @@ void blecent_host_task(void *param) nimble_port_freertos_deinit(); } +#if CONFIG_EXAMPLE_INIT_DEINIT_LOOP +/* This function showcases stack init and deinit procedure. */ +static void stack_init_deinit(void) +{ + int rc; + while(1) { + + vTaskDelay(1000); + + ESP_LOGI(tag, "Deinit host"); + + rc = nimble_port_stop(); + + if (rc == 0) { + nimble_port_deinit(); + ESP_ERROR_CHECK(esp_nimble_hci_and_controller_deinit()); + } + + vTaskDelay(1000); + + ESP_LOGI(tag, "Init host"); + + ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init()); + nimble_port_init(); + nimble_port_freertos_init(blecent_host_task); + + ESP_LOGI(tag, "Waiting for 1 second"); + } +} +#endif + void app_main(void) { @@ -556,4 +589,8 @@ app_main(void) nimble_port_freertos_init(blecent_host_task); +#if CONFIG_EXAMPLE_INIT_DEINIT_LOOP + stack_init_deinit(); +#endif + }