Line 25... |
Line 25... |
input rst,
|
input rst,
|
|
|
input gmii_clk,
|
input gmii_clk,
|
input gmii_ctrl,
|
input gmii_ctrl,
|
input [7:0] gmii_data,
|
input [7:0] gmii_data,
|
|
input giga_mode,
|
|
|
input [7:0] ptp_msgid_mask,
|
input [7:0] ptp_msgid_mask,
|
|
|
input rtc_timer_clk,
|
input rtc_timer_clk,
|
input [79:0] rtc_timer_in, // timeStamp1s_48bit + timeStamp1ns_32bit
|
input [79:0] rtc_timer_in, // timeStamp1s_48bit + timeStamp1ns_32bit
|
Line 38... |
Line 39... |
input q_rd_en,
|
input q_rd_en,
|
output [ 7:0] q_rd_stat,
|
output [ 7:0] q_rd_stat,
|
output [127:0] q_rd_data // null_16bit + timeStamp1s_48bit + timeStamp1ns_32bit + msgId_4bit + ckSum_12bit + seqId_16bit
|
output [127:0] q_rd_data // null_16bit + timeStamp1s_48bit + timeStamp1ns_32bit + msgId_4bit + ckSum_12bit + seqId_16bit
|
);
|
);
|
|
|
|
// mii to gmii converter
|
|
reg nibble_h;
|
|
always @(posedge rst or posedge gmii_clk) begin
|
|
if (rst)
|
|
nibble_h <= 1'b0;
|
|
else if (gmii_ctrl)
|
|
nibble_h <= !nibble_h;
|
|
end
|
|
|
|
reg gmii_ctrl_conv;
|
|
reg [7:0] gmii_data_conv;
|
|
always @(posedge rst or posedge gmii_clk) begin
|
|
if (rst) begin
|
|
gmii_ctrl_conv <= 1'b0;
|
|
gmii_data_conv <= 8'd0;
|
|
end
|
|
else begin
|
|
if (giga_mode) begin
|
|
gmii_ctrl_conv <= gmii_ctrl;
|
|
gmii_data_conv[7:0] <= gmii_data[7:0];
|
|
end
|
|
else begin
|
|
// 4b-8b datapath gearbox
|
|
if (gmii_ctrl) begin
|
|
gmii_ctrl_conv <= ( nibble_h)? 1'b1:1'b0;
|
|
gmii_data_conv[7:4] <= ( nibble_h)? gmii_data[3:0]:gmii_data_conv[7:4];
|
|
gmii_data_conv[3:0] <= (!nibble_h)? gmii_data[3:0]:gmii_data_conv[3:0];
|
|
end
|
|
else begin
|
|
gmii_ctrl_conv <= 1'b0;
|
|
gmii_data_conv[7:4] <= gmii_data_conv[7:4];
|
|
gmii_data_conv[3:0] <= gmii_data_conv[3:0];
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
// buffer gmii input
|
// buffer gmii input
|
|
reg gmii_ctrl_conv_d1, gmii_ctrl_conv_d2, gmii_ctrl_conv_d3, gmii_ctrl_conv_d4,
|
|
gmii_ctrl_conv_d5, gmii_ctrl_conv_d6, gmii_ctrl_conv_d7, gmii_ctrl_conv_d8,
|
|
gmii_ctrl_conv_d9, gmii_ctrl_conv_da;
|
|
reg [7:0] gmii_data_conv_d1, gmii_data_conv_d2, gmii_data_conv_d3, gmii_data_conv_d4,
|
|
gmii_data_conv_d5, gmii_data_conv_d6, gmii_data_conv_d7, gmii_data_conv_d8,
|
|
gmii_data_conv_d9, gmii_data_conv_da;
|
|
always @(posedge rst or posedge gmii_clk) begin
|
|
if (rst) begin
|
|
gmii_ctrl_conv_d1 <= 1'b0;
|
|
gmii_ctrl_conv_d2 <= 1'b0;
|
|
gmii_ctrl_conv_d3 <= 1'b0;
|
|
gmii_ctrl_conv_d4 <= 1'b0;
|
|
gmii_ctrl_conv_d5 <= 1'b0;
|
|
gmii_ctrl_conv_d6 <= 1'b0;
|
|
gmii_ctrl_conv_d7 <= 1'b0;
|
|
gmii_ctrl_conv_d8 <= 1'b0;
|
|
gmii_ctrl_conv_d9 <= 1'b0;
|
|
gmii_ctrl_conv_da <= 1'b0;
|
|
gmii_data_conv_d1 <= 8'd0;
|
|
gmii_data_conv_d2 <= 8'd0;
|
|
gmii_data_conv_d3 <= 8'd0;
|
|
gmii_data_conv_d4 <= 8'd0;
|
|
gmii_data_conv_d5 <= 8'd0;
|
|
gmii_data_conv_d6 <= 8'd0;
|
|
gmii_data_conv_d7 <= 8'd0;
|
|
gmii_data_conv_d8 <= 8'd0;
|
|
gmii_data_conv_d9 <= 8'd0;
|
|
gmii_data_conv_da <= 8'd0;
|
|
end
|
|
else begin
|
|
gmii_ctrl_conv_d1 <= gmii_ctrl_conv;
|
|
gmii_ctrl_conv_d2 <= gmii_ctrl_conv_d1;
|
|
gmii_ctrl_conv_d3 <= gmii_ctrl_conv_d2;
|
|
gmii_ctrl_conv_d4 <= gmii_ctrl_conv_d3;
|
|
gmii_ctrl_conv_d5 <= gmii_ctrl_conv_d4;
|
|
gmii_ctrl_conv_d6 <= gmii_ctrl_conv_d5;
|
|
gmii_ctrl_conv_d7 <= gmii_ctrl_conv_d6;
|
|
gmii_ctrl_conv_d8 <= gmii_ctrl_conv_d7;
|
|
gmii_ctrl_conv_d9 <= gmii_ctrl_conv_d8;
|
|
gmii_ctrl_conv_da <= gmii_ctrl_conv_d9;
|
|
gmii_data_conv_d1 <= gmii_data_conv;
|
|
gmii_data_conv_d2 <= gmii_data_conv_d1;
|
|
gmii_data_conv_d3 <= gmii_data_conv_d2;
|
|
gmii_data_conv_d4 <= gmii_data_conv_d3;
|
|
gmii_data_conv_d5 <= gmii_data_conv_d4;
|
|
gmii_data_conv_d6 <= gmii_data_conv_d5;
|
|
gmii_data_conv_d7 <= gmii_data_conv_d6;
|
|
gmii_data_conv_d8 <= gmii_data_conv_d7;
|
|
gmii_data_conv_d9 <= gmii_data_conv_d8;
|
|
gmii_data_conv_da <= gmii_data_conv_d9;
|
|
end
|
|
end
|
|
|
|
// choose buffered gmii input
|
reg int_gmii_ctrl;
|
reg int_gmii_ctrl;
|
reg int_gmii_ctrl_d1, int_gmii_ctrl_d2, int_gmii_ctrl_d3, int_gmii_ctrl_d4, int_gmii_ctrl_d5;
|
reg int_gmii_ctrl_d1, int_gmii_ctrl_d2, int_gmii_ctrl_d3, int_gmii_ctrl_d4,
|
|
int_gmii_ctrl_d5;
|
reg [7:0] int_gmii_data;
|
reg [7:0] int_gmii_data;
|
reg [7:0] int_gmii_data_d1;
|
reg [7:0] int_gmii_data_d1, int_gmii_data_d2, int_gmii_data_d3, int_gmii_data_d4,
|
|
int_gmii_data_d5;
|
always @(posedge rst or posedge gmii_clk) begin
|
always @(posedge rst or posedge gmii_clk) begin
|
if (rst) begin
|
if (rst) begin
|
int_gmii_ctrl <= 1'b0;
|
int_gmii_ctrl <= 1'b0;
|
|
int_gmii_data <= 8'h00;
|
int_gmii_ctrl_d1 <= 1'b0;
|
int_gmii_ctrl_d1 <= 1'b0;
|
|
int_gmii_data_d1 <= 8'h00;
|
int_gmii_ctrl_d2 <= 1'b0;
|
int_gmii_ctrl_d2 <= 1'b0;
|
|
int_gmii_data_d2 <= 8'h00;
|
int_gmii_ctrl_d3 <= 1'b0;
|
int_gmii_ctrl_d3 <= 1'b0;
|
|
int_gmii_data_d3 <= 8'h00;
|
int_gmii_ctrl_d4 <= 1'b0;
|
int_gmii_ctrl_d4 <= 1'b0;
|
|
int_gmii_data_d4 <= 8'h00;
|
int_gmii_ctrl_d5 <= 1'b0;
|
int_gmii_ctrl_d5 <= 1'b0;
|
int_gmii_data <= 8'h00;
|
int_gmii_data_d5 <= 8'h00;
|
int_gmii_data_d1 <= 8'h00;
|
end
|
|
else begin
|
|
if (giga_mode) begin
|
|
int_gmii_ctrl <= gmii_ctrl_conv;
|
|
int_gmii_data <= gmii_data_conv;
|
|
int_gmii_ctrl_d1 <= gmii_ctrl_conv_d1;
|
|
int_gmii_data_d1 <= gmii_data_conv_d1;
|
|
int_gmii_ctrl_d2 <= gmii_ctrl_conv_d2;
|
|
int_gmii_data_d2 <= gmii_data_conv_d2;
|
|
int_gmii_ctrl_d3 <= gmii_ctrl_conv_d3;
|
|
int_gmii_data_d3 <= gmii_data_conv_d3;
|
|
int_gmii_ctrl_d4 <= gmii_ctrl_conv_d4;
|
|
int_gmii_data_d4 <= gmii_data_conv_d4;
|
|
int_gmii_ctrl_d5 <= gmii_ctrl_conv_d5;
|
|
int_gmii_data_d5 <= gmii_data_conv_d5;
|
end
|
end
|
else begin
|
else begin
|
int_gmii_ctrl <= gmii_ctrl;
|
int_gmii_ctrl <= gmii_ctrl_conv;
|
int_gmii_ctrl_d1 <= int_gmii_ctrl;
|
int_gmii_data <= gmii_data_conv;
|
int_gmii_ctrl_d2 <= int_gmii_ctrl_d1;
|
int_gmii_ctrl_d1 <= gmii_ctrl_conv_d2;
|
int_gmii_ctrl_d3 <= int_gmii_ctrl_d2;
|
int_gmii_data_d1 <= gmii_data_conv_d2;
|
int_gmii_ctrl_d4 <= int_gmii_ctrl_d3;
|
int_gmii_ctrl_d2 <= gmii_ctrl_conv_d4;
|
int_gmii_ctrl_d5 <= int_gmii_ctrl_d4;
|
int_gmii_data_d2 <= gmii_data_conv_d4;
|
int_gmii_data <= gmii_data;
|
int_gmii_ctrl_d3 <= gmii_ctrl_conv_d6;
|
int_gmii_data_d1 <= int_gmii_data;
|
int_gmii_data_d3 <= gmii_data_conv_d6;
|
|
int_gmii_ctrl_d4 <= gmii_ctrl_conv_d8;
|
|
int_gmii_data_d4 <= gmii_data_conv_d8;
|
|
int_gmii_ctrl_d5 <= gmii_ctrl_conv_da;
|
|
int_gmii_data_d5 <= gmii_data_conv_da;
|
|
end
|
end
|
end
|
end
|
end
|
|
|
// ptp CDC time stamping
|
// ptp CDC time stamping
|
wire ts_req = int_gmii_ctrl; // TODO: check frame start delimiter
|
wire ts_req = int_gmii_ctrl; // TODO: check frame start delimiter
|
Line 138... |
Line 256... |
reg [31:0] int_data;
|
reg [31:0] int_data;
|
always @(posedge rst or posedge gmii_clk) begin
|
always @(posedge rst or posedge gmii_clk) begin
|
if (rst)
|
if (rst)
|
int_bcnt <= 2'd0;
|
int_bcnt <= 2'd0;
|
else
|
else
|
if (int_gmii_ctrl_d1 | (int_bcnt!=2'd0))
|
if ( int_gmii_ctrl & !int_gmii_ctrl_d1)
|
int_bcnt <= int_bcnt + 2'd1;
|
int_bcnt <= 2'd0; // clear on sop
|
else
|
else if ( int_gmii_ctrl)
|
int_bcnt <= 2'd0;
|
int_bcnt <= int_bcnt + 2'd1; // increment
|
|
else if (!int_gmii_ctrl & int_gmii_ctrl_d3 & (int_bcnt!=2'd0))
|
|
int_bcnt <= int_bcnt + 2'd1; // end on eop with mod
|
end
|
end
|
always @(posedge rst or posedge gmii_clk) begin
|
always @(posedge rst or posedge gmii_clk) begin
|
if (rst) begin
|
if (rst) begin
|
int_data <= 32'd0;
|
int_data <= 32'd0;
|
int_valid <= 1'b0;
|
int_valid <= 1'b0;
|
int_mod <= 2'd0;
|
int_mod <= 2'd0;
|
end
|
end
|
else begin
|
else begin
|
if (int_gmii_ctrl_d1) begin
|
if (int_gmii_ctrl) begin
|
int_data[ 7: 0] <= (int_bcnt==2'd3)? int_gmii_data_d1:int_data[ 7: 0];
|
int_data[ 7: 0] <= (int_bcnt==2'd3)? int_gmii_data_d1:int_data[ 7: 0];
|
int_data[15: 8] <= (int_bcnt==2'd2)? int_gmii_data_d1:int_data[15: 8];
|
int_data[15: 8] <= (int_bcnt==2'd2)? int_gmii_data_d1:int_data[15: 8];
|
int_data[23:16] <= (int_bcnt==2'd1)? int_gmii_data_d1:int_data[23:16];
|
int_data[23:16] <= (int_bcnt==2'd1)? int_gmii_data_d1:int_data[23:16];
|
int_data[31:24] <= (int_bcnt==2'd0)? int_gmii_data_d1:int_data[31:24];
|
int_data[31:24] <= (int_bcnt==2'd0)? int_gmii_data_d1:int_data[31:24];
|
end
|
end
|
|
|
if (int_bcnt==2'd3)
|
if (int_gmii_ctrl & int_bcnt==2'd3)
|
int_valid <= 1'b1;
|
int_valid <= 1'b1;
|
else
|
else
|
int_valid <= 1'b0;
|
int_valid <= 1'b0;
|
|
|
if (int_gmii_ctrl_d1 & !int_gmii_ctrl_d2)
|
if (int_gmii_ctrl_d1 & !int_gmii_ctrl_d2)
|
int_mod <= 2'd0;
|
int_mod <= 2'd0;
|
else if (!int_gmii_ctrl_d1 & int_gmii_ctrl_d2)
|
else if (!int_gmii_ctrl_d1 & int_gmii_ctrl_d2)
|
int_mod <= int_bcnt;
|
int_mod <= int_bcnt;
|
|
|
if (int_gmii_ctrl & !int_gmii_ctrl_d5 & int_bcnt==2'd3)
|
if (int_gmii_ctrl_d4 & !int_gmii_ctrl_d5 & int_bcnt==2'd3)
|
int_sop <= 1'b1;
|
int_sop <= 1'b1;
|
else
|
else
|
int_sop <= 1'b0;
|
int_sop <= 1'b0;
|
|
|
if (!int_gmii_ctrl & int_bcnt==2'd3)
|
if (!int_gmii_ctrl & int_gmii_ctrl_d3 & int_bcnt==2'd3)
|
int_eop <= 1'b1;
|
int_eop <= 1'b1;
|
else
|
else
|
int_eop <= 1'b0;
|
int_eop <= 1'b0;
|
|
|
end
|
end
|