2018-10-26 05:14:19 +00:00
|
|
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef ESP_EVENT_INTERNAL_H_
|
|
|
|
#define ESP_EVENT_INTERNAL_H_
|
|
|
|
|
|
|
|
#include "esp_event.h"
|
2019-02-15 13:28:24 +00:00
|
|
|
#include "stdatomic.h"
|
2018-10-26 05:14:19 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-12-10 00:37:46 +00:00
|
|
|
typedef SLIST_HEAD(base_nodes, base_node) base_nodes_t;
|
|
|
|
|
2020-01-17 04:37:41 +00:00
|
|
|
typedef struct esp_event_handler_context {
|
2018-10-26 05:14:19 +00:00
|
|
|
esp_event_handler_t handler; /**< event handler function*/
|
2020-01-17 04:37:41 +00:00
|
|
|
void* arg;
|
|
|
|
} esp_event_handler_instance_context_t; /**< event handler argument */
|
|
|
|
|
|
|
|
/// Event handler
|
|
|
|
typedef struct esp_event_handler_node {
|
|
|
|
esp_event_handler_instance_context_t* handler_ctx; /**< event handler context*/
|
2019-04-29 10:54:02 +00:00
|
|
|
#ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
|
2018-12-10 00:37:46 +00:00
|
|
|
uint32_t invoked; /**< number of times this handler has been invoked */
|
|
|
|
int64_t time; /**< total runtime of this handler across all calls */
|
2018-10-26 05:14:19 +00:00
|
|
|
#endif
|
2020-01-17 04:37:41 +00:00
|
|
|
SLIST_ENTRY(esp_event_handler_node) next; /**< next event handler in the list */
|
|
|
|
} esp_event_handler_node_t;
|
2018-10-26 05:14:19 +00:00
|
|
|
|
2020-01-17 04:37:41 +00:00
|
|
|
typedef SLIST_HEAD(esp_event_handler_instances, esp_event_handler_node) esp_event_handler_nodes_t;
|
2018-10-26 05:14:19 +00:00
|
|
|
|
2018-12-10 00:37:46 +00:00
|
|
|
/// Event
|
|
|
|
typedef struct esp_event_id_node {
|
|
|
|
int32_t id; /**< id number of the event */
|
2020-01-17 04:37:41 +00:00
|
|
|
esp_event_handler_nodes_t handlers; /**< list of handlers to be executed when
|
2018-10-26 05:14:19 +00:00
|
|
|
this event is raised */
|
2018-12-10 00:37:46 +00:00
|
|
|
SLIST_ENTRY(esp_event_id_node) next; /**< pointer to the next event node on the linked list */
|
|
|
|
} esp_event_id_node_t;
|
2018-10-26 05:14:19 +00:00
|
|
|
|
2018-12-10 00:37:46 +00:00
|
|
|
typedef SLIST_HEAD(esp_event_id_nodes, esp_event_id_node) esp_event_id_nodes_t;
|
2018-10-26 05:14:19 +00:00
|
|
|
|
2018-12-10 00:37:46 +00:00
|
|
|
typedef struct esp_event_base_node {
|
2018-10-26 05:14:19 +00:00
|
|
|
esp_event_base_t base; /**< base identifier of the event */
|
2020-01-17 04:37:41 +00:00
|
|
|
esp_event_handler_nodes_t handlers; /**< event base level handlers, handlers for
|
2018-10-26 05:14:19 +00:00
|
|
|
all events with this base */
|
2018-12-10 00:37:46 +00:00
|
|
|
esp_event_id_nodes_t id_nodes; /**< list of event ids with this base */
|
|
|
|
SLIST_ENTRY(esp_event_base_node) next; /**< pointer to the next base node on the linked list */
|
|
|
|
} esp_event_base_node_t;
|
|
|
|
|
|
|
|
typedef SLIST_HEAD(esp_event_base_nodes, esp_event_base_node) esp_event_base_nodes_t;
|
|
|
|
|
|
|
|
typedef struct esp_event_loop_node {
|
2020-01-17 04:37:41 +00:00
|
|
|
esp_event_handler_nodes_t handlers; /** event loop level handlers */
|
2018-12-10 00:37:46 +00:00
|
|
|
esp_event_base_nodes_t base_nodes; /** list of event bases registered to the loop */
|
|
|
|
SLIST_ENTRY(esp_event_loop_node) next; /** pointer to the next loop node containing
|
|
|
|
event loop level handlers and the rest of
|
|
|
|
event bases registered to the loop */
|
|
|
|
} esp_event_loop_node_t;
|
2018-10-26 05:14:19 +00:00
|
|
|
|
2018-12-10 00:37:46 +00:00
|
|
|
typedef SLIST_HEAD(esp_event_loop_nodes, esp_event_loop_node) esp_event_loop_nodes_t;
|
2018-10-26 05:14:19 +00:00
|
|
|
|
|
|
|
/// Event loop
|
|
|
|
typedef struct esp_event_loop_instance {
|
|
|
|
const char* name; /**< name of this event loop */
|
|
|
|
QueueHandle_t queue; /**< event queue */
|
|
|
|
TaskHandle_t task; /**< task that consumes the event queue */
|
2018-12-10 00:37:46 +00:00
|
|
|
TaskHandle_t running_task; /**< for loops with no dedicated task, the
|
2018-10-26 05:14:19 +00:00
|
|
|
task that consumes the queue */
|
|
|
|
SemaphoreHandle_t mutex; /**< mutex for updating the events linked list */
|
2018-12-10 00:37:46 +00:00
|
|
|
esp_event_loop_nodes_t loop_nodes; /**< set of linked lists containing the
|
|
|
|
registered handlers for the loop */
|
2019-04-29 10:54:02 +00:00
|
|
|
#ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
|
2019-02-15 13:28:24 +00:00
|
|
|
atomic_uint_least32_t events_recieved; /**< number of events successfully posted to the loop */
|
|
|
|
atomic_uint_least32_t events_dropped; /**< number of events dropped due to queue being full */
|
2018-12-10 00:37:46 +00:00
|
|
|
SemaphoreHandle_t profiling_mutex; /**< mutex used for profiliing */
|
|
|
|
SLIST_ENTRY(esp_event_loop_instance) next; /**< next event loop in the list */
|
2018-10-26 05:14:19 +00:00
|
|
|
#endif
|
|
|
|
} esp_event_loop_instance_t;
|
|
|
|
|
2019-04-29 10:54:02 +00:00
|
|
|
#if CONFIG_ESP_EVENT_POST_FROM_ISR
|
2019-02-15 13:28:24 +00:00
|
|
|
typedef union esp_event_post_data {
|
|
|
|
uint32_t val;
|
|
|
|
void *ptr;
|
|
|
|
} esp_event_post_data_t;
|
|
|
|
#else
|
|
|
|
typedef void* esp_event_post_data_t;
|
|
|
|
#endif
|
|
|
|
|
2018-10-26 05:14:19 +00:00
|
|
|
/// Event posted to the event queue
|
|
|
|
typedef struct esp_event_post_instance {
|
2019-04-29 10:54:02 +00:00
|
|
|
#if CONFIG_ESP_EVENT_POST_FROM_ISR
|
2019-05-16 03:51:57 +00:00
|
|
|
bool data_allocated; /**< indicates whether data is allocated from heap */
|
|
|
|
bool data_set; /**< indicates if data is null */
|
2019-02-15 13:28:24 +00:00
|
|
|
#endif
|
2018-10-26 05:14:19 +00:00
|
|
|
esp_event_base_t base; /**< the event base */
|
|
|
|
int32_t id; /**< the event id */
|
2019-02-15 13:28:24 +00:00
|
|
|
esp_event_post_data_t data; /**< data associated with the event */
|
2018-10-26 05:14:19 +00:00
|
|
|
} esp_event_post_instance_t;
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2019-04-29 10:54:02 +00:00
|
|
|
#endif // #ifndef ESP_EVENT_INTERNAL_H_
|