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. * diff --git a/os/ports/GCC/ARM/chtypes.h b/os/ports/GCC/ARM/chtypes.h index eb0c04c77..a4067e915 100644 --- a/os/ports/GCC/ARM/chtypes.h +++ b/os/ports/GCC/ARM/chtypes.h @@ -46,7 +46,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint32_t tprio_t; /**< Thread priority. */ typedef int32_t msg_t; /**< Inter-thread message. */ typedef int32_t eventid_t; /**< Event Id. */ -typedef uint32_t eventmask_t; /**< Events mask. */ +typedef uint32_t eventmask_t; /**< Event mask. */ +typedef uint32_t flagsmask_t; /**< Event flags. */ typedef uint32_t systime_t; /**< System time. */ typedef int32_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/GCC/ARMCMx/chtypes.h b/os/ports/GCC/ARMCMx/chtypes.h index 4d896fea0..70feda2fe 100644 --- a/os/ports/GCC/ARMCMx/chtypes.h +++ b/os/ports/GCC/ARMCMx/chtypes.h @@ -44,7 +44,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint32_t tprio_t; /**< Thread priority. */ typedef int32_t msg_t; /**< Inter-thread message. */ typedef int32_t eventid_t; /**< Event Id. */ -typedef uint32_t eventmask_t; /**< Events mask. */ +typedef uint32_t eventmask_t; /**< Event mask. */ +typedef uint32_t flagsmask_t; /**< Event flags. */ typedef uint32_t systime_t; /**< System time. */ typedef int32_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/GCC/AVR/chtypes.h b/os/ports/GCC/AVR/chtypes.h index 0c8197823..96ed68aa3 100644 --- a/os/ports/GCC/AVR/chtypes.h +++ b/os/ports/GCC/AVR/chtypes.h @@ -46,7 +46,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint8_t tprio_t; /**< Thread priority. */ typedef int16_t msg_t; /**< Inter-thread message. */ typedef uint8_t eventid_t; /**< Event Id. */ -typedef uint8_t eventmask_t; /**< Events mask. */ +typedef uint8_t eventmask_t; /**< Event mask. */ +typedef uint8_t flagsmask_t; /**< Event flags. */ typedef uint16_t systime_t; /**< System time. */ typedef int8_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/GCC/MSP430/chtypes.h b/os/ports/GCC/MSP430/chtypes.h index a56351016..d195f3fb3 100644 --- a/os/ports/GCC/MSP430/chtypes.h +++ b/os/ports/GCC/MSP430/chtypes.h @@ -46,7 +46,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint16_t tprio_t; /**< Thread priority. */ typedef int16_t msg_t; /**< Inter-thread message. */ typedef int16_t eventid_t; /**< Event Id. */ -typedef uint16_t eventmask_t; /**< Events mask. */ +typedef uint16_t eventmask_t; /**< Event mask. */ +typedef uint16_t flagsmask_t; /**< Event flags. */ typedef uint16_t systime_t; /**< System time. */ typedef int16_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/GCC/PPC/chtypes.h b/os/ports/GCC/PPC/chtypes.h index debc5f0f8..3a1844ef9 100644 --- a/os/ports/GCC/PPC/chtypes.h +++ b/os/ports/GCC/PPC/chtypes.h @@ -54,11 +54,12 @@ typedef int32_t bool_t; /**< Fast boolean type. */ typedef uint8_t tmode_t; /**< Thread flags. */ typedef uint8_t tstate_t; /**< Thread state. */ typedef uint8_t trefs_t; /**< Thread references counter. */ -typedef uint8_t tslices_t; /**< Thread time slices counter. */ +typedef uint8_t tslices_t; /**< Thread time slices counter.*/ typedef uint32_t tprio_t; /**< Thread priority. */ typedef int32_t msg_t; /**< Inter-thread message. */ typedef int32_t eventid_t; /**< Event Id. */ -typedef uint32_t eventmask_t; /**< Events mask. */ +typedef uint32_t eventmask_t; /**< Event mask. */ +typedef uint32_t flagsmask_t; /**< Event flags. */ typedef uint32_t systime_t; /**< System time. */ typedef int32_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/GCC/SIMIA32/chtypes.h b/os/ports/GCC/SIMIA32/chtypes.h index 54d701044..7b24597c2 100644 --- a/os/ports/GCC/SIMIA32/chtypes.h +++ b/os/ports/GCC/SIMIA32/chtypes.h @@ -38,7 +38,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint32_t tprio_t; /**< Thread priority. */ typedef int32_t msg_t; /**< Inter-thread message. */ typedef int32_t eventid_t; /**< Event Id. */ -typedef uint32_t eventmask_t; /**< Events mask. */ +typedef uint32_t eventmask_t; /**< Event mask. */ +typedef uint32_t flagsmask_t; /**< Event flags. */ typedef uint32_t systime_t; /**< System time. */ typedef int32_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/IAR/ARMCMx/chtypes.h b/os/ports/IAR/ARMCMx/chtypes.h index 221b2819b..ec370ba3e 100644 --- a/os/ports/IAR/ARMCMx/chtypes.h +++ b/os/ports/IAR/ARMCMx/chtypes.h @@ -44,7 +44,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint32_t tprio_t; /**< Thread priority. */ typedef int32_t msg_t; /**< Inter-thread message. */ typedef int32_t eventid_t; /**< Event Id. */ -typedef uint32_t eventmask_t; /**< Events mask. */ +typedef uint32_t eventmask_t; /**< Event mask. */ +typedef uint32_t flagsmask_t; /**< Event flags. */ typedef uint32_t systime_t; /**< System time. */ typedef int32_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/IAR/STM8/chtypes.h b/os/ports/IAR/STM8/chtypes.h index a7f2d423b..a5753f410 100644 --- a/os/ports/IAR/STM8/chtypes.h +++ b/os/ports/IAR/STM8/chtypes.h @@ -45,7 +45,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint8_t tprio_t; /**< Thread priority. */ typedef int16_t msg_t; /**< Inter-thread message. */ typedef int8_t eventid_t; /**< Event Id. */ -typedef uint8_t eventmask_t; /**< Events mask. */ +typedef uint8_t eventmask_t; /**< Event mask. */ +typedef uint8_t flagsmask_t; /**< Event flags. */ typedef uint16_t systime_t; /**< System time. */ typedef int8_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/RC/STM8/chtypes.h b/os/ports/RC/STM8/chtypes.h index 7d5ebdb31..b87d77baa 100644 --- a/os/ports/RC/STM8/chtypes.h +++ b/os/ports/RC/STM8/chtypes.h @@ -55,7 +55,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint8_t tprio_t; /**< Thread priority. */ typedef int16_t msg_t; /**< Inter-thread message. */ typedef int8_t eventid_t; /**< Event Id. */ -typedef uint8_t eventmask_t; /**< Events mask. */ +typedef uint8_t eventmask_t; /**< Event mask. */ +typedef uint8_t flagsmask_t; /**< Event flags. */ typedef uint16_t systime_t; /**< System time. */ typedef int8_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/RVCT/ARMCMx/chtypes.h b/os/ports/RVCT/ARMCMx/chtypes.h index 8619dcdfe..7c0bbd72e 100644 --- a/os/ports/RVCT/ARMCMx/chtypes.h +++ b/os/ports/RVCT/ARMCMx/chtypes.h @@ -44,7 +44,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint32_t tprio_t; /**< Thread priority. */ typedef int32_t msg_t; /**< Inter-thread message. */ typedef int32_t eventid_t; /**< Event Id. */ -typedef uint32_t eventmask_t; /**< Events mask. */ +typedef uint32_t eventmask_t; /**< Event mask. */ +typedef uint32_t flagsmask_t; /**< Event flags. */ typedef uint32_t systime_t; /**< System time. */ typedef int32_t cnt_t; /**< Resources counter. */ diff --git a/os/ports/cosmic/STM8/chtypes.h b/os/ports/cosmic/STM8/chtypes.h index 9c1749a96..48c9271c7 100644 --- a/os/ports/cosmic/STM8/chtypes.h +++ b/os/ports/cosmic/STM8/chtypes.h @@ -55,7 +55,8 @@ typedef uint8_t tslices_t; /**< Thread time slices counter. */ typedef uint8_t tprio_t; /**< Thread priority. */ typedef int16_t msg_t; /**< Inter-thread message. */ typedef int8_t eventid_t; /**< Event Id. */ -typedef uint8_t eventmask_t; /**< Events mask. */ +typedef uint8_t eventmask_t; /**< Event mask. */ +typedef uint8_t flagsmask_t; /**< Event flags. */ typedef uint16_t systime_t; /**< System time. */ typedef int8_t cnt_t; /**< Resources counter. */ diff --git a/readme.txt b/readme.txt index c465f4acf..f508a8e61 100644 --- a/readme.txt +++ b/readme.txt @@ -85,6 +85,9 @@ *** 2.5.1 *** - FIX: Fixed Data available event not generated in serial_usb driver (bug 3567992). +- NEW: Improved the kernel events subsystem, now event sources can associate + source-specific flags to the listener, the flags can then be retrieved + using the new APIs chEvtGetAndClearFlags() and chEvtGetAndClearFlagsI(). - NEW: Added VLE support to the Power Architecture GCC port. - NEW: Reorganized the Power Architecture GCC port along the lines of the ARMCMx port, now it can support multiple core types. diff --git a/test/testevt.c b/test/testevt.c index 00a1f3fed..9ad9906d2 100644 --- a/test/testevt.c +++ b/test/testevt.c @@ -137,7 +137,7 @@ static void evt2_setup(void) { static msg_t thread1(void *p) { chThdSleepMilliseconds(50); - chEvtSignalFlags((Thread *)p, 1); + chEvtSignal((Thread *)p, 1); return 0; }