Event chEvtWaitAnyTimeout flags

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

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

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

Event chEvtWaitAnyTimeout flags

Postby omcdr » Thu Aug 31, 2017 10:28 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Event chEvtWaitAnyTimeout flags

Postby Giovanni » Thu Aug 31, 2017 11:26 am

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

Postby omcdr » Thu Aug 31, 2017 8:27 pm

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


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 21 guests