1 // Copyright (C) 2022 Beken Corporation 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 #pragma once 16 17 #include <os/os.h> 18 #include "bk_list.h" 19 #include <components/event.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define EVENT_TAG "event" 26 #define EVENT_LOGI(...) BK_LOGI(EVENT_TAG, ##__VA_ARGS__) 27 #define EVENT_LOGW(...) BK_LOGW(EVENT_TAG, ##__VA_ARGS__) 28 #define EVENT_LOGE(...) BK_LOGE(EVENT_TAG, ##__VA_ARGS__) 29 30 #define EVENT_DEBUG 0 31 #if EVENT_DEBUG 32 #define EVENT_LOGD(...) BK_LOGI(EVENT_TAG, ##__VA_ARGS__) 33 #else 34 #define EVENT_LOGD(...) BK_LOGD(EVENT_TAG, ##__VA_ARGS__) 35 #endif 36 37 #ifndef CFG_EVENT_TASK_PRIORITY 38 #define EVENT_TASK_PRIORITY 10 39 #else 40 #define EVENT_TASK_PRIORITY CFG_EVENT_TASK_PRIORITY 41 #endif 42 43 #ifndef CFG_EVENT_TASK_STACK_SIZE 44 #define EVENT_TASK_STACK_SIZE 2048 45 #else 46 #define EVENT_TASK_STACK_SIZE CFG_EVENT_TASK_STACK_SIZE 47 #endif 48 49 #define EVENT_QUEUE_SIZE 16 50 51 typedef struct { 52 event_module_t event_module_id; 53 struct list_head next; 54 struct list_head event_node_list; 55 struct list_head cb_list; 56 } event_module_node_t; 57 58 typedef struct { 59 int event_id; 60 struct list_head next; 61 struct list_head cb_list; 62 } event_node_t; 63 64 typedef struct { 65 event_cb_t event_cb; 66 void *event_cb_arg; 67 struct list_head next; 68 } event_cb_node_t; 69 70 typedef struct { 71 event_module_t event_module_id; 72 int event_id; 73 void *event_data; 74 } event_info_t; 75 76 typedef struct { 77 event_module_t event_module_id; 78 int event_id; 79 event_cb_t event_cb; 80 void *event_cb_arg; 81 } event_register_info_t; 82 83 enum { 84 EVENT_MSG_REGISTER = 0, 85 EVENT_MSG_UNREGISTER, 86 EVENT_MSG_DEINIT, 87 EVENT_MSG_POST, 88 #if EVENT_DEBUG 89 EVENT_MSG_DUMP, 90 #endif 91 EVENT_MSG_COUNT, 92 }; 93 94 typedef struct { 95 int msg_type; 96 int sync_msg_ret; 97 beken_semaphore_t sync_msg_sem; 98 bool is_sync_msg; 99 union { 100 event_info_t event_info; 101 event_register_info_t register_info; 102 } msg; 103 } event_msg_t; 104 105 #ifdef __cplusplus 106 } 107 #endif 108