1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef PLATFORM_EVENT_H 10 #define PLATFORM_EVENT_H 11 12 #include "hdf_base.h" 13 #include "hdf_dlist.h" 14 #include "osal_sem.h" 15 #include "osal_spinlock.h" 16 #include "osal_thread.h" 17 18 #ifdef __cplusplus 19 #if __cplusplus 20 extern "C" { 21 #endif 22 #endif /* __cplusplus */ 23 24 struct PlatformEvent { 25 OsalSpinlock spin; 26 struct OsalSem sem; 27 struct DListHead waiters; 28 int32_t waiterCnt; 29 uint32_t irqSave; 30 uint32_t eventsWord; 31 }; 32 33 enum PlatformEventType { 34 PLAT_EVENT_DEVICE_DEAD = (0x1 << 0), 35 PLAT_EVENT_RMSG_PENDING = (0x1 << 1), 36 PLAT_EVENT_WMSG_PENDING = (0x1 << 2), 37 }; 38 39 enum PlatformEventMode { 40 PLAT_EVENT_MODE_AND = 0x1 << 1, 41 PLAT_EVENT_MODE_CLEAR = 0x1 << 2, 42 PLAT_EVENT_MODE_ASYNC = 0x1 << 3, 43 }; 44 45 struct PlatformEventListener { 46 /** Private data passed to the callback function. */ 47 void *data; 48 /** Mask bits for the interested events */ 49 uint32_t mask; 50 /** The call back function for target events. */ 51 int32_t (*cb)(struct PlatformEventListener *listener, uint32_t events); 52 }; 53 54 /** 55 * @brief Initialize a platform event instance. 56 * 57 * @param pe Indicates the pointer to the the platform event instance 58 * 59 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 60 * 61 * @since 1.0 62 */ 63 int32_t PlatformEventInit(struct PlatformEvent *pe); 64 65 /** 66 * @brief Uninitialize a platform event instance. 67 * 68 * @param pe Indicates the pointer to the the platform event instance 69 * 70 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 71 * 72 * @since 1.0 73 */ 74 int32_t PlatformEventUninit(struct PlatformEvent *pe); 75 76 /** 77 * @brief Write the events to a platform event instance. 78 * 79 * @param pe Indicates the pointer to the the platform event instance 80 * @param events The events to write. 81 * 82 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 83 * 84 * @since 1.0 85 */ 86 int32_t PlatformEventPost(struct PlatformEvent *pe, uint32_t events); 87 88 /** 89 * @brief Listen for CAN bus events. 90 * 91 * @param pe Indicates the pointer to the the platform event instance 92 * @param mask Mask bits of the interested events. 93 * @param mode Platorm event mode for this listening. 94 * @param events Pointer for receiving the events. 95 * 96 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 97 * 98 * @since 1.0 99 */ 100 int32_t PlatformEventWait(struct PlatformEvent *pe, uint32_t mask, int32_t mode, uint32_t tms, uint32_t *events); 101 102 /** 103 * @brief Listen to a platform event instance. 104 * 105 * @param pe Indicates the pointer to the the platform event instance 106 * @param listener The pointer to the listener. 107 * 108 * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise. 109 * 110 * @since 1.0 111 */ 112 int32_t PlatformEventListen(struct PlatformEvent *pe, const struct PlatformEventListener *listener); 113 114 /** 115 * @brief Unlisten to a platform event instance. 116 * 117 * @param pe Indicates the pointer to the the platform event instance 118 * @param listener The pointer to the listener. 119 * 120 * @since 1.0 121 */ 122 void PlatformEventUnlisten(struct PlatformEvent *pe, const struct PlatformEventListener *listener); 123 124 #ifdef __cplusplus 125 #if __cplusplus 126 } 127 #endif 128 #endif /* __cplusplus */ 129 130 #endif /* PLATFORM_EVENT_H */ 131