Hardware Timestamps from kernel module

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
pevsonic
Posts: 4
Joined: Thu 5. Nov 2015, 12:55

Hardware Timestamps from kernel module

Post by pevsonic » Mon 16. Sep 2019, 12:51

Hi all,

I've got several different Peak CAN interfaces that we use on development / test rigs for some physical hardware. To control the interface I've got a kernel module that I've written that's basically a fork of the CAN-BCM module but adapted for more controlled deterministic message tx/rx rather than the basic cyclic transmission.

What I'm wanting to do is get hardware time-stamps from within the kernel module to look at received packets from the device under test and measure accuracy etc. However, I can't see a way to do this - is it possible?

Likewise, when I was last working on this (about a year or so ago!) I had to use the separate peak driver for hardware timestamping, is this still the case or can I use the mainline kernel driver now?

Thanks!

~Pev

User avatar
S.Grosjean
Software Development
Software Development
Posts: 321
Joined: Wed 4. Jul 2012, 17:02

Re: Hardware Timestamps from kernel module

Post by S.Grosjean » Mon 16. Sep 2019, 14:38

Hello,

Depending on your PEAK-Sytem CAN interface:
  • The peak_usb driver for the PEAK-System USB devices give hardware timestamps to the network layer.
  • The peak_pci driver doesn't provide hardware timestamps because the SJA1000 controller does not allow it.
  • The peak_pciefd doesn't provide hardware timestamps at the moment but should in a future version of the Kernel.
You could also use our pcan driver that proposes hw timestamps for all interfaces as well as the socket-can interface.

Regards,
— Stéphane

pevsonic
Posts: 4
Joined: Thu 5. Nov 2015, 12:55

Re: Hardware Timestamps from kernel module

Post by pevsonic » Mon 16. Sep 2019, 16:41

Hi Stephane,

Thanks for the quick reply!

So, the two interfaces that I think I can use with hardware timestamps are the PCAN-USB Pro and PCAN-USB X6, is that right?

I've got a simple test app that Im playing with based off the linux-can test code :
https://github.com/linux-can/can-tests/ ... x-sendto.c

Are you saying that for these interfaces, the value gained via ioctl(s, SIOCGSTAMP, &tv) in the code above should, by default, be the hardware timestamp value from the interface when using either peak_usb or pcan drivers?

I only ask as the last time I looked at this, I think I ended up trying to follow the instructions at :
https://www.kernel.org/doc/Documentatio ... amping.txt

if memory serves me, I tried to configure manually via SIOCSHWTSTAMP and could never get to work... Is there any example code you may be able to point me at?

Also, in your opinion, is there any reason I should use either the peak_usb driver or pcan driver specifically? I don't have any particular leaning either way currently.

Thanks!

User avatar
S.Grosjean
Software Development
Software Development
Posts: 321
Joined: Wed 4. Jul 2012, 17:02

Re: Hardware Timestamps from kernel module

Post by S.Grosjean » Tue 17. Sep 2019, 11:38

Hi,

Having a look to candump.c (https://github.com/linux-can/can-utils) should show you how to request the so called hardware timestamps from a linux-can managed CAN interface. In particular:

Code: Select all

if (timestamp || log || logfrmt) {

        if (hwtimestamp) {
Regards,
— Stéphane

User avatar
S.Grosjean
Software Development
Software Development
Posts: 321
Joined: Wed 4. Jul 2012, 17:02

Re: Hardware Timestamps from kernel module

Post by S.Grosjean » Thu 16. Jan 2020, 10:02

Hi,

UPDATE: the ability to get hardware timestamps from the PCAN PCIe FD cards family using the socket-can peak_pciefd mainline driver, was pushed to the linux-can maintainers list during September 2019. It is now part of next Kernel 5.5 release candidates.

Regards,
— Stéphane

Post Reply