chEvtBroadcastFlags doesn't work like I thought it would

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
mikemoretti
Posts: 12
Joined: Sun Nov 29, 2015 9:37 pm

chEvtBroadcastFlags doesn't work like I thought it would

Post by mikemoretti »

Hi,

So, you can do chEvtRegisterMaskWithFlags, and chEvtBroadcastFlags, which from looking at some of the chibios code in chevent.c (see below) is supposed to notify my thread only when a specific event mask and flag bits are set, which is exactly what it seems to do (through testing it out). However, it also appears to be pooping into the flags even when the eventmask+flags don't match. So if I do a broadcast with other flags, and then the ones I actually want, I get all the stuff I didn't want, and all the stuff I do want, and I can't distinguish wtf really happened. Is it supposed to do this?

Code: Select all

void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) {
  event_listener_t *elp;

  chDbgCheckClassI();
  chDbgCheck(esp != NULL);

  elp = esp->es_next;
  /*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
  while (elp != (event_listener_t *)esp) {
  /*lint -restore*/
// Hey I'm gonna poop into the flags no matter what!  Maybe this should go just before chEvtSignal below instead?
    elp->el_flags |= flags;
    /* When flags == 0 the thread will always be signaled because the
       source does not emit any flag.*/
    if ((flags == (eventflags_t)0) ||
        ((elp->el_flags & elp->el_wflags) != (eventflags_t)0)) {
      chEvtSignalI(elp->el_listener, elp->el_events);
    }
    elp = elp->el_next;
  }
}


Am I wrong about this? If so, this seems like a not to usable thing.

My use case is this:

I have a keypad task that reads keys and whether they are long-pressed or just pressed. A bunch of other tasks can register to listen for specific keys and keypress or press and hold events. So whenever a keypress or key press and hold happens, I or those key/press bits into a flag that I broadcast. The other tasks wait for events and only get notified when the specific keys / press status they want happen.

Thanks,
-Mike
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chEvtBroadcastFlags doesn't work like I thought it would

Post by Giovanni »

Hi,

It is the intended behavior, flags are always ORed with the flags mask until the condition is met and the thread is signaled.

Note that nothing forbids adding your own broadcast variant to the application if you need something different.

Giovanni
mikemoretti
Posts: 12
Joined: Sun Nov 29, 2015 9:37 pm

Re: chEvtBroadcastFlags doesn't work like I thought it would

Post by mikemoretti »

Thanks. I just wanted to make sure that that was the expected behavior so I know if I need to get around it or submit a patch.
Post Reply