diff --git a/rtl/ptp_clock.v b/rtl/ptp_clock.v index 96d55f935..27d074cb5 100644 --- a/rtl/ptp_clock.v +++ b/rtl/ptp_clock.v @@ -112,10 +112,6 @@ reg [15:0] drift_rate_reg = DRIFT_RATE; reg [INC_NS_WIDTH-1:0] ts_inc_ns_reg = 0; reg [FNS_WIDTH-1:0] ts_inc_fns_reg = 0; -reg [INC_NS_WIDTH-1:0] ts_inc_ns_delay_reg = 0; -reg [FNS_WIDTH-1:0] ts_inc_fns_delay_reg = 0; -reg [30:0] ts_inc_ns_ovf_reg = 0; -reg [FNS_WIDTH-1:0] ts_inc_fns_ovf_reg = 0; reg [47:0] ts_96_s_reg = 0; reg [29:0] ts_96_ns_reg = 0; @@ -254,17 +250,14 @@ always @(posedge clk) begin end // 96 bit timestamp - {ts_inc_ns_delay_reg, ts_inc_fns_delay_reg} <= {ts_inc_ns_reg, ts_inc_fns_reg}; - {ts_inc_ns_ovf_reg, ts_inc_fns_ovf_reg} <= {NS_PER_S, {FNS_WIDTH{1'b0}}} - {ts_inc_ns_reg, ts_inc_fns_reg}; - - {ts_96_ns_inc_reg, ts_96_fns_inc_reg} <= {ts_96_ns_inc_reg, ts_96_fns_inc_reg} + {ts_inc_ns_delay_reg, ts_inc_fns_delay_reg}; - {ts_96_ns_ovf_reg, ts_96_fns_ovf_reg} <= {ts_96_ns_inc_reg, ts_96_fns_inc_reg} - {ts_inc_ns_ovf_reg, ts_inc_fns_ovf_reg}; + {ts_96_ns_inc_reg, ts_96_fns_inc_reg} <= {ts_96_ns_inc_reg, ts_96_fns_inc_reg} + {ts_inc_ns_reg, ts_inc_fns_reg}; + {ts_96_ns_ovf_reg, ts_96_fns_ovf_reg} <= {ts_96_ns_inc_reg, ts_96_fns_inc_reg} + (-{NS_PER_S, {FNS_WIDTH{1'b0}}} | {ts_inc_ns_reg, ts_inc_fns_reg}); {ts_96_ns_reg, ts_96_fns_reg} <= {ts_96_ns_inc_reg, ts_96_fns_inc_reg}; if (!ts_96_ns_ovf_reg[30]) begin // if the overflow lookahead did not borrow, one second has elapsed // increment seconds field, pre-compute normal increment, force overflow lookahead borrow bit set - {ts_96_ns_inc_reg, ts_96_fns_inc_reg} <= {ts_96_ns_ovf_reg, ts_96_fns_ovf_reg} + {ts_inc_ns_delay_reg, ts_inc_fns_delay_reg}; + {ts_96_ns_inc_reg, ts_96_fns_inc_reg} <= {ts_96_ns_ovf_reg, ts_96_fns_ovf_reg} + {ts_inc_ns_reg, ts_inc_fns_reg}; ts_96_ns_ovf_reg[30] <= 1'b1; {ts_96_ns_reg, ts_96_fns_reg} <= {ts_96_ns_ovf_reg, ts_96_fns_ovf_reg}; ts_96_s_reg <= ts_96_s_reg + 1; diff --git a/rtl/ptp_clock_cdc.v b/rtl/ptp_clock_cdc.v index 0c402bbb7..bddf79a15 100644 --- a/rtl/ptp_clock_cdc.v +++ b/rtl/ptp_clock_cdc.v @@ -101,8 +101,6 @@ localparam TIME_ERR_INT_WIDTH = NS_WIDTH+FNS_WIDTH; localparam [30:0] NS_PER_S = 31'd1_000_000_000; reg [NS_WIDTH+FNS_WIDTH-1:0] period_ns_reg = 0, period_ns_next = 0; -reg [NS_WIDTH+FNS_WIDTH-1:0] period_ns_delay_reg = 0, period_ns_delay_next = 0; -reg [31+FNS_WIDTH-1:0] period_ns_ovf_reg = 0, period_ns_ovf_next = 0; reg [47:0] src_ts_s_capt_reg = 0; reg [TS_NS_WIDTH+CMP_FNS_WIDTH-1:0] src_ts_ns_capt_reg = 0; @@ -595,19 +593,16 @@ always @* begin gain_sel_next = gain_sel_reg; // PTP clock - period_ns_delay_next = period_ns_reg; - period_ns_ovf_next = {NS_PER_S, {FNS_WIDTH{1'b0}}} - period_ns_reg; - if (TS_WIDTH == 96) begin // 96 bit timestamp - ts_ns_inc_next = ts_ns_inc_reg + period_ns_delay_reg; - ts_ns_ovf_next = ts_ns_inc_reg - period_ns_ovf_reg; + ts_ns_inc_next = ts_ns_inc_reg + period_ns_reg; + ts_ns_ovf_next = ts_ns_inc_reg + (-{NS_PER_S, {FNS_WIDTH{1'b0}}} | period_ns_reg); ts_ns_next = ts_ns_inc_reg; if (!ts_ns_ovf_reg[30+FNS_WIDTH]) begin // if the overflow lookahead did not borrow, one second has elapsed // increment seconds field, pre-compute normal increment, force overflow lookahead borrow bit set - ts_ns_inc_next = ts_ns_ovf_reg + period_ns_delay_reg; + ts_ns_inc_next = ts_ns_ovf_reg + period_ns_reg; ts_ns_ovf_next[30+FNS_WIDTH] = 1'b1; ts_ns_next = ts_ns_ovf_reg; ts_s_next = ts_s_reg + 1; @@ -767,8 +762,6 @@ end always @(posedge output_clk) begin period_ns_reg <= period_ns_next; - period_ns_delay_reg <= period_ns_delay_next; - period_ns_ovf_reg <= period_ns_ovf_next; ts_s_reg <= ts_s_next; ts_ns_reg <= ts_ns_next;