change(esp_event): reformat files with astyle

This commit is contained in:
Jakob Hasse 2024-01-31 10:24:05 +08:00
parent 389cf54d52
commit 417de470ec
9 changed files with 611 additions and 612 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -15,14 +15,14 @@ static esp_event_loop_handle_t s_default_loop = NULL;
/* ---------------------------- Public API ---------------------------------- */
esp_err_t esp_event_handler_register(esp_event_base_t event_base, int32_t event_id,
esp_event_handler_t event_handler, void* event_handler_arg)
esp_event_handler_t event_handler, void* event_handler_arg)
{
if (s_default_loop == NULL) {
return ESP_ERR_INVALID_STATE;
}
return esp_event_handler_register_with(s_default_loop, event_base, event_id,
event_handler, event_handler_arg);
event_handler, event_handler_arg);
}
esp_err_t esp_event_handler_instance_register(esp_event_base_t event_base,
@ -44,14 +44,14 @@ esp_err_t esp_event_handler_instance_register(esp_event_base_t event_base,
}
esp_err_t esp_event_handler_unregister(esp_event_base_t event_base, int32_t event_id,
esp_event_handler_t event_handler)
esp_event_handler_t event_handler)
{
if (s_default_loop == NULL) {
return ESP_ERR_INVALID_STATE;
}
return esp_event_handler_unregister_with(s_default_loop, event_base, event_id,
event_handler);
event_handler);
}
esp_err_t esp_event_handler_instance_unregister(esp_event_base_t event_base,
@ -66,31 +66,29 @@ esp_err_t esp_event_handler_instance_unregister(esp_event_base_t event_base,
}
esp_err_t esp_event_post(esp_event_base_t event_base, int32_t event_id,
const void* event_data, size_t event_data_size, TickType_t ticks_to_wait)
const void* event_data, size_t event_data_size, TickType_t ticks_to_wait)
{
if (s_default_loop == NULL) {
return ESP_ERR_INVALID_STATE;
}
return esp_event_post_to(s_default_loop, event_base, event_id,
event_data, event_data_size, ticks_to_wait);
event_data, event_data_size, ticks_to_wait);
}
#if CONFIG_ESP_EVENT_POST_FROM_ISR
esp_err_t esp_event_isr_post(esp_event_base_t event_base, int32_t event_id,
const void* event_data, size_t event_data_size, BaseType_t* task_unblocked)
const void* event_data, size_t event_data_size, BaseType_t* task_unblocked)
{
if (s_default_loop == NULL) {
return ESP_ERR_INVALID_STATE;
}
return esp_event_isr_post_to(s_default_loop, event_base, event_id,
event_data, event_data_size, task_unblocked);
event_data, event_data_size, task_unblocked);
}
#endif
esp_err_t esp_event_loop_create_default(void)
{
if (s_default_loop) {

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -24,7 +24,7 @@
#ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
// LOOP @<address, name> rx:<recieved events no.> dr:<dropped events no.>
#define LOOP_DUMP_FORMAT "LOOP @%p,%s rx:%" PRIu32 " dr:%" PRIu32 "\n"
// handler @<address> ev:<base, id> inv:<times invoked> time:<runtime>
// handler @<address> ev:<base, id> inv:<times invoked> time:<runtime>
#define HANDLER_DUMP_FORMAT " HANDLER @%p ev:%s,%s inv:%" PRIu32 " time:%lld us\n"
#define PRINT_DUMP_INFO(dst, sz, ...) do { \
@ -41,17 +41,15 @@ static const char* esp_event_any_base = "any";
#ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
static SLIST_HEAD(esp_event_loop_instance_list_t, esp_event_loop_instance) s_event_loops =
SLIST_HEAD_INITIALIZER(s_event_loops);
SLIST_HEAD_INITIALIZER(s_event_loops);
static portMUX_TYPE s_event_loops_spinlock = portMUX_INITIALIZER_UNLOCKED;
#endif
/* ------------------------- Static Functions ------------------------------- */
#ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
static int esp_event_dump_prepare(void)
{
esp_event_loop_instance_t* loop_it;
@ -90,7 +88,7 @@ static int esp_event_dump_prepare(void)
// Reserve slightly more memory than computed
int allowance = 3;
int size = (((loops + allowance) * (sizeof(LOOP_DUMP_FORMAT) + 10 + 20 + 2 * 11)) +
((handlers + allowance) * (sizeof(HANDLER_DUMP_FORMAT) + 10 + 2 * 20 + 11 + 20)));
((handlers + allowance) * (sizeof(HANDLER_DUMP_FORMAT) + 10 + 2 * 20 + 11 + 20)));
return size;
}
@ -103,7 +101,7 @@ static void esp_event_loop_run_task(void* args)
ESP_LOGD(TAG, "running task for loop %p", event_loop);
while(1) {
while (1) {
err = esp_event_loop_run(event_loop, portMAX_DELAY);
if (err != ESP_OK) {
break;
@ -151,7 +149,7 @@ static void handler_execute(esp_event_loop_instance_t* loop, esp_event_handler_n
esp_event_handler_node_t* handler_node;
SLIST_FOREACH(loop_node, &(loop->loop_nodes), next) {
SLIST_FOREACH(handler_node, &(loop_node->handlers), next) {
if(handler_node == handler) {
if (handler_node == handler) {
handler->invoked++;
handler->time += diff;
}
@ -166,7 +164,9 @@ static esp_err_t handler_instances_add(esp_event_handler_nodes_t* handlers, esp_
{
esp_event_handler_node_t *handler_instance = calloc(1, sizeof(*handler_instance));
if (!handler_instance) return ESP_ERR_NO_MEM;
if (!handler_instance) {
return ESP_ERR_NO_MEM;
}
esp_event_handler_instance_context_t *context = calloc(1, sizeof(*context));
@ -181,13 +181,12 @@ static esp_err_t handler_instances_add(esp_event_handler_nodes_t* handlers, esp_
if (SLIST_EMPTY(handlers)) {
SLIST_INSERT_HEAD(handlers, handler_instance, next);
}
else {
} else {
esp_event_handler_node_t *it = NULL, *last = NULL;
SLIST_FOREACH(it, handlers, next) {
if (legacy) {
if(event_handler == it->handler_ctx->handler) {
if (event_handler == it->handler_ctx->handler) {
it->handler_ctx->arg = event_handler_arg;
ESP_LOGW(TAG, "handler already registered, overwriting");
free(handler_instance);
@ -211,16 +210,15 @@ static esp_err_t handler_instances_add(esp_event_handler_nodes_t* handlers, esp_
}
static esp_err_t base_node_add_handler(esp_event_base_node_t* base_node,
int32_t id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_context_t **handler_ctx,
bool legacy)
int32_t id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_context_t **handler_ctx,
bool legacy)
{
if (id == ESP_EVENT_ANY_ID) {
return handler_instances_add(&(base_node->handlers), event_handler, event_handler_arg, handler_ctx, legacy);
}
else {
} else {
esp_err_t err = ESP_OK;
esp_event_id_node_t *it = NULL, *id_node = NULL, *last_id_node = NULL;
@ -248,8 +246,7 @@ static esp_err_t base_node_add_handler(esp_event_base_node_t* base_node,
if (err == ESP_OK) {
if (!last_id_node) {
SLIST_INSERT_HEAD(&(base_node->id_nodes), id_node, next);
}
else {
} else {
SLIST_INSERT_AFTER(last_id_node, id_node, next);
}
} else {
@ -257,25 +254,23 @@ static esp_err_t base_node_add_handler(esp_event_base_node_t* base_node,
}
return err;
}
else {
} else {
return handler_instances_add(&(id_node->handlers), event_handler, event_handler_arg, handler_ctx, legacy);
}
}
}
static esp_err_t loop_node_add_handler(esp_event_loop_node_t* loop_node,
esp_event_base_t base,
int32_t id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_context_t **handler_ctx,
bool legacy)
esp_event_base_t base,
int32_t id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_context_t **handler_ctx,
bool legacy)
{
if (base == esp_event_any_base && id == ESP_EVENT_ANY_ID) {
return handler_instances_add(&(loop_node->handlers), event_handler, event_handler_arg, handler_ctx, legacy);
}
else {
} else {
esp_err_t err = ESP_OK;
esp_event_base_node_t *it = NULL, *base_node = NULL, *last_base_node = NULL;
@ -287,9 +282,9 @@ static esp_err_t loop_node_add_handler(esp_event_loop_node_t* loop_node,
}
if (!last_base_node ||
!base_node ||
(base_node && !SLIST_EMPTY(&(base_node->id_nodes)) && id == ESP_EVENT_ANY_ID) ||
(last_base_node && last_base_node->base != base && !SLIST_EMPTY(&(last_base_node->id_nodes)) && id == ESP_EVENT_ANY_ID)) {
!base_node ||
(base_node && !SLIST_EMPTY(&(base_node->id_nodes)) && id == ESP_EVENT_ANY_ID) ||
(last_base_node && last_base_node->base != base && !SLIST_EMPTY(&(last_base_node->id_nodes)) && id == ESP_EVENT_ANY_ID)) {
base_node = (esp_event_base_node_t*) calloc(1, sizeof(*base_node));
if (!base_node) {
@ -307,8 +302,7 @@ static esp_err_t loop_node_add_handler(esp_event_loop_node_t* loop_node,
if (err == ESP_OK) {
if (!last_base_node) {
SLIST_INSERT_HEAD(&(loop_node->base_nodes), base_node, next);
}
else {
} else {
SLIST_INSERT_AFTER(last_base_node, base_node, next);
}
} else {
@ -347,13 +341,11 @@ static esp_err_t handler_instances_remove(esp_event_handler_nodes_t* handlers, e
return ESP_ERR_NOT_FOUND;
}
static esp_err_t base_node_remove_handler(esp_event_base_node_t* base_node, int32_t id, esp_event_handler_instance_context_t* handler_ctx, bool legacy)
{
if (id == ESP_EVENT_ANY_ID) {
return handler_instances_remove(&(base_node->handlers), handler_ctx, legacy);
}
else {
} else {
esp_event_id_node_t *it, *temp;
SLIST_FOREACH_SAFE(it, &(base_node->id_nodes), next, temp) {
if (it->id == id) {
@ -377,8 +369,7 @@ static esp_err_t loop_node_remove_handler(esp_event_loop_node_t* loop_node, esp_
{
if (base == esp_event_any_base && id == ESP_EVENT_ANY_ID) {
return handler_instances_remove(&(loop_node->handlers), handler_ctx, legacy);
}
else {
} else {
esp_event_base_node_t *it, *temp;
SLIST_FOREACH_SAFE(it, &(loop_node->base_nodes), next, temp) {
if (it->base == base) {
@ -469,7 +460,7 @@ esp_err_t esp_event_loop_create(const esp_event_loop_args_t* event_loop_args, es
return err;
}
loop->queue = xQueueCreate(event_loop_args->queue_size , sizeof(esp_event_post_instance_t));
loop->queue = xQueueCreate(event_loop_args->queue_size, sizeof(esp_event_post_instance_t));
if (loop->queue == NULL) {
ESP_LOGE(TAG, "create event loop queue failed");
goto on_err;
@ -494,8 +485,8 @@ esp_err_t esp_event_loop_create(const esp_event_loop_args_t* event_loop_args, es
// Create the loop task if requested
if (event_loop_args->task_name != NULL) {
BaseType_t task_created = xTaskCreatePinnedToCore(esp_event_loop_run_task, event_loop_args->task_name,
event_loop_args->task_stack_size, (void*) loop,
event_loop_args->task_priority, &(loop->task), event_loop_args->task_core_id);
event_loop_args->task_stack_size, (void*) loop,
event_loop_args->task_priority, &(loop->task), event_loop_args->task_core_id);
if (task_created != pdPASS) {
ESP_LOGE(TAG, "create task for loop failed");
@ -566,7 +557,7 @@ esp_err_t esp_event_loop_run(esp_event_loop_handle_t event_loop, TickType_t tick
int64_t remaining_ticks = ticks_to_run;
#endif
while(xQueueReceive(loop->queue, &post, ticks_to_run) == pdTRUE) {
while (xQueueReceive(loop->queue, &post, ticks_to_run) == pdTRUE) {
// The event has already been unqueued, so ensure it gets executed.
xSemaphoreTakeRecursive(loop->mutex, portMAX_DELAY);
@ -674,7 +665,7 @@ esp_err_t esp_event_loop_delete(esp_event_loop_handle_t event_loop)
// Drop existing posts on the queue
esp_event_post_instance_t post;
while(xQueueReceive(loop->queue, &post, 0) == pdTRUE) {
while (xQueueReceive(loop->queue, &post, 0) == pdTRUE) {
post_instance_delete(&post);
}
@ -693,8 +684,8 @@ esp_err_t esp_event_loop_delete(esp_event_loop_handle_t event_loop)
}
esp_err_t esp_event_handler_register_with_internal(esp_event_loop_handle_t event_loop, esp_event_base_t event_base,
int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg,
esp_event_handler_instance_context_t** handler_ctx_arg, bool legacy)
int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg,
esp_event_handler_instance_context_t** handler_ctx_arg, bool legacy)
{
assert(event_loop);
assert(event_handler);
@ -723,7 +714,7 @@ esp_err_t esp_event_handler_register_with_internal(esp_event_loop_handle_t event
bool is_loop_level_handler = (event_base == esp_event_any_base) && (event_id == ESP_EVENT_ANY_ID);
if (!last_loop_node ||
(last_loop_node && !SLIST_EMPTY(&(last_loop_node->base_nodes)) && is_loop_level_handler)) {
(last_loop_node && !SLIST_EMPTY(&(last_loop_node->base_nodes)) && is_loop_level_handler)) {
loop_node = (esp_event_loop_node_t*) calloc(1, sizeof(*loop_node));
if (!loop_node) {
@ -740,15 +731,13 @@ esp_err_t esp_event_handler_register_with_internal(esp_event_loop_handle_t event
if (err == ESP_OK) {
if (!last_loop_node) {
SLIST_INSERT_HEAD(&(loop->loop_nodes), loop_node, next);
}
else {
} else {
SLIST_INSERT_AFTER(last_loop_node, loop_node, next);
}
} else {
free(loop_node);
}
}
else {
} else {
err = loop_node_add_handler(last_loop_node, event_base, event_id, event_handler, event_handler_arg, handler_ctx_arg, legacy);
}
@ -758,20 +747,20 @@ on_err:
}
esp_err_t esp_event_handler_register_with(esp_event_loop_handle_t event_loop, esp_event_base_t event_base,
int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg)
int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg)
{
return esp_event_handler_register_with_internal(event_loop, event_base, event_id, event_handler, event_handler_arg, NULL, true);
}
esp_err_t esp_event_handler_instance_register_with(esp_event_loop_handle_t event_loop, esp_event_base_t event_base,
int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg,
esp_event_handler_instance_t* handler_ctx_arg)
int32_t event_id, esp_event_handler_t event_handler, void* event_handler_arg,
esp_event_handler_instance_t* handler_ctx_arg)
{
return esp_event_handler_register_with_internal(event_loop, event_base, event_id, event_handler, event_handler_arg, (esp_event_handler_instance_context_t**) handler_ctx_arg, false);
}
esp_err_t esp_event_handler_unregister_with_internal(esp_event_loop_handle_t event_loop, esp_event_base_t event_base,
int32_t event_id, esp_event_handler_instance_context_t* handler_ctx, bool legacy)
int32_t event_id, esp_event_handler_instance_context_t* handler_ctx, bool legacy)
{
assert(event_loop);
assert(handler_ctx);
@ -817,9 +806,11 @@ esp_err_t esp_event_handler_unregister_with(esp_event_loop_handle_t event_loop,
}
esp_err_t esp_event_handler_instance_unregister_with(esp_event_loop_handle_t event_loop, esp_event_base_t event_base,
int32_t event_id, esp_event_handler_instance_t handler_ctx_arg)
int32_t event_id, esp_event_handler_instance_t handler_ctx_arg)
{
if (!handler_ctx_arg) return ESP_ERR_INVALID_ARG;
if (!handler_ctx_arg) {
return ESP_ERR_INVALID_ARG;
}
return esp_event_handler_unregister_with_internal(event_loop, event_base, event_id, (esp_event_handler_instance_context_t*) handler_ctx_arg, false);
}
@ -902,7 +893,7 @@ esp_err_t esp_event_post_to(esp_event_loop_handle_t event_loop, esp_event_base_t
#if CONFIG_ESP_EVENT_POST_FROM_ISR
esp_err_t esp_event_isr_post_to(esp_event_loop_handle_t event_loop, esp_event_base_t event_base, int32_t event_id,
const void* event_data, size_t event_data_size, BaseType_t* task_unblocked)
const void* event_data, size_t event_data_size, BaseType_t* task_unblocked)
{
assert(event_loop);
@ -976,7 +967,7 @@ esp_err_t esp_event_dump(FILE* file)
events_recieved = atomic_load(&loop_it->events_recieved);
events_dropped = atomic_load(&loop_it->events_dropped);
PRINT_DUMP_INFO(dst, sz, LOOP_DUMP_FORMAT, loop_it, loop_it->task != NULL ? loop_it->name : "none" ,
PRINT_DUMP_INFO(dst, sz, LOOP_DUMP_FORMAT, loop_it, loop_it->task != NULL ? loop_it->name : "none",
events_recieved, events_dropped);
int sz_bak = sz;
@ -989,7 +980,7 @@ esp_err_t esp_event_dump(FILE* file)
SLIST_FOREACH(base_node_it, &(loop_node_it->base_nodes), next) {
SLIST_FOREACH(handler_it, &(base_node_it->handlers), next) {
PRINT_DUMP_INFO(dst, sz, HANDLER_DUMP_FORMAT, handler_it->handler_ctx->handler, base_node_it->base ,
PRINT_DUMP_INFO(dst, sz, HANDLER_DUMP_FORMAT, handler_it->handler_ctx->handler, base_node_it->base,
"ESP_EVENT_ANY_ID", handler_it->invoked, handler_it->time);
}
@ -998,7 +989,7 @@ esp_err_t esp_event_dump(FILE* file)
memset(id_str_buf, 0, sizeof(id_str_buf));
snprintf(id_str_buf, sizeof(id_str_buf), "%" PRIi32, id_node_it->id);
PRINT_DUMP_INFO(dst, sz, HANDLER_DUMP_FORMAT, handler_it->handler_ctx->handler, base_node_it->base ,
PRINT_DUMP_INFO(dst, sz, HANDLER_DUMP_FORMAT, handler_it->handler_ctx->handler, base_node_it->base,
id_str_buf, handler_it->invoked, handler_it->time);
}
}

View File

@ -22,8 +22,7 @@ bool esp_event_is_handler_registered(esp_event_loop_handle_t event_loop, esp_eve
SLIST_FOREACH(loop_node, &(loop->loop_nodes), next) {
SLIST_FOREACH(handler, &(loop_node->handlers), next) {
if(event_base == ESP_EVENT_ANY_BASE && event_id == ESP_EVENT_ANY_ID && handler->handler_ctx->handler == event_handler)
{
if (event_base == ESP_EVENT_ANY_BASE && event_id == ESP_EVENT_ANY_ID && handler->handler_ctx->handler == event_handler) {
result = true;
goto out;
}
@ -32,18 +31,16 @@ bool esp_event_is_handler_registered(esp_event_loop_handle_t event_loop, esp_eve
SLIST_FOREACH(base_node, &(loop_node->base_nodes), next) {
if (base_node->base == event_base) {
SLIST_FOREACH(handler, &(base_node->handlers), next) {
if(event_id == ESP_EVENT_ANY_ID && handler->handler_ctx->handler == event_handler)
{
if (event_id == ESP_EVENT_ANY_ID && handler->handler_ctx->handler == event_handler) {
result = true;
goto out;
}
}
SLIST_FOREACH(id_node, &(base_node->id_nodes), next) {
if(id_node->id == event_id) {
if (id_node->id == event_id) {
SLIST_FOREACH(handler, &(id_node->handlers), next) {
if(handler->handler_ctx->handler == event_handler)
{
if (handler->handler_ctx->handler == event_handler) {
result = true;
goto out;
}

View File

@ -7,7 +7,6 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "esp_event.h"
@ -20,7 +19,6 @@ extern "C" {
#include "Mockqueue.h"
}
namespace {
const uint32_t QUEUE_SIZE = 32;
@ -45,7 +43,8 @@ void dummy_handler(void* event_handler_arg, esp_event_base_t event_base, int32_t
}
// TODO: IDF-2693, function definition just to satisfy linker, implement esp_common instead
const char *esp_err_to_name(esp_err_t code) {
const char *esp_err_to_name(esp_err_t code)
{
return "test";
}
@ -141,11 +140,12 @@ TEST_CASE("test esp_event_loop_create with_task(void)")
xQueueGiveMutexRecursive_StopIgnore();
}
TEST_CASE("registering with ANY_BASE but specific ID fails") {
TEST_CASE("registering with ANY_BASE but specific ID fails")
{
esp_event_loop_handle_t loop = reinterpret_cast<esp_event_loop_handle_t>(1);
CHECK(esp_event_handler_register_with(loop,
ESP_EVENT_ANY_BASE,
47,
dummy_handler,
nullptr) == ESP_ERR_INVALID_ARG);
ESP_EVENT_ANY_BASE,
47,
dummy_handler,
nullptr) == ESP_ERR_INVALID_ARG);
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -208,11 +208,11 @@ esp_err_t esp_event_handler_register_with(esp_event_loop_handle_t event_loop,
* - Others: Fail
*/
esp_err_t esp_event_handler_instance_register_with(esp_event_loop_handle_t event_loop,
esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_t *instance);
esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_t *instance);
/**
* @brief Register an instance of event handler to the default loop.
@ -243,10 +243,10 @@ esp_err_t esp_event_handler_instance_register_with(esp_event_loop_handle_t event
* - Others: Fail
*/
esp_err_t esp_event_handler_instance_register(esp_event_base_t event_base,
int32_t event_id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_t *instance);
int32_t event_id,
esp_event_handler_t event_handler,
void *event_handler_arg,
esp_event_handler_instance_t *instance);
/**
* @brief Unregister a handler with the system event loop (legacy).

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -19,10 +19,10 @@ extern "C" {
// Event loop library types
typedef const char* esp_event_base_t; /**< unique pointer to a subsystem that exposes events */
typedef void* esp_event_loop_handle_t; /**< a number that identifies an event with respect to a base */
typedef void (*esp_event_handler_t)(void* event_handler_arg,
esp_event_base_t event_base,
int32_t event_id,
void* event_data); /**< function called when an event is posted to the queue */
typedef void (*esp_event_handler_t)(void* event_handler_arg,
esp_event_base_t event_base,
int32_t event_id,
void* event_data); /**< function called when an event is posted to the queue */
typedef void* esp_event_handler_instance_t; /**< context identifying an instance of a registered event handler */
// Defines for registering/unregistering event handlers

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@ -30,7 +30,6 @@
#include "test_utils.h"
static const char* TAG = "test_event";
static const TickType_t ZERO_DELAY = 0;
@ -154,7 +153,7 @@ static void test_event_simple_handler_registration_task(void* args)
xSemaphoreTake(arg->start, portMAX_DELAY);
for(int i = 0; i < data->num; i++) {
for (int i = 0; i < data->num; i++) {
if (data->is_registration) {
TEST_ESP_OK(esp_event_handler_register_with(data->loop, data->base, data->id, data->handles[i], NULL));
} else {
@ -261,7 +260,7 @@ TEST_CASE("can register/unregister handlers simultaneously", "[event]")
registration_data[i].is_registration = true;
for (int j = 0; j < TEST_CONFIG_ITEMS_TO_REGISTER; j++) {
registration_data[i].handles[j] = (void*) (i * TEST_CONFIG_ITEMS_TO_REGISTER) + (j + TEST_CONFIG_ITEMS_TO_REGISTER);
registration_data[i].handles[j] = (void*)(i * TEST_CONFIG_ITEMS_TO_REGISTER) + (j + TEST_CONFIG_ITEMS_TO_REGISTER);
}
registration_arg[i].start = xSemaphoreCreateBinary();
@ -381,8 +380,7 @@ TEST_CASE("can post and run events simultaneously", "[event]")
post_event_data_t* post_event_data = calloc(TEST_CONFIG_TASKS_TO_SPAWN, sizeof(*post_event_data));
task_arg_t* post_event_arg = calloc(TEST_CONFIG_TASKS_TO_SPAWN, sizeof(*post_event_arg));
for (int i = 0; i < TEST_CONFIG_TASKS_TO_SPAWN; i++)
{
for (int i = 0; i < TEST_CONFIG_TASKS_TO_SPAWN; i++) {
post_event_data[i].base = s_test_base1;
post_event_data[i].id = TEST_EVENT_BASE1_EV1;
post_event_data[i].loop = loop;
@ -459,8 +457,7 @@ TEST_CASE("can post and run events simultaneously with instances", "[event]")
post_event_data_t* post_event_data = calloc(TEST_CONFIG_TASKS_TO_SPAWN, sizeof(*post_event_data));
task_arg_t* post_event_arg = calloc(TEST_CONFIG_TASKS_TO_SPAWN, sizeof(*post_event_arg));
for (int i = 0; i < TEST_CONFIG_TASKS_TO_SPAWN; i++)
{
for (int i = 0; i < TEST_CONFIG_TASKS_TO_SPAWN; i++) {
post_event_data[i].base = s_test_base1;
post_event_data[i].id = TEST_EVENT_BASE1_EV1;
post_event_data[i].loop = loop;
@ -514,7 +511,7 @@ static void loop_run_task(void* args)
{
esp_event_loop_handle_t event_loop = (esp_event_loop_handle_t) args;
while(1) {
while (1) {
esp_event_loop_run(event_loop, portMAX_DELAY);
}
}
@ -527,8 +524,8 @@ static void performance_test(bool dedicated_task)
const char test_base[] = "qwertyuiopasdfghjklzxvbnmmnbvcxz";
#define TEST_CONFIG_BASES (sizeof(test_base) - 1)
#define TEST_CONFIG_IDS (TEST_CONFIG_BASES / 2)
#define TEST_CONFIG_BASES (sizeof(test_base) - 1)
#define TEST_CONFIG_IDS (TEST_CONFIG_BASES / 2)
// Create loop
esp_event_loop_args_t loop_args = test_event_get_default_loop_args();
@ -583,7 +580,7 @@ static void performance_test(bool dedicated_task)
int rand_b = rand() % bases;
int temp = post_bases[rand_a];
post_bases[rand_a]= post_bases[rand_b];
post_bases[rand_a] = post_bases[rand_b];
post_bases[rand_b] = temp;
}
@ -592,7 +589,7 @@ static void performance_test(bool dedicated_task)
int rand_b = rand() % ids;
int temp = post_ids[rand_a];
post_ids[rand_a]= post_ids[rand_b];
post_ids[rand_a] = post_ids[rand_b];
post_ids[rand_b] = temp;
}
@ -617,7 +614,7 @@ static void performance_test(bool dedicated_task)
}
}
int average = (int) (running_sum / (running_count));
int average = (int)(running_sum / (running_count));
if (!dedicated_task) {
((esp_event_loop_instance_t*) loop)->task = mtask;
@ -700,7 +697,7 @@ static void test_handler_post_from_isr(void* event_handler_arg, esp_event_base_t
SemaphoreHandle_t *sem = (SemaphoreHandle_t*) event_handler_arg;
// Event data is just the address value (maybe have been truncated due to casting).
int *data = (int*) event_data;
TEST_ASSERT_EQUAL(*data, (int) (*sem));
TEST_ASSERT_EQUAL(*data, (int)(*sem));
xSemaphoreGive(*sem);
}

View File

@ -54,7 +54,6 @@ components_not_formatted_temporary:
- "/components/efuse/"
- "/components/esp_coex/"
- "/components/esp_eth/"
- "/components/esp_event/"
- "/components/esp_gdbstub/"
- "/components/esp_hid/"
- "/components/esp_http_client/"