Page 2 of 2

Re: The Event Question

Posted: Fri Jan 16, 2015 1:16 pm
by Tabulous
steved wrote:Nice to see I'm not the only one that has to think hard about events!

I've been using a slightly different arrangement, which works well if only one thread needs to know about the event (and if you don't have too many threads). It doesn't need a specific listener.

Code: Select all

void watchdogNotify(uint8_t threadNumber)
{
chEvtSignal(mainThread, EVENT_MASK(threadNumber));
}

Each monitored thread calls watchdogNotify() periodically; threadNumber is an arbitrary value (within limits) which uniquely identifies the thread.
mainThread is a pointer to the main thread! (or the thread which is triggering the watchdog).

Then use chEvtWaitAll(<your_sources_mask>); as previously mentioned.


Nice steve, i followed your approach but added the ability for threads to register into the watchdog, this is because i have some threads that only start if configured to.
It wraps around the independent watchdog driver.

Ive attached the files so it may be of use to others :-)