Problem with events

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Problem with events

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with events

Post 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
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Problem with events

Post 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. :)
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with events

Post by Giovanni »

It is not a limitation, a listener is an object meant to link a source to a thread 1-to-1.

Giovanni
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Problem with events

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with events

Post by Giovanni »

Try here: viewtopic.php?f=2&t=1348

Giovanni
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Problem with events

Post by Korken »

Precisely what I needed! Thanks!
Jeroen3
Posts: 35
Joined: Wed Apr 02, 2014 10:14 am

Re: Problem with events

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problem with events

Post 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
Post Reply