This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/AM4378: PTP timestamp

Part Number: AM4378
Other Parts Discussed in Thread: AM4379,

Tool/software: Code Composer Studio

Hi:

I am trying to use the timestamp.

Host :Ubuntu 18

1.When I try to read the timestamp by this code in my Host:

if (clock_gettime(CLOCK_REALTIME, &ts)) {
perror("clock_gettime");
} 
else {
printf("clock time: %ld.%09ld or %s",
ts.tv_sec, ts.tv_nsec, ctime(&ts.tv_sec));
}

It shows:

clock time: 1570078608.584780715 or Thu Oct  3 12:56:48 2019

and that is correct.

2.But when I try to use this in my Host:

#define DEVICE "/dev/ptp0"
char *device = DEVICE;
fd = open(device, O_RDWR);
if (fd < 0) {
	fprintf(stderr, "opening %s: %s\n", device, strerror(errno));
	return -1;
}
clkid = get_clockid(fd);
if (clock_gettime(clkid, &ts)) {
perror("clock_gettime");
} 
else {
printf("clock time: %ld.%09ld or %s",
ts.tv_sec, ts.tv_nsec, ctime(&ts.tv_sec));
}

It shows:

clock time: 1570107585.623349515 or Thu Oct 3 20:59:45 2019

SO what make the two results different?

--------------------------------------------------------------------------------------------------

3.Then,I try to synchronize my board

My board:AM4379

Host(ubuntu):sudo  ./ptp4l -E -2 -H -i enp4s0 -l 7 -m -q -p /dev/ptp0 
Slave(board):sudo ./ptp4l -E -2 -H -i eth0 -s -l 7 -m -q -p /dev/ptp0

It works!my board shows:

In my board,I use this code to read timestamp

#define DEVICE "/dev/ptp0"
char *device = DEVICE;
fd = open(device, O_RDWR);
if (fd < 0) {
	fprintf(stderr, "opening %s: %s\n", device, strerror(errno));
	return -1;
}
clkid = get_clockid(fd);
if (clock_gettime(clkid, &ts)) {
perror("clock_gettime");
} 
else {
printf("clock time: %ld.%09ld or %s",
ts.tv_sec, ts.tv_nsec, ctime(&ts.tv_sec));
}

It shows:

the time is correct but the timestamp is not the same to my host

---------------------------------------------------------------------------------------------------------------

I want to get the timestamp in my board.the timestamp should be the same with my host(Ubuntu)

So what is the problem maybe?

Regards.

  • Hi,

    You have two threads on this topic, I closed the other thread and we will work on your question in this thread. Are you using this code here?

    https://www.mjmwired.net/kernel/Documentation/ptp/testptp.c

    What is the file system that you are running on the target board, the TI SDK file system? Are you using a TI EVM or a custom board?

    Best Regards,

    Schuyler

  • Hi:

    1.yes,I am using this code.

    ./testptp -g

    2.No ,I am just running linux.it is a minimal version of linux I ported 

    3.I have two board,a TI am4378 evm and a custorm board.

    I have tried on two boards.the result is the same...

    I have check the driver files  of My linux,it  is the same to the TI-sdk-linux

    ,and the /dev/ptp0 is existed.

    So is it the right way to get the timestamp?

    Best Regards

  • user4941429 said:
    the time is correct but the timestamp is not the same to my host

    The code calls ctime to convert the time to a string, and ctime takes account of the local timezone which has been set. If the timezone is not set the same on the Ubuntu host and the AM4379 board that will cause ctime to report different timestamps. Try calling gmtime instead of ctime, since gmtime outputs UTC time.

    user4941429 said:
    SO what make the two results different?

    Your command to synchronise the clocks show only ptp4l being used. ptp4l synchronises the PTP clock but doesn't synchronise the system CLOCK_REALTIME to the PTP clock. To synchronise CLOCK_REALTIME to the PTP clock you also need to run phc2sys.

  • Hi:

     I am uising this:

    sudo ./phc2sys  -c /dev/ptp0 -s CLOCK_REALTIME -O 0 -m

    to ynchronise the system CLOCK_REALTIME to the PTP clock

    And it works!!!!!!!!

    Thank you!!!

    But I still have a question

    Host(ubuntu):sudo ./ptp4l -E -2 -H -i enp4s0 -l 7 -m -q -p /dev/ptp0
    Slave(board):sudo ./ptp4l -E -2 -H -i eth0 -s -l 7 -m -q -p /dev/ptp0

    And I use this code to read the timestamp both in my Board and my Host

    #define DEVICE "/dev/ptp0"
    char *device = DEVICE;
    fd = open(device, O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "opening %s: %s\n", device, strerror(errno));
        return -1;
    }
    clkid = get_clockid(fd);
    if (clock_gettime(clkid, &ts)) {
    perror("clock_gettime");
    }
    else {
    printf("clock time: %ld.%09ld or %s",
    ts.tv_sec, ts.tv_nsec, ctime(&ts.tv_sec));
    }
    

    the result was:

    above is my host,then below my board

    there is about 1570536143.566200472 - 1570536143.598541915 =  - 0.032341443  difference

    It seems that they are not exactly the same.

    How can I  make them  exactly the same or almost the same.

    It seems the accuracy  isn't very good..

    Regards.

  • Hi,

    Concerning the accuracy question how are the two machines synchronized to read the time stamps? What is the accuracy level that you are trying to get to?

    Best Regards,

    Schuyler

  • Hi,

    Since we have not heard back we will assume that you were able to move past this issue and I will close the thread. 

    Best Regards,

    Schuyler

  • Hi:

    Sorry so long to reply you.

    I think difference about  0.003  is OK