Skip to content

Commit

Permalink
Fix timestamp capture/sync logic
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Forencich <alex@alexforencich.com>
  • Loading branch information
alexforencich committed Nov 30, 2023
1 parent 16cd841 commit 5560fa2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions rtl/ptp_clock_cdc.v
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ always @(posedge output_clk) begin
ts_capt_valid_reg <= 1'b1;
end

ts_sync_valid_reg <= 1'b0;

if (src_sync_sync2_reg ^ src_sync_sync3_reg) begin
// store captured source TS
if (TS_WIDTH == 96) begin
Expand All @@ -501,7 +499,11 @@ always @(posedge output_clk) begin
src_ts_ns_sync_reg <= src_ts_ns_capt_reg;
src_ts_step_sync_reg <= src_ts_step_capt_reg;

ts_sync_valid_reg <= ts_capt_valid_reg;
ts_sync_valid_reg <= 1'b1;
end

if (ts_sync_valid_reg && ts_capt_valid_reg) begin
ts_sync_valid_reg <= 1'b0;
ts_capt_valid_reg <= 1'b0;
end

Expand Down Expand Up @@ -595,7 +597,7 @@ always @* begin
ts_ns_next = ts_ns_reg + period_ns_reg;
end

if (ts_sync_valid_reg) begin
if (ts_sync_valid_reg && ts_capt_valid_reg) begin
// Read new value
if (TS_WIDTH == 96) begin
if (src_ts_step_sync_reg || load_ts_reg) begin
Expand Down
12 changes: 6 additions & 6 deletions rtl/ptp_td_leaf.v
Original file line number Diff line number Diff line change
Expand Up @@ -533,24 +533,24 @@ always @(posedge clk) begin
dst_load_cnt_reg <= dst_load_cnt_reg + 1;
end

ts_sync_valid_reg <= 1'b0;

if (src_sync_sync2_reg ^ src_sync_sync3_reg) begin
// store captured source TS
src_ns_sync_reg <= src_ns_reg >> (SRC_FNS_W-CMP_FNS_W);

ts_sync_valid_reg <= ts_capt_valid_reg;
ts_capt_valid_reg <= 1'b0;
ts_sync_valid_reg <= 1'b1;
end

if (src_marker_sync2_reg ^ src_marker_sync3_reg) begin
dst_load_cnt_reg <= 0;
end

phase_err_out_valid_reg <= 1'b0;
if (ts_sync_valid_reg) begin
if (ts_sync_valid_reg && ts_capt_valid_reg) begin
// coarse phase locking

ts_sync_valid_reg <= 1'b0;
ts_capt_valid_reg <= 1'b0;

// phase and frequency detector
phase_last_src_reg <= src_ns_sync_reg[8+CMP_FNS_W];
phase_last_dst_reg <= dst_ns_capt_reg[8+CMP_FNS_W];
Expand Down Expand Up @@ -827,7 +827,7 @@ always @* begin
end
end

if (ts_sync_valid_reg) begin
if (ts_sync_valid_reg && ts_capt_valid_reg) begin
// compute difference
ts_ns_diff_valid_next = freq_locked_reg;
ts_ns_diff_next = src_ns_sync_reg - dst_ns_capt_reg;
Expand Down

0 comments on commit 5560fa2

Please sign in to comment.