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