MySensors icon indicating copy to clipboard operation
MySensors copied to clipboard

Support for custom ISR (WDT_vect)

Open HolgerHees opened this issue 5 years ago • 1 comments

Hello,

currently I implement my own custom WDT_vect which conflicts with the one defined my mysensor. The reason why I need to implement a custom one is, that I need to know if a wakeup happens because of an interrupt or by the watchdog timer. I can't use the solution where I call the sleep function with the interrupt parameter, because I need also to implement my own custom interrupt handler to handle data from w132 weather sensor.

to handle this, my custom WDT_vect is setting a flag and directly after a wakeup. I check this flag and if it is not true I sleep again without reinitializing the WDT. In this way I sleep the amount of milliseconds from the WDT and "ignore" the interrupt for the wakeup.

now my question is how could this be supported by MySensors.

the simplest solution is to introduce a new DEFINE "MY_CUSTOM_WDT_VECT". If this is defined we could skip the empty WDT Vector from myHW... and rely completely on the custom solution. You have to take care to add this WDT_Vect.

Good thing is that it is very simple. Bad thing is that I still have to implement my own sleep function.

Another solution is to fix the mysensor sleep function. If I call sleep(10000), I want to sleep 10s. Also if an interrupt occurs in the mean time.

I personally would prefer the first one, because this described scenario is already an advanced scenario which is ok to be not handled by default. But with the new defined variable it gives you the maximum of flexibility also for upcoming situations where we have to implement a custom WDT.

how should I proceed. Is it ok to create a pull request for solution one or do you thing it is a bad way to go?

HolgerHees avatar Jul 19 '20 10:07 HolgerHees

Could we just give the WDT_vect a weak attribute (__attribute__((weak))), and let users override it (similar to what we do for receive(), before(), etc https://github.com/mysensors/MySensors/blob/3308df3a13fb3ded8e8a2b0384886cec966706f1/core/MySensorsCore.h#L460 ) ?

mfalkvidd avatar Jul 20 '20 22:07 mfalkvidd