CAN driver

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
jschall
Posts: 25
Joined: Wed Sep 06, 2017 4:29 am
Has thanked: 2 times

Re: CAN driver

Postby jschall » Fri Nov 24, 2017 11:37 pm

Actually, there may be no way of doing this, because the internal counter used in TTCM is not exposed in any documented register...

jschall
Posts: 25
Joined: Wed Sep 06, 2017 4:29 am
Has thanked: 2 times

Re: CAN driver

Postby jschall » Sat Nov 25, 2017 2:33 am

Here's a patch for review. I think it actually fixes some bugs with the canTransmitTimeout and canReceiveTimeout functions, where they could block for longer than timeout.

https://drive.google.com/file/d/1QbyYGM ... sp=sharing

steved
Posts: 518
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 50 times

Re: CAN driver

Postby steved » Mon Nov 27, 2017 3:47 pm

Can you suggest a utility for applying the patches under Windows, given that I don't operate a git repository?

(Or possibly just zip up the changed files - Winmerge works well for reviewing the changes, and would usually be the next step after applying the pach anyway!)

steved
Posts: 518
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 50 times

Re: CAN driver

Postby steved » Mon Nov 27, 2017 3:53 pm

jschall wrote:
jschall wrote:For a reference on the speed setting API, maybe check out Pavel Kirienko's libcanard driver (MIT-licensed): https://github.com/UAVCAN/libcanard/blo ... m32.h#L174

Thanks; that looks a useful way of doing it, and nicely generic, at first sight.

I've also thought a bit about the mode setting routine. That needs to control a line which switches the hardware-level CAN driver between normal and monitor modes, so will have to consider the best way to implement that.

jschall
Posts: 25
Joined: Wed Sep 06, 2017 4:29 am
Has thanked: 2 times

Re: CAN driver

Postby jschall » Fri Dec 08, 2017 5:48 pm

Also for reference: I've given up on the ChibiOS driver and written my own abstraction layer and driver. Perhaps it can be adapted and adopted.

Code: Select all

- Transmit priority queue
- Transmit frame allocator based on a memory pool - supports atomic allocation of a group of frames
- Atomic allocation of a list of frames
- Transmit timestamp publishing on custom publish-subscribe system
- Frame expiration
- Guarantees FIFO ordering of messages with the same priority
- Handles the inner priority inversion problem by only enqueueing frames in hardware when they will be highest priority in the hardware queue
    - Ready to support more complex schemes where transmission is aborted to allow a higher priority frame to be enqueued
- Abstraction layer that supports multiple driver backends, which may later include SPI CAN controllers (which the ChibiOS HAL would need to be redesigned to support, I think?)
- Timestamps received messages, publishes on pubsub


One issue is that the transmit queue is not very memory efficient - a transmit frame currently sits at about 32 bytes. I intend to change it so that there are will be two types of objects - frames and frame group headers. Frames will have ID, payload and payload length and next pointer. Frame group headers will have a frame list head, creation time, expiration time, and the pubsub topic to publish the transmit timestamp on. Timestamps may be changed to 16-bit to further conserve memory.

Another issue is configuration for assigning instance IDs to drivers. That should be relatively trivial to set up.

As far as adopting it for ChibiOS - as-is it doesn't fit all that well with the ChibiOS model. It is maybe slightly more opinionated than a ChibiOS driver as to how it should be used - e.g. the use of pubsub, inclusion of a transmit queue and allocator.

Abstraction layer:
https://github.com/OpenMotorDrive/frame ... odules/can

Driver:
https://github.com/OpenMotorDrive/frame ... iver_stm32

jschall
Posts: 25
Joined: Wed Sep 06, 2017 4:29 am
Has thanked: 2 times

Re: CAN driver

Postby jschall » Fri Dec 08, 2017 5:50 pm

steved wrote:Can you suggest a utility for applying the patches under Windows, given that I don't operate a git repository?

(Or possibly just zip up the changed files - Winmerge works well for reviewing the changes, and would usually be the next step after applying the pach anyway!)


Yes: Ubuntu under a virtual machine or in an amazon AWS instance, or Cygwin.

steved
Posts: 518
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 50 times

Re: CAN driver

Postby steved » Thu Feb 22, 2018 11:35 am

Been thinking about the priority inversion problem. If I've read the patch file correctly, the proposed code reads messages back out of the CAN peripheral to determine their priority. This sounds like quite an overhead.
As an alternative, how about the transmit routine maintaining a store of the priority of the last message sent to each mailbox? Then update this in the sending routine to reflect the transmit status flags. Finding the highest priority message available for transmission is then a question of examining these locations.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 1 guest