OpenCores
URL https://opencores.org/ocsvn/ethmac/ethmac/trunk

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_txstatem.v] - Diff between revs 335 and 338

Only display areas with differences | Details | Blame | View Log

Rev 335 Rev 338
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
////  eth_txstatem.v                                              ////
////  eth_txstatem.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/projects/ethmac/                   ////
////  http://www.opencores.org/projects/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                     ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
//
// CVS Revision History
// CVS Revision History
//
//
// $Log: not supported by cvs2svn $
// $Log: not supported by cvs2svn $
// Revision 1.4  2002/01/23 10:28:16  mohor
// Revision 1.4  2002/01/23 10:28:16  mohor
// Link in the header changed.
// Link in the header changed.
//
//
// Revision 1.3  2001/10/19 08:43:51  mohor
// Revision 1.3  2001/10/19 08:43:51  mohor
// eth_timescale.v changed to timescale.v This is done because of the
// eth_timescale.v changed to timescale.v This is done because of the
// simulation of the few cores in a one joined project.
// simulation of the few cores in a one joined project.
//
//
// Revision 1.2  2001/09/11 14:17:00  mohor
// Revision 1.2  2001/09/11 14:17:00  mohor
// Few little NCSIM warnings fixed.
// Few little NCSIM warnings fixed.
//
//
// Revision 1.1  2001/08/06 14:44:29  mohor
// Revision 1.1  2001/08/06 14:44:29  mohor
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
// Include files fixed to contain no path.
// Include files fixed to contain no path.
// File names and module names changed ta have a eth_ prologue in the name.
// File names and module names changed ta have a eth_ prologue in the name.
// File eth_timescale.v is used to define timescale
// File eth_timescale.v is used to define timescale
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
// and Mdo_OE. The bidirectional signal must be created on the top level. This
// and Mdo_OE. The bidirectional signal must be created on the top level. This
// is done due to the ASIC tools.
// is done due to the ASIC tools.
//
//
// Revision 1.1  2001/07/30 21:23:42  mohor
// Revision 1.1  2001/07/30 21:23:42  mohor
// Directory structure changed. Files checked and joind together.
// Directory structure changed. Files checked and joind together.
//
//
// Revision 1.3  2001/06/19 18:16:40  mohor
// Revision 1.3  2001/06/19 18:16:40  mohor
// TxClk changed to MTxClk (as discribed in the documentation).
// TxClk changed to MTxClk (as discribed in the documentation).
// Crc changed so only one file can be used instead of two.
// Crc changed so only one file can be used instead of two.
//
//
// Revision 1.2  2001/06/19 10:38:07  mohor
// Revision 1.2  2001/06/19 10:38:07  mohor
// Minor changes in header.
// Minor changes in header.
//
//
// Revision 1.1  2001/06/19 10:27:57  mohor
// Revision 1.1  2001/06/19 10:27:57  mohor
// TxEthMAC initial release.
// TxEthMAC initial release.
//
//
//
//
//
//
//
//
 
 
 
 
`include "timescale.v"
`include "timescale.v"
 
 
 
 
module eth_txstatem  (MTxClk, Reset, ExcessiveDefer, CarrierSense, NibCnt, IPGT, IPGR1,
module eth_txstatem  (MTxClk, Reset, ExcessiveDefer, CarrierSense, NibCnt, IPGT, IPGR1,
                      IPGR2, FullD, TxStartFrm, TxEndFrm, TxUnderRun, Collision, UnderRun,
                      IPGR2, FullD, TxStartFrm, TxEndFrm, TxUnderRun, Collision, UnderRun,
                      StartTxDone, TooBig, NibCntEq7, NibCntEq15, MaxFrame, Pad, CrcEn,
                      StartTxDone, TooBig, NibCntEq7, NibCntEq15, MaxFrame, Pad, CrcEn,
                      NibbleMinFl, RandomEq0, ColWindow, RetryMax, NoBckof, RandomEqByteCnt,
                      NibbleMinFl, RandomEq0, ColWindow, RetryMax, NoBckof, RandomEqByteCnt,
                      StateIdle, StateIPG, StatePreamble, StateData, StatePAD, StateFCS,
                      StateIdle, StateIPG, StatePreamble, StateData, StatePAD, StateFCS,
                      StateJam, StateJam_q, StateBackOff, StateDefer, StartFCS, StartJam,
                      StateJam, StateJam_q, StateBackOff, StateDefer, StartFCS, StartJam,
                      StartBackoff, StartDefer, StartPreamble, StartData, StartIPG
                      StartBackoff, StartDefer, StartPreamble, StartData, StartIPG
                     );
                     );
 
 
