From c5d069444ab9f912140e4fbb8b56e0e406d5f861 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Sun, 11 Feb 2024 13:01:03 -0800 Subject: [PATCH] Move alternate offset switch near the end of the current second to extend reconstruction range for timestamps in the past Signed-off-by: Alex Forencich --- rtl/ptp_td_phc.v | 6 +++--- tb/ptp_td.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rtl/ptp_td_phc.v b/rtl/ptp_td_phc.v index 9c84d4a8..bb7102a9 100644 --- a/rtl/ptp_td_phc.v +++ b/rtl/ptp_td_phc.v @@ -454,13 +454,13 @@ always @(posedge clk) begin adder_b_reg <= -NS_PER_S; adder_cin_reg <= 0; - if (ts_tod_ns_reg[29]) begin - // latter half of second; compute offset for next second + if (ts_tod_ns_reg[29:27] == 3'b111) begin + // latter portion of second; compute offset for next second adder_b_reg <= -NS_PER_S; update_state_reg <= 12; adder_busy_reg <= 1'b1; end else begin - // former half of second; compute offset for previous second + // former portion of second; compute offset for previous second adder_b_reg <= NS_PER_S; update_state_reg <= 14; adder_busy_reg <= 1'b1; diff --git a/tb/ptp_td.py b/tb/ptp_td.py index 635b7b99..cffa914b 100644 --- a/tb/ptp_td.py +++ b/tb/ptp_td.py @@ -255,12 +255,12 @@ async def _run(self): self.ts_tod_offset_ns = (self.ts_tod_ns - self.ts_rel_ns) & 0xffffffff # compute alternate offset - if self.ts_tod_ns & (1 << 29): - # latter half of second; compute offset for next second + if self.ts_tod_ns >> 27 == 7: + # latter portion of second; compute offset for next second self.ts_tod_alt_s = self.ts_tod_s+1 self.ts_tod_alt_offset_ns = (self.ts_tod_offset_ns - 1000000000) & 0xffffffff else: - # former half of second; compute offset for previous second + # former portion of second; compute offset for previous second self.ts_tod_alt_s = self.ts_tod_s-1 self.ts_tod_alt_offset_ns = (self.ts_tod_offset_ns + 1000000000) & 0xffffffff