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

master
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. * Event sources setup.
*/ */
chEvtRegister(&EMACFrameReceived, &el0, FRAME_RECEIVED_ID); 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); evtStart(&evt1);
chEvtRegister(&evt1.et_es, &el1, PERIODIC_TIMER_ID); chEvtRegister(&evt1.et_es, &el1, PERIODIC_TIMER_ID);
evtInit(&evt2, CH_FREQUENCY * 10); evtInit(&evt2, S2ST(10));
evtStart(&evt2); evtStart(&evt2);
chEvtRegister(&evt2.et_es, &el2, ARP_TIMER_ID); chEvtRegister(&evt2.et_es, &el2, ARP_TIMER_ID);
@ -176,7 +176,8 @@ msg_t WebThread(void *p) {
uip_sethostaddr(ipaddr); uip_sethostaddr(ipaddr);
httpd_init(); httpd_init();
while (TRUE) while (TRUE) {
chEvtWait(ALL_EVENTS, evhndl); chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
}
return 0; return 0;
} }

View File

@ -133,7 +133,7 @@
* provide the \p __heap_base__ and \p __heap_end__ symbols. * provide the \p __heap_base__ and \p __heap_end__ symbols.
* @note requires \p CH_USE_HEAP. * @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 /** Configuration option: enforces the use of the C-runtime \p malloc() and
* \p free() functions as backend for the system heap allocator.*/ * \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. * chEvtDispatch() - Invokes the event handlers associated to a mask.
* chEvtPend() - Quickly self-pends some events. * chEvtPend() - Quickly self-pends some events.
* chEvtRegisterMask() - Registers a set of flags on a single source. * 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. All the "wait"-type APIs have a timeout-capable variant.
- CHANGE: The old chEvtWait() and chEvtWaitTimeout() APIs are now deprecated - CHANGE: The old EventMask(), chEvtWait() and chEvtWaitTimeout() APIs are
and will be removed in version 1.0.0. now deprecated and will be removed in version 1.0.0.
- CHANGE: Modified chDbgAssert() to syntax check the condition even when the - 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 CH_USE_DEBUG is disabled, it produces no code but allows to check the
optional code without have to compile twice. 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. * Invokes the event handlers associated with a mask.
* @param mask mask of the events that should be invoked by the function, * @param mask mask of the events to be dispatched
* \p ALL_EVENTS enables all the sources
* @param handlers an array of \p evhandler_t. The array must be * @param handlers an array of \p evhandler_t. The array must be
* have indexes from zero up the higher registered event * have indexes from zero up the higher registered event
* identifier. The array can be \p NULL or contain \p NULL * identifier.
* elements (no callbacks specified).
*/ */
void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) { void chEvtDispatch(const evhandler_t handlers[], eventmask_t mask) {
eventid_t i; eventid_t eid;
eventmask_t m;
i = 0, m = 1; eid = 0;
while ((mask & m) == 0) { while (mask) {
i += 1, m <<= 1; if (mask & EVENT_MASK(eid)) {
mask &= ~m; mask &= ~EVENT_MASK(eid);
handlers[i](i); handlers[eid](eid);
}
eid++;
} }
} }

View File

@ -52,9 +52,13 @@ typedef struct EventSource {
EventListener *es_next; EventListener *es_next;
} EventSource; } 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)) #define EventMask(eid) (1 << (eid))
/** Returns the event mask from the event identifier.*/
#define EVENT_MASK(eid) (1 << (eid))
/** /**
* Initializes an Event Source. * Initializes an Event Source.
* @param esp pointer to the \p EventSource structure * @param esp pointer to the \p EventSource structure
@ -85,6 +89,7 @@ extern "C" {
eventmask_t chEvtPend(eventmask_t mask); eventmask_t chEvtPend(eventmask_t mask);
void chEvtBroadcast(EventSource *esp); void chEvtBroadcast(EventSource *esp);
void chEvtBroadcastI(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) #if defined(CH_OPTIMIZE_SPEED) || !defined(CH_USE_EVENT_TIMEOUT)
eventmask_t chEvtWaitOne(eventmask_t ewmask); eventmask_t chEvtWaitOne(eventmask_t ewmask);
eventmask_t chEvtWaitAny(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 * @note Multiple Event Listeners can use the same event identifier, the
* listener will share the callback function. * 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) #if !defined(CH_OPTIMIZE_SPEED) && defined(CH_USE_EVENT_TIMEOUT)
#define chEvtWaitOne(ewmask) chEvtWaitOneTimeout(ewmask, TIME_INFINITE) #define chEvtWaitOne(ewmask) chEvtWaitOneTimeout(ewmask, TIME_INFINITE)