Skip to content

Commit

Permalink
Convert ticks from hardware timestamp
Browse files Browse the repository at this point in the history
When getting the hardware timestamp, the higher resolution part is measured
in ticks and a conversion based on the nominal clocks is done to convert
to user units
  • Loading branch information
EmilioPeJu committed Feb 15, 2024
1 parent 1889c83 commit 6c95ae6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config_d/registers
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BLOCKS_COMPAT_VERSION = 0

# Hardware timestamps
PCAP_TS_SEC 10
PCAP_TS_NSEC 11
PCAP_TS_TICKS 11

# Position capture control
PCAP_ARM 13
Expand Down
6 changes: 2 additions & 4 deletions server/data_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ static void update_start_timestamp(void)
pcap_start_ts = pcap_drv_start_ts;
pcap_hw_ts_offset_ns_valid = false;
} else {
int64_t drv_ts_num =
(int64_t) pcap_drv_start_ts.tv_sec * 1000000000
int64_t drv_ts_num = (int64_t) pcap_drv_start_ts.tv_sec * NSECS
+ pcap_drv_start_ts.tv_nsec;
int64_t hw_ts_num =
(int64_t) pcap_hw_start_ts.tv_sec * 1000000000
int64_t hw_ts_num = (int64_t) pcap_hw_start_ts.tv_sec * NSECS
+ pcap_hw_start_ts.tv_nsec;
pcap_start_ts = pcap_hw_start_ts;
pcap_hw_ts_offset_ns = drv_ts_num - hw_ts_num;
Expand Down
5 changes: 4 additions & 1 deletion server/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ void hw_get_start_ts(struct timespec *ts)
void hw_get_hw_start_ts(struct timespec *ts)
{
ts->tv_sec = (time_t) read_named_register(PCAP_TS_SEC);
ts->tv_nsec = (typeof(ts->tv_nsec)) read_named_register(PCAP_TS_NSEC);
ts->tv_nsec = (typeof(ts->tv_nsec)) ((double)
read_named_register(PCAP_TS_TICKS) * NSECS / hw_read_nominal_clock());
ts->tv_sec = ts->tv_nsec / NSECS;
ts->tv_nsec = ts->tv_nsec % NSECS;
}

#endif
Expand Down

0 comments on commit 6c95ae6

Please sign in to comment.