diff options
-rw-r--r-- | demos/ARM7-LPC214x-GCC/main.c | 6 | ||||
-rw-r--r-- | readme.txt | 12 | ||||
-rw-r--r-- | src/chevents.c | 24 | ||||
-rw-r--r-- | src/include/events.h | 21 | ||||
-rw-r--r-- | test/test.c | 8 | ||||
-rw-r--r-- | test/test.mk | 5 | ||||
-rw-r--r-- | test/testsem.c | 4 |
7 files changed, 53 insertions, 27 deletions
diff --git a/demos/ARM7-LPC214x-GCC/main.c b/demos/ARM7-LPC214x-GCC/main.c index 3ff516077..9b231408f 100644 --- a/demos/ARM7-LPC214x-GCC/main.c +++ b/demos/ARM7-LPC214x-GCC/main.c @@ -60,13 +60,17 @@ static msg_t Thread2(void *arg) { return 0;
}
+static WorkingArea(waTestThread, 128);
+
/*
* Executed as event handler at 500mS intervals.
*/
static void TimerHandler(eventid_t id) {
if (!(IO0PIN & 0x00018000)) { // Both buttons
- TestThread(&COM1);
+ Thread *tp = chThdCreateStatic(waTestThread, sizeof(waTestThread),
+ NORMALPRIO, TestThread, &COM1);
+ chThdWait(tp);
PlaySound(500, 100);
}
else {
diff --git a/readme.txt b/readme.txt index 36ec1d975..92444beab 100644 --- a/readme.txt +++ b/readme.txt @@ -77,17 +77,19 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, - NEW: Improved events subsystems, now it is also possible to use it just as
"event flags" without have to use event handler callbacks.
Some new APIs were introduced:
- * chEvtWaitOne() - Wait for a single event.
- * chEvtWaitAny() - Wait with OR condition.
- * chEvtWaitAll() - Wait with AND condition.
- * chEvtDispatch() - Invokes the event handlers associated to a mask.
- * chEvtPend() - Quickly self-pends some events.
+ * chEvtWaitOne() - Wait for a single event.
+ * chEvtWaitAny() - Wait with OR condition.
+ * chEvtWaitAll() - Wait with AND condition.
+ * chEvtDispatch() - Invokes the event handlers associated to a mask.
+ * chEvtPend() - Quickly self-pends some events.
+ * chEvtRegisterMask() - Registers a set of flags on a single source.
All the "wait"-type APIs have a timeout-capable variant.
- CHANGE: The old chEvtWait() and chEvtWaitTimeout() APIs are now deprecated
and will be removed in version 1.0.0.
- CHANGE: Modified chDbgAssert() to syntax check the condition even when the
CH_USE_DEBUG is disabled, it produces no code but allows to check the
optional code without have to compile twice.
+- FIX: Fixed a warning generated by the chEvtIsListening() macro.
- Added a new benchmark to the test suite (timers set/reset performance).
- Renamed the macro fifo_init() to queue_init() because it is used to init
both FIFO queues and priority queues.
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)
diff --git a/test/test.c b/test/test.c index 667b89749..9a1af1725 100644 --- a/test/test.c +++ b/test/test.c @@ -24,6 +24,7 @@ #include "testsem.h"
#include "testmtx.h"
#include "testmsg.h"
+#include "testevt.h"
#include "testheap.h"
#include "testpools.h"
#include "testdyn.h"
@@ -35,14 +36,21 @@ static const struct testcase *tests[] = {
&testrdy1,
&testrdy2,
+#ifdef CH_USE_SEMAPHORES
&testsem1,
&testsem2,
+#endif
#ifdef CH_USE_MUTEXES
&testmtx1,
&testmtx2,
&testmtx3,
#endif
+#ifdef CH_USE_MESSAGES
&testmsg1,
+#endif
+#ifdef CH_USE_EVENTS
+ &testevt1,
+#endif
#ifdef CH_USE_HEAP
&testheap1,
#endif
diff --git a/test/test.mk b/test/test.mk index 9ea33e412..e65db3345 100644 --- a/test/test.mk +++ b/test/test.mk @@ -1,4 +1,5 @@ # List of all the ChibiOS/RT test files.
TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \
- ../../test/testmtx.c ../../test/testmsg.c ../../test/testheap.c \
- ../../test/testpools.c ../../test/testdyn.c ../../test/testbmk.c
+ ../../test/testmtx.c ../../test/testmsg.c ../../test/testevt.c \
+ ../../test/testheap.c ../../test/testpools.c ../../test/testdyn.c \
+ ../../test/testbmk.c
diff --git a/test/testsem.c b/test/testsem.c index f2105a7dd..26c5556f5 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -21,6 +21,8 @@ #include "test.h"
+#ifdef CH_USE_SEMAPHORES
+
#define ALLOWED_DELAY MS2ST(5)
static Semaphore sem1;
@@ -100,3 +102,5 @@ const struct testcase testsem2 = { sem2_teardown,
sem2_execute
};
+
+#endif /* CH_USE_SEMAPHORES */
|