Argument to PAL UART 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.
josesimoes
Posts: 91
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 43 times
Been thanked: 23 times

Argument to PAL UART callbacks  Topic is solved

Postby josesimoes » Mon Aug 27, 2018 3:42 pm

Unlike several other callbacks the UART are missing an argument. Having that is VERY VERY handy for a bunch of use cases.
I couldn't find any thread requesting this, but I would be surprised if I was the first suggesting this.

Please consider this suggestion for a future improvement or link to an already existing suggestion!

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Argument to PAL UART callbacks

Postby RoccoMarco » Mon Aug 27, 2018 8:55 pm

HI,
Moved in a more proper section.

Anyway we are talking of PAL or UART? Can you explain with a code example what you are talking about?
Ciao,
RM

josesimoes
Posts: 91
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 43 times
Been thanked: 23 times

Re: Argument to PAL UART callbacks

Postby josesimoes » Mon Aug 27, 2018 9:58 pm

Hi,

Thanks for the prompt reply!

Here's an example of a callback that has args: palSetLineCallback
You have the line, the callback AND an argument that you can pass whatever is convinient for your code AT the event handler.

On the other hand UARTConfig has several callbacks for Tx, Rx, etc (uartcb_t) but that declaration only accepts the UARTDriver as argument. If it could accept a void arg as the above, it would be awesome because one could use that in the event handler (if needed, of course).

As we are at it, this is valid for any other driver callback that does not support args, btw.


Hope I've explained myself a little better now! ;)

apmorton
Posts: 36
Joined: Fri Sep 29, 2017 10:26 am
Been thanked: 16 times

Re: Argument to PAL UART callbacks

Postby apmorton » Wed Sep 05, 2018 11:33 am

I haven't looked at all drivers, but it seems like a pretty common pattern in ChibiOS HAL.

At least for the UART driver it exists.

https://github.com/ChibiOS/ChibiOS/blob ... lld.h#L550

If you add the following to your halconf you can include any additional fields in the UARTDriver structure that you need.

Code: Select all

#define UART_DRIVER_EXT_FIELDS \
void *mycontext; \
int myotherthing;


Since the callbacks get a pointer to the UARTDriver structure you can access them like so:

Code: Select all

void txend1_cb(UARTDriver *uartp) {
   MyContextType *ctx = (MyContextType*)uartp->mycontext;
   
   doSomething(ctx, ...);
}

josesimoes
Posts: 91
Joined: Sat Feb 18, 2017 11:50 am
Has thanked: 43 times
Been thanked: 23 times

Re: Argument to PAL UART callbacks

Postby josesimoes » Wed Sep 05, 2018 11:51 am

That looks promising. Thanks for the tip! :)

My suggestion with arguments was to make it kind of in line with other drivers callbacks.
It should do its purpose with any of those alternatives.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Argument to PAL UART callbacks

Postby Giovanni » Sat Jan 05, 2019 4:58 pm

Hi,

HAL callbacks do not have parameters, this is true for all driver except PAL (see below), this is not necessary because you can extend the driver structure as suggested by apmorton.

The PAL driver has arguments because it is a special case, it does not have an object that can be extended.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 13 guests