Skip to content

Commit

Permalink
Move alternate offset switch near the end of the current second to ex…
Browse files Browse the repository at this point in the history
…tend reconstruction range for timestamps in the past

Signed-off-by: Alex Forencich <[email protected]>
  • Loading branch information
alexforencich committed Feb 11, 2024
1 parent 870cebb commit c5d0694
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions rtl/ptp_td_phc.v
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tb/ptp_td.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c5d0694

Please sign in to comment.