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 Bernie Innocenti <bernie@codewiz.org>
33 * \brief Events handling
35 * This module implements a common system for executing
36 * a user defined action calling a hook function.
39 * \author Bernie Innocenti <bernie@codewiz.org>
45 #include <cfg/compiler.h>
46 #include "cfg/cfg_proc.h"
47 #include "cfg/cfg_signal.h"
50 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
51 #include <kern/signal.h>
59 /// User defined callback type
60 typedef void (*Hook)(void *);
64 void (*action)(struct Event *);
67 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
70 struct Process *sig_proc; /* Process to be signalled */
71 sigbit_t sig_bit; /* Signal to send */
76 Hook func; /* Pointer to softint hook */
77 void *user_data; /* Data to be passed back to user hook */
82 void event_hook_ignore(Event *event);
83 void event_hook_signal(Event *event);
84 void event_hook_softint(Event *event);
86 /** Initialize the event \a e as a no-op */
87 #define event_initNone(e) \
88 ((e)->action = event_hook_ignore)
90 /** Same as event_initNone(), but returns the initialized event */
91 INLINE Event event_createNone(void);
92 INLINE Event event_createNone(void)
95 e.action = event_hook_ignore;
99 /** Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
100 #define event_initSoftint(e,f,u) \
101 ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
103 /** Same as event_initSoftint(), but returns the initialized event */
104 INLINE Event event_createSoftint(Hook func, void *user_data)
107 e.action = event_hook_softint;
108 e.Ev.Int.func = func;
109 e.Ev.Int.user_data = user_data;
113 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
115 /** Initialize the event \a e with a signal (send signal \a s to process \a p) */
116 #define event_initSignal(e,p,s) \
117 ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
119 /** Same as event_initSignal(), but returns the initialized event */
120 INLINE Event event_createSignal(struct Process *proc, sigbit_t bit)
123 e.action = event_hook_signal;
124 e.Ev.Sig.sig_proc = proc;
125 e.Ev.Sig.sig_bit = bit;
131 /** Trigger an event */
132 INLINE void event_do(struct Event *e)
137 #endif /* KERN_EVENT_H */