FPGA 学习小组
直播中

alexdos

6年用户 804经验值
擅长:可编程逻辑 电源/新能源 嵌入式技术 模拟技术
私信 关注

以太网控制器计数器模块实现代码

计数器模块提供数据发送过程中需要的所有计数器:DlyCrcCnt 用来在 CRC 校验序列产生过程中计数;按照 4 位传输时采用 NibCnt 计数;按照字节传输时采用 ByteCnt 计数。计数器模块的主要代码如下:

  1. //四位传输计数器
  2. always @ (posedge MTxClk or posedge Reset)
  3. begin
  4. if(Reset)
  5. NibCnt <= #Tp 16'h0;
  6. else
  7. begin
  8. if(ResetNibCnt)
  9. NibCnt <= #Tp 16'h0;
  10. else
  11. if(IncrementNibCnt)
  12. NibCnt <= #Tp NibCnt + 1'b1;
  13. end
  14. end
  15. assign NibCntEq7 = &NibCnt[2:0];
  16. assign NibCntEq15 = &NibCnt[3:0];
  17. assign NibbleMinFl = NibCnt >= (((MinFL-3'h4)<<1) -1); // FCS should not be included inNibbleMinFl
  18. assign ExcessiveDeferCnt = NibCnt[13:0] == 16'h17b7;
  19. assign ExcessiveDefer = NibCnt[13:0] == 16'h17b7 & ~ExDfrEn; // 6071 nibbles
  20. assign IncrementByteCnt = StateData[1] & ~ByteCntMax & ~|DlyCrcCnt[2:0]
  21. | StateBackOff & (&NibCnt[6:0])
  22. | (StatePAD | StateFCS) & NibCnt[0] & ~ByteCntMax;
  23. assign ResetByteCnt = StartBackoff | StateIdle & TxStartFrm | PacketFinished_q;
  24. // 字节传输计数器
  25. always @ (posedge MTxClk or posedge Reset)
  26. begin
  27. if(Reset)
  28. ByteCnt[15:0] <= #Tp 16'h0;
  29. else
  30. begin
  31. if(ResetByteCnt)
  32. ByteCnt[15:0] <= #Tp 16'h0;
  33. else
  34. if(IncrementByteCnt)
  35. ByteCnt[15:0] <= #Tp ByteCnt[15:0] + 1'b1;
  36. end
  37. end
  38. assign MaxFrame = ByteCnt[15:0] == MaxFL[15:0] & ~HugEn;
  39. assign ByteCntMax = &ByteCnt[15:0];
  40. //CRC 计数器
  41. always @ (posedge MTxClk or posedge Reset)
  42. begin
  43. if(Reset)
  44. DlyCrcCnt <= #Tp 3'h0;
  45. else
  46. begin
  47. if(StateData[1] & DlyCrcCnt == 3'h4 | StartJam | PacketFinished_q)
  48. DlyCrcCnt <= #Tp 3'h0;
  49. else
  50. if(DlyCrcEn & (StateSFD | StateData[1] & (|DlyCrcCnt[2:0])))
  51. DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
  52. end
  53. end

更多回帖

发帖
×
20
完善资料,
赚取积分