数据发送模块和数据接收模块单独工作时,以太网控制器工作在半双工状态。当以太网控制器工作在 100Mbit/s 全双工时,数据流程由控制模块控制。控制模块由两部分组成。
• 数据传输控制。
• 数据接收控制。
控制模块的顶层程序连接两个子模块,主要代码如下:
- `include "timescale.v"
- module eth_maccontrol (MTxClk, MRxClk, TxReset, RxReset, TPauseRq, TxDataIn, TxStartFrmIn,
- TxUsedDataIn, TxEndFrmIn, TxDoneIn, TxAbortIn, RxData, RxValid, RxStartFrm, RxEndFrm,
- ReceiveEnd,
- ReceivedPacketGood, ReceivedLengthOK, TxFlow, RxFlow, DlyCrcEn, TxPauseTV, MAC, PadIn,
- PadOut,
- CrcEnIn, CrcEnOut, TxDataOut, TxStartFrmOut, TxEndFrmOut, TxDoneOut, TxAbortOut,
- TxUsedDataOut, WillSendControlFrame, TxCtrlEndFrm,ReceivedPauseFrm, ControlFrmAddressOK,
- SetPauseTimer, r_PassAll, RxStatusWriteLatched_sync2 );
- parameter Tp = 1;
- //输入输出信号
- input MTxClk; //传输时钟信号
- input MRxClk; //接收时钟信号
- ……
- //连线与寄存器
- reg TxUsedDataOutDetected;
- ……
- //正在传输数据
- always @ (posedge MTxClk or posedge TxReset)
- begin
- if(TxReset)
- TxUsedDataOutDetected <= #Tp 1'b0;
- else
- if(TxDoneIn | TxAbortIn)
- TxUsedDataOutDetected <= #Tp 1'b0;
- else
- if(TxUsedDataOut)
- TxUsedDataOutDetected <= #Tp 1'b1;
- end
- //锁存变量
- always @ (posedge MTxClk or posedge TxReset)
- begin
- if(TxReset)
- begin
- TxAbortInLatched <= #Tp 1'b0;
- TxDoneInLatched <= #Tp 1'b0;
- end
- else
- begin
- TxAbortInLatched <= #Tp TxAbortIn;
- TxDoneInLatched <= #Tp TxDoneIn;
- end
- end
- //产生复用退出信号
- always @ (posedge MTxClk or posedge TxReset)
- begin
- if(TxReset)
- MuxedAbort <= #Tp 1'b0;
- else
- if(TxStartFrmIn)
- MuxedAbort <= #Tp 1'b0;
- else
- if(TxAbortIn & ~TxAbortInLatched & TxUsedDataOutDetected)
- MuxedAbort <= #Tp 1'b1;
- end
- //产生复用结束信号
- always @ (posedge MTxClk or posedge TxReset)
- begin
- if(TxReset)
- MuxedDone <= #Tp 1'b0;
- else
- if(TxStartFrmIn)
- MuxedDone <= #Tp 1'b0;
- else
- if(TxDoneIn & (~TxDoneInLatched) & TxUsedDataOutDetected)
- MuxedDone <= #Tp 1'b1;
- end
- // 输出发送数据结束信号
- assign TxDoneOut = CtrlMux? ((~TxStartFrmIn) & (~BlockTxDone) & MuxedDone) :
- ((~TxStartFrmIn) & (~BlockTxDone) & TxDoneIn);
- //发送数据退出信号
- assign TxAbortOut = CtrlMux? ((~TxStartFrmIn) & (~BlockTxDone) & MuxedAbort) :
- ((~TxStartFrmIn) & (~BlockTxDone) & TxAbortIn);
- //发送使用过数据输出信号
- assign TxUsedDataOut = ~CtrlMux & TxUsedDataIn;
- //传输帧起始信号
- assign TxStartFrmOut = CtrlMux? TxCtrlStartFrm : (TxStartFrmIn & ~Pause);
- //传输帧结束信号
- assign TxEndFrmOut = CtrlMux? TxCtrlEndFrm : TxEndFrmIn;
- //发送数据内容
- assign TxDataOut[7:0] = CtrlMux? ControlData[7:0] : TxDataIn[7:0];
- assign PadOut = PadIn | SendingCtrlFrm;
- //CRC 校验使能信号输出
- assign CrcEnOut = CrcEnIn | SendingCtrlFrm;
- //连接接收控制模块
- eth_receivecontrol receivecontrol1
- (
- .MTxClk(MTxClk), .MRxClk(MRxClk), .TxReset(TxReset), .RxReset(RxReset), .RxData(RxData),
- .RxValid(RxValid), .RxStartFrm(RxStartFrm), .RxEndFrm(RxEndFrm), .RxFlow(RxFlow),
- .ReceiveEnd(ReceiveEnd), .MAC(MAC), .DlyCrcEn(DlyCrcEn), .TxDoneIn(TxDoneIn),
- .TxAbortIn(TxAbortIn), .TxStartFrmOut(TxStartFrmOut), .ReceivedLengthOK(ReceivedLengthOK
- ),
- .ReceivedPacketGood(ReceivedPacketGood), .TxUsedDataOutDetected(TxUsedDataOutDetected),
- .Pause(Pause), .ReceivedPauseFrm(ReceivedPauseFrm), .AddressOK(ControlFrmAddressOK),
- .r_PassAll(r_PassAll), .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2), .SetPaus
- eTimer(SetPauseTimer)
- );
- //连接传输控制模块
- eth_transmitcontrol transmitcontrol1
- (
- .MTxClk(MTxClk), .TxReset(TxReset), .TxUsedDataIn(TxUsedDataIn), .TxUsedDataOut(TxUsedDa
- taOut),
- .TxDoneIn(TxDoneIn), .TxAbortIn(TxAbortIn), .TxStartFrmIn(TxStartFrmIn), .TPauseRq(TPaus
- eRq),
- .TxUsedDataOutDetected(TxUsedDataOutDetected), .TxFlow(TxFlow), .DlyCrcEn(DlyCrcEn), .Tx
- PauseTV(TxPauseTV),
- .MAC(MAC), .TxCtrlStartFrm(TxCtrlStartFrm), .TxCtrlEndFrm(TxCtrlEndFrm), .SendingCtrlFrm
- (SendingCtrlFrm),
- .CtrlMux(CtrlMux), .ControlData(ControlData), .WillSendControlFrame(WillSendControlFrame
- ), .BlockTxDone(BlockTxDone)
- );
- endmodule
复制代码
0
|
|
|
|