esp_event_internal.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /// Event handler
  20. typedef struct esp_event_handler_instance {
  21. esp_event_handler_t handler; /**< event handler function*/
  22. void* arg; /**< event handler argument */
  23. #ifdef CONFIG_EVENT_LOOP_PROFILING
  24. uint32_t total_times_invoked; /**< number of times this handler has been invoked */
  25. int64_t total_runtime; /**< total runtime of this handler across all calls */
  26. #endif
  27. SLIST_ENTRY(esp_event_handler_instance) handler_entry; /**< next event handler in the list */
  28. } esp_event_handler_instance_t;
  29. typedef SLIST_HEAD(esp_event_handler_instances, esp_event_handler_instance) esp_event_handler_instances_t;
  30. typedef struct esp_event_id_instance {
  31. int32_t id;
  32. esp_event_handler_instances_t handlers; /**< list of handlers to be executed when
  33. this event is raised */
  34. SLIST_ENTRY(esp_event_id_instance) event_id_entry; /**< pointer to the next event node on the linked list */
  35. #ifdef CONFIG_EVENT_LOOP_PROFILING
  36. uint32_t handlers_invoked; /**< total number of times the event has been
  37. raised and processed in the loop */
  38. int64_t handlers_runtime; /**< total time spent in executing handlers */
  39. #endif
  40. } esp_event_id_instance_t;
  41. typedef SLIST_HEAD(esp_event_id_instances, esp_event_id_instance) esp_event_id_instances_t;
  42. /// Event
  43. typedef struct esp_event_base_instance {
  44. esp_event_base_t base; /**< base identifier of the event */
  45. esp_event_handler_instances_t base_handlers; /**< event base level handlers, handlers for
  46. all events with this base */
  47. esp_event_id_instances_t event_ids; /**< list of event ids with this base */
  48. SLIST_ENTRY(esp_event_base_instance) event_base_entry; /**< pointer to the next event node on the linked list */
  49. #ifdef CONFIG_EVENT_LOOP_PROFILING
  50. uint32_t base_handlers_invoked; /**< total number of base-level handlers invoked */
  51. int64_t base_handlers_runtime; /**< amount of time processing base-level handlers */
  52. #endif
  53. } esp_event_base_instance_t;
  54. typedef SLIST_HEAD(esp_event_base_instances, esp_event_base_instance) esp_event_base_instances_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_handler_instances_t loop_handlers; /**< loop level handlers, handlers for all events
  64. registered in the loop */
  65. esp_event_base_instances_t event_bases; /**< events linked list head pointer */
  66. #ifdef CONFIG_EVENT_LOOP_PROFILING
  67. uint32_t events_recieved; /**< number of events successfully posted to the loop */
  68. uint32_t events_dropped; /**< number of events dropped due to queue being full */
  69. uint32_t loop_handlers_invoked; /**< total number of loop-level handlers invoked */
  70. int64_t loop_handlers_runtime; /**< amount of time processing loop-level handlers */
  71. uint32_t total_handlers_invoked; /**< total number of handlers invoked */
  72. int64_t total_handlers_runtime; /**< total amount of time dedicated to processing this loop */
  73. SLIST_ENTRY(esp_event_loop_instance) loop_entry; /**< next event loop in the list */
  74. SemaphoreHandle_t profiling_mutex;
  75. #endif
  76. } esp_event_loop_instance_t;
  77. /// Event posted to the event queue
  78. typedef struct esp_event_post_instance {
  79. esp_event_base_t base; /**< the event base */
  80. int32_t id; /**< the event id */
  81. void** data; /**< data associated with the event */
  82. } esp_event_post_instance_t;
  83. #ifdef __cplusplus
  84. } // extern "C"
  85. #endif
  86. #endif // #ifndef ESP_EVENT_INTERNAL_H_