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 16, 2024
1 parent 1889c83 commit a335b79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 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
13 changes: 7 additions & 6 deletions server/data_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ static void update_start_timestamp(void)
struct timespec pcap_drv_start_ts, pcap_hw_start_ts;
hw_get_start_ts(&pcap_drv_start_ts);
hw_get_hw_start_ts(&pcap_hw_start_ts);
if (pcap_hw_start_ts.tv_sec == 0 && pcap_hw_start_ts.tv_nsec == 0) {
if (pcap_hw_start_ts.tv_sec == 0 && pcap_hw_start_ts.tv_nsec == 0)
{
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
}
else
{
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)) ((uint64_t)
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 a335b79

Please sign in to comment.