Events fail with exception Topic is solved

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

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

Events fail with exception

Postby elagil » Fri Sep 22, 2017 9:32 am

Hello!

I am trying to use events. I have a thread that checks buttons and an event should be broadcast in case of a button press to multiple other threads that implement listeners.

The listening threads are like this:

Code: Select all

THD_WORKING_AREA(wa_asic_thread, ASIC_THREAD_STACK_SIZE);
THD_FUNCTION(Thread_asic, p) {
  (void)p;

  event_listener_t switch_listener;

  /*
   * Registering on the switch thread as event 0
   */
  chEvtRegister(&switch_event_source, &switch_listener, 0);
 
    while (true) {
    /*
     * Switch position changed? Reconfigure if detected.
     * Wait for switch event to start.
     */
     
    eventmask_t evt = chEvtWaitAny(ALL_EVENTS);

    if (evt & EVENT_MASK(0)) {
      /* Event from the switches, do something */
        chThdSleepMilliseconds(1000);
    }
 


The switch checker is like this:

Code: Select all

event_source_t switch_event_source;

THD_WORKING_AREA(wa_Switch, 128);
THD_FUNCTION(Thread_Switch, arg) {
 
    while (true) {
    /*
     * Do detection stuff... Switch position changed?
     */
     if (new_switch_settings) chEvtBroadcast(&switch_event_source);

     chThdSleepMilliseconds(100);
    }
}


The functions are inside individual .c files and the "switch_event_source" variable is defined as external in a common header.

Code: Select all

extern event_source_t switch_event_source;


I always jump into _unhandled_exception(void) when calling the chEvtBroadcast(). Do you have any idea why?

Thanks in advance,
Adrian

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

Re: Events fail with exception  Topic is solved

Postby Giovanni » Fri Sep 22, 2017 9:39 am

Hi,

Is the event source object initialized?

Giovanni

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

Re: Events fail with exception

Postby elagil » Fri Sep 22, 2017 10:05 am

No, I forgot this! Now the exception is gone. However, the event listener does never trigger. I am sure that the event broadcast is called, however.

elagil
Posts: 92
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 8 times
Been thanked: 7 times

Re: Events fail with exception

Postby elagil » Fri Sep 22, 2017 10:24 am

Sorry, it works. I should have initialized the event source first and then register it in the listener.

Thank you for your help!

So, fixing step:
Add initialization of the event source before registering a listener or broadcasting an event!


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 9 guests