esp_event_internal.h 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef ESP_EVENT_INTERNAL_H_
  14. #define ESP_EVENT_INTERNAL_H_
  15. #include "esp_event.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. typedef SLIST_HEAD(base_nodes, base_node) base_nodes_t;
  20. /// Event handler
  21. typedef struct esp_event_handler_instance {
  22. esp_event_handler_t handler; /**< event handler function*/
  23. void* arg; /**< event handler argument */
  24. #ifdef CONFIG_EVENT_LOOP_PROFILING
  25. uint32_t invoked; /**< number of times this handler has been invoked */
  26. int64_t time; /**< total runtime of this handler across all calls */
  27. #endif
  28. SLIST_ENTRY(esp_event_handler_instance) next; /**< next event handler in the list */
  29. } esp_event_handler_instance_t;
  30. typedef SLIST_HEAD(esp_event_handler_instances, esp_event_handler_instance) esp_event_handler_instances_t;
  31. /// Event
  32. typedef struct esp_event_id_node {
  33. int32_t id; /**< id number of the event */
  34. esp_event_handler_instances_t handlers; /**< list of handlers to be executed when
  35. this event is raised */
  36. SLIST_ENTRY(esp_event_id_node) next; /**< pointer to the next event node on the linked list */
  37. } esp_event_id_node_t;
  38. typedef SLIST_HEAD(esp_event_id_nodes, esp_event_id_node) esp_event_id_nodes_t;
  39. typedef struct esp_event_base_node {
  40. esp_event_base_t base; /**< base identifier of the event */
  41. esp_event_handler_instances_t handlers; /**< event base level handlers, handlers for
  42. all events with this base */
  43. esp_event_id_nodes_t id_nodes; /**< list of event ids with this base */
  44. SLIST_ENTRY(esp_event_base_node) next; /**< pointer to the next base node on the linked list */
  45. } esp_event_base_node_t;
  46. typedef SLIST_HEAD(esp_event_base_nodes, esp_event_base_node) esp_event_base_nodes_t;
  47. typedef struct esp_event_loop_node {
  48. esp_event_handler_instances_t handlers; /** event loop level handlers */
  49. esp_event_base_nodes_t base_nodes; /** list of event bases registered to the loop */
  50. SLIST_ENTRY(esp_event_loop_node) next; /** pointer to the next loop node containing
  51. event loop level handlers and the rest of
  52. event bases registered to the loop */
  53. } esp_event_loop_node_t;
  54. typedef SLIST_HEAD(esp_event_loop_nodes, esp_event_loop_node) esp_event_loop_nodes_t;
  55. /// Event loop
  56. typedef struct esp_event_loop_instance {
  57. const char* name; /**< name of this event loop */
  58. QueueHandle_t queue; /**< event queue */
  59. TaskHandle_t task; /**< task that consumes the event queue */
  60. TaskHandle_t running_task; /**< for loops with no dedicated task, the
  61. task that consumes the queue */
  62. SemaphoreHandle_t mutex; /**< mutex for updating the events linked list */
  63. esp_event_loop_nodes_t loop_nodes; /**< set of linked lists containing the
  64. registered handlers for the loop */
  65. #ifdef CONFIG_EVENT_LOOP_PROFILING
  66. uint32_t events_recieved; /**< number of events successfully posted to the loop */
  67. uint32_t events_dropped; /**< number of events dropped due to queue being full */
  68. SemaphoreHandle_t profiling_mutex; /**< mutex used for profiliing */
  69. SLIST_ENTRY(esp_event_loop_instance) next; /**< next event loop in the list */
  70. #endif
  71. } esp_event_loop_instance_t;
  72. /// Event posted to the event queue
  73. typedef struct esp_event_post_instance {
  74. esp_event_base_t base; /**< the event base */
  75. int32_t id; /**< the event id */
  76. void* data; /**< data associated with the event */
  77. } esp_event_post_instance_t;
  78. #ifdef __cplusplus
  79. } // extern "C"
  80. #endif
  81. #endif // #ifndef ESP_EVENT_INTERNAL_H_