parameter Tp = 1;
parameter Tp = 1;
 
 
input MTxClk;
input MTxClk;
input Reset;
input Reset;
input ExcessiveDefer;
input ExcessiveDefer;
input CarrierSense;
input CarrierSense;
input [6:0] NibCnt;
input [6:0] NibCnt;
input [6:0] IPGT;
input [6:0] IPGT;
input [6:0] IPGR1;
input [6:0] IPGR1;
input [6:0] IPGR2;
input [6:0] IPGR2;
input FullD;
input FullD;
input TxStartFrm;
input TxStartFrm;
input TxEndFrm;
input TxEndFrm;
input TxUnderRun;
input TxUnderRun;
input Collision;
input Collision;
input UnderRun;
input UnderRun;
input StartTxDone;
input StartTxDone;
input TooBig;
input TooBig;
input NibCntEq7;
input NibCntEq7;
input NibCntEq15;
input NibCntEq15;
input MaxFrame;
input MaxFrame;
input Pad;
input Pad;
input CrcEn;
input CrcEn;
input NibbleMinFl;
input NibbleMinFl;
input RandomEq0;
input RandomEq0;
input ColWindow;
input ColWindow;
input RetryMax;
input RetryMax;
input NoBckof;
input NoBckof;
input RandomEqByteCnt;
input RandomEqByteCnt;
 
 
 
 
output StateIdle;         // Idle state
output StateIdle;         // Idle state
output StateIPG;          // IPG state
output StateIPG;          // IPG state
output StatePreamble;     // Preamble state
output StatePreamble;     // Preamble state
output [1:0] StateData;   // Data state
output [1:0] StateData;   // Data state
output StatePAD;          // PAD state
output StatePAD;          // PAD state
output StateFCS;          // FCS state
output StateFCS;          // FCS state
output StateJam;          // Jam state
output StateJam;          // Jam state
output StateJam_q;        // Delayed Jam state
output StateJam_q;        // Delayed Jam state
output StateBackOff;      // Backoff state
output StateBackOff;      // Backoff state
output StateDefer;        // Defer state
output StateDefer;        // Defer state
 
 
output StartFCS;          // FCS state will be activated in next clock
output StartFCS;          // FCS state will be activated in next clock
output StartJam;          // Jam state will be activated in next clock
output StartJam;          // Jam state will be activated in next clock
output StartBackoff;      // Backoff state will be activated in next clock
output StartBackoff;      // Backoff state will be activated in next clock
output StartDefer;        // Defer state will be activated in next clock
output StartDefer;        // Defer state will be activated in next clock
output StartPreamble;     // Preamble state will be activated in next clock
output StartPreamble;     // Preamble state will be activated in next clock
output [1:0] StartData;   // Data state will be activated in next clock
output [1:0] StartData;   // Data state will be activated in next clock
output StartIPG;          // IPG state will be activated in next clock
output StartIPG;          // IPG state will be activated in next clock
 
 
wire StartIdle;           // Idle state will be activated in next clock
wire StartIdle;           // Idle state will be activated in next clock
wire StartPAD;            // PAD state will be activated in next clock
wire StartPAD;            // PAD state will be activated in next clock
 
 
 
 
reg StateIdle;
reg StateIdle;
reg StateIPG;
reg StateIPG;
reg StatePreamble;
reg StatePreamble;
reg [1:0] StateData;
reg [1:0] StateData;
reg StatePAD;
reg StatePAD;
reg StateFCS;
reg StateFCS;
reg StateJam;
reg StateJam;
reg StateJam_q;
reg StateJam_q;
reg StateBackOff;
reg StateBackOff;
reg StateDefer;
reg StateDefer;
reg Rule1;
reg Rule1;
 
 
 
 
// Defining the next state
// Defining the next state
assign StartIPG = StateDefer & ~ExcessiveDefer & ~CarrierSense;
assign StartIPG = StateDefer & ~ExcessiveDefer & ~CarrierSense;
 
 
assign StartIdle = StateIPG & (Rule1 & NibCnt[6:0] >= IPGT | ~Rule1 & NibCnt[6:0] >= IPGR2);
assign StartIdle = StateIPG & (Rule1 & NibCnt[6:0] >= IPGT | ~Rule1 & NibCnt[6:0] >= IPGR2);
 
 
assign StartPreamble = StateIdle & TxStartFrm & ~CarrierSense;
assign StartPreamble = StateIdle & TxStartFrm & ~CarrierSense;
 
 
assign StartData[0] = ~Collision & (StatePreamble & NibCntEq15 | StateData[1] & ~TxEndFrm);
assign StartData[0] = ~Collision & (StatePreamble & NibCntEq15 | StateData[1] & ~TxEndFrm);
 
 
assign StartData[1] = ~Collision & StateData[0] & ~TxUnderRun & ~MaxFrame;
assign StartData[1] = ~Collision & StateData[0] & ~TxUnderRun & ~MaxFrame;
 
 
assign StartPAD = ~Collision & StateData[1] & TxEndFrm & Pad & ~NibbleMinFl;
assign StartPAD = ~Collision & StateData[1] & TxEndFrm & Pad & ~NibbleMinFl;
 
 
assign StartFCS = ~Collision & StateData[1] & TxEndFrm & (~Pad | Pad & NibbleMinFl) & CrcEn
assign StartFCS = ~Collision & StateData[1] & TxEndFrm & (~Pad | Pad & NibbleMinFl) & CrcEn
                | ~Collision & StatePAD & NibbleMinFl & CrcEn;
                | ~Collision & StatePAD & NibbleMinFl & CrcEn;
 
 
