Multiple events management

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
bitto
Posts: 16
Joined: Thu Jan 30, 2014 9:45 am

Multiple events management

Post by bitto »

Hello,
I just want to make sure I got it right with events.

I have the following code:

Code: Select all

static void sendNlsPktHandler(eventid_t id);
static void sendNhsPktHandler(eventid_t id);

static THD_FUNCTION(serialThread, param) {

  (void) param;
 
  static const evhandler_t evhndl[] = {
    sendNlsPktHandler,
    sendNhsPktHandler,
  };

  event_listener_t  el_nls;
  event_listener_t  el_nhs;
 
  chRegSetThreadName("SERIAL");

  chEvtRegister(&dispatcher_event_nls, &el_nls, 0);
  chEvtRegister(&dispatcher_event_nhs, &el_nhs, 1);

    while(TRUE) {
      chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, TIME_MS2I(500)));
    }
}


Basically the above thread waits for two different events broadcast from other threads and processes them with two handlers.

My question is the following: is it right that, should the two events be broadcast at the same time, the two event handlers will be called one after the other? IOW, if, for example, both handlers access the same UART to send some data, canI avoid protecting such access with a mutex in order not to mess the two transmissions?

Thanks in advance.
Alberto
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Multiple events management

Post by Giovanni »

Hi,

The two handlers would be called in sequence and in the context of the same thread. There is no need of mutex unless also other threads can access the same UART and, note, there are uartAcquireBus() and uartReleaseBus() for that.

Events handling is synchronous, sequential and not concurrent.

Giovanni
bitto
Posts: 16
Joined: Thu Jan 30, 2014 9:45 am

Re: Multiple events management

Post by bitto »

Thanks a lot.

I think I may start getting a grip on events.

Alberto
Post Reply