Skip to content

Commit c3982ab

Browse files
committed
feat(esp_event): add esp_event components from esp-idf
Commit ID: 463a9d8b
1 parent 622482e commit c3982ab

21 files changed

+4074
-0
lines changed

components/esp_event/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
idf_component_register(SRCS "default_event_loop.c"
2+
"esp_event.c"
3+
"esp_event_private.c"
4+
"event_loop_legacy.c"
5+
"event_send.c"
6+
INCLUDE_DIRS "include"
7+
PRIV_INCLUDE_DIRS "private_include"
8+
REQUIRES log tcpip_adapter
9+
PRIV_REQUIRES esp_eth
10+
LDFRAGMENTS linker.lf)
11+
12+
if(GCC_NOT_5_2_0 AND CONFIG_ESP_EVENT_LOOP_PROFILING)
13+
# uses C11 atomic feature
14+
set_source_files_properties(esp_event.c PROPERTIES COMPILE_FLAGS -std=gnu11)
15+
endif()

components/esp_event/Kconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
menu "Event Loop Library"
2+
3+
config ESP_EVENT_LOOP_PROFILING
4+
bool "Enable event loop profiling"
5+
default n
6+
help
7+
Enables collections of statistics in the event loop library such as the number of events posted
8+
to/recieved by an event loop, number of callbacks involved, number of events dropped to to a full event
9+
loop queue, run time of event handlers, and number of times/run time of each event handler.
10+
11+
config ESP_EVENT_POST_FROM_ISR
12+
bool "Support posting events from ISRs"
13+
default y
14+
help
15+
Enable posting events from interrupt handlers.
16+
17+
config ESP_EVENT_POST_FROM_IRAM_ISR
18+
bool "Support posting events from ISRs placed in IRAM"
19+
default y
20+
depends on ESP_EVENT_POST_FROM_ISR
21+
help
22+
Enable posting events from interrupt handlers placed in IRAM. Enabling this option places API functions
23+
esp_event_post and esp_event_post_to in IRAM.
24+
25+
endmenu

components/esp_event/component.mk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Component Makefile
3+
#
4+
COMPONENT_ADD_INCLUDEDIRS := include
5+
COMPONENT_PRIV_INCLUDEDIRS := private_include
6+
COMPONENT_SRCDIRS := .
7+
COMPONENT_ADD_LDFRAGMENTS := linker.lf
8+
9+
ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
10+
PROFILING_ENABLED := 1
11+
else
12+
PROFILING_ENABLED := 0
13+
endif
14+
15+
ifeq ($(and $(GCC_NOT_5_2_0),$(PROFILING_ENABLED)), 1)
16+
# uses C11 atomic feature
17+
esp_event.o: CFLAGS += -std=gnu11
18+
endif
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "esp_event.h"
16+
#include "esp_event_internal.h"
17+
#include "esp_task.h"
18+
19+
/* ------------------------- Static Variables ------------------------------- */
20+
21+
static esp_event_loop_handle_t s_default_loop = NULL;
22+
23+
/* ---------------------------- Public API ---------------------------------- */
24+
25+
esp_err_t esp_event_handler_register(esp_event_base_t event_base, int32_t event_id,
26+
esp_event_handler_t event_handler, void* event_handler_arg)
27+
{
28+
if (s_default_loop == NULL) {
29+
return ESP_ERR_INVALID_STATE;
30+
}
31+
32+
return esp_event_handler_register_with(s_default_loop, event_base, event_id,
33+
event_handler, event_handler_arg);
34+
}
35+
36+
esp_err_t esp_event_handler_unregister(esp_event_base_t event_base, int32_t event_id,
37+
esp_event_handler_t event_handler)
38+
{
39+
if (s_default_loop == NULL) {
40+
return ESP_ERR_INVALID_STATE;
41+
}
42+
43+
return esp_event_handler_unregister_with(s_default_loop, event_base, event_id,
44+
event_handler);
45+
}
46+
47+
esp_err_t esp_event_post(esp_event_base_t event_base, int32_t event_id,
48+
void* event_data, size_t event_data_size, TickType_t ticks_to_wait)
49+
{
50+
if (s_default_loop == NULL) {
51+
return ESP_ERR_INVALID_STATE;
52+
}
53+
54+
return esp_event_post_to(s_default_loop, event_base, event_id,
55+
event_data, event_data_size, ticks_to_wait);
56+
}
57+
58+
59+
#if CONFIG_ESP_EVENT_POST_FROM_ISR
60+
esp_err_t esp_event_isr_post(esp_event_base_t event_base, int32_t event_id,
61+
void* event_data, size_t event_data_size, BaseType_t* task_unblocked)
62+
{
63+
if (s_default_loop == NULL) {
64+
return ESP_ERR_INVALID_STATE;
65+
}
66+
67+
return esp_event_isr_post_to(s_default_loop, event_base, event_id,
68+
event_data, event_data_size, task_unblocked);
69+
}
70+
#endif
71+
72+
73+
esp_err_t esp_event_loop_create_default()
74+
{
75+
if (s_default_loop) {
76+
return ESP_ERR_INVALID_STATE;
77+
}
78+
79+
esp_event_loop_args_t loop_args = {
80+
.queue_size = CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE,
81+
.task_name = "sys_evt",
82+
.task_stack_size = ESP_TASKD_EVENT_STACK,
83+
.task_priority = ESP_TASKD_EVENT_PRIO,
84+
.task_core_id = 0
85+
};
86+
87+
esp_err_t err;
88+
89+
err = esp_event_loop_create(&loop_args, &s_default_loop);
90+
if (err != ESP_OK) {
91+
return err;
92+
}
93+
94+
return ESP_OK;
95+
}
96+
97+
esp_err_t esp_event_loop_delete_default()
98+
{
99+
if (!s_default_loop) {
100+
return ESP_ERR_INVALID_STATE;
101+
}
102+
103+
esp_err_t err;
104+
105+
err = esp_event_loop_delete(s_default_loop);
106+
107+
if (err != ESP_OK) {
108+
return err;
109+
}
110+
111+
s_default_loop = NULL;
112+
113+
return ESP_OK;
114+
}
115+
116+
117+
/* Include the code to forward legacy system_event_t events to the this default
118+
* event loop.
119+
*/
120+
#include "event_send_compat.inc"

0 commit comments

Comments
 (0)