diff --git a/examples/common/thread_border_router/src/border_router_launch.c b/examples/common/thread_border_router/src/border_router_launch.c index 95dc9a7..b864219 100644 --- a/examples/common/thread_border_router/src/border_router_launch.c +++ b/examples/common/thread_border_router/src/border_router_launch.c @@ -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) @@ -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))); @@ -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(); @@ -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); }