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 2005 Develer S.r.l. (http://www.develer.com/)
33 * \brief Events handling implementation
36 * \author Giovanni Bajo <rasky@develer.com>
41 #include "cfg/cfg_signal.h"
42 #include "cfg/cfg_timer.h"
44 #include <drv/timer.h> /* timer_clock() */
46 void event_hook_ignore(UNUSED_ARG(Event *, e))
50 #if CONFIG_KERN_SIGNALS
51 void event_hook_signal(Event *e)
53 sig_post((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit);
56 void event_hook_generic_signal(Event *e)
58 sig_postSignal(&e->Ev.SigGen.sig,
59 e->Ev.SigGen.sig_proc,
60 EVENT_GENERIC_SIGNAL);
64 void event_hook_softint(Event *e)
66 e->Ev.Int.func(e->Ev.Int.user_data);
69 void event_hook_generic(Event *e)
71 e->Ev.Gen.completed = true;
76 * Wait for multiple events
78 * On success return the offset in the \a evs vector of the Event that
79 * happened, -1 if the timeout expires.
81 * NOTE: timeout == 0 means no timeout.
83 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
84 int event_select(Event **evs, int n, ticks_t timeout)
86 sigmask_t mask = (1 << n) - 1;
89 ASSERT(n <= SIG_USER_MAX);
90 for (i = 0; i < n; i++)
93 /* Map each event to a distinct signal bit */
94 event_initSignal(e, proc_current(), 1 << i);
96 mask = timeout ? sig_waitTimeout(mask, timeout) : sig_wait(mask);
99 return i < n ? i : -1;
102 int event_select(Event **evs, int n, ticks_t timeout)
104 ticks_t end = timer_clock() + timeout;
109 for (i = 0; i < n; i++)
112 if (ACCESS_SAFE(e->Ev.Gen.completed) == true)
114 e->Ev.Gen.completed = false;
119 if (timeout && TIMER_AFTER(timer_clock(), end))