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.2 2004/06/03 11:27:09 bernie
22 * Add dual-license information.
24 * Revision 1.1 2004/05/23 17:27:00 bernie
25 * Import kern/ subdirectory.
34 #include "config_kern.h"
35 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
48 EVENT_IGNORE, /*!< No-op event */
49 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
50 EVENT_SIGNAL, /*!< Send a signal to a process */
52 EVENT_SOFTINT /*!< Trigger a software interrupt (i.e.: call user hook) */
55 //! User defined callback type
56 typedef void (*Hook)(void *);
60 enum EventAction action;
63 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
66 struct Process *sig_proc; /* Process to be signalled */
67 sig_t sig_bit; /* Signal to send */
72 Hook func; /* Pointer to softint hook */
73 void *user_data; /* Data to be passed back to user hook */
79 /*! Initialize an event with a softint */
80 #define INITEVENT_INT(e,f,u) \
81 ((e)->action = EVENT_SOFTINT,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
84 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
86 /*! Initialize an event with a signal */
87 #define INITEVENT_SIG(e,p,s) \
88 ((e)->action = EVENT_SIGNAL,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
90 /*! Trigger an event */
93 if ((e)->action == EVENT_SIGNAL) \
94 sig_signal((e)->Ev.Sig.sig_proc, (e)->Sig.sig_bit); \
95 else if ((e)->action == EVENT_SOFTINT) \
96 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
99 /*! Trigger an event (to be used inside interrupts) */
100 #define DOEVENT_INTR(e) \
102 if ((e)->action == EVENT_SIGNAL) \
103 _sig_signal((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit); \
104 else if ((e)->action == EVENT_SOFTINT) \
105 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
108 #else /* !CONFIG_KERN_SIGNALS */
110 /*! Trigger an event */
113 if ((e)->action == EVENT_SOFTINT) \
114 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
117 /*! Trigger an event (to be used inside interrupts) */
118 #define DOEVENT_INTR(e) \
120 if ((e)->action == EVENT_SOFTINT) \
121 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
126 #endif /* KERN_EVENT_H */