4 * Copyright 2003, 2004, 2005 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 README.devlib 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.7 2006/03/20 17:52:22 bernie
22 *#* Add missing forward declaration.
24 *#* Revision 1.6 2006/02/24 01:17:44 bernie
25 *#* Update for new emulator.
27 *#* Revision 1.5 2006/02/24 00:26:21 bernie
30 *#* Revision 1.4 2006/02/10 12:24:42 bernie
31 *#* Fix standalone build.
33 *#* Revision 1.3 2006/01/16 03:27:49 bernie
34 *#* Rename sig_t to sigbit_t to avoid clash with POSIX.
36 *#* Revision 1.2 2005/11/27 03:02:55 bernie
37 *#* Convert to appconfig.h.
39 *#* Revision 1.1 2005/11/27 01:39:48 bernie
40 *#* Move event.[ch] from kern/ to mware/.
42 *#* Revision 1.11 2005/04/11 19:10:28 bernie
43 *#* Include top-level headers from cfg/ subdir.
45 *#* Revision 1.10 2005/01/24 04:22:02 bernie
46 *#* Update copyright information.
48 *#* Revision 1.9 2005/01/24 04:19:55 bernie
49 *#* Remove obsolete names.
51 *#* Revision 1.8 2005/01/24 04:19:05 bernie
52 *#* Function pointer based event dispatching.
54 *#* Revision 1.7 2004/08/25 14:12:09 rasky
55 *#* Aggiornato il comment block dei log RCS
57 *#* Revision 1.6 2004/08/14 19:37:57 rasky
58 *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
60 *#* Revision 1.5 2004/07/30 14:30:27 rasky
61 *#* Resa la sig_signal interrupt safe (con il nuovo scheduler IRQ-safe)
62 *#* Rimossa event_doIntr (ora inutile) e semplificata la logica delle macro con funzioni inline
64 *#* Revision 1.4 2004/06/07 15:58:00 aleph
65 *#* Add function prototypes
67 *#* Revision 1.3 2004/06/06 18:25:44 bernie
68 *#* Rename event macros to look like regular functions.
70 *#* Revision 1.2 2004/06/03 11:27:09 bernie
71 *#* Add dual-license information.
73 *#* Revision 1.1 2004/05/23 17:27:00 bernie
74 *#* Import kern/ subdirectory.
80 #include <cfg/compiler.h>
81 #include <appconfig.h>
84 #include <config_kern.h>
85 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
86 #include <kern/signal.h>
94 //! User defined callback type
95 typedef void (*Hook)(void *);
99 void (*action)(struct Event *);
102 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
105 struct Process *sig_proc; /* Process to be signalled */
106 sigbit_t sig_bit; /* Signal to send */
111 Hook func; /* Pointer to softint hook */
112 void *user_data; /* Data to be passed back to user hook */
117 void event_hook_ignore(Event *event);
118 void event_hook_signal(Event *event);
119 void event_hook_softint(Event *event);
121 /*! Initialize the event \a e as a no-op */
122 #define event_initNone(e) \
123 ((e)->action = event_hook_ignore)
125 /*! Same as event_initNone(), but returns the initialized event */
126 INLINE Event event_createNone(void);
127 INLINE Event event_createNone(void)
130 e.action = event_hook_ignore;
134 /*! Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
135 #define event_initSoftInt(e,f,u) \
136 ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
138 /*! Same as event_initSoftInt(), but returns the initialized event */
139 INLINE Event event_createSoftInt(Hook func, void *user_data)
142 e.action = event_hook_softint;
143 e.Ev.Int.func = func;
144 e.Ev.Int.user_data = user_data;
149 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
151 /*! Initialize the event \a e with a signal (send signal \a s to process \a p) */
152 #define event_initSignal(e,p,s) \
153 ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
155 /*! Same as event_initSignal(), but returns the initialized event */
156 INLINE Event event_createSignal(struct Process *proc, sigbit_t bit)
159 e.action = event_hook_signal;
160 e.Ev.Sig.sig_proc = proc;
161 e.Ev.Sig.sig_bit = bit;
167 /*! Trigger an event */
168 INLINE void event_do(struct Event *e)
173 #endif /* KERN_EVENT_H */