4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 1999, 2001, 2003 Bernardo Innocenti <bernie@develer.com>
34 * \brief Events handling
36 * This module implements a common system for executing
37 * a user defined action calling a hook function.
41 * \author Bernardo Innocenti <bernie@develer.com>
46 *#* Revision 1.8 2006/07/19 12:56:27 bernie
47 *#* Convert to new Doxygen style.
49 *#* Revision 1.7 2006/03/20 17:52:22 bernie
50 *#* Add missing forward declaration.
52 *#* Revision 1.6 2006/02/24 01:17:44 bernie
53 *#* Update for new emulator.
55 *#* Revision 1.5 2006/02/24 00:26:21 bernie
58 *#* Revision 1.4 2006/02/10 12:24:42 bernie
59 *#* Fix standalone build.
61 *#* Revision 1.3 2006/01/16 03:27:49 bernie
62 *#* Rename sig_t to sigbit_t to avoid clash with POSIX.
64 *#* Revision 1.2 2005/11/27 03:02:55 bernie
65 *#* Convert to appconfig.h.
67 *#* Revision 1.1 2005/11/27 01:39:48 bernie
68 *#* Move event.[ch] from kern/ to mware/.
70 *#* Revision 1.11 2005/04/11 19:10:28 bernie
71 *#* Include top-level headers from cfg/ subdir.
73 *#* Revision 1.10 2005/01/24 04:22:02 bernie
74 *#* Update copyright information.
76 *#* Revision 1.9 2005/01/24 04:19:55 bernie
77 *#* Remove obsolete names.
79 *#* Revision 1.8 2005/01/24 04:19:05 bernie
80 *#* Function pointer based event dispatching.
82 *#* Revision 1.7 2004/08/25 14:12:09 rasky
83 *#* Aggiornato il comment block dei log RCS
85 *#* Revision 1.6 2004/08/14 19:37:57 rasky
86 *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
88 *#* Revision 1.5 2004/07/30 14:30:27 rasky
89 *#* Resa la sig_signal interrupt safe (con il nuovo scheduler IRQ-safe)
90 *#* Rimossa event_doIntr (ora inutile) e semplificata la logica delle macro con funzioni inline
92 *#* Revision 1.4 2004/06/07 15:58:00 aleph
93 *#* Add function prototypes
95 *#* Revision 1.3 2004/06/06 18:25:44 bernie
96 *#* Rename event macros to look like regular functions.
98 *#* Revision 1.2 2004/06/03 11:27:09 bernie
99 *#* Add dual-license information.
101 *#* Revision 1.1 2004/05/23 17:27:00 bernie
102 *#* Import kern/ subdirectory.
108 #include <cfg/compiler.h>
109 #include <appconfig.h>
112 #include <config_kern.h>
113 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
114 #include <kern/signal.h>
122 /// User defined callback type
123 typedef void (*Hook)(void *);
127 void (*action)(struct Event *);
130 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
133 struct Process *sig_proc; /* Process to be signalled */
134 sigbit_t sig_bit; /* Signal to send */
139 Hook func; /* Pointer to softint hook */
140 void *user_data; /* Data to be passed back to user hook */
145 void event_hook_ignore(Event *event);
146 void event_hook_signal(Event *event);
147 void event_hook_softint(Event *event);
149 /** Initialize the event \a e as a no-op */
150 #define event_initNone(e) \
151 ((e)->action = event_hook_ignore)
153 /** Same as event_initNone(), but returns the initialized event */
154 INLINE Event event_createNone(void);
155 INLINE Event event_createNone(void)
158 e.action = event_hook_ignore;
162 /** Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
163 #define event_initSoftInt(e,f,u) \
164 ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
166 /** Same as event_initSoftInt(), but returns the initialized event */
167 INLINE Event event_createSoftInt(Hook func, void *user_data)
170 e.action = event_hook_softint;
171 e.Ev.Int.func = func;
172 e.Ev.Int.user_data = user_data;
177 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
179 /** Initialize the event \a e with a signal (send signal \a s to process \a p) */
180 #define event_initSignal(e,p,s) \
181 ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
183 /** Same as event_initSignal(), but returns the initialized event */
184 INLINE Event event_createSignal(struct Process *proc, sigbit_t bit)
187 e.action = event_hook_signal;
188 e.Ev.Sig.sig_proc = proc;
189 e.Ev.Sig.sig_bit = bit;
195 /** Trigger an event */
196 INLINE void event_do(struct Event *e)
201 #endif /* KERN_EVENT_H */