Skip to content

Commit

Permalink
Merge branch 'fix/main_task_stack_over_flow_when_some_config_enable' …
Browse files Browse the repository at this point in the history
…into 'main'

fix(BR): move ot init into task

See merge request espressif/esp-thread-br!133
  • Loading branch information
chshu committed Jul 26, 2024
2 parents 3d6f5f2 + 4683648 commit bc2547a
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions examples/common/thread_border_router/src/border_router_launch.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,37 @@ static void rcp_failure_handler(void)
{
#if CONFIG_AUTO_UPDATE_RCP
esp_rcp_mark_image_unusable();
try_update_ot_rcp(&s_openthread_platform_config);
#endif // CONFIG_AUTO_UPDATE_RCP
esp_rcp_reset();
char internal_rcp_version[RCP_VERSION_MAX_SIZE];
if (esp_rcp_load_version_in_storage(internal_rcp_version, sizeof(internal_rcp_version)) == ESP_OK) {
ESP_LOGI(TAG, "Internal RCP Version: %s", internal_rcp_version);
update_rcp();
} else {
ESP_LOGI(TAG, "RCP firmware not found in storage, will reboot to try next image");
esp_rcp_mark_image_verified(false);
esp_restart();
}
#endif
}

static void ot_br_init(void *ctx)
{
#if CONFIG_OPENTHREAD_BR_AUTO_START
#if !CONFIG_EXAMPLE_CONNECT_WIFI && !CONFIG_EXAMPLE_CONNECT_ETHERNET
#error No backbone netif!
#endif
ESP_ERROR_CHECK(example_connect());
#if CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
#endif
esp_openthread_lock_acquire(portMAX_DELAY);
esp_openthread_set_backbone_netif(get_example_netif());
ESP_ERROR_CHECK(esp_openthread_border_router_init());
otOperationalDatasetTlvs dataset;
otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL));
#endif // CONFIG_OPENTHREAD_BR_AUTO_START
esp_openthread_lock_release();
vTaskDelete(NULL);
}

static void ot_task_worker(void *ctx)
Expand All @@ -97,6 +125,12 @@ static void ot_task_worker(void *ctx)

assert(openthread_netif != NULL);

// Initialize the OpenThread stack
esp_openthread_register_rcp_failure_handler(rcp_failure_handler);
ESP_ERROR_CHECK(esp_openthread_init(&s_openthread_platform_config));
#if CONFIG_AUTO_UPDATE_RCP
try_update_ot_rcp(&s_openthread_platform_config);
#endif
// Initialize border routing features
esp_openthread_lock_acquire(portMAX_DELAY);
ESP_ERROR_CHECK(esp_netif_attach(openthread_netif, esp_openthread_netif_glue_init(&s_openthread_platform_config)));
Expand All @@ -109,6 +143,7 @@ static void ot_task_worker(void *ctx)
esp_openthread_cli_create_task();
esp_openthread_lock_release();

xTaskCreate(ot_br_init, "ot_br_init", 6144, NULL, 4, NULL);
// Run the main loop
esp_openthread_launch_mainloop();

Expand All @@ -120,39 +155,11 @@ static void ot_task_worker(void *ctx)
vTaskDelete(NULL);
}

static void ot_br_init(void *ctx)
{
#if CONFIG_OPENTHREAD_BR_AUTO_START
#if !CONFIG_EXAMPLE_CONNECT_WIFI && !CONFIG_EXAMPLE_CONNECT_ETHERNET
#error No backbone netif!
#endif
ESP_ERROR_CHECK(example_connect());
#if CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
#endif
esp_openthread_lock_acquire(portMAX_DELAY);
esp_openthread_set_backbone_netif(get_example_netif());
ESP_ERROR_CHECK(esp_openthread_border_router_init());
otOperationalDatasetTlvs dataset;
otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL));
#endif // CONFIG_OPENTHREAD_BR_AUTO_START
esp_openthread_lock_release();
vTaskDelete(NULL);
}

void launch_openthread_border_router(const esp_openthread_platform_config_t *platform_config,
const esp_rcp_update_config_t *update_config)
{
s_openthread_platform_config = *platform_config;
ESP_ERROR_CHECK(esp_rcp_update_init(update_config));

// Initialize the OpenThread stack
esp_openthread_register_rcp_failure_handler(rcp_failure_handler);
ESP_ERROR_CHECK(esp_openthread_init(&s_openthread_platform_config));
#if CONFIG_AUTO_UPDATE_RCP
try_update_ot_rcp(&s_openthread_platform_config);
#endif
xTaskCreate(ot_task_worker, "ot_br_main", 6144, xTaskGetCurrentTaskHandle(), 5, NULL);
xTaskCreate(ot_br_init, "ot_br_init", 6144, NULL, 4, NULL);
}

0 comments on commit bc2547a

Please sign in to comment.