Event chEvtWaitAnyTimeout flags

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Event chEvtWaitAnyTimeout flags

Post by omcdr »

In my external input module I have code, broadcast event only with one flag: EV_MSK_IN16_SHORT, I don't use EV_MSK_IN12_SHORT flag.

Code: Select all

#define EV_MSK_IN12_SHORT (1UL << 12)
#define EV_MSK_IN15_SHORT (1UL << 15)
#define EV_MSK_IN16_SHORT (1UL << 16)

EVENTSOURCE_DECL(evInShort);
chEvtObjectInit(&evInLong);

chEvtBroadcastFlagsI(&evInShort, EV_MSK_IN16_SHORT);



In another thread I have:

Code: Select all

   event_listener_t evlInShort;

   chEvtRegisterMask(&evInShort, &evlInShort, EV_MSK_IN11_SHORT | EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT);
   eventmask_t evt = 0;
   uint32_t x12 = EV_MSK_IN12_SHORT;
   uint32_t x16 = EV_MSK_IN16_SHORT;   
   
   while (1)
   {
//      evt = chEvtWaitOneTimeout(EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT, MS2ST(50));   
      evt = chEvtWaitAnyTimeout(EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT, MS2ST(50));
//      evt = chEvtWaitAllTimeout(EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT, MS2ST(50));      
      
      if(evt & EV_MSK_IN16_SHORT)
      {
         (...)
      }

      if(evt & EV_MSK_IN12_SHORT)
      {
         (...)      
      }

With

Code: Select all

      evt = chEvtWaitOneTimeout(EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT, MS2ST(50));

I got if(evt & EV_MSK_IN12_SHORT) as true - why 12 ?

Code: Select all

Variable   Value   Location   Type   
evlInShort   <struct>   0x20001E50   event_listener_t   
next   evInShort (0x20000870)   0x20001E50   event_listener_t *   
listener   0x20001E78 (waThreadDump + 640)   0x20001E54   thread_t *   
events   0x00011800   0x20001E58   uint32_t   
flags   0x00010000   0x20001E5C   uint32_t   
wflags   0xFFFFFFFF   0x20001E60   uint32_t   
evt   0x00001000   R5   uint32_t   
x12   0x00001000   R6   uint32_t   
x16   0x00010000   R7   uint32_t


with

Code: Select all

      evt = chEvtWaitAnyTimeout(EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT, MS2ST(50));

I got if(evt & EV_MSK_IN16_SHORT) and if(evt & EV_MSK_IN12_SHORT) as true - why 2 flags ?

Code: Select all

Variable   Value   Location   Type   
evlInShort   <struct>   0x20001E50   event_listener_t   
next   evInShort (0x20000870)   0x20001E50   event_listener_t *   
listener   0x20001E78 (waThreadDump + 640)   0x20001E54   thread_t *   
events   0x00011800   0x20001E58   uint32_t   
flags   0x00010000   0x20001E5C   uint32_t   
wflags   0xFFFFFFFF   0x20001E60   uint32_t   
evt   0x00011000   R5   uint32_t   
x12   0x00001000   R6   uint32_t   
x16   0x00010000   R7   uint32_t



Could you explain this behaviour ?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Event chEvtWaitAnyTimeout flags

Post by Giovanni »

chEvtBroadcastFlagsI(&evInShort, EV_MSK_IN16_SHORT);

The second parameter is not a mask of events but a mask of source flags, two different things.

chEvtRegisterMask(&evInShort, &evlInShort, EV_MSK_IN11_SHORT | EV_MSK_IN12_SHORT | EV_MSK_IN16_SHORT);

Here is the problem, you are telling the system to raise ALL those flags when evInShort is broadcasted, also, you are passing two times the listener, the source is the first parameter.

There could be more problems.

Giovanni
omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Re: Event chEvtWaitAnyTimeout flags

Post by omcdr »

Thank you for explanations, I have mixed mask of events and mask of source flags.
My code is working correctly now.
Post Reply