confused in Event flag concept

Discussions and support about ChibiOS/RT, the free embedded RTOS.
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

confused in Event flag concept

Postby ep.hobbyiest » Mon Jan 16, 2017 4:15 pm

hi,

I got one doubt while using event flag. what is difference between following API's

Code: Select all

chEvtWaitAllTimeout
chEvtWaitAnyTimeout
chEvtWaitOneTimeout

I read the documents, here is my understanding if i m not wrong,
if we pass ALL_EVENT as event_mask then i think all will behave same only.

Again, i was going through one demo other than deom shared in chibi_studio.


I am bit confuse here in the following statement

Code: Select all

   chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));

i found following snippet(simplified).

Code: Select all

static EVENTSOURCE_DECL(inserted_event);
static EVENTSOURCE_DECL(removed_event);


void main(void)
{
   evhandler_t evhndl[] = {
           InsertHandler,
           RemoveHandler
   };
   struct event_listener el0, el1;
  chEvtRegister(&inserted_event, &el0, 0);
  chEvtRegister(&removed_event, &el1, 1);
  while(1)
  {
   chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
   }
}

static void InsertHandler(eventid_t id) {
//do something
}


static void RemoveHandler(eventid_t id) {
//do something
}

void task(void)
{
   if(mmc_available)
   {
           chEvtBroadcastI(&inserted_event);
   }
   else
   {
         chEvtBroadcastI(&removed_event);
   }
}

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: confused in Event flag concept

Postby Giovanni » Mon Jan 16, 2017 7:02 pm

Hi,

Those all/any/one variants work as follow:

all: The thread is restarted when all the specified event flags are set, it is an AND.
any: It is an OR, one of those specified.
one: It is still an OR but only one flag is returned among those pending. The returned mask only contains one bit set.

Code: Select all

   chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));


It executes one event handler then it returns into the wait function. The difference with "any" is that the timeout is reset after serving each event flag.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 36 guests