Explanation for Events needed

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
CalM
Posts: 15
Joined: Tue Jul 12, 2011 8:02 pm

Explanation for Events needed

Post by CalM »

Hello

i am just trying to get, how the Eventsystem in ChibiOS is working. From what i found is, there are:
1. Eventsources
2. Eventlistener
3. Threads

The connection between a Eventsource and a Eventlistender is done by chEvtRegisterMask(...); wich will connect a Eventlistener with the specified Bitmask to a Eventsources.
If the Eventsources fires, the Eventlistener will be notified and set his Bistmask.
But here my problem starts: How is the Eventlistener connected to a specific Thread? Thats something i havent't find out yet. A Bit of explanation would be hellpfull, or a smal snippet of Code

Mfg

ClaM
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Explanation for Events needed

Post by Giovanni »

Hi,

It is very simple, when you call chEvtRegisterMask() the listener is automatically associated to the calling thread.

Each thread that need to be notified by an EventSource calls chEvtRegisterMask() in order to register on the source, the EventListener structure is just a proxy.

An example is present in: ./demos/AVR-ATmega128-GCC/main.c

An event timer is started and the button state is checked within the event handler, the code is valid in all architectures.

Giovanni
CalM
Posts: 15
Joined: Tue Jul 12, 2011 8:02 pm

Re: Explanation for Events needed

Post by CalM »

Thanks for the fast answare,

will it in future Version of ChibiOS be possible to pre Register Threads to Eventsources? So before startup of the System i can call a function, to register certin Threads to Eventsources.
I guess just a modification to pass the threds pointer in the call of chEvtRegisterMask will do horrible things?


CalM
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Explanation for Events needed

Post by Giovanni »

It is not possible to pass directly the thread, the relationship between sources and threads is "many to many", one thread could be associated to an arbitrary number of sources and a source can have an arbitrary number of threads associated.

This is why that "listener" is required, it is the memory required to represent a "1 to 1" association.

Anyway if you need a simpler way then you can use chEvtSignalFlags(), this function directly signals a specific thread with a mask of flags, without sources and listeners involved. It is the easiest way if a source only need to signal a specific thread.

About pre-registering, it is possible if you make sources and listeners constants and pre-initialize them using the correct values.

Giovanni
Post Reply