root / usrp2 / fpga / simple_gemac / simple_gemac_tb.v @ c1950e29
History | View | Annotate | Download (1.9 kB)
| 1 | |
|---|---|
| 2 | |
| 3 | module simple_gemac_tb; |
| 4 | |
| 5 | |
| 6 | reg clk = 0; |
| 7 | reg reset = 1; |
| 8 | |
| 9 | initial #1000 reset = 0; |
| 10 | always #50 clk = ~clk; |
| 11 | |
| 12 | wire GMII_RX_DV, GMII_RX_ER, GMII_TX_EN, GMII_TX_ER; |
| 13 | wire [7:0] GMII_RXD, GMII_TXD; |
| 14 | |
| 15 | wire rx_valid, rx_error, rx_ack; |
| 16 | wire tx_ack; |
| 17 | reg tx_valid = 0, tx_error = 0; |
| 18 | |
| 19 | wire [7:0] rx_data; |
| 20 | reg [7:0] tx_data; |
| 21 | |
| 22 | wire [15:0] pause_time = 16'hBEEF; |
| 23 | reg pause_req = 0; |
| 24 | |
| 25 | simple_gemac simple_gemac |
| 26 | (.clk125(clk), .reset(reset), |
| 27 | .GMII_GTX_CLK(GMII_GTX_CLK), .GMII_TX_EN(GMII_TX_EN), |
| 28 | .GMII_TX_ER(GMII_TX_ER), .GMII_TXD(GMII_TXD), |
| 29 | .GMII_RX_CLK(GMII_RX_CLK), .GMII_RX_DV(GMII_RX_DV), |
| 30 | .GMII_RX_ER(GMII_RX_ER), .GMII_RXD(GMII_RXD), |
| 31 | .pause_req(pause_req), .pause_time(pause_time), |
| 32 | .rx_clk(rx_clk), .rx_data(rx_data), |
| 33 | .rx_valid(rx_valid), .rx_error(rx_error), .rx_ack(rx_ack), |
| 34 | .tx_clk(tx_clk), .tx_data(tx_data), |
| 35 | .tx_valid(tx_valid), .tx_error(tx_error), .tx_ack(tx_ack) |
| 36 | ); |
| 37 | |
| 38 | task SendFlowCtrl; |
| 39 | begin |
| 40 | $display("Sending Flow Control");
|
| 41 | @(posedge clk); |
| 42 | pause_req <= 1; |
| 43 | @(posedge clk); |
| 44 | pause_req <= 0; |
| 45 | end |
| 46 | endtask // SendFlowCtrl |
| 47 | |
| 48 | reg [31:0] count; |
| 49 | task SendPacket; |
| 50 | input [7:0] data_start; |
| 51 | input [31:0] data_len; |
| 52 | begin |
| 53 | $display("Sending Packet");
|
| 54 | count <= 0; |
| 55 | tx_data <= data_start; |
| 56 | tx_error <= 0; |
| 57 | tx_valid <= 1; |
| 58 | while(~tx_ack) |
| 59 | @(posedge tx_clk); |
| 60 | while(count < data_len) |
| 61 | begin |
| 62 | tx_data <= tx_data + 1; |
| 63 | count <= count + 1; |
| 64 | @(posedge clk); |
| 65 | end |
| 66 | tx_valid <= 0; |
| 67 | @(posedge tx_clk); |
| 68 | end |
| 69 | endtask // SendPacket |
| 70 | |
| 71 | initial $dumpfile("simple_gemac_tb.vcd");
|
| 72 | initial $dumpvars(0,simple_gemac_tb); |
| 73 | |
| 74 | initial |
| 75 | begin |
| 76 | @(negedge reset); |
| 77 | repeat (20) |
| 78 | @(posedge clk); |
| 79 | SendFlowCtrl; |
| 80 | repeat (100) |
| 81 | @(posedge clk); |
| 82 | SendPacket(8'hAA,10); |
| 83 | repeat (1000) |
| 84 | @(posedge clk); |
| 85 | $finish; |
| 86 | end |
| 87 | |
| 88 | endmodule // simple_gemac_tb |