Adding an argument to PAL event callbacks Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
austin_boulderes
Posts: 10
Joined: Wed Nov 05, 2014 9:38 pm
Has thanked: 1 time
Been thanked: 1 time

Adding an argument to PAL event callbacks

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Adding an argument to PAL event callbacks

Post 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
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Adding an argument to PAL event callbacks

Post 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 :-)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Adding an argument to PAL event callbacks

Post 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
austin_boulderes
Posts: 10
Joined: Wed Nov 05, 2014 9:38 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Adding an argument to PAL event callbacks

Post by austin_boulderes »

Great, I'm glad to see it!
josesimoes
Posts: 91
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 43 times
Been thanked: 23 times

Re: Adding an argument to PAL event callbacks

Post by josesimoes »

+1 for having a parameter on the callback!
That is most useful for a lot of use cases.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Adding an argument to PAL event callbacks

Post by Giovanni »

Hi,

Change implemented in repository trunk.

Giovanni
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Adding an argument to PAL event callbacks

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Adding an argument to PAL event callbacks

Post 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
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Adding an argument to PAL event callbacks

Post 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
Post Reply