assign StartJam = (Collision | UnderRun) & ((StatePreamble & NibCntEq15) | (|StateData[1:0]) | StatePAD | StateFCS);
assign StartJam = (Collision | UnderRun) & ((StatePreamble & NibCntEq15) | (|StateData[1:0]) | StatePAD | StateFCS);
 
 
assign StartBackoff = StateJam & ~RandomEq0 & ColWindow & ~RetryMax & NibCntEq7 & ~NoBckof;
assign StartBackoff = StateJam & ~RandomEq0 & ColWindow & ~RetryMax & NibCntEq7 & ~NoBckof;
 
 
assign StartDefer = StateIPG & ~Rule1 & CarrierSense & NibCnt[6:0] <= IPGR1 & NibCnt[6:0] != IPGR2
assign StartDefer = StateIPG & ~Rule1 & CarrierSense & NibCnt[6:0] <= IPGR1 & NibCnt[6:0] != IPGR2
                  | StateIdle & CarrierSense
                  | StateIdle & CarrierSense
                  | StateJam & NibCntEq7 & (NoBckof | RandomEq0 | ~ColWindow | RetryMax)
                  | StateJam & NibCntEq7 & (NoBckof | RandomEq0 | ~ColWindow | RetryMax)
                  | StateBackOff & (TxUnderRun | RandomEqByteCnt)
                  | StateBackOff & (TxUnderRun | RandomEqByteCnt)
                  | StartTxDone | TooBig;
                  | StartTxDone | TooBig;
 
 
 
 
 
 
