Skip to content

Commit

Permalink
Split out and pipeline relative timestamp LSB increment in PTP TD lea…
Browse files Browse the repository at this point in the history
…f clock

Signed-off-by: Alex Forencich <[email protected]>
  • Loading branch information
alexforencich committed Feb 6, 2024
1 parent eb0f01f commit 0ac15c6
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions rtl/ptp_td_leaf.v
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,17 @@ reg [PERIOD_NS_W+FNS_W-1:0] period_ns_reg = 0, period_ns_next = 0;
reg [9+CMP_FNS_W-1:0] dst_ns_capt_reg = 0;
reg [9+CMP_FNS_W-1:0] src_ns_sync_reg = 0;

reg [FNS_W-1:0] ts_fns_lsb_reg = 0, ts_fns_lsb_next = 0;
reg [FNS_W-1:0] ts_fns_reg = 0, ts_fns_next = 0;

reg [8:0] ts_rel_ns_lsb_reg = 0, ts_rel_ns_lsb_next = 0;
reg [TS_NS_W-1:0] ts_rel_ns_reg = 0, ts_rel_ns_next = 0;
reg ts_tod_step_reg = 1'b0, ts_tod_step_next;
reg ts_rel_step_reg = 1'b0, ts_rel_step_next;

reg [TS_TOD_S_W-1:0] ts_tod_s_reg = 0, ts_tod_s_next = 0;
reg [TS_TOD_NS_W-1:0] ts_tod_ns_reg = 0, ts_tod_ns_next = 0;
reg [8:0] ts_tod_offset_ns_reg = 0, ts_tod_offset_ns_next = 0;
reg ts_rel_step_reg = 1'b0, ts_rel_step_next;
reg ts_tod_step_reg = 1'b0, ts_tod_step_next;

reg pps_reg = 1'b0, pps_next;
reg pps_str_reg = 1'b0, pps_str_next;
Expand Down Expand Up @@ -641,8 +643,10 @@ assign locked = ptp_locked_reg && freq_locked_reg && dst_sync_locked_reg;
always @* begin
period_ns_next = period_ns_reg;

ts_fns_lsb_next = ts_fns_lsb_reg;
ts_fns_next = ts_fns_reg;

ts_rel_ns_lsb_next = ts_rel_ns_lsb_reg;
ts_rel_ns_next = ts_rel_ns_reg;
ts_rel_step_next = 1'b0;

Expand Down Expand Up @@ -738,13 +742,18 @@ always @* begin

// PTP clock

// shared fractional ns
ts_fns_next = ts_fns_reg + period_ns_reg;
// shared fractional ns and relative timestamp least significant bits
{ts_rel_ns_lsb_next, ts_fns_lsb_next} = ({ts_rel_ns_lsb_reg, ts_fns_lsb_reg} + period_ns_reg);
ts_fns_next = ts_fns_lsb_reg;

// relative timestamp
ts_rel_ns_next = ({ts_rel_ns_reg, ts_fns_reg} + period_ns_reg) >> FNS_W;
ts_rel_ns_next[8:0] = ts_rel_ns_lsb_reg;

if (TS_REL_EN) begin
if (!ts_rel_ns_next[8] && ts_rel_ns_reg[8]) begin
ts_rel_ns_next[TS_REL_NS_W-1:9] = ts_rel_ns_reg[TS_REL_NS_W-1:9] + 1;
end

if (dst_update_reg && !dst_sync_reg && dst_rel_shadow_valid_reg && (dst_load_cnt_reg == 0)) begin
// check timestamp MSBs
if (dst_rel_step_shadow_reg || ts_rel_load_ts_reg) begin
Expand Down Expand Up @@ -774,9 +783,9 @@ always @* begin
end
end

// absolute time-of-day timestamp
if (TS_TOD_EN) begin
// absolute time-of-day timestamp
ts_tod_ns_next[8:0] = ts_rel_ns_next[8:0] + ts_tod_offset_ns_reg;
ts_tod_ns_next[8:0] = ts_rel_ns_lsb_reg + ts_tod_offset_ns_reg;

if (ts_tod_ns_reg[TS_TOD_NS_W-1]) begin
pps_str_next = 1'b0;
Expand Down Expand Up @@ -929,8 +938,10 @@ end
always @(posedge clk) begin
period_ns_reg <= period_ns_next;

ts_fns_lsb_reg <= ts_fns_lsb_next;
ts_fns_reg <= ts_fns_next;

ts_rel_ns_lsb_reg <= ts_rel_ns_lsb_next;
ts_rel_ns_reg <= ts_rel_ns_next;
ts_rel_step_reg <= ts_rel_step_next;

Expand Down Expand Up @@ -975,7 +986,9 @@ always @(posedge clk) begin

if (rst) begin
period_ns_reg <= 0;
ts_fns_lsb_reg <= 0;
ts_fns_reg <= 0;
ts_rel_ns_lsb_reg <= 0;
ts_rel_ns_reg <= 0;
ts_rel_step_reg <= 1'b0;
ts_tod_s_reg <= 0;
Expand Down

0 comments on commit 0ac15c6

Please sign in to comment.