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

This commit is contained in:
gdisirio 2008-11-15 09:51:40 +00:00
parent aafa0564b8
commit bc3964df26
5 changed files with 27 additions and 21 deletions

View File

@ -151,13 +151,13 @@ msg_t WebThread(void *p) {
* Event sources setup.
*/
chEvtRegister(&EMACFrameReceived, &el0, FRAME_RECEIVED_ID);
chEvtBroadcast(&EMACFrameReceived); /* In case some frames are already buffered */
chEvtPend(EVENT_MASK(FRAME_RECEIVED_ID)); /* In case some frames are already buffered */
evtInit(&evt1, CH_FREQUENCY / 2);
evtInit(&evt1, MS2ST(500));
evtStart(&evt1);
chEvtRegister(&evt1.et_es, &el1, PERIODIC_TIMER_ID);
evtInit(&evt2, CH_FREQUENCY * 10);
evtInit(&evt2, S2ST(10));
evtStart(&evt2);
chEvtRegister(&evt2.et_es, &el2, ARP_TIMER_ID);
@ -176,7 +176,8 @@ msg_t WebThread(void *p) {
uip_sethostaddr(ipaddr);
httpd_init();
while (TRUE)
chEvtWait(ALL_EVENTS, evhndl);
while (TRUE) {
chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
}
return 0;
}

View File

@ -133,7 +133,7 @@
* provide the \p __heap_base__ and \p __heap_end__ symbols.
* @note requires \p CH_USE_HEAP.
*/
#define CH_HEAP_SIZE 0
#define CH_HEAP_SIZE 512
/** Configuration option: enforces the use of the C-runtime \p malloc() and
* \p free() functions as backend for the system heap allocator.*/

View File

@ -84,9 +84,10 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
* 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.
* EVENT_MASK() - Replaces the old EventMask() macro.
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: The old EventMask(), 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.

View File

@ -142,22 +142,21 @@ void chEvtBroadcastI(EventSource *esp) {
/**
* Invokes the event handlers associated with a mask.
* @param mask mask of the events that should be invoked by the function,
* \p ALL_EVENTS enables all the sources
* @param mask mask of the events to be dispatched
* @param handlers an array of \p evhandler_t. The array must be
* have indexes from zero up the higher registered event
* identifier. The array can be \p NULL or contain \p NULL
* elements (no callbacks specified).
* identifier.
*/
void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) {
eventid_t i;
eventmask_t m;
eventid_t eid;
i = 0, m = 1;
while ((mask & m) == 0) {
i += 1, m <<= 1;
mask &= ~m;
handlers[i](i);
eid = 0;
while (mask) {
if (mask & EVENT_MASK(eid)) {
mask &= ~EVENT_MASK(eid);
handlers[eid](eid);
}
eid++;
}
}

View File

@ -52,9 +52,13 @@ typedef struct EventSource {
EventListener *es_next;
} EventSource;
/** Returns the event mask from the event identifier.*/
/** Returns the event mask from the event identifier.
* @deprecated use EVENT_MASK() instead.*/
#define EventMask(eid) (1 << (eid))
/** Returns the event mask from the event identifier.*/
#define EVENT_MASK(eid) (1 << (eid))
/**
* Initializes an Event Source.
* @param esp pointer to the \p EventSource structure
@ -85,6 +89,7 @@ extern "C" {
eventmask_t chEvtPend(eventmask_t mask);
void chEvtBroadcast(EventSource *esp);
void chEvtBroadcastI(EventSource *esp);
void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask);
#if defined(CH_OPTIMIZE_SPEED) || !defined(CH_USE_EVENT_TIMEOUT)
eventmask_t chEvtWaitOne(eventmask_t ewmask);
eventmask_t chEvtWaitAny(eventmask_t ewmask);
@ -115,7 +120,7 @@ extern "C" {
* @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))
#define chEvtRegister(esp, elp, eid) chEvtRegisterMask(esp, elp, EVENT_MASK(eid))
#if !defined(CH_OPTIMIZE_SPEED) && defined(CH_USE_EVENT_TIMEOUT)
#define chEvtWaitOne(ewmask) chEvtWaitOneTimeout(ewmask, TIME_INFINITE)