Skip to content

Commit

Permalink
fix(BR): move ot init into task
Browse files Browse the repository at this point in the history
  • Loading branch information
zwx1995esp committed Jul 26, 2024
1 parent 3d6f5f2 commit a64cb85
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions examples/common/thread_border_router/src/border_router_launch.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,40 @@ static void rcp_failure_handler(void)
esp_rcp_reset();
}

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)
{
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD();
esp_netif_t *openthread_netif = esp_netif_new(&cfg);

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 +136,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 +148,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 a64cb85

Please sign in to comment.