diff options
Diffstat (limited to 'os/kernel/include/chevents.h')
-rw-r--r-- | os/kernel/include/chevents.h | 161 |
1 files changed, 99 insertions, 62 deletions
diff --git a/os/kernel/include/chevents.h b/os/kernel/include/chevents.h index 87996353b..2cedea7b9 100644 --- a/os/kernel/include/chevents.h +++ b/os/kernel/include/chevents.h @@ -34,6 +34,22 @@ #if CH_USE_EVENTS || defined(__DOXYGEN__)
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
typedef struct EventListener EventListener;
/**
@@ -66,6 +82,20 @@ typedef struct EventSource { */
typedef void (*evhandler_t)(eventid_t);
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
+
+/**
+ * @brief All events allowed mask.
+ */
+#define ALL_EVENTS ((eventmask_t)-1)
+
+/**
+ * @brief Returns an event mask from an event identifier.
+ */
+#define EVENT_MASK(eid) ((eventmask_t)(1 << (eid)))
+
/**
* @brief Data part of a static event source initializer.
* @details This macro should be used when statically initializing an event
@@ -83,20 +113,64 @@ typedef void (*evhandler_t)(eventid_t); */
#define EVENTSOURCE_DECL(name) EventSource name = _EVENTSOURCE_DATA(name)
-/**
- * @brief All events allowed mask.
- */
-#define ALL_EVENTS ((eventmask_t)-1)
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
-/**
- * @brief Returns an event mask from an event identifier.
- */
-#define EVENT_MASK(eid) ((eventmask_t)(1 << (eid)))
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void chEvtRegisterMask(EventSource *esp,
+ EventListener *elp,
+ eventmask_t mask);
+ void chEvtUnregister(EventSource *esp, EventListener *elp);
+ eventmask_t chEvtGetAndClearEvents(eventmask_t mask);
+ eventmask_t chEvtAddEvents(eventmask_t mask);
+ flagsmask_t chEvtGetAndClearFlags(EventListener *elp);
+ flagsmask_t chEvtGetAndClearFlagsI(EventListener *elp);
+ void chEvtSignal(thread_t *tp, eventmask_t mask);
+ void chEvtSignalI(thread_t *tp, eventmask_t mask);
+ void chEvtBroadcastFlags(EventSource *esp, flagsmask_t flags);
+ void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags);
+ void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask);
+#if CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT
+ eventmask_t chEvtWaitOne(eventmask_t mask);
+ eventmask_t chEvtWaitAny(eventmask_t mask);
+ eventmask_t chEvtWaitAll(eventmask_t mask);
+#endif
+#if CH_USE_EVENTS_TIMEOUT
+ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time);
+ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time);
+ eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#if !CH_OPTIMIZE_SPEED && CH_USE_EVENTS_TIMEOUT
+#define chEvtWaitOne(mask) chEvtWaitOneTimeout(mask, TIME_INFINITE)
+#define chEvtWaitAny(mask) chEvtWaitAnyTimeout(mask, TIME_INFINITE)
+#define chEvtWaitAll(mask) chEvtWaitAllTimeout(mask, TIME_INFINITE)
+#endif
+
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
/**
- * @name Macro Functions
- * @{
+ * @brief Initializes an Event Source.
+ * @note This function can be invoked before the kernel is initialized
+ * because it just prepares a @p EventSource structure.
+ *
+ * @param[in] esp pointer to the @p EventSource structure
+ *
+ * @init
*/
+static inline void chEvtInit(EventSource *esp) {
+
+ esp->es_next = (EventListener *)(void *)esp;
+}
+
/**
* @brief Registers an Event Listener on an Event Source.
* @note Multiple Event Listeners can use the same event identifier, the
@@ -112,20 +186,12 @@ typedef void (*evhandler_t)(eventid_t); *
* @api
*/
-#define chEvtRegister(esp, elp, eid) \
- chEvtRegisterMask(esp, elp, EVENT_MASK(eid))
+static inline void chEvtRegister(EventSource *esp,
+ EventListener *elp,
+ eventid_t eid) {
-/**
- * @brief Initializes an Event Source.
- * @note This function can be invoked before the kernel is initialized
- * because it just prepares a @p EventSource structure.
- *
- * @param[in] esp pointer to the @p EventSource structure
- *
- * @init
- */
-#define chEvtInit(esp) \
- ((esp)->es_next = (EventListener *)(void *)(esp))
+ chEvtRegisterMask(esp, elp, EVENT_MASK(eid));
+}
/**
* @brief Verifies if there is at least one @p EventListener registered.
@@ -134,8 +200,10 @@ typedef void (*evhandler_t)(eventid_t); *
* @iclass
*/
-#define chEvtIsListeningI(esp) \
- ((void *)(esp) != (void *)(esp)->es_next)
+static inline bool chEvtIsListeningI(EventSource *esp) {
+
+ return (bool)((void *)esp != (void *)esp->es_next);
+}
/**
* @brief Signals all the Event Listeners registered on the specified Event
@@ -145,7 +213,10 @@ typedef void (*evhandler_t)(eventid_t); *
* @api
*/
-#define chEvtBroadcast(esp) chEvtBroadcastFlags(esp, 0)
+static inline void chEvtBroadcast(EventSource *esp) {
+
+ chEvtBroadcastFlags(esp, 0);
+}
/**
* @brief Signals all the Event Listeners registered on the specified Event
@@ -159,44 +230,10 @@ typedef void (*evhandler_t)(eventid_t); *
* @iclass
*/
-#define chEvtBroadcastI(esp) chEvtBroadcastFlagsI(esp, 0)
-/** @} */
+static inline void chEvtBroadcastI(EventSource *esp) {
-#ifdef __cplusplus
-extern "C" {
-#endif
- void chEvtRegisterMask(EventSource *esp,
- EventListener *elp,
- eventmask_t mask);
- void chEvtUnregister(EventSource *esp, EventListener *elp);
- eventmask_t chEvtGetAndClearEvents(eventmask_t mask);
- eventmask_t chEvtAddEvents(eventmask_t mask);
- flagsmask_t chEvtGetAndClearFlags(EventListener *elp);
- flagsmask_t chEvtGetAndClearFlagsI(EventListener *elp);
- void chEvtSignal(thread_t *tp, eventmask_t mask);
- void chEvtSignalI(thread_t *tp, eventmask_t mask);
- void chEvtBroadcastFlags(EventSource *esp, flagsmask_t flags);
- void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags);
- void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask);
-#if CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT
- eventmask_t chEvtWaitOne(eventmask_t mask);
- eventmask_t chEvtWaitAny(eventmask_t mask);
- eventmask_t chEvtWaitAll(eventmask_t mask);
-#endif
-#if CH_USE_EVENTS_TIMEOUT
- eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time);
- eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time);
- eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time);
-#endif
-#ifdef __cplusplus
+ chEvtBroadcastFlagsI(esp, 0);
}
-#endif
-
-#if !CH_OPTIMIZE_SPEED && CH_USE_EVENTS_TIMEOUT
-#define chEvtWaitOne(mask) chEvtWaitOneTimeout(mask, TIME_INFINITE)
-#define chEvtWaitAny(mask) chEvtWaitAnyTimeout(mask, TIME_INFINITE)
-#define chEvtWaitAll(mask) chEvtWaitAllTimeout(mask, TIME_INFINITE)
-#endif
#endif /* CH_USE_EVENTS */
|