// Tx State Machine
// Tx State Machine
always @ (posedge MTxClk or posedge Reset)
always @ (posedge MTxClk or posedge Reset)
begin
begin
  if(Reset)
  if(Reset)
    begin
    begin
      StateIPG        <= #Tp 1'b0;
      StateIPG        <= #Tp 1'b0;
      StateIdle       <= #Tp 1'b0;
      StateIdle       <= #Tp 1'b0;
      StatePreamble   <= #Tp 1'b0;
      StatePreamble   <= #Tp 1'b0;
      StateData[1:0]  <= #Tp 2'b0;
      StateData[1:0]  <= #Tp 2'b0;
      StatePAD        <= #Tp 1'b0;
      StatePAD        <= #Tp 1'b0;
      StateFCS        <= #Tp 1'b0;
      StateFCS        <= #Tp 1'b0;
      StateJam        <= #Tp 1'b0;
      StateJam        <= #Tp 1'b0;
      StateJam_q      <= #Tp 1'b0;
      StateJam_q      <= #Tp 1'b0;
      StateBackOff    <= #Tp 1'b0;
      StateBackOff    <= #Tp 1'b0;
      StateDefer      <= #Tp 1'b1;
      StateDefer      <= #Tp 1'b1;
    end
    end
  else
  else
    begin
    begin
      StateData[1:0] <= #Tp StartData[1:0];
      StateData[1:0] <= #Tp StartData[1:0];
      StateJam_q <= #Tp StateJam;
      StateJam_q <= #Tp StateJam;
 
 
      if(StartDefer | StartIdle)
      if(StartDefer | StartIdle)
        StateIPG <= #Tp 1'b0;
        StateIPG <= #Tp 1'b0;
      else
      else
      if(StartIPG)
      if(StartIPG)
        StateIPG <= #Tp 1'b1;
        StateIPG <= #Tp 1'b1;
 
 
      if(StartDefer | StartPreamble)
      if(StartDefer | StartPreamble)
        StateIdle <= #Tp 1'b0;
        StateIdle <= #Tp 1'b0;
      else
      else
      if(StartIdle)
      if(StartIdle)
        StateIdle <= #Tp 1'b1;
        StateIdle <= #Tp 1'b1;
 
 
      if(StartData[0] | StartJam)
      if(StartData[0] | StartJam)
        StatePreamble <= #Tp 1'b0;
        StatePreamble <= #Tp 1'b0;
      else
      else
      if(StartPreamble)
      if(StartPreamble)
        StatePreamble <= #Tp 1'b1;
        StatePreamble <= #Tp 1'b1;
 
 
      if(StartFCS | StartJam)
      if(StartFCS | StartJam)
        StatePAD <= #Tp 1'b0;
        StatePAD <= #Tp 1'b0;
      else
      else
      if(StartPAD)
      if(StartPAD)
        StatePAD <= #Tp 1'b1;
        StatePAD <= #Tp 1'b1;
 
 
      if(StartJam | StartDefer)
      if(StartJam | StartDefer)
        StateFCS <= #Tp 1'b0;
        StateFCS <= #Tp 1'b0;
      else
      else
      if(StartFCS)
      if(StartFCS)
        StateFCS <= #Tp 1'b1;
        StateFCS <= #Tp 1'b1;
 
 
      if(StartBackoff | StartDefer)
      if(StartBackoff | StartDefer)
        StateJam <= #Tp 1'b0;
        StateJam <= #Tp 1'b0;
      else
      else
      if(StartJam)
      if(StartJam)
        StateJam <= #Tp 1'b1;
        StateJam <= #Tp 1'b1;
 
 
      if(StartDefer)
      if(StartDefer)
        StateBackOff <= #Tp 1'b0;
        StateBackOff <= #Tp 1'b0;
      else
      else
      if(StartBackoff)
      if(StartBackoff)
        StateBackOff <= #Tp 1'b1;
        StateBackOff <= #Tp 1'b1;
 
 
      if(StartIPG)
      if(StartIPG)
        StateDefer <= #Tp 1'b0;
        StateDefer <= #Tp 1'b0;
      else
      else
      if(StartDefer)
      if(StartDefer)
        StateDefer <= #Tp 1'b1;
        StateDefer <= #Tp 1'b1;
    end
    end
end
end
 
 
 
 
// This sections defines which interpack gap rule to use
// This sections defines which interpack gap rule to use
always @ (posedge MTxClk or posedge Reset)
always @ (posedge MTxClk or posedge Reset)
begin
begin
  if(Reset)
  if(Reset)
    Rule1 <= #Tp 1'b0;
    Rule1 <= #Tp 1'b0;
  else
  else
    begin
    begin
      if(StateIdle | StateBackOff)
      if(StateIdle | StateBackOff)
        Rule1 <= #Tp 1'b0;
        Rule1 <= #Tp 1'b0;
      else
      else
      if(StatePreamble | FullD)
      if(StatePreamble | FullD)
        Rule1 <= #Tp 1'b1;
        Rule1 <= #Tp 1'b1;
    end
    end
end
end
 
 
 
 
 
 
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.