Linux timestamp

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
redaNex
Posts: 2
Joined: Thu 27. Sep 2018, 11:58

Linux timestamp

Post by redaNex » Thu 27. Sep 2018, 12:23

Hello,

I use 2 CAN-miniPCIe cards in a Linux system, for historical reasons I use the driver V7.10.

I need to get the absolute date of CAN frames: the Linux system date.
This poses several questions:

How to get the current date used for the time stamp (there is CAN_GetSystemTime, but how to do it with libpcan)?

Is there a drift between the Linux system clock and the clock used by the CAN frame timestamp?

I use 2 CAN-miniPCIe cards in the same system. Are the timestamps of the 2 cards synchronous: does the same message received by the 2 cards have the same timestamp, even after several hours of use?

Best regards

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

Re: Linux timestamp

Post by S.Grosjean » Thu 27. Sep 2018, 16:41

Hello,

Due to the fact that such cards are SJA1000 based, the received CAN frames are time stamped with the host time, at the moment the frame has been read from the controller. There is no possibility of any hardware timestamps in that case. Thus, there is no notion of any clock drift at all.

This old version of pcan provides only timestamps expressed in ms + us, based on the time the driver has been loaded. That is, timestamps start from 0.000. There is no way for the application to get the time base of the driver.

You could anyway try something:

1 - edit "driver/src/pcan_main.c"
2 - search "get_relative_time()" function
3 - add a comment ("//") in front of the last line of the function

You should get this:

Code: Select all

// get relative time to start of driver
void get_relative_time(struct timeval *tv, struct timeval *tr)
{
  if (!tv)
    DO_GETTIMEOFDAY((*tr));
  else
    memcpy(tr, tv, sizeof(*tr));

//  subtract_timeval(tr, &pcan_drv.sInitTime);
}
4 - save your modification
5 - rebuild the driver (and reinstall it).

Doing this, you'll get absolute timestamps. Note that your application SHOULD handle the wrapping of the "ms" counter!

Hope this helps.
— Stéphane

redaNex
Posts: 2
Joined: Thu 27. Sep 2018, 11:58

Re: Linux timestamp

Post by redaNex » Fri 28. Sep 2018, 11:08

Thank you for these valuable informations.

To go further, by posing some restrictions:
- Use only the PCIE driver, chardev version
- Use only the libpcan librarie
- Only use my app

Can I get a system date for the frame instead of a ms/us date by doing:
- modify the structure TPCANRdMsg (WORD wUsec become DWORD wUsec)
- Update the very few places using wUsec like pcan_parse.c
- I remove "subtract_timeval ()" call from get_relative_time ()
- I remove timeval2pcan() call in pcan_chardev_rx() function in pcan_main_linux.c file

Build driver and library

Could it work or I forgot something?

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

Re: Linux timestamp

Post by S.Grosjean » Fri 28. Sep 2018, 11:34

Hi,

As far as you know what you're doing, you can change the sources files of the pcan driver by your own. If the change is an improvement that concern the community of pcan users, you should share it with everyone in that forum.

Simply note that we won't be able to help you in fixing issues that might come from a modified pcan driver.

Regards,
— Stéphane

Post Reply