Skip to content

Commit c5d0694

Browse files
committed
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 <[email protected]>
1 parent 870cebb commit c5d0694

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

rtl/ptp_td_phc.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,13 @@ always @(posedge clk) begin
454454
adder_b_reg <= -NS_PER_S;
455455
adder_cin_reg <= 0;
456456

457-
if (ts_tod_ns_reg[29]) begin
458-
// latter half of second; compute offset for next second
457+
if (ts_tod_ns_reg[29:27] == 3'b111) begin
458+
// latter portion of second; compute offset for next second
459459
adder_b_reg <= -NS_PER_S;
460460
update_state_reg <= 12;
461461
adder_busy_reg <= 1'b1;
462462
end else begin
463-
// former half of second; compute offset for previous second
463+
// former portion of second; compute offset for previous second
464464
adder_b_reg <= NS_PER_S;
465465
update_state_reg <= 14;
466466
adder_busy_reg <= 1'b1;

tb/ptp_td.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ async def _run(self):
255255
self.ts_tod_offset_ns = (self.ts_tod_ns - self.ts_rel_ns) & 0xffffffff
256256

257257
# compute alternate offset
258-
if self.ts_tod_ns & (1 << 29):
259-
# latter half of second; compute offset for next second
258+
if self.ts_tod_ns >> 27 == 7:
259+
# latter portion of second; compute offset for next second
260260
self.ts_tod_alt_s = self.ts_tod_s+1
261261
self.ts_tod_alt_offset_ns = (self.ts_tod_offset_ns - 1000000000) & 0xffffffff
262262
else:
263-
# former half of second; compute offset for previous second
263+
# former portion of second; compute offset for previous second
264264
self.ts_tod_alt_s = self.ts_tod_s-1
265265
self.ts_tod_alt_offset_ns = (self.ts_tod_offset_ns + 1000000000) & 0xffffffff
266266

0 commit comments

Comments
 (0)