mirror of
https://github.com/alexforencich/verilog-ethernet.git
synced 2025-01-28 07:03:08 +08:00
Split out and pipeline relative timestamp LSB increment in PTP TD leaf clock
Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
parent
eb0f01f276
commit
0ac15c6872
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user