Page 1 of 1

Problem with events

Posted: Fri May 23, 2014 1:37 pm
by Korken
Hi,

I'm using events to sync threads to "new data" events, but when I register to the event sources I get an unhandeled exception after a few iterations.
I register like this:

Code: Select all

/* Event registration for new sensor data */
event_listener_t el;
event_source_t *es;
eventmask_t acc_gyro_mask, mag_mask;

/* Register to new data from accelerometer and gyroscope */
es = ptrGetAccelerometerAndGyroscopeEventSource(&acc_gyro_mask);
chEvtRegisterMask(es, &el, acc_gyro_mask);

/* Register to new data from magnetometer */
es = ptrGetMagnetometerEventSource(&mag_mask);
chEvtRegisterMask(es, &el, mag_mask);

...

while (1) {
    ...

    /* Wait for new measurement data */   
    chEvtWaitOne(acc_gyro_mask);

    ...
}

Where ptrGetAccelerometerAndGyroscopeEventSource and ptrGetMagnetometerEventSource return the pointers to the event sources and the corresponding event masks.

Have I misunderstood how events work or can I not register to two different events?
Because if I comment out one of the registrations it works as expected.

Re: Problem with events

Posted: Fri May 23, 2014 2:45 pm
by Giovanni
Few things,

You need multiple EventListener, one for each source you want to listen for.
You need to initialize the EventSource
Usually the EventSource object is declared in the context of the entity broadcasting events.

Giovanni

Re: Problem with events

Posted: Fri May 23, 2014 3:34 pm
by Korken
Okey, then the problem is in the number of event listeners. Thanks for the clarification!
Now that I'm aware of the limitations I will design accordingly. :)

Re: Problem with events

Posted: Fri May 23, 2014 4:17 pm
by Giovanni
It is not a limitation, a listener is an object meant to link a source to a thread 1-to-1.

Giovanni

Re: Problem with events

Posted: Fri May 23, 2014 5:17 pm
by Korken
Hmm, I am unable to find that.
Should this not be defined here: http://chibios.sourceforge.net/html/gro ... 04ae43e2b0 ?
Or is the basic structure of the event system defined elsewhere?

Re: Problem with events

Posted: Fri May 23, 2014 5:21 pm
by Giovanni
Try here: viewtopic.php?f=2&t=1348

Giovanni

Re: Problem with events

Posted: Sat May 24, 2014 1:07 pm
by Korken
Precisely what I needed! Thanks!

Re: Problem with events

Posted: Tue Aug 12, 2014 8:17 am
by Jeroen3
Giovanni wrote:You need multiple EventListener, one for each source you want to listen for.

This part of crucial information is missing from the doxygens.

If I'm understanding the mechanism correctly the only 1-to-many design allowed is: one EventSource to many EventListener. Let me describe.
An EventSource is the starting point of a linked-list. Each node is an EventListener containing the Thread*, flags and filters and the next listener.
So when registering an EventListener, it is appended to the end of the linked-list.
Reversed operation of one EventListener with many EventSources, is a problem because EventSources are not capable of being a node in a linked list. And if they could it would create a world of complexity.

Re: Problem with events

Posted: Tue Aug 12, 2014 9:55 am
by Giovanni
You may also read:

this article http://www.chibios.org/dokuwiki/doku.ph ... :kb:events

and this contributed guide: viewtopic.php?f=2&t=1348

Giovanni