mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(openthread): make ot task queue sending non-permanent blocking
This commit is contained in:
parent
3883a17f54
commit
050030f039
@ -1 +1 @@
|
||||
Subproject commit 34d698a274940730901b934caa023a3281aca53e
|
||||
Subproject commit 203c78501e9a6ea9ca3a929e6f9b6b9691ef16ee
|
@ -99,8 +99,11 @@ static void ot_cli_loop(void *context)
|
||||
printf("Internal error: %s\n", esp_err_to_name(err));
|
||||
}
|
||||
} else {
|
||||
esp_openthread_cli_input(line);
|
||||
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
|
||||
if (esp_openthread_cli_input(line) == ESP_OK) {
|
||||
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
|
||||
} else {
|
||||
printf("Openthread task is busy, failed to run command: %s\n", line);
|
||||
}
|
||||
}
|
||||
linenoiseHistoryAdd(line);
|
||||
}
|
||||
|
@ -23,6 +23,12 @@
|
||||
|
||||
#define OPENTHREAD_IP6_MTU 1280
|
||||
|
||||
#if CONFIG_OPENTHREAD_BORDER_ROUTER
|
||||
#if CONFIG_LWIP_IPV6_NUM_ADDRESSES != 12
|
||||
#error CONFIG_LWIP_IPV6_NUM_ADDRESSES should be set to 12, please configure it using `idf.py menuconfig`
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static err_t openthread_netif_init(struct netif *netif);
|
||||
static void openthread_netif_input(void *h, void *buffer, size_t len, void *eb);
|
||||
|
||||
|
@ -21,6 +21,8 @@ static QueueHandle_t s_task_queue = NULL;
|
||||
static int s_task_queue_event_fd = -1;
|
||||
static const char *task_queue_workflow = "task_queue";
|
||||
|
||||
#define OT_TASK_QUEUE_SENDING_WAIT_TIME pdMS_TO_TICKS(100)
|
||||
|
||||
typedef struct {
|
||||
esp_openthread_task_t task;
|
||||
void *arg;
|
||||
@ -60,7 +62,7 @@ esp_err_t IRAM_ATTR esp_openthread_task_queue_post(esp_openthread_task_t task, v
|
||||
ESP_RETURN_ON_FALSE_ISR(xQueueSendFromISR(s_task_queue, &task_storage, &task_woken), ESP_FAIL, OT_PLAT_LOG_TAG,
|
||||
"Failed to post task to OpenThread task queue");
|
||||
} else {
|
||||
ESP_RETURN_ON_FALSE(xQueueSend(s_task_queue, &task_storage, portMAX_DELAY), ESP_FAIL, OT_PLAT_LOG_TAG,
|
||||
ESP_RETURN_ON_FALSE(xQueueSend(s_task_queue, &task_storage, OT_TASK_QUEUE_SENDING_WAIT_TIME), ESP_FAIL, OT_PLAT_LOG_TAG,
|
||||
"Failed to post task to OpenThread task queue");
|
||||
}
|
||||
ret = write(s_task_queue_event_fd, &val, sizeof(val));
|
||||
|
@ -73,29 +73,15 @@ static void ot_task_worker(void *aContext)
|
||||
|
||||
// Initialize the OpenThread stack
|
||||
ESP_ERROR_CHECK(esp_openthread_init(&config));
|
||||
|
||||
// Initialize border routing features
|
||||
esp_openthread_lock_acquire(portMAX_DELAY);
|
||||
#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
|
||||
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
|
||||
#endif
|
||||
ESP_ERROR_CHECK(esp_netif_attach(openthread_netif, esp_openthread_netif_glue_init(&config)));
|
||||
|
||||
esp_openthread_lock_acquire(portMAX_DELAY);
|
||||
(void)otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL);
|
||||
esp_openthread_cli_init();
|
||||
|
||||
#if CONFIG_OPENTHREAD_BR_AUTO_START
|
||||
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_cli_custom_command_init();
|
||||
esp_openthread_cli_create_task();
|
||||
esp_openthread_lock_release();
|
||||
|
||||
// Run the main loop
|
||||
esp_openthread_cli_create_task();
|
||||
esp_openthread_launch_mainloop();
|
||||
|
||||
// Clean up
|
||||
@ -105,36 +91,15 @@ static void ot_task_worker(void *aContext)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
void ot_br_init(void *ctx)
|
||||
{
|
||||
// Used eventfds:
|
||||
// * netif
|
||||
// * task queue
|
||||
// * border router
|
||||
esp_vfs_eventfd_config_t eventfd_config = {
|
||||
#if CONFIG_OPENTHREAD_RADIO_NATIVE || CONFIG_OPENTHREAD_RADIO_SPINEL_SPI
|
||||
// * radio driver (A native radio device needs a eventfd for radio driver.)
|
||||
// * SpiSpinelInterface (The Spi Spinel Interface needs a eventfd.)
|
||||
// The above will not exist at the same time.
|
||||
.max_fds = 4,
|
||||
#else
|
||||
.max_fds = 3,
|
||||
#endif
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config));
|
||||
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
#if CONFIG_EXAMPLE_CONNECT_WIFI
|
||||
#if CONFIG_OPENTHREAD_BR_AUTO_START
|
||||
ESP_ERROR_CHECK(example_connect());
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
|
||||
#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_OPENTHREAD_RADIO_NATIVE
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
|
||||
ESP_ERROR_CHECK(esp_coex_wifi_i154_enable());
|
||||
#else
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
|
||||
|
||||
#if CONFIG_EXTERNAL_COEX_ENABLE
|
||||
ot_br_external_coexist_init();
|
||||
@ -155,5 +120,44 @@ void app_main(void)
|
||||
|
||||
ESP_ERROR_CHECK(mdns_init());
|
||||
ESP_ERROR_CHECK(mdns_hostname_set("esp-ot-br"));
|
||||
xTaskCreate(ot_task_worker, "ot_br_main", 20480, xTaskGetCurrentTaskHandle(), 5, NULL);
|
||||
|
||||
// Initialize border routing features
|
||||
esp_openthread_lock_acquire(portMAX_DELAY);
|
||||
#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
|
||||
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
|
||||
#endif
|
||||
|
||||
#if CONFIG_OPENTHREAD_BR_AUTO_START
|
||||
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 app_main(void)
|
||||
{
|
||||
// Used eventfds:
|
||||
// * netif
|
||||
// * task queue
|
||||
// * border router
|
||||
esp_vfs_eventfd_config_t eventfd_config = {
|
||||
#if CONFIG_OPENTHREAD_RADIO_NATIVE || CONFIG_OPENTHREAD_RADIO_SPINEL_SPI
|
||||
// * radio driver (A native radio device needs a eventfd for radio driver.)
|
||||
// * SpiSpinelInterface (The Spi Spinel Interface needs a eventfd.)
|
||||
// The above will not exist at the same time.
|
||||
.max_fds = 4,
|
||||
#else
|
||||
.max_fds = 3,
|
||||
#endif
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config));
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
xTaskCreate(ot_task_worker, "ot_br_main", 8192, xTaskGetCurrentTaskHandle(), 5, NULL);
|
||||
xTaskCreate(ot_br_init, "ot_br_init", 6144, NULL, 4, NULL);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ CONFIG_OPENTHREAD_RADIO_SPINEL_UART=y
|
||||
# lwIP
|
||||
#
|
||||
CONFIG_LWIP_IPV6_FORWARD=y
|
||||
CONFIG_LWIP_IPV6_NUM_ADDRESSES=8
|
||||
CONFIG_LWIP_IPV6_NUM_ADDRESSES=12
|
||||
CONFIG_LWIP_MULTICAST_PING=y
|
||||
CONFIG_LWIP_NETIF_STATUS_CALLBACK=y
|
||||
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
|
||||
|
Loading…
Reference in New Issue
Block a user