-
#include "esp_log.h"
-
#include "esp_event.h"
-
#include "freertos/FreeRTOS.h"
-
#include "freertos/task.h"
-
-
static const char *TAG = "demo";
-
-
ESP_EVENT_DECLARE_BASE(EVENT_BASE);
-
ESP_EVENT_DEFINE_BASE(EVENT_BASE);
-
-
enum {
-
EVENT_ID_1
-
};
-
-
static void
-
app_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {
-
ESP_LOGW(TAG, "Before");
-
vTaskDelay(500 / portTICK_PERIOD_MS);
-
ESP_LOGW(TAG, "After");
-
}
-
-
void app_main(void) {
-
ESP_LOGI(TAG, "Start Demo");
-
esp_event_loop_create_default();
-
esp_event_handler_register(EVENT_BASE, EVENT_ID_1, app_event_handler, NULL);
-
ESP_LOGE(TAG, "Start");
-
esp_event_post(EVENT_BASE, EVENT_ID_1, NULL, 0, 500 / portTICK_RATE_MS);
-
ESP_LOGE(TAG, "End");
-
}
执行结果
可见在响应代码执行完毕之前 esp_event_post
() 函数已经返回。
分析代码 esp_event_post
() -> esp_event_post_to() 简化代码如下:
p, li { white-space: pre-wrap; }hr { height: 1px; border-width: 0; }
-
esp_err_t esp_event_post_to()
-
{
-
esp_event_post_instance_t post;
-
...
-
xQueueSendToBack(loop->queue, &post, ticks_to_wait);
-
...
-
post_instance_delete(&post);
-
...
-
return ESP_OK;
-
}
可见 esp_event_post
() 最终是将事件相关参数传送到事件循环对象的队列里面就返回了
阅读(731) | 评论(0) | 转发(0) |