From 5b39691e9eaa4f03b14794b824487f324aea7ca2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Sep 2012 08:31:38 +0000 Subject: Kernel events improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4667 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chevents.h | 9 ++++-- os/kernel/src/chevents.c | 75 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 16 deletions(-) (limited to 'os/kernel') diff --git a/os/kernel/include/chevents.h b/os/kernel/include/chevents.h index d4ac87ef3..7550ca2b7 100644 --- a/os/kernel/include/chevents.h +++ b/os/kernel/include/chevents.h @@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* + Concepts and parts of this file have been contributed by Scott (skute). + */ /** * @file chevents.h @@ -45,6 +48,8 @@ struct EventListener { eventmask_t el_mask; /**< @brief Event flags mask associated by the thread to the Event Source. */ + flagsmask_t el_flags; /**< @brief Flags added to the listener + bu the event source.*/ }; /** @@ -166,8 +171,8 @@ extern "C" { void chEvtUnregister(EventSource *esp, EventListener *elp); eventmask_t chEvtClearFlags(eventmask_t mask); eventmask_t chEvtAddFlags(eventmask_t mask); - void chEvtSignalFlags(Thread *tp, eventmask_t mask); - void chEvtSignalFlagsI(Thread *tp, eventmask_t mask); + void chEvtSignal(Thread *tp, eventmask_t mask); + void chEvtSignalI(Thread *tp, eventmask_t mask); void chEvtBroadcastFlags(EventSource *esp, eventmask_t mask); void chEvtBroadcastFlagsI(EventSource *esp, eventmask_t mask); void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask); diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index 2b3247543..3518b6975 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* + Concepts and parts of this file have been contributed by Scott (skute). + */ /** * @file chevents.c @@ -77,10 +80,11 @@ void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t mask) { chDbgCheck((esp != NULL) && (elp != NULL), "chEvtRegisterMask"); chSysLock(); - elp->el_next = esp->es_next; - esp->es_next = elp; + elp->el_next = esp->es_next; + esp->es_next = elp; elp->el_listener = currp; - elp->el_mask = mask; + elp->el_mask = mask; + elp->el_flags = 0; chSysUnlock(); } @@ -154,25 +158,25 @@ eventmask_t chEvtAddFlags(eventmask_t mask) { } /** - * @brief Adds (OR) a set of event flags on the specified @p Thread. + * @brief Adds a set of event flags directly to specified @p Thread. * * @param[in] tp the thread to be signaled * @param[in] mask the event flags set to be ORed * * @api */ -void chEvtSignalFlags(Thread *tp, eventmask_t mask) { +void chEvtSignal(Thread *tp, eventmask_t mask) { chDbgCheck(tp != NULL, "chEvtSignal"); chSysLock(); - chEvtSignalFlagsI(tp, mask); + chEvtSignalI(tp, mask); chSchRescheduleS(); chSysUnlock(); } /** - * @brief Adds (OR) a set of event flags on the specified @p Thread. + * @brief Adds a set of event flags directly to specified @p Thread. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit @@ -183,7 +187,7 @@ void chEvtSignalFlags(Thread *tp, eventmask_t mask) { * * @iclass */ -void chEvtSignalFlagsI(Thread *tp, eventmask_t mask) { +void chEvtSignalI(Thread *tp, eventmask_t mask) { chDbgCheckClassI(); chDbgCheck(tp != NULL, "chEvtSignalI"); @@ -206,14 +210,14 @@ void chEvtSignalFlagsI(Thread *tp, eventmask_t mask) { * @p EventListener objects. * * @param[in] esp pointer to the @p EventSource structure - * @param[in] mask the event flags set to be ORed + * @param[in] flags the flags set to be added to the listener flags mask * * @api */ -void chEvtBroadcastFlags(EventSource *esp, eventmask_t mask) { +void chEvtBroadcastFlags(EventSource *esp, flagsmask_t flags) { chSysLock(); - chEvtBroadcastFlagsI(esp, mask); + chEvtBroadcastFlagsI(esp, flags); chSchRescheduleS(); chSysUnlock(); } @@ -231,11 +235,11 @@ void chEvtBroadcastFlags(EventSource *esp, eventmask_t mask) { * reschedule must not be performed in ISRs. * * @param[in] esp pointer to the @p EventSource structure - * @param[in] mask the event flags set to be ORed + * @param[in] flags the flags set to be added to the listener flags mask * * @iclass */ -void chEvtBroadcastFlagsI(EventSource *esp, eventmask_t mask) { +void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags) { EventListener *elp; chDbgCheckClassI(); @@ -243,11 +247,54 @@ void chEvtBroadcastFlagsI(EventSource *esp, eventmask_t mask) { elp = esp->es_next; while (elp != (EventListener *)esp) { - chEvtSignalFlagsI(elp->el_listener, elp->el_mask | mask); + elp->el_flags |= flags; + chEvtSignalI(elp->el_listener, elp->el_mask); elp = elp->el_next; } } +/** + * @brief Returns the flags associated to an @p EventListener. + * @details The flags are returned and the @p EventListener flags mask is + * cleared. + * + * @param[in] elp pointer to the @p EventListener structure + * @return The flags added to the listener by the associated + * event source. + * + * @iclass + */ +flagsmask_t chEvtGetAndClearFlagsI(EventListener *elp) { + flagsmask_t flags; + + flags = elp->el_flags; + elp->el_flags = 0; + + return flags; +} + +/** + * @brief Returns the flags associated to an @p EventListener. + * @details The flags are returned and the @p EventListener flags mask is + * cleared. + * + * @param[in] elp pointer to the @p EventListener structure + * @return The flags added to the listener by the associated + * event source. + * + * @iclass + */ +flagsmask_t chEvtGetAndClearFlags(EventListener *elp) { + flagsmask_t flags; + + chSysLock(); + flags = elp->el_flags; + elp->el_flags = 0; + chSysUnlock(); + + return flags; +} + /** * @brief Invokes the event handlers associated to an event flags mask. * -- cgit v1.2.3