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.3 2004/06/06 18:25:44 bernie
22 * Rename event macros to look like regular functions.
24 * Revision 1.2 2004/06/03 11:27:09 bernie
25 * Add dual-license information.
27 * Revision 1.1 2004/05/23 17:27:00 bernie
28 * Import kern/ subdirectory.
37 #include "config_kern.h"
38 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
51 EVENT_IGNORE, /*!< No-op event */
52 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
53 EVENT_SIGNAL, /*!< Send a signal to a process */
55 EVENT_SOFTINT /*!< Trigger a software interrupt (i.e.: call user hook) */
58 //! User defined callback type
59 typedef void (*Hook)(void *);
63 enum EventAction action;
66 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
69 struct Process *sig_proc; /* Process to be signalled */
70 sig_t sig_bit; /* Signal to send */
75 Hook func; /* Pointer to softint hook */
76 void *user_data; /* Data to be passed back to user hook */
82 /*! Initialize the event \a e as a no-op */
83 #define event_initNone(e) \
84 ((e)->action = EVENT_IGNORE)
86 /*! Same as event_initNone(), but returns the initialized event */
87 INLINE Event event_createNone(void)
90 e.action = EVENT_IGNORE;
94 /*! Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
95 #define event_initSoftInt(e,f,u) \
96 ((e)->action = EVENT_SOFTINT,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
98 /*! Same as event_initSoftInt(), but returns the initialized event */
99 INLINE Event event_createSoftInt(Hook func, void* user_data)
102 e.action = EVENT_SOFTINT;
103 e.Ev.Int.func = func;
104 e.Ev.Int.user_data = user_data;
109 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
111 /*! Initialize the event \a e with a signal (send signal \a s to process \a p) */
112 #define event_initSignal(e,p,s) \
113 ((e)->action = EVENT_SIGNAL,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
115 /*! Same as event_initSignal(), but returns the initialized event */
116 INLINE Event event_createSignal(struct Process* proc, sig_t bit)
119 e.action = EVENT_SOFTINT;
120 e.Ev.Sig.sig_proc = proc;
121 e.Ev.Sig.sig_bit = bit;
125 /*! Trigger an event */
126 #define event_do(e) \
128 if ((e)->action == EVENT_SIGNAL) \
129 sig_signal((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit); \
130 else if ((e)->action == EVENT_SOFTINT) \
131 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
134 /*! Trigger an event (to be used inside interrupts) */
135 #define event_doIntr(e) \
137 if ((e)->action == EVENT_SIGNAL) \
138 _sig_signal((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit); \
139 else if ((e)->action == EVENT_SOFTINT) \
140 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
143 #else /* !CONFIG_KERN_SIGNALS */
145 /*! Trigger an event */
146 #define event_do(e) \
148 if ((e)->action == EVENT_SOFTINT) \
149 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
152 /*! Trigger an event (to be used inside interrupts) */
153 #define event_doIntr(e) \
155 if ((e)->action == EVENT_SOFTINT) \
156 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
161 #ifdef CONFIG_KERN_OLDNAMES
162 #define INITEVENT_SIG event_initSignal
163 #define INITEVENT_INT event_initSoftInt
164 #define DOEVENT event_do
165 #define DOEVENT_INTR event_doIntr
168 #endif /* KERN_EVENT_H */