Events have the potential to be very powerful but the feature seems to be missing what appears to be an easy to implement but important capability - at least in the way I understand to use them which may be totally wrong so feel free to correct me if necessary.
In any case, the way I understand events is they are a 1 to N type of signaling mechanism. I also see that there can be potentially many different event sources for many different events or types of events which may need to be signaled to a thread. I understand how to create an event source. How to create listeners, register them and wait for the event to happen and it works fine.
The capability I find missing is if I have a thread that is listening to two different event sources. chEvtWaitOne (or any of the other chEvtWaitxxx functions) do not have an EventSource parameter and the only way to determine which event source a thread woke up from is via the event mask parameter. While this provides up to 32 events (which may not be a problem for most) this one event mask is shared across the entire system and requires coordinating their values in a way that has less structure than I like. it seems cleaner to me if each event mask were associated with only one event source and I could do something like the following in a thread:
Code: Select all
static msg_t buttonsThread(void *arg)
{
chRegSetThreadName("ButtonPoll");
EventListener button1_el;
EventListener button2_el;
chEvtRegister(&buttonOnePressEvent, &button1_el, buttonsPressEvent);
chEvtRegister(&buttonTwoButtonEvent, &button2_el,buttonsPressEvent)
while (True)
{
switch (buttonState)
{
case 0:
// Start of new sequence - Waiting for button event
chEvtWaitOne(&buttonOnePressEvent, buttonsPressEvent);
if (BUTTON_DRV0.state == ICU_ACTIVE)
.
.
.
.
break;
case 1:
chEvtWaitOne(&buttonTwoPressEvent, buttonsPressEvent);
.
.
.
break;
case 2:
.
.
.
.
.
}
I may be all wet in this thought process but it allows me to have unlimited events that won't collide with each other over a single unified event mask as it current stands. Also, the code above isn't real code. I just tried to make something up quickly and it may be completely stupid so let's not get bogged down in that code. It's sole purpose was to show the type of mechanism I'm talking about.
Thanks,
Ron