Page 1 of 2

Adding an argument to PAL event callbacks

Posted: Wed Apr 12, 2017 12:20 am
by austin_boulderes
I was excited to see that the PAL driver is getting events -- this seems like it'll be a much better way to handle sharing of interrupt resources between modules than the EXT driver.

As someone who'd like to have his cake and eat it too, however, I'd love to see palcallback_t be modified to have a generic pointer argument. Something like:

Code: Select all

typedef void (*palcallback_t)(void *);


with the event enable function then defined to be:

Code: Select all

#if !defined(pal_lld_enablepadevent) || defined(__DOXYGEN__)
#define palPadEnableEventI(port, pad, mode, callback, arg)
#else
#define palPadEnableEventI(port, pad, mode, callback, arg)                       \
  pal_lld_enablepadevent(port, pad, mode, callback, arg)
#endif


I've found this pattern greatly increases code reusability, and avoids forcing the use of file- or project-global variables. The cost (as far as I understand it) should be fairly low -- just an extra pointer saved alongside the callback itself.

I figured this would be a good time to make the request, since PAL event handling is still in its infancy.

Re: Adding an argument to PAL event callbacks

Posted: Wed Apr 12, 2017 7:49 am
by Giovanni
Hi,

Moving this in "bug reports" so it will not be lost, probably this will happen during next development cycle, currently I am just bug fixing before next release.

Giovanni

Re: Adding an argument to PAL event callbacks

Posted: Wed Apr 12, 2017 12:42 pm
by alex31
hello, i remember having asked for a user param in the callback years ago (for the EXTI module at the time: second question of old post), and i can confirm that this would be nice !

Alexandre -- nearly 5 years using ChibiOS, and still happy with it :-)

Re: Adding an argument to PAL event callbacks

Posted: Wed Apr 12, 2017 1:35 pm
by Giovanni
I am glad to hear that :)

Anyway, this is matter of next dev cycle, I will make a list of all things that should become part of HAL 6 at some point, there are several.

Giovanni

Re: Adding an argument to PAL event callbacks

Posted: Wed Apr 12, 2017 3:30 pm
by austin_boulderes
Great, I'm glad to see it!

Re: Adding an argument to PAL event callbacks

Posted: Thu Aug 17, 2017 6:43 pm
by josesimoes
+1 for having a parameter on the callback!
That is most useful for a lot of use cases.

Re: Adding an argument to PAL event callbacks

Posted: Tue Aug 29, 2017 9:53 am
by Giovanni
Hi,

Change implemented in repository trunk.

Giovanni

Re: Adding an argument to PAL event callbacks

Posted: Sat Sep 02, 2017 4:52 am
by FXCoder
Hi Giovanni,
Are you planning to make the PAL event system conditionally enabled?
I'm asking because the implementation in trunk so far takes over the EXT IRQ handler definitions unconditionally.
This causes a linker conflict with any user code implemented IRQ handler.

I've defined handlers in stm32_isr.c with __attribute__((weak)) as a temporary workaround only.

Thanks,

Bob

Re: Adding an argument to PAL event callbacks

Posted: Sat Sep 02, 2017 7:35 am
by Giovanni
Hi,

The idea is to remove EXT after the work is complete on PAL in HAL 6. EXT has always been an eyesore of a driver.

Giovanni

Re: Adding an argument to PAL event callbacks

Posted: Sat Sep 02, 2017 8:07 am
by FXCoder
OK. Understood that EXT will be deprecated (it did the job but was a little quirky).

However, sometimes a custom coded fast interrupt handler for EXTI (i.e. without the IRQ handler PROLOGUE/EPILOGUE) might be needed.
So then a means of implementing an IRQ handler which directly replaces the PAL event IRQ handler would be required.

Does that make sense?

Thanks,

Bob