components/esp32: fix renaming of esp_event_set_cb, minor clean up

This commit is contained in:
Ivan Grokhotkov 2016-09-26 12:35:09 +08:00
parent 62aaec630c
commit 890fadc394

View File

@ -27,7 +27,6 @@
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "tcpip_adapter.h"
#include "esp_log.h"
#include "sdkconfig.h"
@ -38,7 +37,7 @@ static QueueHandle_t s_event_queue = NULL;
static system_event_cb_t s_event_handler_cb = NULL;
static void *s_event_ctx = NULL;
static esp_err_t esp_wifi_post_event_to_user(system_event_t *event)
static esp_err_t esp_event_post_to_user(system_event_t *event)
{
if (s_event_handler_cb) {
return (*s_event_handler_cb)(s_event_ctx, event);
@ -46,18 +45,16 @@ static esp_err_t esp_wifi_post_event_to_user(system_event_t *event)
return ESP_OK;
}
static void esp_system_event_task(void *pvParameters)
static void esp_event_loop_task(void *pvParameters)
{
system_event_t evt;
esp_err_t ret;
while (1) {
system_event_t evt;
if (xQueueReceive(s_event_queue, &evt, portMAX_DELAY) == pdPASS) {
ret = esp_event_process_default(&evt);
esp_err_t ret = esp_event_process_default(&evt);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "default event handler failed!");
}
ret = esp_wifi_post_event_to_user(&evt);
ret = esp_event_post_to_user(&evt);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "post event to user fail!");
}
@ -65,23 +62,18 @@ static void esp_system_event_task(void *pvParameters)
}
}
system_event_cb_t esp_event_set_cb(system_event_cb_t cb, void *ctx)
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx)
{
system_event_cb_t old_cb = s_event_handler_cb;
s_event_handler_cb = cb;
s_event_ctx = ctx;
return old_cb;
}
esp_err_t esp_event_send(system_event_t *event)
{
portBASE_TYPE ret;
ret = xQueueSendToBack(s_event_queue, event, 0);
if (pdPASS != ret) {
portBASE_TYPE ret = xQueueSendToBack(s_event_queue, event, 0);
if (ret != pdPASS) {
if (event) {
ESP_LOGE(TAG, "e=%d f", event->event_id);
} else {
@ -89,7 +81,6 @@ esp_err_t esp_event_send(system_event_t *event)
}
return ESP_FAIL;
}
return ESP_OK;
}
@ -103,13 +94,11 @@ esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
if (s_event_init_flag) {
return ESP_FAIL;
}
s_event_handler_cb = cb;
s_event_ctx = ctx;
s_event_queue = xQueueCreate(CONFIG_SYSTEM_EVENT_QUEUE_SIZE, sizeof(system_event_t));
xTaskCreatePinnedToCore(esp_system_event_task, "eventTask",
xTaskCreatePinnedToCore(esp_event_loop_task, "eventTask",
ESP_TASKD_EVENT_STACK, NULL, ESP_TASKD_EVENT_PRIO, NULL, 0);
s_event_init_flag = true;