山一程 水一程 https://passport2.21ic.com/?809790 [收藏] [复制] [RSS] OPTIMISM, PASSION & HARDWORK

日志

TX module:生成随机数 以太网MAC控制器Opencore代码学习

已有 1177 次阅读2013-10-3 17:13 |个人分类:FPGA|系统分类:通信网络| MAC, 以太网

       
  1. `include "timescale.v"

  2. module eth_random (MTxClk, Reset, StateJam, StateJam_q, RetryCnt, NibCnt, ByteCnt, 
  3.                    RandomEq0, RandomEqByteCnt);

  4. input MTxClk;
  5. input Reset;
  6. input StateJam;
  7. input StateJam_q;
  8. input [3:0] RetryCnt;
  9. input [15:0] NibCnt;
  10. input [9:0] ByteCnt;
  11. output RandomEq0;
  12. output RandomEqByteCnt;

  13. wire Feedback;
  14. reg [9:0] x;
  15. wire [9:0] Random;
  16. reg  [9:0] RandomLatched;

  17. //Feedback Shift Register 
  18. always @ (posedge MTxClk or posedge Reset)
  19. begin
  20.   if(Reset)
  21.     x[9:0] <=  0;
  22.   else
  23.     x[9:0] <=  {x[8:0], Feedback};
  24. end

  25. assign Feedback = ~(x[2] ^ x[9]);
  26. //generate Random number accoding to Retry times and rusult above
  27. assign Random [0] = x[0];
  28. assign Random [1] = (RetryCnt > 1) ? x[1] : 1'b0;
  29. assign Random [2] = (RetryCnt > 2) ? x[2] : 1'b0;
  30. assign Random [3] = (RetryCnt > 3) ? x[3] : 1'b0;
  31. assign Random [4] = (RetryCnt > 4) ? x[4] : 1'b0;
  32. assign Random [5] = (RetryCnt > 5) ? x[5] : 1'b0;
  33. assign Random [6] = (RetryCnt > 6) ? x[6] : 1'b0;
  34. assign Random [7] = (RetryCnt > 7) ? x[7] : 1'b0;
  35. assign Random [8] = (RetryCnt > 8) ? x[8] : 1'b0;
  36. assign Random [9] = (RetryCnt > 9) ? x[9] : 1'b0;

  37. //after Jam , get a Random number
  38. always @ (posedge MTxClk or posedge Reset)
  39. begin
  40.   if(Reset)
  41.     RandomLatched <=  10'h000;
  42.   else
  43.     begin
  44.       if(StateJam & StateJam_q)
  45.         RandomLatched <=  Random;
  46.     end
  47. end

  48. // Random Number == 0      IEEE 802.3 page 68. If 0 we go to defer and not to backoff.
  49. assign RandomEq0 = RandomLatched == 10'h0; 

  50. assign RandomEqByteCnt = ByteCnt[9:0] == RandomLatched & (&NibCnt[6:0]);

  51. endmodule
复制代码

RTL结构


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)