cleaned up a little
[debian/gnuradio] / usrp2 / fpga / simple_gemac / simple_gemac_tb.v
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, %d", $time);
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 Len=%d, %d", data_len, $time);
54          count <= 1;
55          tx_data  <= data_start;
56          tx_error <= 0;
57          tx_valid <= 1;
58          while(~tx_ack)
59            @(posedge tx_clk);
60          $display("Packet Accepted, %d", $time);
61          while(count < data_len)
62            begin
63               tx_data <= tx_data + 1;
64               count   <= count + 1;
65               @(posedge clk);
66            end
67          tx_valid <= 0;
68          @(posedge tx_clk);
69       end
70    endtask // SendPacket
71         
72    task SendPacketFromFile;
73       input [31:0] data_len;
74       begin
75          $display("Sending Packet From File Len=%d, %d",data_len,$time);
76          $readmemh( "test_packet.mem",pkt_rom );     
77          count    = 0;
78          tx_data  = pkt_rom[count];
79          tx_error = 0;
80          tx_valid = 1;
81          while(~tx_ack)
82            @(posedge tx_clk);
83          $display("Packet Accepted, %d",$time);
84          count = 1;
85          while(count < data_len)
86            begin
87               tx_data = pkt_rom[count];
88               count   = count + 1;
89               @(posedge clk);
90            end
91          tx_valid <= 0;
92          @(posedge tx_clk);
93       end
94    endtask // SendPacket
95         
96    initial $dumpfile("simple_gemac_tb.vcd");
97    initial $dumpvars(0,simple_gemac_tb);
98
99    integer i; 
100    reg [7:0] pkt_rom[0:65535];
101    reg [1023:0] ROMFile;
102    
103    initial
104      for (i=0;i<65536;i=i+1)
105        pkt_rom[i] <= 8'h0;
106       
107    initial
108      begin
109         @(negedge reset);
110         repeat (10)
111           @(posedge clk);
112         SendFlowCtrl;
113         repeat (20)
114           @(posedge clk);
115         SendPacket(8'hAA,10);
116         repeat (10)
117           @(posedge clk);
118         SendPacketFromFile(60);
119         repeat (10)
120           @(posedge clk);
121         SendPacketFromFile(61);
122         repeat (10)
123           @(posedge clk);
124         SendPacketFromFile(62);
125         repeat (10)
126           @(posedge clk);
127         SendPacketFromFile(63);
128         repeat (1)
129           @(posedge clk);
130         SendPacketFromFile(64);
131         repeat (10)
132           @(posedge clk);
133         SendPacketFromFile(59);
134         repeat (1)
135           @(posedge clk);
136         SendPacketFromFile(58);
137         #10000 $finish;
138      end
139
140    always @(posedge clk)
141      if(GMII_TX_EN)
142        $display("%x",GMII_TXD);
143    
144 endmodule // simple_gemac_tb
145
146 /*
147     if ( !$value$plusargs( "rom=%s", ROMFile ) )
148         begin
149            $display( "Using default ROM file, 'flash.rom'" );
150            ROMFile = "flash.rom";
151         end
152       else
153         $display( "Using %s as ROM file.", ROMFile);
154       
155       #1 $readmemh( ROMFile,rom );     
156    end
157  */