2018-10-23 23:34:43 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2015-2017 Alex Forencich
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Language: Verilog 2001
|
|
|
|
|
|
|
|
`timescale 1ns / 1ps
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AXI4-Stream XGMII frame transmitter (AXI in, XGMII out)
|
|
|
|
*/
|
|
|
|
module axis_xgmii_tx_32 #
|
|
|
|
(
|
|
|
|
parameter ENABLE_PADDING = 1,
|
|
|
|
parameter ENABLE_DIC = 1,
|
|
|
|
parameter MIN_FRAME_LENGTH = 64
|
|
|
|
)
|
|
|
|
(
|
|
|
|
input wire clk,
|
|
|
|
input wire rst,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AXI input
|
|
|
|
*/
|
2018-11-07 22:35:06 -08:00
|
|
|
input wire [31:0] s_axis_tdata,
|
|
|
|
input wire [3:0] s_axis_tkeep,
|
|
|
|
input wire s_axis_tvalid,
|
|
|
|
output wire s_axis_tready,
|
|
|
|
input wire s_axis_tlast,
|
|
|
|
input wire s_axis_tuser,
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XGMII output
|
|
|
|
*/
|
|
|
|
output wire [31:0] xgmii_txd,
|
|
|
|
output wire [3:0] xgmii_txc,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configuration
|
|
|
|
*/
|
2019-01-31 17:00:23 -08:00
|
|
|
input wire [7:0] ifg_delay,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Status
|
|
|
|
*/
|
|
|
|
output wire start_packet
|
2018-10-23 23:34:43 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
localparam MIN_FL_NOCRC = MIN_FRAME_LENGTH-4;
|
|
|
|
localparam MIN_FL_NOCRC_MS = MIN_FL_NOCRC & 16'hfffc;
|
|
|
|
localparam MIN_FL_NOCRC_LS = MIN_FL_NOCRC & 16'h0003;
|
|
|
|
|
2018-11-08 13:15:47 -08:00
|
|
|
localparam [7:0]
|
|
|
|
ETH_PRE = 8'h55,
|
|
|
|
ETH_SFD = 8'hD5;
|
|
|
|
|
|
|
|
localparam [7:0]
|
|
|
|
XGMII_IDLE = 8'h07,
|
|
|
|
XGMII_START = 8'hfb,
|
|
|
|
XGMII_TERM = 8'hfd,
|
|
|
|
XGMII_ERROR = 8'hfe;
|
|
|
|
|
2018-10-23 23:34:43 -07:00
|
|
|
localparam [3:0]
|
|
|
|
STATE_IDLE = 4'd0,
|
|
|
|
STATE_PREAMBLE = 4'd1,
|
|
|
|
STATE_PAYLOAD = 4'd2,
|
|
|
|
STATE_PAD = 4'd3,
|
|
|
|
STATE_FCS_1 = 4'd4,
|
|
|
|
STATE_FCS_2 = 4'd5,
|
|
|
|
STATE_FCS_3 = 4'd6,
|
|
|
|
STATE_IFG = 4'd7,
|
|
|
|
STATE_WAIT_END = 4'd8;
|
|
|
|
|
|
|
|
reg [2:0] state_reg = STATE_IDLE, state_next;
|
|
|
|
|
|
|
|
// datapath control signals
|
|
|
|
reg reset_crc;
|
|
|
|
reg update_crc;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
reg [31:0] s_axis_tdata_masked;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
reg [31:0] s_tdata_reg = 64'd0, s_tdata_next;
|
|
|
|
reg [3:0] s_tkeep_reg = 8'd0, s_tkeep_next;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
reg [31:0] fcs_output_txd_0;
|
|
|
|
reg [31:0] fcs_output_txd_1;
|
|
|
|
reg [3:0] fcs_output_txc_0;
|
|
|
|
reg [3:0] fcs_output_txc_1;
|
|
|
|
|
|
|
|
reg [7:0] ifg_offset;
|
|
|
|
|
|
|
|
reg extra_cycle;
|
|
|
|
|
|
|
|
reg [15:0] frame_ptr_reg = 16'd0, frame_ptr_next;
|
|
|
|
|
|
|
|
reg [7:0] ifg_count_reg = 8'd0, ifg_count_next;
|
|
|
|
reg [1:0] deficit_idle_count_reg = 2'd0, deficit_idle_count_next;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
reg s_axis_tready_reg = 1'b0, s_axis_tready_next;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
reg [31:0] crc_state = 32'hFFFFFFFF;
|
|
|
|
|
|
|
|
wire [31:0] crc_next0;
|
|
|
|
wire [31:0] crc_next1;
|
|
|
|
wire [31:0] crc_next2;
|
|
|
|
wire [31:0] crc_next3;
|
|
|
|
|
2018-11-08 13:15:47 -08:00
|
|
|
reg [31:0] xgmii_txd_reg = {4{XGMII_IDLE}}, xgmii_txd_next;
|
2018-10-23 23:34:43 -07:00
|
|
|
reg [3:0] xgmii_txc_reg = 4'b1111, xgmii_txc_next;
|
|
|
|
|
2019-01-31 17:00:23 -08:00
|
|
|
reg start_packet_reg = 1'b0, start_packet_next;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
assign s_axis_tready = s_axis_tready_reg;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
assign xgmii_txd = xgmii_txd_reg;
|
|
|
|
assign xgmii_txc = xgmii_txc_reg;
|
|
|
|
|
2019-01-31 17:00:23 -08:00
|
|
|
assign start_packet = start_packet_reg;
|
|
|
|
|
2018-10-23 23:34:43 -07:00
|
|
|
lfsr #(
|
|
|
|
.LFSR_WIDTH(32),
|
|
|
|
.LFSR_POLY(32'h4c11db7),
|
|
|
|
.LFSR_CONFIG("GALOIS"),
|
|
|
|
.LFSR_FEED_FORWARD(0),
|
|
|
|
.REVERSE(1),
|
|
|
|
.DATA_WIDTH(8),
|
|
|
|
.STYLE("AUTO")
|
|
|
|
)
|
|
|
|
eth_crc_8 (
|
2018-11-07 22:35:06 -08:00
|
|
|
.data_in(s_tdata_reg[7:0]),
|
2018-10-23 23:34:43 -07:00
|
|
|
.state_in(crc_state),
|
|
|
|
.data_out(),
|
|
|
|
.state_out(crc_next0)
|
|
|
|
);
|
|
|
|
|
|
|
|
lfsr #(
|
|
|
|
.LFSR_WIDTH(32),
|
|
|
|
.LFSR_POLY(32'h4c11db7),
|
|
|
|
.LFSR_CONFIG("GALOIS"),
|
|
|
|
.LFSR_FEED_FORWARD(0),
|
|
|
|
.REVERSE(1),
|
|
|
|
.DATA_WIDTH(16),
|
|
|
|
.STYLE("AUTO")
|
|
|
|
)
|
|
|
|
eth_crc_16 (
|
2018-11-07 22:35:06 -08:00
|
|
|
.data_in(s_tdata_reg[15:0]),
|
2018-10-23 23:34:43 -07:00
|
|
|
.state_in(crc_state),
|
|
|
|
.data_out(),
|
|
|
|
.state_out(crc_next1)
|
|
|
|
);
|
|
|
|
|
|
|
|
lfsr #(
|
|
|
|
.LFSR_WIDTH(32),
|
|
|
|
.LFSR_POLY(32'h4c11db7),
|
|
|
|
.LFSR_CONFIG("GALOIS"),
|
|
|
|
.LFSR_FEED_FORWARD(0),
|
|
|
|
.REVERSE(1),
|
|
|
|
.DATA_WIDTH(24),
|
|
|
|
.STYLE("AUTO")
|
|
|
|
)
|
|
|
|
eth_crc_24 (
|
2018-11-07 22:35:06 -08:00
|
|
|
.data_in(s_tdata_reg[23:0]),
|
2018-10-23 23:34:43 -07:00
|
|
|
.state_in(crc_state),
|
|
|
|
.data_out(),
|
|
|
|
.state_out(crc_next2)
|
|
|
|
);
|
|
|
|
|
|
|
|
lfsr #(
|
|
|
|
.LFSR_WIDTH(32),
|
|
|
|
.LFSR_POLY(32'h4c11db7),
|
|
|
|
.LFSR_CONFIG("GALOIS"),
|
|
|
|
.LFSR_FEED_FORWARD(0),
|
|
|
|
.REVERSE(1),
|
|
|
|
.DATA_WIDTH(32),
|
|
|
|
.STYLE("AUTO")
|
|
|
|
)
|
|
|
|
eth_crc_32 (
|
2018-11-07 22:35:06 -08:00
|
|
|
.data_in(s_tdata_reg[31:0]),
|
2018-10-23 23:34:43 -07:00
|
|
|
.state_in(crc_state),
|
|
|
|
.data_out(),
|
|
|
|
.state_out(crc_next3)
|
|
|
|
);
|
|
|
|
|
|
|
|
function [2:0] keep2count;
|
|
|
|
input [3:0] k;
|
|
|
|
casez (k)
|
|
|
|
4'bzzz0: keep2count = 3'd0;
|
|
|
|
4'bzz01: keep2count = 3'd1;
|
|
|
|
4'bz011: keep2count = 3'd2;
|
|
|
|
4'b0111: keep2count = 3'd3;
|
|
|
|
4'b1111: keep2count = 3'd4;
|
|
|
|
endcase
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
// Mask input data
|
|
|
|
integer j;
|
|
|
|
|
|
|
|
always @* begin
|
|
|
|
for (j = 0; j < 4; j = j + 1) begin
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tdata_masked[j*8 +: 8] = s_axis_tkeep[j] ? s_axis_tdata[j*8 +: 8] : 8'd0;
|
2018-10-23 23:34:43 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
// FCS cycle calculation
|
|
|
|
always @* begin
|
2018-11-07 22:35:06 -08:00
|
|
|
casez (s_tkeep_reg)
|
2018-10-23 23:34:43 -07:00
|
|
|
4'bzz01: begin
|
2018-11-07 22:35:06 -08:00
|
|
|
fcs_output_txd_0 = {~crc_next0[23:0], s_tdata_reg[7:0]};
|
2018-11-08 13:15:47 -08:00
|
|
|
fcs_output_txd_1 = {{2{XGMII_IDLE}}, XGMII_TERM, ~crc_next0[31:24]};
|
2018-10-23 23:34:43 -07:00
|
|
|
fcs_output_txc_0 = 4'b0000;
|
|
|
|
fcs_output_txc_1 = 4'b1110;
|
|
|
|
ifg_offset = 8'd3;
|
|
|
|
extra_cycle = 1'b0;
|
|
|
|
end
|
|
|
|
4'bz011: begin
|
2018-11-07 22:35:06 -08:00
|
|
|
fcs_output_txd_0 = {~crc_next1[15:0], s_tdata_reg[15:0]};
|
2018-11-08 13:15:47 -08:00
|
|
|
fcs_output_txd_1 = {XGMII_IDLE, XGMII_TERM, ~crc_next1[31:16]};
|
2018-10-23 23:34:43 -07:00
|
|
|
fcs_output_txc_0 = 4'b0000;
|
|
|
|
fcs_output_txc_1 = 4'b1100;
|
|
|
|
ifg_offset = 8'd2;
|
|
|
|
extra_cycle = 1'b0;
|
|
|
|
end
|
|
|
|
4'b0111: begin
|
2018-11-07 22:35:06 -08:00
|
|
|
fcs_output_txd_0 = {~crc_next2[7:0], s_tdata_reg[23:0]};
|
2018-11-08 13:15:47 -08:00
|
|
|
fcs_output_txd_1 = {XGMII_TERM, ~crc_next2[31:8]};
|
2018-10-23 23:34:43 -07:00
|
|
|
fcs_output_txc_0 = 4'b0000;
|
|
|
|
fcs_output_txc_1 = 4'b1000;
|
|
|
|
ifg_offset = 8'd1;
|
|
|
|
extra_cycle = 1'b0;
|
|
|
|
end
|
|
|
|
4'b1111: begin
|
2018-11-07 22:35:06 -08:00
|
|
|
fcs_output_txd_0 = s_tdata_reg;
|
2018-10-23 23:34:43 -07:00
|
|
|
fcs_output_txd_1 = ~crc_next3;
|
|
|
|
fcs_output_txc_0 = 4'b0000;
|
|
|
|
fcs_output_txc_1 = 4'b0000;
|
|
|
|
ifg_offset = 8'd4;
|
|
|
|
extra_cycle = 1'b1;
|
|
|
|
end
|
|
|
|
default: begin
|
2019-01-22 14:19:43 -08:00
|
|
|
fcs_output_txd_0 = {4{XGMII_ERROR}};
|
|
|
|
fcs_output_txd_1 = {4{XGMII_ERROR}};
|
|
|
|
fcs_output_txc_0 = 4'b1111;
|
|
|
|
fcs_output_txc_1 = 4'b1111;
|
2018-10-23 23:34:43 -07:00
|
|
|
ifg_offset = 8'd0;
|
|
|
|
extra_cycle = 1'b0;
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @* begin
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
|
|
|
|
reset_crc = 1'b0;
|
|
|
|
update_crc = 1'b0;
|
|
|
|
|
|
|
|
frame_ptr_next = frame_ptr_reg;
|
|
|
|
|
|
|
|
ifg_count_next = ifg_count_reg;
|
|
|
|
deficit_idle_count_next = deficit_idle_count_reg;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tdata_next = s_tdata_reg;
|
|
|
|
s_tkeep_next = s_tkeep_reg;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
// XGMII idle
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {4{XGMII_IDLE}};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b1111;
|
|
|
|
|
2019-01-31 17:00:23 -08:00
|
|
|
start_packet_next = 1'b0;
|
|
|
|
|
2018-10-23 23:34:43 -07:00
|
|
|
case (state_reg)
|
|
|
|
STATE_IDLE: begin
|
|
|
|
// idle state - wait for data
|
|
|
|
frame_ptr_next = 16'd4;
|
|
|
|
reset_crc = 1'b1;
|
|
|
|
|
|
|
|
// XGMII idle
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {4{XGMII_IDLE}};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b1111;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tdata_next = s_axis_tdata_masked;
|
|
|
|
s_tkeep_next = s_axis_tkeep;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
if (s_axis_tvalid) begin
|
2018-10-23 23:34:43 -07:00
|
|
|
// XGMII start and preamble
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {{3{ETH_PRE}}, XGMII_START};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b0001;
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b1;
|
2018-10-23 23:34:43 -07:00
|
|
|
state_next = STATE_PREAMBLE;
|
|
|
|
end else begin
|
|
|
|
ifg_count_next = 8'd0;
|
|
|
|
deficit_idle_count_next = 2'd0;
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_PREAMBLE: begin
|
|
|
|
// send preamble
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tdata_next = s_axis_tdata_masked;
|
|
|
|
s_tkeep_next = s_axis_tkeep;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {ETH_SFD, {3{ETH_PRE}}};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b0000;
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b1;
|
2019-01-31 17:00:23 -08:00
|
|
|
start_packet_next = 1'b1;
|
2018-10-23 23:34:43 -07:00
|
|
|
state_next = STATE_PAYLOAD;
|
|
|
|
end
|
|
|
|
STATE_PAYLOAD: begin
|
|
|
|
// transfer payload
|
|
|
|
update_crc = 1'b1;
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b1;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
frame_ptr_next = frame_ptr_reg + 16'd4;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
xgmii_txd_next = s_tdata_reg;
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b0000;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tdata_next = s_axis_tdata_masked;
|
|
|
|
s_tkeep_next = s_axis_tkeep;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
if (s_axis_tvalid) begin
|
|
|
|
if (s_axis_tlast) begin
|
|
|
|
frame_ptr_next = frame_ptr_reg + keep2count(s_axis_tkeep);
|
|
|
|
s_axis_tready_next = 1'b0;
|
|
|
|
if (s_axis_tuser) begin
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {XGMII_TERM, {3{XGMII_ERROR}}};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b1111;
|
|
|
|
frame_ptr_next = 16'd0;
|
|
|
|
ifg_count_next = 8'd10;
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
if (ENABLE_PADDING && (frame_ptr_reg < MIN_FL_NOCRC_MS || (frame_ptr_reg == MIN_FL_NOCRC_MS && keep2count(s_axis_tkeep) < MIN_FL_NOCRC_LS))) begin
|
|
|
|
s_tkeep_next = 4'hf;
|
2018-10-23 23:34:43 -07:00
|
|
|
frame_ptr_next = frame_ptr_reg + 16'd4;
|
|
|
|
|
|
|
|
if (frame_ptr_reg < (MIN_FL_NOCRC_LS > 0 ? MIN_FL_NOCRC_MS : MIN_FL_NOCRC_MS-4)) begin
|
|
|
|
state_next = STATE_PAD;
|
|
|
|
end else begin
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tkeep_next = 4'hf >> ((4-MIN_FL_NOCRC_LS) % 4);
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
state_next = STATE_FCS_1;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_FCS_1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_PAYLOAD;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
// tvalid deassert, fail frame
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {XGMII_TERM, {3{XGMII_ERROR}}};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b1111;
|
|
|
|
frame_ptr_next = 16'd0;
|
|
|
|
ifg_count_next = 8'd10;
|
|
|
|
state_next = STATE_WAIT_END;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_PAD: begin
|
|
|
|
// pad frame to MIN_FRAME_LENGTH
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
xgmii_txd_next = s_tdata_reg;
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b0000;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tdata_next = 32'd0;
|
|
|
|
s_tkeep_next = 4'hf;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
update_crc = 1'b1;
|
|
|
|
frame_ptr_next = frame_ptr_reg + 16'd4;
|
|
|
|
|
|
|
|
if (frame_ptr_reg < (MIN_FL_NOCRC_LS > 0 ? MIN_FL_NOCRC_MS : MIN_FL_NOCRC_MS-4)) begin
|
|
|
|
state_next = STATE_PAD;
|
|
|
|
end else begin
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tkeep_next = 4'hf >> ((4-MIN_FL_NOCRC_LS) % 4);
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
state_next = STATE_FCS_1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_FCS_1: begin
|
|
|
|
// last cycle
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
xgmii_txd_next = fcs_output_txd_0;
|
|
|
|
xgmii_txc_next = fcs_output_txc_0;
|
|
|
|
|
|
|
|
frame_ptr_next = 16'd0;
|
|
|
|
|
|
|
|
ifg_count_next = (ifg_delay > 8'd12 ? ifg_delay : 8'd12) - ifg_offset + deficit_idle_count_reg;
|
|
|
|
state_next = STATE_FCS_2;
|
|
|
|
end
|
|
|
|
STATE_FCS_2: begin
|
|
|
|
// last cycle
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
xgmii_txd_next = fcs_output_txd_1;
|
|
|
|
xgmii_txc_next = fcs_output_txc_1;
|
|
|
|
|
|
|
|
frame_ptr_next = 16'd0;
|
|
|
|
|
|
|
|
if (extra_cycle) begin
|
|
|
|
state_next = STATE_FCS_3;
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_FCS_3: begin
|
|
|
|
// last cycle
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_next = {{3{XGMII_IDLE}}, XGMII_TERM};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_next = 4'b1111;
|
|
|
|
|
|
|
|
reset_crc = 1'b1;
|
|
|
|
frame_ptr_next = 16'd0;
|
|
|
|
|
|
|
|
if (ENABLE_DIC) begin
|
|
|
|
if (ifg_count_next > 8'd3) begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
|
|
|
deficit_idle_count_next = ifg_count_next;
|
|
|
|
ifg_count_next = 8'd0;
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_next = 1'b1;
|
2018-10-23 23:34:43 -07:00
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
if (ifg_count_next > 8'd0) begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_IFG: begin
|
|
|
|
// send IFG
|
|
|
|
if (ifg_count_reg > 8'd4) begin
|
|
|
|
ifg_count_next = ifg_count_reg - 8'd4;
|
|
|
|
end else begin
|
|
|
|
ifg_count_next = 8'd0;
|
|
|
|
end
|
|
|
|
|
|
|
|
reset_crc = 1'b1;
|
|
|
|
|
|
|
|
if (ENABLE_DIC) begin
|
|
|
|
if (ifg_count_next > 8'd3) begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
|
|
|
deficit_idle_count_next = ifg_count_next;
|
|
|
|
ifg_count_next = 8'd0;
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
if (ifg_count_next > 8'd0) begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
STATE_WAIT_END: begin
|
|
|
|
// wait for end of frame
|
2019-03-25 15:06:45 -07:00
|
|
|
s_axis_tready_next = 1'b1;
|
|
|
|
|
|
|
|
if (ifg_count_reg > 8'd4) begin
|
|
|
|
ifg_count_next = ifg_count_reg - 8'd4;
|
2018-10-23 23:34:43 -07:00
|
|
|
end else begin
|
|
|
|
ifg_count_next = 8'd0;
|
|
|
|
end
|
|
|
|
|
|
|
|
reset_crc = 1'b1;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
if (s_axis_tvalid) begin
|
|
|
|
if (s_axis_tlast) begin
|
2019-03-25 15:06:45 -07:00
|
|
|
s_axis_tready_next = 1'b0;
|
|
|
|
|
2018-10-23 23:34:43 -07:00
|
|
|
if (ENABLE_DIC) begin
|
|
|
|
if (ifg_count_next > 8'd3) begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
|
|
|
deficit_idle_count_next = ifg_count_next;
|
|
|
|
ifg_count_next = 8'd0;
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
if (ifg_count_next > 8'd0) begin
|
|
|
|
state_next = STATE_IFG;
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_IDLE;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_WAIT_END;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
state_next = STATE_WAIT_END;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (rst) begin
|
|
|
|
state_reg <= STATE_IDLE;
|
|
|
|
|
|
|
|
frame_ptr_reg <= 16'd0;
|
|
|
|
|
|
|
|
ifg_count_reg <= 8'd0;
|
|
|
|
deficit_idle_count_reg <= 2'd0;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_reg <= 1'b0;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
2018-11-08 13:15:47 -08:00
|
|
|
xgmii_txd_reg <= {4{XGMII_IDLE}};
|
2018-10-23 23:34:43 -07:00
|
|
|
xgmii_txc_reg <= 4'b1111;
|
|
|
|
|
2019-01-31 17:00:23 -08:00
|
|
|
start_packet_reg <= 1'b0;
|
|
|
|
|
2018-10-23 23:34:43 -07:00
|
|
|
crc_state <= 32'hFFFFFFFF;
|
|
|
|
end else begin
|
|
|
|
state_reg <= state_next;
|
|
|
|
|
|
|
|
frame_ptr_reg <= frame_ptr_next;
|
|
|
|
|
|
|
|
ifg_count_reg <= ifg_count_next;
|
|
|
|
deficit_idle_count_reg <= deficit_idle_count_next;
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_axis_tready_reg <= s_axis_tready_next;
|
2018-10-23 23:34:43 -07:00
|
|
|
|
|
|
|
xgmii_txd_reg <= xgmii_txd_next;
|
|
|
|
xgmii_txc_reg <= xgmii_txc_next;
|
|
|
|
|
2019-01-31 17:00:23 -08:00
|
|
|
start_packet_reg <= start_packet_next;
|
|
|
|
|
2018-10-23 23:34:43 -07:00
|
|
|
// datapath
|
|
|
|
if (reset_crc) begin
|
|
|
|
crc_state <= 32'hFFFFFFFF;
|
|
|
|
end else if (update_crc) begin
|
|
|
|
crc_state <= crc_next3;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-07 22:35:06 -08:00
|
|
|
s_tdata_reg <= s_tdata_next;
|
|
|
|
s_tkeep_reg <= s_tkeep_next;
|
2018-10-23 23:34:43 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|