USB_I2C_MAC_FPGA_Code.rar

源代码在线查看: eth_receivecontrol.v

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

相关代码

				
				
				`include "timescale.v"
				
				
				module eth_receivecontrol (MTxClk, MRxClk, TxReset, RxReset, RxData, RxValid, RxStartFrm, 
				                           RxEndFrm, RxFlow, ReceiveEnd, MAC, DlyCrcEn, TxDoneIn, 
				                           TxAbortIn, TxStartFrmOut, ReceivedLengthOK, ReceivedPacketGood, 
				                           TxUsedDataOutDetected, Pause, ReceivedPauseFrm, AddressOK, 
				                           RxStatusWriteLatched_sync2, r_PassAll, SetPauseTimer
				                          );
				
				parameter Tp = 1;
				
				
				input       MTxClk;
				input       MRxClk;
				input       TxReset; 
				input       RxReset; 
				input [7:0] RxData;
				input       RxValid;
				input       RxStartFrm;
				input       RxEndFrm;
				input       RxFlow;
				input       ReceiveEnd;
				input [47:0]MAC;
				input       DlyCrcEn;
				input       TxDoneIn;
				input       TxAbortIn;
				input       TxStartFrmOut;
				input       ReceivedLengthOK;
				input       ReceivedPacketGood;
				input       TxUsedDataOutDetected;
				input       RxStatusWriteLatched_sync2;
				input       r_PassAll;
				
				output      Pause;
				output      ReceivedPauseFrm;
				output      AddressOK;
				output      SetPauseTimer;
				
				
				reg         Pause;
				reg         AddressOK;                // Multicast or unicast address detected
				reg         TypeLengthOK;             // Type/Length field contains 0x8808
				reg         DetectionWindow;          // Detection of the PAUSE frame is possible within this window
				reg         OpCodeOK;                 // PAUSE opcode detected (0x0001)
				reg  [2:0]  DlyCrcCnt;
				reg  [4:0]  ByteCnt;
				reg [15:0]  AssembledTimerValue;
				reg [15:0]  LatchedTimerValue;
				reg         ReceivedPauseFrm;
				reg         ReceivedPauseFrmWAddr;
				reg         PauseTimerEq0_sync1;
				reg         PauseTimerEq0_sync2;
				reg [15:0]  PauseTimer;
				reg         Divider2;
				reg  [5:0]  SlotTimer;
				
				wire [47:0] ReservedMulticast;        // 0x0180C2000001
				wire [15:0] TypeLength;               // 0x8808
				wire        ResetByteCnt;             // 
				wire        IncrementByteCnt;         // 
				wire        ByteCntEq0;               // ByteCnt = 0
				wire        ByteCntEq1;               // ByteCnt = 1
				wire        ByteCntEq2;               // ByteCnt = 2
				wire        ByteCntEq3;               // ByteCnt = 3
				wire        ByteCntEq4;               // ByteCnt = 4
				wire        ByteCntEq5;               // ByteCnt = 5
				wire        ByteCntEq12;              // ByteCnt = 12
				wire        ByteCntEq13;              // ByteCnt = 13
				wire        ByteCntEq14;              // ByteCnt = 14
				wire        ByteCntEq15;              // ByteCnt = 15
				wire        ByteCntEq16;              // ByteCnt = 16
				wire        ByteCntEq17;              // ByteCnt = 17
				wire        ByteCntEq18;              // ByteCnt = 18
				wire        DecrementPauseTimer;      // 
				wire        PauseTimerEq0;            // 
				wire        ResetSlotTimer;           // 
				wire        IncrementSlotTimer;       // 
				wire        SlotFinished;             // 
				
				
				
				// Reserved multicast address and Type/Length for PAUSE control
				assign ReservedMulticast = 48'h0180C2000001;
				assign TypeLength = 16'h8808;
				
				
				// Address Detection (Multicast or unicast)
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    AddressOK 				  else
				  if(DetectionWindow & ByteCntEq0)
				    AddressOK 				  else
				  if(DetectionWindow & ByteCntEq1)
				    AddressOK 				  else
				  if(DetectionWindow & ByteCntEq2)
				    AddressOK 				  else
				  if(DetectionWindow & ByteCntEq3)
				    AddressOK 				  else
				  if(DetectionWindow & ByteCntEq4)
				    AddressOK 				  else
				  if(DetectionWindow & ByteCntEq5)
				    AddressOK 				  else
				  if(ReceiveEnd)
				    AddressOK 				end
				
				
				
				// TypeLengthOK (Type/Length Control frame detected)
				always @ (posedge MRxClk or posedge RxReset )
				begin
				  if(RxReset)
				    TypeLengthOK 				  else
				  if(DetectionWindow & ByteCntEq12)
				    TypeLengthOK 				  else
				  if(DetectionWindow & ByteCntEq13)
				    TypeLengthOK 				  else
				  if(ReceiveEnd)
				    TypeLengthOK 				end
				
				
				
				// Latch Control Frame Opcode
				always @ (posedge MRxClk or posedge RxReset )
				begin
				  if(RxReset)
				    OpCodeOK 				  else
				  if(ByteCntEq16)
				    OpCodeOK 				  else
				    begin
				      if(DetectionWindow & ByteCntEq14)
				        OpCodeOK 				    
				      if(DetectionWindow & ByteCntEq15)
				        OpCodeOK 				    end
				end
				
				
				// ReceivedPauseFrmWAddr (+Address Check)
				always @ (posedge MRxClk or posedge RxReset )
				begin
				  if(RxReset)
				    ReceivedPauseFrmWAddr 				  else
				  if(ReceiveEnd)
				    ReceivedPauseFrmWAddr 				  else
				  if(ByteCntEq16 & TypeLengthOK & OpCodeOK & AddressOK)
				    ReceivedPauseFrmWAddr 				end
				
				
				
				// Assembling 16-bit timer value from two 8-bit data
				always @ (posedge MRxClk or posedge RxReset )
				begin
				  if(RxReset)
				    AssembledTimerValue[15:0] 				  else
				  if(RxStartFrm)
				    AssembledTimerValue[15:0] 				  else
				    begin
				      if(DetectionWindow & ByteCntEq16)
				        AssembledTimerValue[15:8] 				      if(DetectionWindow & ByteCntEq17)
				        AssembledTimerValue[7:0] 				    end
				end
				
				
				// Detection window (while PAUSE detection is possible)
				always @ (posedge MRxClk or posedge RxReset )
				begin
				  if(RxReset)
				    DetectionWindow 				  else
				  if(ByteCntEq18)
				    DetectionWindow 				  else
				  if(ReceiveEnd)
				    DetectionWindow 				end
				
				
				
				// Latching Timer Value
				always @ (posedge MRxClk or posedge RxReset )
				begin
				  if(RxReset)
				    LatchedTimerValue[15:0] 				  else
				  if(DetectionWindow &  ReceivedPauseFrmWAddr &  ByteCntEq18)
				    LatchedTimerValue[15:0] 				  else
				  if(ReceiveEnd)
				    LatchedTimerValue[15:0] 				end
				
				
				
				// Delayed CEC counter
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    DlyCrcCnt 				  else
				  if(RxValid & RxEndFrm)
				    DlyCrcCnt 				  else
				  if(RxValid & ~RxEndFrm & ~DlyCrcCnt[2])
				    DlyCrcCnt 				end
				
				             
				assign ResetByteCnt = RxEndFrm;
				assign IncrementByteCnt = RxValid & DetectionWindow & ~ByteCntEq18 & (~DlyCrcEn | DlyCrcEn & DlyCrcCnt[2]);
				
				
				// Byte counter
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    ByteCnt[4:0] 				  else
				  if(ResetByteCnt)
				    ByteCnt[4:0] 				  else
				  if(IncrementByteCnt)
				    ByteCnt[4:0] 				end
				
				
				assign ByteCntEq0 = RxValid & ByteCnt[4:0] == 5'h0;
				assign ByteCntEq1 = RxValid & ByteCnt[4:0] == 5'h1;
				assign ByteCntEq2 = RxValid & ByteCnt[4:0] == 5'h2;
				assign ByteCntEq3 = RxValid & ByteCnt[4:0] == 5'h3;
				assign ByteCntEq4 = RxValid & ByteCnt[4:0] == 5'h4;
				assign ByteCntEq5 = RxValid & ByteCnt[4:0] == 5'h5;
				assign ByteCntEq12 = RxValid & ByteCnt[4:0] == 5'h0C;
				assign ByteCntEq13 = RxValid & ByteCnt[4:0] == 5'h0D;
				assign ByteCntEq14 = RxValid & ByteCnt[4:0] == 5'h0E;
				assign ByteCntEq15 = RxValid & ByteCnt[4:0] == 5'h0F;
				assign ByteCntEq16 = RxValid & ByteCnt[4:0] == 5'h10;
				assign ByteCntEq17 = RxValid & ByteCnt[4:0] == 5'h11;
				assign ByteCntEq18 = RxValid & ByteCnt[4:0] == 5'h12 & DetectionWindow;
				
				
				assign SetPauseTimer = ReceiveEnd & ReceivedPauseFrmWAddr & ReceivedPacketGood & ReceivedLengthOK & RxFlow;
				assign DecrementPauseTimer = SlotFinished & |PauseTimer;
				
				
				// PauseTimer[15:0]
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    PauseTimer[15:0] 				  else
				  if(SetPauseTimer)
				    PauseTimer[15:0] 				  else
				  if(DecrementPauseTimer)
				    PauseTimer[15:0] 				end
				
				assign PauseTimerEq0 = ~(|PauseTimer[15:0]);
				
				
				
				// Synchronization of the pause timer
				always @ (posedge MTxClk or posedge TxReset)
				begin
				  if(TxReset)
				    begin
				      PauseTimerEq0_sync1 				      PauseTimerEq0_sync2 				    end
				  else
				    begin
				      PauseTimerEq0_sync1 				      PauseTimerEq0_sync2 				    end
				end
				
				
				// Pause signal generation
				always @ (posedge MTxClk or posedge TxReset)
				begin
				  if(TxReset)
				    Pause 				  else
				  if((TxDoneIn | TxAbortIn | ~TxUsedDataOutDetected) & ~TxStartFrmOut)
				    Pause 				end
				
				
				// Divider2 is used for incrementing the Slot timer every other clock
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    Divider2 				  else
				  if(|PauseTimer[15:0] & RxFlow)
				    Divider2 				  else
				    Divider2 				end
				
				
				assign ResetSlotTimer = RxReset;
				assign IncrementSlotTimer =  Pause & RxFlow & Divider2;
				
				
				// SlotTimer
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    SlotTimer[5:0] 				  else
				  if(ResetSlotTimer)
				    SlotTimer[5:0] 				  else
				  if(IncrementSlotTimer)
				    SlotTimer[5:0] 				end
				
				
				assign SlotFinished = &SlotTimer[5:0] & IncrementSlotTimer;  // Slot is 512 bits (64 bytes)
				
				
				
				// Pause Frame received
				always @ (posedge MRxClk or posedge RxReset)
				begin
				  if(RxReset)
				    ReceivedPauseFrm 				  else
				  if(RxStatusWriteLatched_sync2 & r_PassAll | ReceivedPauseFrm & (~r_PassAll))
				    ReceivedPauseFrm 				  else
				  if(ByteCntEq16 & TypeLengthOK & OpCodeOK)
				    ReceivedPauseFrm 				end
				
				
				endmodule
							

相关资源