mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
NimBLE : Init deinit nimble stack in a loop
This commit is contained in:
@ -12,4 +12,10 @@ menu "Example Configuration"
|
|||||||
prompt "Enable Extended Adv"
|
prompt "Enable Extended Adv"
|
||||||
help
|
help
|
||||||
Use this option to enable extended advertising in the example
|
Use this option to enable extended advertising in the example
|
||||||
|
|
||||||
|
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
|
endmenu
|
||||||
|
@ -577,8 +577,10 @@ blecent_on_sync(void)
|
|||||||
rc = ble_hs_util_ensure_addr(0);
|
rc = ble_hs_util_ensure_addr(0);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
|
|
||||||
|
#if !CONFIG_EXAMPLE_INIT_DEINIT_LOOP
|
||||||
/* Begin scanning for a peripheral to connect to. */
|
/* Begin scanning for a peripheral to connect to. */
|
||||||
blecent_scan();
|
blecent_scan();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void blecent_host_task(void *param)
|
void blecent_host_task(void *param)
|
||||||
@ -590,6 +592,37 @@ void blecent_host_task(void *param)
|
|||||||
nimble_port_freertos_deinit();
|
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();
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(tag, "Nimble port stop failed, rc = %d", rc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
vTaskDelay(1000);
|
||||||
|
|
||||||
|
ESP_LOGI(tag, "Init host");
|
||||||
|
|
||||||
|
nimble_port_init();
|
||||||
|
nimble_port_freertos_init(blecent_host_task);
|
||||||
|
|
||||||
|
ESP_LOGI(tag, "Waiting for 1 second");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
app_main(void)
|
app_main(void)
|
||||||
{
|
{
|
||||||
@ -621,4 +654,8 @@ app_main(void)
|
|||||||
|
|
||||||
nimble_port_freertos_init(blecent_host_task);
|
nimble_port_freertos_init(blecent_host_task);
|
||||||
|
|
||||||
|
#if CONFIG_EXAMPLE_INIT_DEINIT_LOOP
|
||||||
|
stack_init_deinit();
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user