diff options
author | Marcin Miklas <marcin.miklas@symphonyteleca.com> | 2015-09-15 15:36:08 +0200 |
---|---|---|
committer | Marcin Miklas <marcin.miklas@symphonyteleca.com> | 2015-09-16 10:00:17 +0200 |
commit | ad1d4f6164bd96ea3bf93e89feff7b6cc6605b0e (patch) | |
tree | 47d28ed86fc5f06c4d618182905aa6b26cd2b880 | |
parent | ab4e2c73ca1aa433af81b6099d644686534f5e96 (diff) | |
download | Open-AVB-ad1d4f6164bd96ea3bf93e89feff7b6cc6605b0e.tar.gz |
gptplocaltime() localtime.
Returns localtime calculated based on current system time.
-rw-r--r-- | examples/common/avb.c | 24 | ||||
-rw-r--r-- | examples/common/avb.h | 2 |
2 files changed, 26 insertions, 0 deletions
diff --git a/examples/common/avb.c b/examples/common/avb.c index fb056149..e24cb3cd 100644 --- a/examples/common/avb.c +++ b/examples/common/avb.c @@ -137,6 +137,30 @@ int gptpscaling(gPtpTimeData * td, char *memory_offset_buffer) return true; } +bool gptplocaltime(const gPtpTimeData * td, uint64_t* now_local) +{ + struct timespec sys_time; + uint64_t now_system; + uint64_t system_time; + int64_t delta_local; + int64_t delta_system; + + if (!td || !now_local) + return false; + + if (clock_gettime(CLOCK_REALTIME, &sys_time) != 0) + return false; + + now_system = sys_time.tv_sec * 1000000000 + sys_time.tv_nsec; + + system_time = td->local_time + td->ls_phoffset; + delta_system = now_system - system_time; + delta_local = td->ls_freqoffset * delta_system; + *now_local = td->local_time + delta_local; + + return true; +} + /* setters & getters for seventeen22_header */ void avb_set_1722_cd_indicator(seventeen22_header *h1722, uint64_t cd_indicator) { diff --git a/examples/common/avb.h b/examples/common/avb.h index 07c938e6..0a96ad5b 100644 --- a/examples/common/avb.h +++ b/examples/common/avb.h @@ -112,6 +112,8 @@ int pci_connect(device_t * igb_dev); int gptpscaling(gPtpTimeData * td, char *memory_offset_buffer); +bool gptplocaltime(const gPtpTimeData * td, uint64_t* now_local); + void gptpdeinit(int shm_fd, char *memory_offset_buffer); int gptpinit(int *shm_fd, char **memory_offset_buffer); |