From 87d83b1b7e37925f3e32e79e6e6baedb5b13f192 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 9 Nov 2008 09:31:17 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@504 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chevents.c | 24 +++++++++--------------- src/include/events.h | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/chevents.c b/src/chevents.c index 8aab8ca5c..ce2254ab4 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -28,21 +28,18 @@ * Registers an Event Listener on an Event Source. * @param esp pointer to the \p EventSource structure * @param elp pointer to the \p EventListener structure - * @param eid numeric identifier assigned to the Event Listener. The identifier - * is used as index for the event callback function. - * The value must range between zero and the size, in bit, of the - * \p eventid_t type minus one. - * @note Multiple Event Listeners can use the same event identifier, the - * listener will share the callback function. + * @param emask the mask of event flags to be pended to the thread when the + * event source is broadcasted + * @note Multiple Event Listeners can specify the same bits to be pended. */ -void chEvtRegister(EventSource *esp, EventListener *elp, eventid_t eid) { +void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t emask) { chSysLock(); elp->el_next = esp->es_next; esp->es_next = elp; elp->el_listener = currp; - elp->el_id = eid; + elp->el_mask = emask; chSysUnlock(); } @@ -132,14 +129,11 @@ void chEvtBroadcastI(EventSource *esp) { while (elp != (EventListener *)esp) { Thread *tp = elp->el_listener; - tp->p_epending |= EventMask(elp->el_id); + tp->p_epending |= elp->el_mask; /* Test on the AND/OR conditions wait states.*/ - if ((tp->p_state == PRWTOREVT) && - ((tp->p_epending & tp->p_ewmask) != 0)) - chSchReadyI(tp)->p_rdymsg = RDY_OK; - else if ((tp->p_state == PRWTANDEVT) && - ((tp->p_epending & tp->p_ewmask) == tp->p_ewmask)) + if (((tp->p_state == PRWTOREVT) && ((tp->p_epending & tp->p_ewmask) != 0)) || + ((tp->p_state == PRWTANDEVT) && ((tp->p_epending & tp->p_ewmask) == tp->p_ewmask))) chSchReadyI(tp)->p_rdymsg = RDY_OK; elp = elp->el_next; @@ -234,7 +228,7 @@ eventmask_t chEvtWaitAll(eventmask_t ewmask) { if ((currp->p_epending & ewmask) != ewmask) { currp->p_ewmask = ewmask; - chSchGoSleepS(PRWTOREVT); + chSchGoSleepS(PRWTANDEVT); } currp->p_epending &= ~ewmask; diff --git a/src/include/events.h b/src/include/events.h index 6a6b9e41e..ae5d8c740 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -40,8 +40,8 @@ struct EventListener { EventListener *el_next; /** Thread interested in the Event Source.*/ Thread *el_listener; - /** Event identifier associated by the thread to the Event Source.*/ - eventid_t el_id; + /** Event flags mask associated by the thread to the Event Source.*/ + eventmask_t el_mask; }; /** @@ -70,7 +70,7 @@ typedef struct EventSource { * @note Can be called with interrupts disabled or enabled. */ #define chEvtIsListening(esp) \ - ((esp) != (EventListener *)(void *)(esp)->es_next) + ((void *)(esp) != (void *)(esp)->es_next) /** Event Handler callback function.*/ @@ -79,7 +79,7 @@ typedef void (*evhandler_t)(eventid_t); #ifdef __cplusplus extern "C" { #endif - void chEvtRegister(EventSource *esp, EventListener *elp, eventid_t eid); + void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t emask); void chEvtUnregister(EventSource *esp, EventListener *elp); eventmask_t chEvtClear(eventmask_t mask); eventmask_t chEvtPend(eventmask_t mask); @@ -104,6 +104,19 @@ extern "C" { } #endif +/** + * Registers an Event Listener on an Event Source. + * @param esp pointer to the \p EventSource structure + * @param elp pointer to the \p EventListener structure + * @param eid numeric identifier assigned to the Event Listener. The identifier + * is used as index for the event callback function. + * The value must range between zero and the size, in bit, of the + * \p eventid_t type minus one. + * @note Multiple Event Listeners can use the same event identifier, the + * listener will share the callback function. + */ +#define chEvtRegister(esp, elp, eid) chEvtRegisterMask(esp, elp, EventMask(eid)) + #if !defined(CH_OPTIMIZE_SPEED) && defined(CH_USE_EVENT_TIMEOUT) #define chEvtWaitOne(ewmask) chEvtWaitOneTimeout(ewmask, TIME_INFINITE) #define chEvtWaitAny(ewmask) chEvtWaitAnyTimeout(ewmask, TIME_INFINITE) -- cgit v1.2.3