There was a thread a long time ago to modify the CAN driver to use callbacks: viewtopic.php?f=3&t=282 . Any plan to modify HAL CAN?
I think the current system of broadcasting events should be replaced with ISR callbacks. This way, the driver could be used to 'push' the CAN frames into a queue in the ISR context so that they are never lost. As it is right now, the CAN RX processing thread would have to have enough priority to never miss a CAN frame being received - and may actually miss frames when a burst of them come thru (if it's priority isn't high enough).
Change CAN driver to use callbacks
- 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: Change CAN driver to use callbacks
Hi,
Disable events in chconf.h and OSAL will use callbacks instead.
Giovanni
Disable events in chconf.h and OSAL will use callbacks instead.
Giovanni
Re: Change CAN driver to use callbacks
Giovanni wrote:Hi,
Disable events in chconf.h and OSAL will use callbacks instead.
Giovanni
But then we can't use events elsewhere in the project ... Changing HAL CAN to be more like other drivers that use call backs, apart from better design and being more flexible, would also make the HAL interfaces more consistent.
Re: Change CAN driver to use callbacks
I suggest adding callbacks as an option, in the same way as I've done for the Serial Driver.
Basically, if a callback field (in the configuration structure) is non-null, it's used; otherwise an event is signalled. Certainly works well for serial.
I'll be playing with CAN in the coming weeks, and certainly got some mods to the driver; might look at this one at the same time.
Basically, if a callback field (in the configuration structure) is non-null, it's used; otherwise an event is signalled. Certainly works well for serial.
I'll be playing with CAN in the coming weeks, and certainly got some mods to the driver; might look at this one at the same time.
- 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: Change CAN driver to use callbacks
Hi,
I added experimental support for callbacks, it compiles but I haven't tested it.
Giovanni
I added experimental support for callbacks, it compiles but I haven't tested it.
Giovanni
- 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: Change CAN driver to use callbacks
Giovanni wrote:Any feedback about the changes?
Giovanni
Yes, thank you ! Just a small feedback: CAN_ENFORCE_USE_CALLBACKS should be checked by the preprocessor if it defined as TRUE or FALSE. From what I've seen this is more consistent with other drivers in HAL. In the header file, you could have a default definition if it is not defined.
I have not tested the changes yet, will probably do so in the coming week.
Re: Change CAN driver to use callbacks
Is there any code example to use these callbacks??
Is the following correct??
and adding
to mcuconf.h
Is the following correct??
Code: Select all
void cana_rx_ISR(CANDriver *canp, uint32_t flags);
void my_can_init()
{
CAND1.rxfull_cb = cana_rx_ISR;
canStart(&CAND1, &cancfg);
}
void cana_rx_ISR(CANDriver *canp, uint32_t flags)
{
(void)canp;
(void)flahs;
// do sth usefull
}
and adding
Code: Select all
#define CAN_ENFORCE_USE_CALLBACKS TRUE
Who is online
Users browsing this forum: No registered users and 3 guests