diff --git a/rtl/ptp_td_phc.v b/rtl/ptp_td_phc.v index 9c84d4a82..0f3f1357c 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 635b7b994..cffa914b6 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