root / usrp2 / fpga / simple_gemac / simple_gemac_wrapper_tb.v @ 253018c6
History | View | Annotate | Download (5.9 kB)
| 1 | e8896104 | matt | |
|---|---|---|---|
| 2 | e8896104 | matt | |
| 3 | e8896104 | matt | module simple_gemac_wrapper_tb; |
| 4 | e8896104 | matt | `include "eth_tasks.v" |
| 5 | e8896104 | matt | |
| 6 | e8896104 | matt | reg clk = 0; |
| 7 | e8896104 | matt | reg reset = 1; |
| 8 | e8896104 | matt | |
| 9 | e8896104 | matt | initial #1000 reset = 0; |
| 10 | e8896104 | matt | always #50 clk = ~clk; |
| 11 | e8896104 | matt | |
| 12 | e8896104 | matt | reg wb_clk = 0; |
| 13 | e8896104 | matt | wire wb_rst = reset; |
| 14 | e8896104 | matt | always #173 wb_clk = ~wb_clk; |
| 15 | e8896104 | matt | |
| 16 | e8896104 | matt | wire GMII_RX_DV, GMII_RX_ER, GMII_TX_EN, GMII_TX_ER, GMII_GTX_CLK; |
| 17 | e8896104 | matt | wire [7:0] GMII_RXD, GMII_TXD; |
| 18 | e8896104 | matt | |
| 19 | e8896104 | matt | wire rx_valid, rx_error, rx_ack; |
| 20 | e8896104 | matt | wire tx_ack, tx_valid, tx_error; |
| 21 | e8896104 | matt | |
| 22 | e8896104 | matt | wire [7:0] rx_data, tx_data; |
| 23 | e8896104 | matt | |
| 24 | e8896104 | matt | reg [15:0] pause_time; |
| 25 | e8896104 | matt | reg pause_req = 0; |
| 26 | e8896104 | matt | |
| 27 | e8896104 | matt | wire GMII_RX_CLK = GMII_GTX_CLK; |
| 28 | e8896104 | matt | |
| 29 | e8896104 | matt | reg [7:0] FORCE_DAT_ERR = 0; |
| 30 | e8896104 | matt | reg FORCE_ERR = 0; |
| 31 | e8896104 | matt | |
| 32 | e8896104 | matt | // Loopback |
| 33 | e8896104 | matt | assign GMII_RX_DV = GMII_TX_EN; |
| 34 | e8896104 | matt | assign GMII_RX_ER = GMII_TX_ER | FORCE_ERR; |
| 35 | e8896104 | matt | assign GMII_RXD = GMII_TXD ^ FORCE_DAT_ERR; |
| 36 | e8896104 | matt | |
| 37 | e8896104 | matt | |
| 38 | e8896104 | matt | wire rx_ll_sof, rx_ll_eof, rx_ll_src_rdy, rx_ll_dst_rdy; |
| 39 | e8896104 | matt | wire rx_ll_sof2, rx_ll_eof2, rx_ll_src_rdy2; |
| 40 | e8896104 | matt | reg rx_ll_dst_rdy2 = 1; |
| 41 | e8896104 | matt | wire [7:0] rx_ll_data, rx_ll_data2; |
| 42 | e8896104 | matt | wire rx_ll_error, rx_ll_error2; |
| 43 | e8896104 | matt | |
| 44 | e8896104 | matt | wire [31:0] wb_dat_o; |
| 45 | e8896104 | matt | reg [31:0] wb_dat_i; |
| 46 | e8896104 | matt | reg [7:0] wb_adr; |
| 47 | e8896104 | matt | reg wb_stb=0, wb_cyc=0, wb_we=0; |
| 48 | e8896104 | matt | wire wb_ack; |
| 49 | e8896104 | matt | |
| 50 | e8896104 | matt | simple_gemac_wrapper simple_gemac_wrapper |
| 51 | e8896104 | matt | (.clk125(clk), .reset(reset), |
| 52 | e8896104 | matt | .GMII_GTX_CLK(GMII_GTX_CLK), .GMII_TX_EN(GMII_TX_EN), |
| 53 | e8896104 | matt | .GMII_TX_ER(GMII_TX_ER), .GMII_TXD(GMII_TXD), |
| 54 | e8896104 | matt | .GMII_RX_CLK(GMII_RX_CLK), .GMII_RX_DV(GMII_RX_DV), |
| 55 | e8896104 | matt | .GMII_RX_ER(GMII_RX_ER), .GMII_RXD(GMII_RXD), |
| 56 | e8896104 | matt | .pause_req(pause_req), .pause_time(pause_time), |
| 57 | e8896104 | matt | .rx_clk(rx_clk), .rx_ll_data(rx_ll_data), .rx_ll_sof(rx_ll_sof), |
| 58 | e8896104 | matt | .rx_ll_eof(rx_ll_eof), .rx_ll_src_rdy(rx_ll_src_rdy), .rx_ll_dst_rdy(rx_ll_dst_rdy), |
| 59 | e8896104 | matt | .tx_clk(tx_clk), .tx_ll_data(tx_ll_data), .tx_ll_sof(tx_ll_sof), |
| 60 | e8896104 | matt | .tx_ll_eof(tx_ll_eof), .tx_ll_src_rdy(tx_ll_src_rdy), .tx_ll_dst_rdy(tx_ll_dst_rdy), |
| 61 | e8896104 | matt | .wb_clk(wb_clk), .wb_rst(wb_rst), .wb_stb(wb_stb), .wb_cyc(wb_cyc), .wb_ack(wb_ack), |
| 62 | e8896104 | matt | .wb_we(wb_we), .wb_adr(wb_adr), .wb_dat_i(wb_dat_i), .wb_dat_o(wb_dat_o), |
| 63 | e8896104 | matt | .mdio(mdio), .mdc(mdc) ); |
| 64 | e8896104 | matt | |
| 65 | e8896104 | matt | ll8_shortfifo rx_sfifo |
| 66 | e8896104 | matt | (.clk(clk), .reset(reset), .clear(0), |
| 67 | e8896104 | matt | .datain(rx_ll_data), .sof_i(rx_ll_sof), .eof_i(rx_ll_eof), |
| 68 | e8896104 | matt | .error_i(rx_ll_error), .src_rdy_i(rx_ll_src_rdy), .dst_rdy_o(rx_ll_dst_rdy), |
| 69 | e8896104 | matt | .dataout(rx_ll_data2), .sof_o(rx_ll_sof2), .eof_o(rx_ll_eof2), |
| 70 | e8896104 | matt | .error_o(rx_ll_error2), .src_rdy_o(rx_ll_src_rdy2), .dst_rdy_i(rx_ll_dst_rdy2)); |
| 71 | e8896104 | matt | |
| 72 | e8896104 | matt | wire tx_ll_sof, tx_ll_eof, tx_ll_src_rdy, tx_ll_dst_rdy; |
| 73 | e8896104 | matt | reg tx_ll_sof2=0, tx_ll_eof2=0; |
| 74 | e8896104 | matt | reg tx_ll_src_rdy2 = 0; |
| 75 | e8896104 | matt | wire tx_ll_dst_rdy2; |
| 76 | e8896104 | matt | wire [7:0] tx_ll_data; |
| 77 | e8896104 | matt | reg [7:0] tx_ll_data2 = 0; |
| 78 | e8896104 | matt | wire tx_ll_error; |
| 79 | e8896104 | matt | wire tx_ll_error2 = 0; |
| 80 | e8896104 | matt | |
| 81 | e8896104 | matt | ll8_shortfifo tx_sfifo |
| 82 | e8896104 | matt | (.clk(clk), .reset(reset), .clear(clear), |
| 83 | e8896104 | matt | .datain(tx_ll_data2), .sof_i(tx_ll_sof2), .eof_i(tx_ll_eof2), |
| 84 | e8896104 | matt | .error_i(tx_ll_error2), .src_rdy_i(tx_ll_src_rdy2), .dst_rdy_o(tx_ll_dst_rdy2), |
| 85 | e8896104 | matt | .dataout(tx_ll_data), .sof_o(tx_ll_sof), .eof_o(tx_ll_eof), |
| 86 | e8896104 | matt | .error_o(tx_ll_error), .src_rdy_o(tx_ll_src_rdy), .dst_rdy_i(tx_ll_dst_rdy)); |
| 87 | e8896104 | matt | |
| 88 | e8896104 | matt | initial $dumpfile("simple_gemac_wrapper_tb.vcd");
|
| 89 | e8896104 | matt | initial $dumpvars(0,simple_gemac_wrapper_tb); |
| 90 | e8896104 | matt | |
| 91 | e8896104 | matt | integer i; |
| 92 | e8896104 | matt | reg [7:0] pkt_rom[0:65535]; |
| 93 | e8896104 | matt | reg [1023:0] ROMFile; |
| 94 | e8896104 | matt | |
| 95 | e8896104 | matt | initial |
| 96 | e8896104 | matt | for (i=0;i<65536;i=i+1) |
| 97 | e8896104 | matt | pkt_rom[i] <= 8'h0; |
| 98 | e8896104 | matt | |
| 99 | e8896104 | matt | initial |
| 100 | e8896104 | matt | begin |
| 101 | e8896104 | matt | @(negedge reset); |
| 102 | e8896104 | matt | repeat (10) |
| 103 | e8896104 | matt | @(posedge clk); |
| 104 | e8896104 | matt | WishboneWR(0,6'b111001); |
| 105 | e8896104 | matt | WishboneWR(4,16'hF1F2); |
| 106 | e8896104 | matt | WishboneWR(8,32'hF3F4_F5F6); |
| 107 | e8896104 | matt | WishboneWR(12,16'h0000); |
| 108 | e8896104 | matt | WishboneWR(16,32'h0000_0000); |
| 109 | e8896104 | matt | |
| 110 | e8896104 | matt | @(posedge clk); |
| 111 | e8896104 | matt | SendFlowCtrl(16'h0007); // Send flow control |
| 112 | e8896104 | matt | @(posedge clk); |
| 113 | e8896104 | matt | #30000; |
| 114 | e8896104 | matt | @(posedge clk); |
| 115 | e8896104 | matt | SendFlowCtrl(16'h0009); // Increas flow control before it expires |
| 116 | e8896104 | matt | #10000; |
| 117 | e8896104 | matt | @(posedge clk); |
| 118 | e8896104 | matt | SendFlowCtrl(16'h0000); // Cancel flow control before it expires |
| 119 | e8896104 | matt | @(posedge clk); |
| 120 | e8896104 | matt | |
| 121 | e8896104 | matt | SendPacket_to_ll8(8'hAA,10); // This packet gets dropped by the filters |
| 122 | e8896104 | matt | repeat (10) |
| 123 | e8896104 | matt | @(posedge clk); |
| 124 | e8896104 | matt | |
| 125 | e8896104 | matt | SendPacketFromFile_ll8(60,0,0); // The rest are valid packets |
| 126 | e8896104 | matt | repeat (10) |
| 127 | e8896104 | matt | @(posedge clk); |
| 128 | e8896104 | matt | |
| 129 | e8896104 | matt | SendPacketFromFile_ll8(61,0,0); |
| 130 | e8896104 | matt | repeat (10) |
| 131 | e8896104 | matt | @(posedge clk); |
| 132 | e8896104 | matt | SendPacketFromFile_ll8(62,0,0); |
| 133 | e8896104 | matt | repeat (10) |
| 134 | e8896104 | matt | @(posedge clk); |
| 135 | e8896104 | matt | SendPacketFromFile_ll8(63,0,0); |
| 136 | e8896104 | matt | repeat (1) |
| 137 | e8896104 | matt | @(posedge clk); |
| 138 | e8896104 | matt | SendPacketFromFile_ll8(64,0,0); |
| 139 | e8896104 | matt | repeat (10) |
| 140 | e8896104 | matt | @(posedge clk); |
| 141 | e8896104 | matt | SendPacketFromFile_ll8(59,0,0); |
| 142 | e8896104 | matt | repeat (1) |
| 143 | e8896104 | matt | @(posedge clk); |
| 144 | e8896104 | matt | SendPacketFromFile_ll8(58,0,0); |
| 145 | e8896104 | matt | repeat (1) |
| 146 | e8896104 | matt | @(posedge clk); |
| 147 | e8896104 | matt | SendPacketFromFile_ll8(100,0,0); |
| 148 | e8896104 | matt | repeat (1) |
| 149 | e8896104 | matt | @(posedge clk); |
| 150 | e8896104 | matt | SendPacketFromFile_ll8(200,150,30); // waiting 14 empties the fifo, 15 underruns |
| 151 | e8896104 | matt | repeat (1) |
| 152 | e8896104 | matt | @(posedge clk); |
| 153 | e8896104 | matt | SendPacketFromFile_ll8(100,0,30); |
| 154 | e8896104 | matt | #10000 $finish; |
| 155 | e8896104 | matt | end |
| 156 | e8896104 | matt | |
| 157 | e8896104 | matt | // Force a CRC error |
| 158 | e8896104 | matt | initial |
| 159 | e8896104 | matt | begin |
| 160 | e8896104 | matt | #90000; |
| 161 | e8896104 | matt | @(posedge clk); |
| 162 | e8896104 | matt | FORCE_DAT_ERR <= 8'h10; |
| 163 | e8896104 | matt | @(posedge clk); |
| 164 | e8896104 | matt | FORCE_DAT_ERR <= 8'h00; |
| 165 | e8896104 | matt | end |
| 166 | e8896104 | matt | |
| 167 | e8896104 | matt | // Force an RX_ER error (i.e. link loss) |
| 168 | e8896104 | matt | initial |
| 169 | e8896104 | matt | begin |
| 170 | e8896104 | matt | #116000; |
| 171 | e8896104 | matt | @(posedge clk); |
| 172 | e8896104 | matt | FORCE_ERR <= 1; |
| 173 | e8896104 | matt | @(posedge clk); |
| 174 | e8896104 | matt | FORCE_ERR <= 0; |
| 175 | e8896104 | matt | end |
| 176 | e8896104 | matt | |
| 177 | e8896104 | matt | // Cause receive fifo to fill, causing an RX overrun |
| 178 | e8896104 | matt | initial |
| 179 | e8896104 | matt | begin |
| 180 | e8896104 | matt | #126000; |
| 181 | e8896104 | matt | @(posedge clk); |
| 182 | e8896104 | matt | rx_ll_dst_rdy2 <= 0; |
| 183 | e8896104 | matt | repeat (30) // Repeat of 14 fills the shortfifo, but works. 15 overflows |
| 184 | e8896104 | matt | @(posedge clk); |
| 185 | e8896104 | matt | rx_ll_dst_rdy2 <= 1; |
| 186 | e8896104 | matt | end |
| 187 | e8896104 | matt | |
| 188 | e8896104 | matt | // Tests: Send and recv flow control, send and receive good packets, RX CRC err, RX_ER, RX overrun, TX underrun |
| 189 | e8896104 | matt | // Still need to test: CRC errors on Pause Frames, MDIO, wishbone |
| 190 | e8896104 | matt | |
| 191 | e8896104 | matt | task WishboneWR; |
| 192 | e8896104 | matt | input [7:0] adr; |
| 193 | e8896104 | matt | input [31:0] value; |
| 194 | e8896104 | matt | begin |
| 195 | e8896104 | matt | wb_adr <= adr; |
| 196 | e8896104 | matt | wb_dat_i <= value; |
| 197 | e8896104 | matt | wb_stb <= 1; |
| 198 | e8896104 | matt | wb_cyc <= 1; |
| 199 | e8896104 | matt | wb_we <= 1; |
| 200 | e8896104 | matt | while (~wb_ack) |
| 201 | e8896104 | matt | @(posedge wb_clk); |
| 202 | e8896104 | matt | @(posedge wb_clk); |
| 203 | e8896104 | matt | wb_stb <= 0; |
| 204 | e8896104 | matt | wb_cyc <= 0; |
| 205 | e8896104 | matt | wb_we <= 0; |
| 206 | e8896104 | matt | end |
| 207 | e8896104 | matt | endtask // WishboneWR |
| 208 | e8896104 | matt | |
| 209 | e8896104 | matt | always @(posedge clk) |
| 210 | e8896104 | matt | if(rx_ll_src_rdy2 & rx_ll_dst_rdy2) |
| 211 | e8896104 | matt | begin |
| 212 | e8896104 | matt | if(rx_ll_sof2 & ~rx_ll_eof2) |
| 213 | e8896104 | matt | $display("RX-PKT-START %d",$time);
|
| 214 | e8896104 | matt | $display("RX-PKT SOF %d EOF %d ERR%d DAT %x",rx_ll_sof2,rx_ll_eof2,rx_ll_error2,rx_ll_data2);
|
| 215 | e8896104 | matt | if(rx_ll_eof2 & ~rx_ll_sof2) |
| 216 | e8896104 | matt | $display("RX-PKT-END %d",$time);
|
| 217 | e8896104 | matt | end |
| 218 | e8896104 | matt | |
| 219 | e8896104 | matt | endmodule // simple_gemac_wrapper_tb |