4 * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999,2001,2003 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief Events handling
11 * This module implements a common system for executing
12 * a user defined action calling a hook function.
16 * \author Bernardo Innocenti <bernie@develer.com>
21 * Revision 1.4 2004/06/07 15:58:00 aleph
22 * Add function prototypes
24 * Revision 1.3 2004/06/06 18:25:44 bernie
25 * Rename event macros to look like regular functions.
27 * Revision 1.2 2004/06/03 11:27:09 bernie
28 * Add dual-license information.
30 * Revision 1.1 2004/05/23 17:27:00 bernie
31 * Import kern/ subdirectory.
40 #include "config_kern.h"
41 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
54 EVENT_IGNORE, /*!< No-op event */
55 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
56 EVENT_SIGNAL, /*!< Send a signal to a process */
58 EVENT_SOFTINT /*!< Trigger a software interrupt (i.e.: call user hook) */
61 //! User defined callback type
62 typedef void (*Hook)(void *);
66 enum EventAction action;
69 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
72 struct Process *sig_proc; /* Process to be signalled */
73 sig_t sig_bit; /* Signal to send */
78 Hook func; /* Pointer to softint hook */
79 void *user_data; /* Data to be passed back to user hook */
85 /*! Initialize the event \a e as a no-op */
86 #define event_initNone(e) \
87 ((e)->action = EVENT_IGNORE)
89 /*! Same as event_initNone(), but returns the initialized event */
90 INLINE Event event_createNone(void);
91 INLINE Event event_createNone(void)
94 e.action = EVENT_IGNORE;
98 /*! Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
99 #define event_initSoftInt(e,f,u) \
100 ((e)->action = EVENT_SOFTINT,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
102 /*! Same as event_initSoftInt(), but returns the initialized event */
103 INLINE Event event_createSoftInt(Hook func, void* user_data);
104 INLINE Event event_createSoftInt(Hook func, void* user_data)
107 e.action = EVENT_SOFTINT;
108 e.Ev.Int.func = func;
109 e.Ev.Int.user_data = user_data;
114 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
116 /*! Initialize the event \a e with a signal (send signal \a s to process \a p) */
117 #define event_initSignal(e,p,s) \
118 ((e)->action = EVENT_SIGNAL,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
120 /*! Same as event_initSignal(), but returns the initialized event */
121 INLINE Event event_createSignal(struct Process* proc, sig_t bit);
122 INLINE Event event_createSignal(struct Process* proc, sig_t bit)
125 e.action = EVENT_SOFTINT;
126 e.Ev.Sig.sig_proc = proc;
127 e.Ev.Sig.sig_bit = bit;
131 /*! Trigger an event */
132 #define event_do(e) \
134 if ((e)->action == EVENT_SIGNAL) \
135 sig_signal((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit); \
136 else if ((e)->action == EVENT_SOFTINT) \
137 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
140 /*! Trigger an event (to be used inside interrupts) */
141 #define event_doIntr(e) \
143 if ((e)->action == EVENT_SIGNAL) \
144 _sig_signal((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit); \
145 else if ((e)->action == EVENT_SOFTINT) \
146 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
149 #else /* !CONFIG_KERN_SIGNALS */
151 /*! Trigger an event */
152 #define event_do(e) \
154 if ((e)->action == EVENT_SOFTINT) \
155 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
158 /*! Trigger an event (to be used inside interrupts) */
159 #define event_doIntr(e) \
161 if ((e)->action == EVENT_SOFTINT) \
162 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
167 #ifdef CONFIG_KERN_OLDNAMES
168 #define INITEVENT_SIG event_initSignal
169 #define INITEVENT_INT event_initSoftInt
170 #define DOEVENT event_do
171 #define DOEVENT_INTR event_doIntr
174 #endif /* KERN_EVENT_H */