USB_I2C_MAC_FPGA_Code.rar

源代码在线查看: eth_macstatus.v

软件大小: 1724 K
上传用户: bigfei
关键词: C_MAC_FPGA_Code USB_I
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				//
				
				`include "timescale.v"
				
				
				module eth_macstatus(
				                      MRxClk, Reset, ReceivedLengthOK, ReceiveEnd, ReceivedPacketGood, RxCrcError, 
				                      MRxErr, MRxDV, RxStateSFD, RxStateData, RxStatePreamble, RxStateIdle, Transmitting, 
				                      RxByteCnt, RxByteCntEq0, RxByteCntGreat2, RxByteCntMaxFrame, 
				                      InvalidSymbol, MRxD, LatchedCrcError, Collision, CollValid, RxLateCollision,
				                      r_RecSmall, r_MinFL, r_MaxFL, ShortFrame, DribbleNibble, ReceivedPacketTooBig, r_HugEn,
				                      LoadRxStatus, StartTxDone, StartTxAbort, RetryCnt, RetryCntLatched, MTxClk, MaxCollisionOccured, 
				                      RetryLimit, LateCollision, LateCollLatched, DeferIndication, DeferLatched, TxStartFrm,
				                      StatePreamble, StateData, CarrierSense, CarrierSenseLost, TxUsedData, LatchedMRxErr, Loopback, 
				                      r_FullD
				                    );
				
				
				
				parameter Tp = 1;
				
				
				input         MRxClk;
				input         Reset;
				input         RxCrcError;
				input         MRxErr;
				input         MRxDV;
				
				input         RxStateSFD;
				input   [1:0] RxStateData;
				input         RxStatePreamble;
				input         RxStateIdle;
				input         Transmitting;
				input  [15:0] RxByteCnt;
				input         RxByteCntEq0;
				input         RxByteCntGreat2;
				input         RxByteCntMaxFrame;
				input   [3:0] MRxD;
				input         Collision;
				input   [5:0] CollValid;
				input         r_RecSmall;
				input  [15:0] r_MinFL;
				input  [15:0] r_MaxFL;
				input         r_HugEn;
				input         StartTxDone;
				input         StartTxAbort;
				input   [3:0] RetryCnt;
				input         MTxClk;
				input         MaxCollisionOccured;
				input         LateCollision;
				input         DeferIndication;
				input         TxStartFrm;
				input         StatePreamble;
				input   [1:0] StateData;
				input         CarrierSense;
				input         TxUsedData;
				input         Loopback;
				input         r_FullD;
				
				
				output        ReceivedLengthOK;
				output        ReceiveEnd;
				output        ReceivedPacketGood;
				output        InvalidSymbol;
				output        LatchedCrcError;
				output        RxLateCollision;
				output        ShortFrame;
				output        DribbleNibble;
				output        ReceivedPacketTooBig;
				output        LoadRxStatus;
				output  [3:0] RetryCntLatched;
				output        RetryLimit;
				output        LateCollLatched;
				output        DeferLatched;
				output        CarrierSenseLost;
				output        LatchedMRxErr;
				
				
				reg           ReceiveEnd;
				
				reg           LatchedCrcError;
				reg           LatchedMRxErr;
				reg           LoadRxStatus;
				reg           InvalidSymbol;
				reg     [3:0] RetryCntLatched;
				reg           RetryLimit;
				reg           LateCollLatched;
				reg           DeferLatched;
				reg           CarrierSenseLost;
				
				wire          TakeSample;
				wire          SetInvalidSymbol; // Invalid symbol was received during reception in 100Mbps 
				
				// Crc error
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    LatchedCrcError 				  else
				  if(RxStateSFD)
				    LatchedCrcError 				  else
				  if(RxStateData[0])
				    LatchedCrcError 				end
				
				
				// LatchedMRxErr
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    LatchedMRxErr 				  else
				  if(MRxErr & MRxDV & (RxStatePreamble | RxStateSFD | (|RxStateData) | RxStateIdle & ~Transmitting))
				    LatchedMRxErr 				  else
				    LatchedMRxErr 				end
				
				
				// ReceivedPacketGood
				assign ReceivedPacketGood = ~LatchedCrcError;
				
				
				// ReceivedLengthOK
				assign ReceivedLengthOK = RxByteCnt[15:0] >= r_MinFL[15:0] & RxByteCnt[15:0] 				
				
				
				
				
				// Time to take a sample
				//assign TakeSample = |RxStateData     & ~MRxDV & RxByteCntGreat2  |
				assign TakeSample = (|RxStateData)   & (~MRxDV)                    |
				                      RxStateData[0] &   MRxDV & RxByteCntMaxFrame;
				
				
				// LoadRxStatus
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    LoadRxStatus 				  else
				    LoadRxStatus 				end
				
				
				
				// ReceiveEnd
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    ReceiveEnd  				  else
				    ReceiveEnd  				end
				
				
				// Invalid Symbol received during 100Mbps mode
				assign SetInvalidSymbol = MRxDV & MRxErr & MRxD[3:0] == 4'he;
				
				
				// InvalidSymbol
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    InvalidSymbol 				  else
				  if(LoadRxStatus & ~SetInvalidSymbol)
				    InvalidSymbol 				  else
				  if(SetInvalidSymbol)
				    InvalidSymbol 				end
				
				
				// Late Collision
				
				reg RxLateCollision;
				reg RxColWindow;
				// Collision Window
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    RxLateCollision 				  else
				  if(LoadRxStatus)
				    RxLateCollision 				  else
				  if(Collision & (~r_FullD) & (~RxColWindow | r_RecSmall))
				    RxLateCollision 				end
				
				// Collision Window
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    RxColWindow 				  else
				  if(~Collision & RxByteCnt[5:0] == CollValid[5:0] & RxStateData[1])
				    RxColWindow 				  else
				  if(RxStateIdle)
				    RxColWindow 				end
				
				
				// ShortFrame
				reg ShortFrame;
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    ShortFrame 				  else
				  if(LoadRxStatus)
				    ShortFrame 				  else
				  if(TakeSample)
				    ShortFrame 				end
				
				
				// DribbleNibble
				reg DribbleNibble;
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    DribbleNibble 				  else
				  if(RxStateSFD)
				    DribbleNibble 				  else
				  if(~MRxDV & RxStateData[1])
				    DribbleNibble 				end
				
				
				reg ReceivedPacketTooBig;
				always @ (posedge MRxClk or posedge Reset)
				begin
				  if(Reset)
				    ReceivedPacketTooBig 				  else
				  if(LoadRxStatus)
				    ReceivedPacketTooBig 				  else
				  if(TakeSample)
				    ReceivedPacketTooBig  r_MaxFL[15:0];
				end
				
				
				
				// Latched Retry counter for tx status
				always @ (posedge MTxClk or posedge Reset)
				begin
				  if(Reset)
				    RetryCntLatched 				  else
				  if(StartTxDone | StartTxAbort)
				    RetryCntLatched 				end
				
				
				// Latched Retransmission limit
				always @ (posedge MTxClk or posedge Reset)
				begin
				  if(Reset)
				    RetryLimit 				  else
				  if(StartTxDone | StartTxAbort)
				    RetryLimit 				end
				
				
				// Latched Late Collision
				always @ (posedge MTxClk or posedge Reset)
				begin
				  if(Reset)
				    LateCollLatched 				  else
				  if(StartTxDone | StartTxAbort)
				    LateCollLatched 				end
				
				
				
				// Latched Defer state
				always @ (posedge MTxClk or posedge Reset)
				begin
				  if(Reset)
				    DeferLatched 				  else
				  if(DeferIndication & TxUsedData)
				    DeferLatched 				  else
				  if(TxStartFrm)
				    DeferLatched 				end
				
				
				// CarrierSenseLost
				always @ (posedge MTxClk or posedge Reset)
				begin
				  if(Reset)
				    CarrierSenseLost 				  else
				  if((StatePreamble | (|StateData)) & ~CarrierSense & ~Loopback & ~Collision & ~r_FullD)
				    CarrierSenseLost 				  else
				  if(TxStartFrm)
				    CarrierSenseLost 				end
				
				
				endmodule
							

相关资源