From bc3964df2684cd45fde0802597f4cdf1face4a12 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 15 Nov 2008 09:51:40 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@509 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c | 11 +++++----- demos/MSP430-MSP430x1611-GCC/chconf.h | 2 +- readme.txt | 5 +++-- src/chevents.c | 21 ++++++++++---------- src/include/events.h | 9 +++++++-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c b/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c index 547437047..c9b3b395e 100644 --- a/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c +++ b/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c @@ -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; } diff --git a/demos/MSP430-MSP430x1611-GCC/chconf.h b/demos/MSP430-MSP430x1611-GCC/chconf.h index 5a43ac1b2..785abb912 100644 --- a/demos/MSP430-MSP430x1611-GCC/chconf.h +++ b/demos/MSP430-MSP430x1611-GCC/chconf.h @@ -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.*/ diff --git a/readme.txt b/readme.txt index c6f83ece6..8c8065762 100644 --- a/readme.txt +++ b/readme.txt @@ -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. diff --git a/src/chevents.c b/src/chevents.c index ce2254ab4..f67bea11a 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -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++; } } diff --git a/src/include/events.h b/src/include/events.h index ae5d8c740..2f3eda366 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -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)