git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@504 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2008-11-09 09:31:17 +00:00
parent 5c923f28ba
commit 87d83b1b7e
7 changed files with 53 additions and 27 deletions

View File

@ -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 {

View File

@ -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.

View File

@ -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;

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 */