Issues in getting hardware timestamps on Linux

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
Vicky
Posts: 2
Joined: Wed 15. Jan 2020, 15:55

Issues in getting hardware timestamps on Linux

Post by Vicky » Wed 15. Jan 2020, 16:17

Hello all,

I'm using one of the pcan PCI-FD devices on the Linux development environment. Since I want to get an HW timestamp from this interface, the usage of sockets won't do any good according to this link.
https://www.peak-system.com/forum/viewt ... =3435#wrap. Hence I'm using the char mode driver for data tx/rx. For the installation, I followed all the steps in the documentation and after successful install and insertion of modules, I was able to see the devices listed in the /dev directory. I also modified the *.conf file where deftsmode=2 was provided.

In order to test the driver, I used the receivetest provided in the test directory with appropriate arguments and I got the following output.

Code: Select all

2843402388.878 receivetest: m s 0x00000391 8 00 3c e3 00 00 26 00 10
2843402391.40 receivetest: m s 0x000003dc 8 fc 00 00 00 00 01 00 00
2843402391.266 receivetest: m s 0x000006b2 8 87 6f 35 42 89 e7 6a 07
2843402393.142 receivetest: m e 0x1b000046 8 46 00 04 01 01 00 00 00
2843402393.378 receivetest: m s 0x0000030c 8 e8 f5 3f ff 63 30 00 00
2843402394.385 receivetest: m s 0x0000032a 8 92 0b 00 00 00 02 00 00
2843402395.301 receivetest: m e 0x17333410 8 3d 02 03 01 34 00 03 00
2843402396.999 receivetest: m s 0x00000101 8 6e 05 7e ff 81 16 00 00
2843402398.833 receivetest: m s 0x000003c7 8 01 00 10 00 00 40 a2 00
2843402403.59 receivetest: m s 0x00000107 8 00 00 fe 00 c0 31 00 00
2843402403.348 receivetest: m e 0x1b00004a 8 4a 00 04 01 11 00 00 00
2843402404.48 receivetest: m s 0x0000030b 8 10 25 00 00 08 00 00 10
2843402406.952 receivetest: m s 0x000000fd 8 b7 d5 1f 80 00 00 00 00
2843402413.314 receivetest: m s 0x00000324 8 44 05 00 00 00 00 00 00
So, as we can see from the above output that the epoch timestamps are completely off when compared to the actual epoch (not printed). I would be happy if someone from the community could point what mistake i'm doing and what could be done to rectify this problem.

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

Re: Issues in getting hardware timestamps on Linux

Post by S.Grosjean » Thu 16. Jan 2020, 09:39

Hi,

"receivetest" is kept "as is" for historical reasons: it uses the old CAN API locked to CAN 2.0:

Code: Select all

typedef struct pcan_rd_msg {
        TPCANMsg Msg;          // the above message
        DWORD    dwTime;       // a timestamp in msec, read only
        WORD     wUsec;        // remainder in micro-seconds
} TPCANRdMsg;            // for PCAN_READ_MSG
As you can see, the time in ms. for that API is a 32-bit value, therefore the value receivetest displays is a counter which value has wrapped (epoch ~157916772 s. = [016F ]AD60 5FE0 ms = 2908774368 ms.). Thus, this API should only be used to get relative times rather than absolute times. Either your application should take now this wrapping into account or (better) it should run other the new library that is much more efficient and handles CAN FD. The other example program named "pcanfdtst" (see 4.7.5) shows how things run with this new API (see also Figure 1 p 44):
Annotation 2020-01-16 093658.png
Annotation 2020-01-16 093658.png (74.08 KiB) Viewed 1575 times
With this API you'll get absolute times.

FYI: 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 the next Kernel 5.5 release candidates.

Regards,
— Stéphane

JGarza
Posts: 17
Joined: Wed 2. Dec 2020, 12:01

Re: Issues in getting hardware timestamps on Linux

Post by JGarza » Tue 17. May 2022, 11:59

Hello,

Im using the PCI card for recording CAN messages and I use candump with hardware timestamp, I get the timestamps in the following format: 1970-01-01 01:00:03.222598
can this be converted to the current time? the timestamp should correspond to this date/time: 2022-05-09 13:27:19. If I use software timestamps then the timestamps of consecutive
messages are the same and the messages are no longer useful.

I can set the format to be in epoch in seconds but still when converting I get the format: 1970-01-01 01:00:03.222598

Thanks for the support.

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

Re: Issues in getting hardware timestamps on Linux

Post by S.Grosjean » Tue 17. May 2022, 17:10

Hello,

Can you please give us much more information about this "PCI" card?

FYI, if you're talking about the "PCAN-PCI" card (which partnum is IPEH-002064/2065/2066/2067) then you won't be able to get any "hardware" timestamp since the hardware does not provide them.

Otherwise, we need to know which driver you use: the mainline socket-can driver (that is, the native one) or do you use the peak-linux-driver (aka pcan) in NETDEV mode (which also offers a socket-can interface)?

Thanks and regards,
— Stéphane

JGarza
Posts: 17
Joined: Wed 2. Dec 2020, 12:01

Re: Issues in getting hardware timestamps on Linux

Post by JGarza » Wed 18. May 2022, 09:51

Hello,

The PCI card is a IPEH-004040. I use following command: candump can0 -ta -H.

Thanks for the support.

JGarza
Posts: 17
Joined: Wed 2. Dec 2020, 12:01

Re: Issues in getting hardware timestamps on Linux

Post by JGarza » Wed 18. May 2022, 09:52

Yes, I use the socket CAN driver not the Peak Netdev version.

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

Re: Issues in getting hardware timestamps on Linux

Post by S.Grosjean » Wed 18. May 2022, 10:15

Hi,

Ok, thank you for the replies.

The hw timestamps are given to the socket-can "as is", that is, these are not related to any CLOCKs of the Kernel but are "only" microseconds counters. Therefore, you can't interpret their values as any time of day.
When powered on, this counter starts from 0. This explains why the "date" is close to 1970-01-01.

Regards,
— Stéphane

JGarza
Posts: 17
Joined: Wed 2. Dec 2020, 12:01

Re: Issues in getting hardware timestamps on Linux

Post by JGarza » Thu 2. Jun 2022, 09:52

From what you wrote of powering the PCI card ON, is there a way to find out this time? so that I can save it somewhere and add it to the time of the values I get from the candump. Thanks.
Regards,
Jorge Garza

Post Reply