//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// eth_rxcounters.v ////
|
//// eth_rxcounters.v ////
|
//// ////
|
//// ////
|
//// This file is part of the Ethernet IP core project ////
|
//// This file is part of the Ethernet IP core project ////
|
//// http://www.opencores.org/project,ethmac ////
|
//// http://www.opencores.org/project,ethmac ////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// - Igor Mohor (igorM@opencores.org) ////
|
//// - Igor Mohor (igorM@opencores.org) ////
|
//// - Novan Hartadi (novan@vlsi.itb.ac.id) ////
|
//// - Novan Hartadi (novan@vlsi.itb.ac.id) ////
|
//// - Mahmud Galela (mgalela@vlsi.itb.ac.id) ////
|
//// - Mahmud Galela (mgalela@vlsi.itb.ac.id) ////
|
//// ////
|
//// ////
|
//// All additional information is avaliable in the Readme.txt ////
|
//// All additional information is avaliable in the Readme.txt ////
|
//// file. ////
|
//// file. ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2001 Authors ////
|
//// Copyright (C) 2001 Authors ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// ////
|
//// ////
|
//// This source file is free software; you can redistribute it ////
|
//// This source file is free software; you can redistribute it ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// later version. ////
|
//// later version. ////
|
//// ////
|
//// ////
|
//// This source is distributed in the hope that it will be ////
|
//// This source is distributed in the hope that it will be ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// details. ////
|
//// details. ////
|
//// ////
|
//// ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// Public License along with this source; if not, download it ////
|
//// Public License along with this source; if not, download it ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
|
|
`include "timescale.v"
|
`include "timescale.v"
|
|
|
|
|
module eth_rxcounters
|
module eth_rxcounters
|
(
|
(
|
MRxClk, Reset, MRxDV, StateIdle, StateSFD, StateData, StateDrop, StatePreamble,
|
MRxClk, Reset, MRxDV, StateIdle, StateSFD, StateData, StateDrop, StatePreamble,
|
MRxDEqD, DlyCrcEn, DlyCrcCnt, Transmitting, MaxFL, r_IFG, HugEn, IFGCounterEq24,
|
MRxDEqD, DlyCrcEn, DlyCrcCnt, Transmitting, MaxFL, r_IFG, HugEn, IFGCounterEq24,
|
ByteCntEq0, ByteCntEq1, ByteCntEq2,ByteCntEq3,ByteCntEq4,ByteCntEq5, ByteCntEq6,
|
ByteCntEq0, ByteCntEq1, ByteCntEq2,ByteCntEq3,ByteCntEq4,ByteCntEq5, ByteCntEq6,
|
ByteCntEq7, ByteCntGreat2, ByteCntSmall7, ByteCntMaxFrame, ByteCntOut
|
ByteCntEq7, ByteCntGreat2, ByteCntSmall7, ByteCntMaxFrame, ByteCntOut
|
);
|
);
|
|
|
input MRxClk;
|
input MRxClk;
|
input Reset;
|
input Reset;
|
input MRxDV;
|
input MRxDV;
|
input StateSFD;
|
input StateSFD;
|
input [1:0] StateData;
|
input [1:0] StateData;
|
input MRxDEqD;
|
input MRxDEqD;
|
input StateIdle;
|
input StateIdle;
|
input StateDrop;
|
input StateDrop;
|
input DlyCrcEn;
|
input DlyCrcEn;
|
input StatePreamble;
|
input StatePreamble;
|
input Transmitting;
|
input Transmitting;
|
input HugEn;
|
input HugEn;
|
input [15:0] MaxFL;
|
input [15:0] MaxFL;
|
input r_IFG;
|
input r_IFG;
|
|
|
output IFGCounterEq24; // IFG counter reaches 9600 ns (960 ns)
|
output IFGCounterEq24; // IFG counter reaches 9600 ns (960 ns)
|
output [3:0] DlyCrcCnt; // Delayed CRC counter
|
output [3:0] DlyCrcCnt; // Delayed CRC counter
|
output ByteCntEq0; // Byte counter = 0
|
output ByteCntEq0; // Byte counter = 0
|
output ByteCntEq1; // Byte counter = 1
|
output ByteCntEq1; // Byte counter = 1
|
output ByteCntEq2; // Byte counter = 2
|
output ByteCntEq2; // Byte counter = 2
|
output ByteCntEq3; // Byte counter = 3
|
output ByteCntEq3; // Byte counter = 3
|
output ByteCntEq4; // Byte counter = 4
|
output ByteCntEq4; // Byte counter = 4
|
output ByteCntEq5; // Byte counter = 5
|
output ByteCntEq5; // Byte counter = 5
|
output ByteCntEq6; // Byte counter = 6
|
output ByteCntEq6; // Byte counter = 6
|
output ByteCntEq7; // Byte counter = 7
|
output ByteCntEq7; // Byte counter = 7
|
output ByteCntGreat2; // Byte counter > 2
|
output ByteCntGreat2; // Byte counter > 2
|
output ByteCntSmall7; // Byte counter < 7
|
output ByteCntSmall7; // Byte counter < 7
|
output ByteCntMaxFrame; // Byte counter = MaxFL
|
output ByteCntMaxFrame; // Byte counter = MaxFL
|
output [15:0] ByteCntOut; // Byte counter
|
output [15:0] ByteCntOut; // Byte counter
|
|
|
wire ResetByteCounter;
|
wire ResetByteCounter;
|
wire IncrementByteCounter;
|
wire IncrementByteCounter;
|
wire ResetIFGCounter;
|
wire ResetIFGCounter;
|
wire IncrementIFGCounter;
|
wire IncrementIFGCounter;
|
wire ByteCntMax;
|
wire ByteCntMax;
|
|
|
reg [15:0] ByteCnt;
|
reg [15:0] ByteCnt;
|
reg [3:0] DlyCrcCnt;
|
reg [3:0] DlyCrcCnt;
|
reg [4:0] IFGCounter;
|
reg [4:0] IFGCounter;
|
|
|
wire [15:0] ByteCntDelayed;
|
wire [15:0] ByteCntDelayed;
|
|
|
|
|
|
|
assign ResetByteCounter = MRxDV & (StateSFD & MRxDEqD | StateData[0] & ByteCntMaxFrame);
|
assign ResetByteCounter = MRxDV & (StateSFD & MRxDEqD | StateData[0] & ByteCntMaxFrame);
|
|
|
assign IncrementByteCounter = ~ResetByteCounter & MRxDV &
|
assign IncrementByteCounter = ~ResetByteCounter & MRxDV &
|
(StatePreamble | StateSFD | StateIdle & ~Transmitting |
|
(StatePreamble | StateSFD | StateIdle & ~Transmitting |
|
StateData[1] & ~ByteCntMax & ~(DlyCrcEn & |DlyCrcCnt)
|
StateData[1] & ~ByteCntMax & ~(DlyCrcEn & |DlyCrcCnt)
|
);
|
);
|
|
|
|
|
always @ (posedge MRxClk or posedge Reset)
|
always @ (posedge MRxClk or posedge Reset)
|
begin
|
begin
|
if(Reset)
|
if(Reset)
|
ByteCnt[15:0] <= 16'd0;
|
ByteCnt[15:0] <= 16'd0;
|
else
|
else
|
begin
|
begin
|
if(ResetByteCounter)
|
if(ResetByteCounter)
|
ByteCnt[15:0] <= 16'd0;
|
ByteCnt[15:0] <= 16'd0;
|
else
|
else
|
if(IncrementByteCounter)
|
if(IncrementByteCounter)
|
ByteCnt[15:0] <= ByteCnt[15:0] + 16'd1;
|
ByteCnt[15:0] <= ByteCnt[15:0] + 16'd1;
|
end
|
end
|
end
|
end
|
|
|
assign ByteCntDelayed = ByteCnt + 16'd4;
|
assign ByteCntDelayed = ByteCnt + 16'd4;
|
assign ByteCntOut = DlyCrcEn ? ByteCntDelayed : ByteCnt;
|
assign ByteCntOut = DlyCrcEn ? ByteCntDelayed : ByteCnt;
|
|
|
assign ByteCntEq0 = ByteCnt == 16'd0;
|
assign ByteCntEq0 = ByteCnt == 16'd0;
|
assign ByteCntEq1 = ByteCnt == 16'd1;
|
assign ByteCntEq1 = ByteCnt == 16'd1;
|
assign ByteCntEq2 = ByteCnt == 16'd2;
|
assign ByteCntEq2 = ByteCnt == 16'd2;
|
assign ByteCntEq3 = ByteCnt == 16'd3;
|
assign ByteCntEq3 = ByteCnt == 16'd3;
|
assign ByteCntEq4 = ByteCnt == 16'd4;
|
assign ByteCntEq4 = ByteCnt == 16'd4;
|
assign ByteCntEq5 = ByteCnt == 16'd5;
|
assign ByteCntEq5 = ByteCnt == 16'd5;
|
assign ByteCntEq6 = ByteCnt == 16'd6;
|
assign ByteCntEq6 = ByteCnt == 16'd6;
|
assign ByteCntEq7 = ByteCnt == 16'd7;
|
assign ByteCntEq7 = ByteCnt == 16'd7;
|
assign ByteCntGreat2 = ByteCnt > 16'd2;
|
assign ByteCntGreat2 = ByteCnt > 16'd2;
|
assign ByteCntSmall7 = ByteCnt < 16'd7;
|
assign ByteCntSmall7 = ByteCnt < 16'd7;
|
assign ByteCntMax = ByteCnt == 16'hffff;
|
assign ByteCntMax = ByteCnt == 16'hffff;
|
assign ByteCntMaxFrame = ByteCnt == MaxFL[15:0] & ~HugEn;
|
assign ByteCntMaxFrame = ByteCnt == MaxFL[15:0] & ~HugEn;
|
|
|
|
|
assign ResetIFGCounter = StateSFD & MRxDV & MRxDEqD | StateDrop;
|
assign ResetIFGCounter = StateSFD & MRxDV & MRxDEqD | StateDrop;
|
|
|
assign IncrementIFGCounter = ~ResetIFGCounter & (StateDrop | StateIdle | StatePreamble | StateSFD) & ~IFGCounterEq24;
|
assign IncrementIFGCounter = ~ResetIFGCounter & (StateDrop | StateIdle | StatePreamble | StateSFD) & ~IFGCounterEq24;
|
|
|
always @ (posedge MRxClk or posedge Reset)
|
always @ (posedge MRxClk or posedge Reset)
|
begin
|
begin
|
if(Reset)
|
if(Reset)
|
IFGCounter[4:0] <= 5'h0;
|
IFGCounter[4:0] <= 5'h0;
|
else
|
else
|
begin
|
begin
|
if(ResetIFGCounter)
|
if(ResetIFGCounter)
|
IFGCounter[4:0] <= 5'h0;
|
IFGCounter[4:0] <= 5'h0;
|
else
|
else
|
if(IncrementIFGCounter)
|
if(IncrementIFGCounter)
|
IFGCounter[4:0] <= IFGCounter[4:0] + 5'd1;
|
IFGCounter[4:0] <= IFGCounter[4:0] + 5'd1;
|
end
|
end
|
end
|
end
|
|
|
|
|
|
|
assign IFGCounterEq24 = (IFGCounter[4:0] == 5'h18) | r_IFG; // 24*400 = 9600 ns or r_IFG is set to 1
|
assign IFGCounterEq24 = (IFGCounter[4:0] == 5'h18) | r_IFG; // 24*400 = 9600 ns or r_IFG is set to 1
|
|
|
|
|
always @ (posedge MRxClk or posedge Reset)
|
always @ (posedge MRxClk or posedge Reset)
|
begin
|
begin
|
if(Reset)
|
if(Reset)
|
DlyCrcCnt[3:0] <= 4'h0;
|
DlyCrcCnt[3:0] <= 4'h0;
|
else
|
else
|
begin
|
begin
|
if(DlyCrcCnt[3:0] == 4'h9)
|
if(DlyCrcCnt[3:0] == 4'h9)
|
DlyCrcCnt[3:0] <= 4'h0;
|
DlyCrcCnt[3:0] <= 4'h0;
|
else
|
else
|
if(DlyCrcEn & StateSFD)
|
if(DlyCrcEn & StateSFD)
|
DlyCrcCnt[3:0] <= 4'h1;
|
DlyCrcCnt[3:0] <= 4'h1;
|
else
|
else
|
if(DlyCrcEn & (|DlyCrcCnt[3:0]))
|
if(DlyCrcEn & (|DlyCrcCnt[3:0]))
|
DlyCrcCnt[3:0] <= DlyCrcCnt[3:0] + 4'd1;
|
DlyCrcCnt[3:0] <= DlyCrcCnt[3:0] + 4'd1;
|
end
|
end
|
end
|
end
|
|
|
|
|
endmodule
|
endmodule
|
|
|