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.