OpenCores
URL https://opencores.org/ocsvn/ethmac/ethmac/trunk

Subversion Repositories ethmac

[/] [ethmac/] [trunk/] [bench/] [verilog/] [tb_eth_top.v] - Blame information for rev 49

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 mohor
///////////3///////////////////////////////////////////////////////////
2 15 mohor
////                                                              ////
3
////  tb_eth_top.v                                                ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 41 mohor
////  http://www.opencores.org/projects/ethmac/                   ////
7 15 mohor
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10
////                                                              ////
11
////  All additional information is avaliable in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2001 Authors                                   ////
17
////                                                              ////
18
//// This source file may be used and distributed without         ////
19
//// restriction provided that this copyright statement is not    ////
20
//// removed from the file and that any derivative work contains  ////
21
//// the original copyright notice and the associated disclaimer. ////
22
////                                                              ////
23
//// This source file is free software; you can redistribute it   ////
24
//// and/or modify it under the terms of the GNU Lesser General   ////
25
//// Public License as published by the Free Software Foundation; ////
26
//// either version 2.1 of the License, or (at your option) any   ////
27
//// later version.                                               ////
28
////                                                              ////
29
//// This source is distributed in the hope that it will be       ////
30
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32
//// PURPOSE.  See the GNU Lesser General Public License for more ////
33
//// details.                                                     ////
34
////                                                              ////
35
//// You should have received a copy of the GNU Lesser General    ////
36
//// Public License along with this source; if not, download it   ////
37
//// from http://www.opencores.org/lgpl.shtml                     ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
//
41
// CVS Revision History
42
//
43
// $Log: not supported by cvs2svn $
44 49 mohor
// Revision 1.7  2002/02/06 14:11:35  mohor
45
// non-DMA host interface added. Select the right configutation in eth_defines.
46
//
47 41 mohor
// Revision 1.6  2001/12/08 12:36:00  mohor
48
// TX_BD_NUM register added instead of the RB_BD_ADDR.
49
//
50 36 mohor
// Revision 1.5  2001/10/19 11:24:04  mohor
51
// Number of addresses (wb_adr_i) minimized.
52
//
53 23 mohor
// Revision 1.4  2001/10/19 08:46:53  mohor
54
// eth_timescale.v changed to timescale.v This is done because of the
55
// simulation of the few cores in a one joined project.
56
//
57 22 mohor
// Revision 1.3  2001/09/24 14:55:49  mohor
58
// Defines changed (All precede with ETH_). Small changes because some
59
// tools generate warnings when two operands are together. Synchronization
60
// between two clocks domains in eth_wishbonedma.v is changed (due to ASIC
61
// demands).
62
//
63 19 mohor
// Revision 1.2  2001/08/15 14:04:30  mohor
64
// Signal names changed on the top level for easier pad insertion (ASIC).
65
//
66 17 mohor
// Revision 1.1  2001/08/06 14:41:09  mohor
67
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
68
// Include files fixed to contain no path.
69
// File names and module names changed ta have a eth_ prologue in the name.
70
// File eth_timescale.v is used to define timescale
71
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
72
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
73
// and Mdo_OE. The bidirectional signal must be created on the top level. This
74
// is done due to the ASIC tools.
75
//
76 15 mohor
// Revision 1.1  2001/07/30 21:46:09  mohor
77
// Directory structure changed. Files checked and joind together.
78
//
79
//
80
//
81
//
82
//
83
 
84
 
85
 
86
`include "eth_defines.v"
87 22 mohor
`include "timescale.v"
88 15 mohor
 
89
module tb_eth_top();
90
 
91
 
92
parameter Tp = 1;
93
 
94
 
95
reg           WB_CLK_I;
96
reg           WB_RST_I;
97
reg   [31:0]  WB_DAT_I;
98
 
99
reg   [31:0]  WB_ADR_I;
100
reg    [3:0]  WB_SEL_I;
101
reg           WB_WE_I;
102
reg           WB_CYC_I;
103
reg           WB_STB_I;
104
 
105
wire  [31:0]  WB_DAT_O;
106
wire          WB_ACK_O;
107
wire          WB_ERR_O;
108 41 mohor
reg    [1:0]  WB_ACK_I;
109
 
110
`ifdef WISHBONE_DMA
111 15 mohor
wire   [1:0]  WB_REQ_O;
112
wire   [1:0]  WB_ND_O;
113
wire          WB_RD_O;
114 41 mohor
`else
115
// WISHBONE master
116
wire    [31:0]    m_wb_adr_o;
117
wire     [3:0]    m_wb_sel_o;
118
wire              m_wb_we_o;
119
reg     [31:0]    m_wb_dat_i;
120
wire    [31:0]    m_wb_dat_o;
121
wire              m_wb_cyc_o;
122
wire              m_wb_stb_o;
123
reg               m_wb_ack_i;
124
reg               m_wb_err_i;
125
`endif
126 15 mohor
 
127
reg           MTxClk;
128
wire   [3:0]  MTxD;
129
wire          MTxEn;
130
wire          MTxErr;
131
 
132
reg           MRxClk;
133
reg    [3:0]  MRxD;
134
reg           MRxDV;
135
reg           MRxErr;
136
reg           MColl;
137
reg           MCrs;
138 41 mohor
reg           RxAbort;
139 15 mohor
 
140
reg           Mdi_I;
141
wire          Mdo_O;
142
wire          Mdo_OE;
143
wire          Mdc_O;
144
 
145
 
146
 
147
reg GSR;
148
 
149
reg WishboneBusy;
150
reg StartTB;
151
reg [9:0] TxBDIndex;
152
reg [9:0] RxBDIndex;
153
 
154 41 mohor
`ifdef WISHBONE_DMA
155
`else
156
  integer mcd1;
157
  integer mcd2;
158
`endif
159 15 mohor
 
160
// Connecting Ethernet top module
161
 
162
eth_top ethtop
163
(
164
  // WISHBONE common
165 17 mohor
  .wb_clk_i(WB_CLK_I), .wb_rst_i(WB_RST_I), .wb_dat_i(WB_DAT_I), .wb_dat_o(WB_DAT_O),
166 15 mohor
 
167
  // WISHBONE slave
168 23 mohor
        .wb_adr_i(WB_ADR_I[11:2]), .wb_sel_i(WB_SEL_I), .wb_we_i(WB_WE_I),   .wb_cyc_i(WB_CYC_I),
169 41 mohor
        .wb_stb_i(WB_STB_I),       .wb_ack_o(WB_ACK_O), .wb_err_o(WB_ERR_O), .wb_ack_i(WB_ACK_I),
170
 
171
`ifdef WISHBONE_DMA
172
        .wb_req_o(WB_REQ_O), .wb_nd_o(WB_ND_O),   .wb_rd_o(WB_RD_O),
173
`else
174
// WISHBONE master
175
  .m_wb_adr_o(m_wb_adr_o), .m_wb_sel_o(m_wb_sel_o), .m_wb_we_o(m_wb_we_o), .m_wb_dat_i(m_wb_dat_i),
176
  .m_wb_dat_o(m_wb_dat_o), .m_wb_cyc_o(m_wb_cyc_o), .m_wb_stb_o(m_wb_stb_o), .m_wb_ack_i(m_wb_ack_i),
177
  .m_wb_err_i(m_wb_err_i),
178
`endif
179 15 mohor
 
180
  //TX
181 19 mohor
  .mtx_clk_pad_i(MTxClk), .mtxd_pad_o(MTxD), .mtxen_pad_o(MTxEn), .mtxerr_pad_o(MTxErr),
182 15 mohor
 
183
  //RX
184 19 mohor
  .mrx_clk_pad_i(MRxClk), .mrxd_pad_i(MRxD), .mrxdv_pad_i(MRxDV), .mrxerr_pad_i(MRxErr),
185 17 mohor
  .mcoll_pad_i(MColl), .mcrs_pad_i(MCrs),
186 41 mohor
  .RxAbort(RxAbort), // igor !!! Ta se mora preseliti da bo prisel iz enega izmed modulov. Tu je le zaradi
187
                     // testiranja. Pove, kdaj adresa ni ustrezala in se paketi sklirajo, stevci pa resetirajo.
188 15 mohor
 
189
  // MIIM
190 22 mohor
  .mdc_pad_o(Mdc_O), .md_pad_i(Mdi_I), .md_pad_o(Mdo_O), .md_padoen_o(Mdo_OE),
191
 
192
  .int_o()
193 15 mohor
);
194
 
195
 
196
 
197
 
198
 
199
 
200
 
201
initial
202
begin
203
  WB_CLK_I  =  1'b0;
204 19 mohor
  WB_DAT_I  = 32'h0;
205
  WB_ADR_I  = 32'h0;
206
  WB_SEL_I  =  4'h0;
207
  WB_WE_I   =  1'b0;
208 15 mohor
  WB_CYC_I  =  1'b0;
209
  WB_STB_I  =  1'b0;
210 41 mohor
 
211
`ifdef WISHBONE_DMA
212 15 mohor
  WB_ACK_I  =  2'h0;
213 41 mohor
`else
214
  m_wb_ack_i = 0;
215
  m_wb_err_i = 0;
216
`endif
217 15 mohor
  MTxClk    =  1'b0;
218
  MRxClk    =  1'b0;
219
  MRxD      =  4'h0;
220
  MRxDV     =  1'b0;
221
  MRxErr    =  1'b0;
222
  MColl     =  1'b0;
223
  MCrs      =  1'b0;
224 41 mohor
  RxAbort   =  1'b0;
225 15 mohor
  Mdi_I     =  1'b0;
226
 
227
  WishboneBusy = 1'b0;
228
  TxBDIndex = 10'h0;
229
  RxBDIndex = 10'h0;
230
end
231
 
232
 
233
// Reset pulse
234
initial
235
begin
236 41 mohor
`ifdef WISHBONE_DMA
237
`else
238
  mcd1 = $fopen("ethernet_tx.log");
239
  mcd2 = $fopen("ethernet_rx.log");
240
`endif
241
  WB_RST_I =  1'b1;
242 19 mohor
  GSR           =  1'b1;
243 15 mohor
  #100 WB_RST_I =  1'b0;
244
  GSR           =  1'b0;
245
  #100 StartTB  =  1'b1;
246
end
247
 
248
 
249
assign glbl.GSR = GSR;
250
 
251
 
252
 
253
// Generating WB_CLK_I clock
254
always
255
begin
256 41 mohor
//  forever #2.5 WB_CLK_I = ~WB_CLK_I;  // 2*2.5 ns -> 200.0 MHz    
257 19 mohor
//  forever #5 WB_CLK_I = ~WB_CLK_I;  // 2*5 ns -> 100.0 MHz    
258 15 mohor
//  forever #10 WB_CLK_I = ~WB_CLK_I;  // 2*10 ns -> 50.0 MHz    
259
  forever #15 WB_CLK_I = ~WB_CLK_I;  // 2*10 ns -> 33.3 MHz    
260
//  forever #18 WB_CLK_I = ~WB_CLK_I;  // 2*18 ns -> 27.7 MHz    
261 41 mohor
//  forever #25 WB_CLK_I = ~WB_CLK_I;  // 2*25 ns -> 20.0 MHz
262
//  forever #50 WB_CLK_I = ~WB_CLK_I;  // 2*50 ns -> 10.0 MHz
263
//  forever #55 WB_CLK_I = ~WB_CLK_I;  // 2*55 ns ->  9.1 MHz    
264 15 mohor
end
265
 
266
// Generating MTxClk clock
267
always
268
begin
269
  #3 forever #20 MTxClk = ~MTxClk;   // 2*20 ns -> 25 MHz
270
//  #3 forever #200 MTxClk = ~MTxClk;
271
end
272
 
273
// Generating MRxClk clock
274
always
275
begin
276
  #16 forever #20 MRxClk = ~MRxClk;   // 2*20 ns -> 25 MHz
277
//  #16 forever #250 MRxClk = ~MRxClk;
278
end
279
 
280 41 mohor
`ifdef WISHBONE_DMA
281 15 mohor
initial
282
begin
283
  wait(StartTB);  // Start of testbench
284
 
285 22 mohor
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 1
286
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 0
287 36 mohor
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR<<2}); // r_RxBDAddress = 0x80
288 22 mohor
  WishboneWrite(32'h0002A443, {26'h0, `ETH_MODER_ADR<<2});     // RxEn, Txen, FullD, CrcEn, Pad, DmaEn, r_IFG
289
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR<<2}); //r_TxFlow = 1
290 15 mohor
 
291
 
292
 
293
 
294
  SendPacket(16'h0015, 1'b0);
295
  SendPacket(16'h0043, 1'b1);   // Control frame
296
  SendPacket(16'h0025, 1'b0);
297
  SendPacket(16'h0045, 1'b0);
298
  SendPacket(16'h0025, 1'b0);
299
 
300
 
301
  ReceivePacket(16'h0012, 1'b1);    // Initializes RxBD and then Sends a control packet on the MRxD[3:0] signals.
302
  ReceivePacket(16'h0011, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
303
  ReceivePacket(16'h0016, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
304
  ReceivePacket(16'h0017, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
305
  ReceivePacket(16'h0018, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
306
 
307
 
308 22 mohor
  WishboneRead({26'h0, `ETH_MODER_ADR});   // Read from MODER register
309 15 mohor
 
310 23 mohor
  WishboneRead({24'h04, (8'h0<<2)});       // Read from TxBD register
311
  WishboneRead({24'h04, (8'h1<<2)});       // Read from TxBD register
312
  WishboneRead({24'h04, (8'h2<<2)});       // Read from TxBD register
313
  WishboneRead({24'h04, (8'h3<<2)});       // Read from TxBD register
314
  WishboneRead({24'h04, (8'h4<<2)});       // Read from TxBD register
315 15 mohor
 
316 23 mohor
  WishboneRead({22'h01, (10'h80<<2)});       // Read from RxBD register
317
  WishboneRead({22'h01, (10'h81<<2)});       // Read from RxBD register
318
  WishboneRead({22'h01, (10'h82<<2)});       // Read from RxBD register
319
  WishboneRead({22'h01, (10'h83<<2)});       // Read from RxBD register
320
  WishboneRead({22'h01, (10'h84<<2)});       // Read from RxBD register
321 15 mohor
 
322
  #10000 $stop;
323
end
324
 
325
 
326
 
327
 
328
 
329
 
330
 
331
task WishboneWrite;
332
  input [31:0] Data;
333
  input [31:0] Address;
334
  integer ii;
335
 
336
  begin
337
    wait (~WishboneBusy);
338
    WishboneBusy = 1;
339
    @ (posedge WB_CLK_I);
340
    #1;
341
    WB_ADR_I = Address;
342
    WB_DAT_I = Data;
343
    WB_WE_I  = 1'b1;
344
    WB_CYC_I = 1'b1;
345
    WB_STB_I = 1'b1;
346
    WB_SEL_I = 4'hf;
347
 
348 19 mohor
//    for(ii=0; (ii<20 & ~WB_ACK_O); ii=ii+1)   // Response on the WISHBONE is limited to 20 WB_CLK_I cycles
349
//    begin
350
//      @ (posedge WB_CLK_I);
351
//    end
352 15 mohor
 
353 19 mohor
//    if(ii==20)
354
//      begin
355
//        $display("\nERROR: Task WishboneWrite(Data=0x%0h, Address=0x%0h): Too late or no appeariance of the WB_ACK_O signal, (Time=%0t)", 
356
//          Data, Address, $time);
357
//        #50 $stop;
358
//      end
359 15 mohor
 
360 19 mohor
    wait(WB_ACK_O);   // waiting for acknowledge response
361
 
362
    // Writing information about the access to the screen
363 15 mohor
    @ (posedge WB_CLK_I);
364 23 mohor
      if(~Address[11] & ~Address[10])
365 22 mohor
        $write("\nWrite to register (Data: 0x%x, Reg. Addr: 0x%0x)", Data, Address);
366 15 mohor
      else
367 23 mohor
      if(~Address[11] & Address[10])
368 36 mohor
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
369 15 mohor
          begin
370 22 mohor
            $write("\nWrite to TxBD (Data: 0x%x, TxBD Addr: 0x%0x)\n", Data, Address);
371 23 mohor
            if(Data[9])
372 15 mohor
              $write("Send Control packet (PAUSE = 0x%0h)\n", Data[31:16]);
373
          end
374
        else
375 22 mohor
          $write("\nWrite to RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", Data, Address);
376 15 mohor
      else
377 22 mohor
        $write("\nWB write ??????????????     Data: 0x%x      Addr: 0x%0x", Data, Address);
378 15 mohor
    #1;
379
    WB_ADR_I = 32'hx;
380
    WB_DAT_I = 32'hx;
381
    WB_WE_I  = 1'bx;
382
    WB_CYC_I = 1'b0;
383
    WB_STB_I = 1'b0;
384
    WB_SEL_I = 4'hx;
385
    #5 WishboneBusy = 0;
386
  end
387
endtask
388
 
389
 
390
task WishboneRead;
391
  input [31:0] Address;
392
  reg   [31:0] Data;
393
  integer ii;
394
 
395
  begin
396
    wait (~WishboneBusy);
397
    WishboneBusy = 1;
398
    @ (posedge WB_CLK_I);
399
    #1;
400
    WB_ADR_I = Address;
401
    WB_WE_I  = 1'b0;
402
    WB_CYC_I = 1'b1;
403
    WB_STB_I = 1'b1;
404
    WB_SEL_I = 4'hf;
405
 
406
    for(ii=0; (ii<20 & ~WB_ACK_O); ii=ii+1)   // Response on the WISHBONE is limited to 20 WB_CLK_I cycles
407
    begin
408
      @ (posedge WB_CLK_I);
409
      Data = WB_DAT_O;
410
    end
411
 
412
    if(ii==20)
413
      begin
414
        $display("\nERROR: Task WishboneRead(Address=0x%0h): Too late or no appeariance of the WB_ACK_O signal, (Time=%0t)",
415
          Address, $time);
416
        #50 $stop;
417
      end
418
 
419
    @ (posedge WB_CLK_I);
420 23 mohor
      if(~Address[11] & ~Address[10])
421 22 mohor
        $write("\nRead from register (Data: 0x%x, Reg. Addr: 0x%0x)", Data, Address);
422 15 mohor
      else
423 23 mohor
      if(~Address[11] & Address[10])
424 36 mohor
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
425 15 mohor
          begin
426 22 mohor
            $write("\nRead from TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", Data, Address);
427 15 mohor
          end
428
        else
429 22 mohor
          $write("\nRead from RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", Data, Address);
430 15 mohor
      else
431 22 mohor
        $write("\nWB read  ?????????    Data: 0x%x      Addr: 0x%0x", Data, Address);
432 15 mohor
    #1;
433
    WB_ADR_I = 32'hx;
434
    WB_WE_I  = 1'bx;
435
    WB_CYC_I = 1'b0;
436
    WB_STB_I = 1'b0;
437
    WB_SEL_I = 4'hx;
438
    #5 WishboneBusy = 0;
439
  end
440
endtask
441
 
442
 
443
 
444
 
445
task SendPacket;
446
  input [15:0]  Length;
447
  input         ControlFrame;
448
  reg           Wrap;
449
  reg [31:0]    TempAddr;
450
  reg [31:0]    TempData;
451
 
452
  begin
453
    if(TxBDIndex == 3)    // Only 4 buffer descriptors are used
454
      Wrap = 1'b1;
455
    else
456
      Wrap = 1'b0;
457
 
458 23 mohor
    TempAddr = {22'h01, (TxBDIndex<<2)};
459 22 mohor
    TempData = {Length[15:0], 1'b1, 1'b0, Wrap, 3'h0, ControlFrame, 1'b0, TxBDIndex[7:0]};  // Ready and Wrap = 1
460 15 mohor
 
461
    #1;
462
    if(TxBDIndex == 3)    // Only 4 buffer descriptors are used
463
      TxBDIndex = 0;
464
    else
465
      TxBDIndex = TxBDIndex + 1;
466
 
467
    fork
468
      begin
469
        WishboneWrite(TempData, TempAddr); // Writing status to TxBD
470
      end
471
 
472
      begin
473
        if(~ControlFrame)
474
        WaitingForTxDMARequest(4'h1, Length); // Delay, DMALength
475
      end
476
    join
477
  end
478
endtask
479
 
480
 
481
 
482
task ReceivePacket;    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
483
  input [15:0] LengthRx;
484
  input        RxControlFrame;
485
  reg        WrapRx;
486
  reg [31:0] TempRxAddr;
487
  reg [31:0] TempRxData;
488
  reg abc;
489
  begin
490
    if(RxBDIndex == 3)    // Only 4 buffer descriptors are used
491
      WrapRx = 1'b1;
492
    else
493
      WrapRx = 1'b0;
494
 
495 36 mohor
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex)<<2)};
496 15 mohor
 
497 22 mohor
    TempRxData = {LengthRx[15:0], 1'b1, 1'b0, WrapRx, 5'h0, RxBDIndex[7:0]};  // Ready and WrapRx = 1 or 0
498 15 mohor
 
499
    #1;
500
    if(RxBDIndex == 3)    // Only 4 buffer descriptors are used
501
      RxBDIndex = 0;
502
    else
503
      RxBDIndex = RxBDIndex + 1;
504
 
505
    abc=1;
506
    WishboneWrite(TempRxData, TempRxAddr); // Writing status to RxBD
507
    abc=0;
508
    fork
509
      begin
510
        #200;
511
        if(RxControlFrame)
512
          GetControlDataOnMRxD(LengthRx); // LengthRx = PAUSE timer value.
513
        else
514
          GetDataOnMRxD(LengthRx); // LengthRx bytes is comming on MRxD[3:0] signals
515
      end
516
 
517
      begin
518
        if(RxControlFrame)
519
          WaitingForRxDMARequest(4'h1, 16'h40); // Delay, DMALength = 64 bytes.
520
        else
521
          WaitingForRxDMARequest(4'h1, LengthRx); // Delay, DMALength
522
      end
523
    join
524
  end
525
endtask
526
 
527
 
528
 
529
task WaitingForTxDMARequest;
530
  input [3:0] Delay;
531
  input [15:0] DMALength;
532
  integer pp;
533
  reg [7:0]a, b, c, d;
534
 
535
  for(pp=0; pp*4<DMALength; pp=pp+1)
536
  begin
537
    a = 4*pp[7:0]+3;
538
    b = 4*pp[7:0]+2;
539
    c = 4*pp[7:0]+1;
540
    d = 4*pp[7:0]  ;
541
    @ (posedge WB_REQ_O[0]);
542
    repeat(Delay) @(posedge WB_CLK_I);
543
 
544
    wait (~WishboneBusy);
545
    WishboneBusy = 1;
546
    #1;
547
    WB_DAT_I = {a, b, c, d};
548 23 mohor
//    WB_ADR_I = {20'h20, pp[11:0]};
549
    WB_ADR_I = {22'h02, pp[9:0]};
550 15 mohor
    $display("task WaitingForTxDMARequest: pp=%0d, WB_ADR_I=0x%0h, WB_DAT_I=0x%0h", pp, WB_ADR_I, WB_DAT_I);
551
 
552
    WB_WE_I  = 1'b1;
553
    WB_CYC_I = 1'b1;
554
    WB_STB_I = 1'b1;
555
    WB_SEL_I = 4'hf;
556
    WB_ACK_I[0] = 1'b1;
557
 
558
    @ (posedge WB_CLK_I);
559
    #1;
560
    WB_ADR_I = 32'hx;
561
    WB_DAT_I = 32'hx;
562
    WB_WE_I  = 1'bx;
563
    WB_CYC_I = 1'b0;
564
    WB_STB_I = 1'b0;
565
    WB_SEL_I = 4'hx;
566
    WB_ACK_I[0] = 1'b0;
567
    #5 WishboneBusy = 0;
568
  end
569
endtask
570
 
571
 
572
task WaitingForRxDMARequest;
573
  input [3:0] Delay;
574
  input [15:0] DMALengthRx;
575
  integer rr;
576
 
577
  for(rr=0; rr*4<DMALengthRx; rr=rr+1)
578
  begin
579
    @ (posedge WB_REQ_O[1]);
580
    repeat(Delay) @(posedge WB_CLK_I);
581
 
582
    wait (~WishboneBusy);
583
    WishboneBusy = 1;
584
    #1;
585 23 mohor
//    WB_ADR_I = {20'h20, rr[11:0]};
586
    WB_ADR_I = {22'h02, rr[9:0]};
587 15 mohor
    $display("task WaitingForRxDMARequest: rr=%0d, WB_ADR_I=0x%0h, WB_DAT_O=0x%0h", rr, WB_ADR_I, WB_DAT_O);
588
 
589
    WB_WE_I  = 1'b1;
590
    WB_CYC_I = 1'b1;
591
    WB_STB_I = 1'b1;
592
    WB_SEL_I = 4'hf;
593
    WB_ACK_I[1] = 1'b1;
594
 
595
    @ (posedge WB_CLK_I);
596
    #1;
597
    WB_ADR_I = 32'hx;
598
    WB_WE_I  = 1'bx;
599
    WB_CYC_I = 1'b0;
600
    WB_STB_I = 1'b0;
601
    WB_SEL_I = 4'hx;
602
    WB_ACK_I[1] = 1'b0;
603
    #5 WishboneBusy = 0;
604
  end
605
endtask
606
 
607
 
608
 
609
task GetDataOnMRxD;
610
  input [15:0] Len;
611
  integer tt;
612
 
613
  begin
614
    @ (posedge MRxClk);
615
    MRxDV=1'b1;
616
 
617
    for(tt=0; tt<15; tt=tt+1)
618
    begin
619
      MRxD=4'h5;              // preamble
620
      @ (posedge MRxClk);
621
    end
622
    MRxD=4'hd;                // SFD
623
 
624
    for(tt=0; tt<Len; tt=tt+1)
625
    begin
626
      @ (posedge MRxClk);
627
      MRxD=tt[3:0];
628
      @ (posedge MRxClk);
629
      MRxD=tt[7:4];
630
    end
631
    @ (posedge MRxClk);
632
    MRxDV=1'b0;
633
  end
634
endtask
635
 
636
 
637
task GetControlDataOnMRxD;
638
  input [15:0] Timer;
639
  reg [127:0] Packet;
640
  reg [127:0] Data;
641
  reg [31:0] Crc;
642
  integer tt;
643
 
644
  begin
645
  Packet = 128'h10082C000010_deadbeef0013_8880_0010; // 0180c2000001 + 8808 + 0001
646
  Crc = 32'h6014fe08; // not a correct value
647
 
648
    @ (posedge MRxClk);
649
    MRxDV=1'b1;
650
 
651
    for(tt=0; tt<15; tt=tt+1)
652
    begin
653
      MRxD=4'h5;              // preamble
654
      @ (posedge MRxClk);
655
    end
656
    MRxD=4'hd;                // SFD
657
 
658
    for(tt=0; tt<32; tt=tt+1)
659
    begin
660
      Data = Packet << (tt*4);
661
      @ (posedge MRxClk);
662
      MRxD=Data[127:124];
663
    end
664
 
665
    for(tt=0; tt<2; tt=tt+1)    // timer
666
    begin
667
      Data[15:0] = Timer << (tt*8);
668
      @ (posedge MRxClk);
669
      MRxD=Data[11:8];
670
      @ (posedge MRxClk);
671
      MRxD=Data[15:12];
672
    end
673
 
674
    for(tt=0; tt<42; tt=tt+1)   // padding
675
    begin
676
      Data[7:0] = 8'h0;
677
      @ (posedge MRxClk);
678
      MRxD=Data[3:0];
679
      @ (posedge MRxClk);
680
      MRxD=Data[3:0];
681
    end
682
 
683
    for(tt=0; tt<4; tt=tt+1)    // crc
684
    begin
685
      Data[31:0] = Crc << (tt*8);
686
      @ (posedge MRxClk);
687
      MRxD=Data[27:24];
688
      @ (posedge MRxClk);
689
      MRxD=Data[31:28];
690
    end
691
 
692
 
693
 
694
    @ (posedge MRxClk);
695
    MRxDV=1'b0;
696
  end
697
endtask
698
 
699 41 mohor
`else // No WISHBONE_DMA
700 15 mohor
 
701 41 mohor
initial
702
begin
703
  wait(StartTB);  // Start of testbench
704
 
705
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 1
706
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 0
707
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR<<2}); // r_RxBDAddress = 0x80
708 15 mohor
 
709 49 mohor
  WishboneWrite(32'h00022043, {26'h0, `ETH_MODER_ADR<<2});     // RxEn, Txen, CrcEn, Pad, DmaEn, r_IFG
710 41 mohor
 
711
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR<<2}); //r_TxFlow = 1
712
 
713 49 mohor
  WishboneWrite(32'h12345678, {26'h0, `ETH_HASH0_ADR<<2});
714
  WishboneWrite(32'h98765432, {26'h0, `ETH_HASH1_ADR<<2});
715
  WishboneRead({26'h0, `ETH_HASH0_ADR<<2});   // Read from HASH0 register
716
  WishboneRead({26'h0, `ETH_HASH1_ADR<<2});   // Read from HASH1 register
717 41 mohor
 
718 49 mohor
 
719
  SendPacket(16'h0007, 1'b0);
720 41 mohor
  SendPacket(16'h0011, 1'b0);
721
  SendPacket(16'h0012, 1'b0);
722
  SendPacket(16'h0013, 1'b0);
723
  SendPacket(16'h0014, 1'b0);
724
 
725
  SendPacket(16'h0030, 1'b0);
726
  SendPacket(16'h0031, 1'b0);
727
  SendPacket(16'h0032, 1'b0);
728
  SendPacket(16'h0033, 1'b0);
729
  SendPacket(16'h0025, 1'b0);
730
  SendPacket(16'h0045, 1'b0);
731
  SendPacket(16'h0025, 1'b0);
732
  SendPacket(16'h0017, 1'b0);
733
 
734
//  ReceivePacket(16'h0012, 1'b1, 1'b0);    // Initializes RxBD and then Sends a control packet on the MRxD[3:0] signals.
735 49 mohor
  ReceivePacket(16'h000b, 1'b0, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
736 41 mohor
  ReceivePacket(16'h0016, 1'b0, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
737
  ReceivePacket(16'h0017, 1'b0, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
738
  ReceivePacket(16'h0018, 1'b0, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
739
 
740
  repeat(5000) @ (posedge MRxClk);        // Waiting some time for all accesses to finish before reading out the statuses.
741
 
742
  WishboneRead({26'h0, `ETH_MODER_ADR});   // Read from MODER register
743
 
744
  WishboneRead({24'h04, (8'h0<<2)});       // Read from TxBD register
745
  WishboneRead({24'h04, (8'h1<<2)});       // Read from TxBD register
746
  WishboneRead({24'h04, (8'h2<<2)});       // Read from TxBD register
747
  WishboneRead({24'h04, (8'h3<<2)});       // Read from TxBD register
748
  WishboneRead({24'h04, (8'h4<<2)});       // Read from TxBD register
749
 
750
 
751
  WishboneRead({22'h01, (10'h80<<2)});       // Read from RxBD register
752
  WishboneRead({22'h01, (10'h81<<2)});       // Read from RxBD register
753
  WishboneRead({22'h01, (10'h82<<2)});       // Read from RxBD register
754
  WishboneRead({22'h01, (10'h83<<2)});       // Read from RxBD register
755
  WishboneRead({22'h01, (10'h84<<2)});       // Read from RxBD register
756
  WishboneRead({22'h01, (10'h85<<2)});       // Read from RxBD register
757
  WishboneRead({22'h01, (10'h86<<2)});       // Read from RxBD register
758
  WishboneRead({22'h01, (10'h87<<2)});       // Read from RxBD register
759
 
760
  #100000 $stop;
761
end
762
 
763 49 mohor
integer ijk;
764 41 mohor
 
765 49 mohor
initial
766
ijk = 0;    // for stoping generation of the m_wb_ack_i signal at the right moment so we get underrun
767 41 mohor
 
768
// Answering to master Wishbone requests
769 49 mohor
//wire [31:0] daatax = 32'h87654321;
770
//wire [31:0] daatay = 32'h00edcba9;
771
 
772 41 mohor
always @ (posedge WB_CLK_I)
773
begin
774
  if(m_wb_cyc_o & m_wb_stb_o) // Add valid address range
775
    begin
776
      repeat(3) @ (posedge WB_CLK_I);
777
        begin
778 49 mohor
          if(ijk==6) // mama
779
            MColl = 1;
780
//          if(ijk==9)
781
          else
782
            MColl = 0;
783 41 mohor
//            begin
784
//              repeat(1000) @ (posedge WB_CLK_I);
785
//            end
786
//          else
787
            m_wb_ack_i <=#Tp 1'b1;
788
          if(~m_wb_we_o)
789
            begin
790
              #Tp m_wb_dat_i = m_wb_adr_o + 1'b1; // For easier following of the data
791 49 mohor
//                #Tp m_wb_dat_i = ijk? daatay : daatax;
792 41 mohor
              $fdisplay(mcd1, "(%0t) master read (0x%0x) = 0x%0x", $time, m_wb_adr_o, m_wb_dat_i);
793
            end
794
          else
795
            $fdisplay(mcd2, "(%0t) master write (0x%0x) = 0x%0x", $time, m_wb_adr_o, m_wb_dat_o);
796
        end
797
      @ (posedge WB_CLK_I);
798 49 mohor
      ijk = ijk + 1;
799 41 mohor
      m_wb_ack_i <=#Tp 1'b0;
800
    end
801
end
802
 
803
// Generating error
804
always @ (posedge WB_CLK_I)
805
begin
806
  if(m_wb_cyc_o & m_wb_stb_o & ~(&m_wb_sel_o))  // Add false address range
807
    m_wb_err_i <=#Tp 1'b1;
808
end
809
 
810
always @ (posedge WB_CLK_I)
811
  if(tb_eth_top.ethtop.wishbone.RxStatusWrite)
812
    $fdisplay(mcd2, "");  // newline added
813
 
814
task WishboneWrite;
815
  input [31:0] Data;
816
  input [31:0] Address;
817
  integer ii;
818
 
819
  begin
820
    wait (~WishboneBusy);
821
    WishboneBusy = 1;
822
    @ (posedge WB_CLK_I);
823
    #1;
824
    WB_ADR_I = Address;
825
    WB_DAT_I = Data;
826
    WB_WE_I  = 1'b1;
827
    WB_CYC_I = 1'b1;
828
    WB_STB_I = 1'b1;
829
    WB_SEL_I = 4'hf;
830
 
831
 
832
    wait(WB_ACK_O);   // waiting for acknowledge response
833
 
834
    // Writing information about the access to the screen
835
    @ (posedge WB_CLK_I);
836
      if(~Address[11] & ~Address[10])
837
        $write("\n(%0t) Write to register (Data: 0x%x, Reg. Addr: 0x%0x)", $time, Data, Address);
838
      else
839
      if(~Address[11] & Address[10])
840
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
841
          begin
842
            $write("\n(%0t) Write to TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", $time, Data, Address);
843
            if(Data[9])
844
              $write("(%0t) Send Control packet (PAUSE = 0x%0h)\n", $time, Data[31:16]);
845
          end
846
        else
847
          $write("\n(%0t) Write to RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", $time, Data, Address);
848
      else
849
        $write("\n(%0t) WB write ??????????????     Data: 0x%x      Addr: 0x%0x", $time, Data, Address);
850
    #1;
851
    WB_ADR_I = 32'hx;
852
    WB_DAT_I = 32'hx;
853
    WB_WE_I  = 1'bx;
854
    WB_CYC_I = 1'b0;
855
    WB_STB_I = 1'b0;
856
    WB_SEL_I = 4'hx;
857
    #5 WishboneBusy = 0;
858
  end
859
endtask
860
 
861
 
862
task WishboneRead;
863
  input [31:0] Address;
864
 
865
  begin
866
    wait (~WishboneBusy);
867
    WishboneBusy = 1;
868
    @ (posedge WB_CLK_I);
869
    #1;
870
    WB_ADR_I = Address;
871
    WB_WE_I  = 1'b0;
872
    WB_CYC_I = 1'b1;
873
    WB_STB_I = 1'b1;
874
    WB_SEL_I = 4'hf;
875
 
876
    wait(WB_ACK_O);   // waiting for acknowledge response
877
    @ (posedge WB_CLK_I);
878
 
879
      if(~Address[11] & ~Address[10])
880
        $write("\n(%0t) Read from register (Data: 0x%x, Reg. Addr: 0x%0x)", $time, WB_DAT_O, Address);
881
      else
882
      if(~Address[11] & Address[10])
883
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
884
          begin
885
            $write("\n(%0t) Read from TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", $time, WB_DAT_O, Address);
886
          end
887
        else
888
          $write("\n(%0t) Read from RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", $time, WB_DAT_O, Address);
889
      else
890
        $write("\n(%0t) WB read  ?????????    Data: 0x%x      Addr: 0x%0x", $time, WB_DAT_O, Address);
891
    #1;
892
    WB_ADR_I = 32'hx;
893
    WB_WE_I  = 1'bx;
894
    WB_CYC_I = 1'b0;
895
    WB_STB_I = 1'b0;
896
    WB_SEL_I = 4'hx;
897
    #5 WishboneBusy = 0;
898
  end
899
endtask
900
 
901
 
902
 
903
 
904
task SendPacket;
905
  input [15:0]  Length;
906
  input         ControlFrame;
907
  reg           Wrap;
908
  reg [31:0]    TempAddr;
909
  reg [31:0]    TempData;
910
 
911
  begin
912
//    if(TxBDIndex == 6)    // Only 3 buffer descriptors are used 
913
//      Wrap = 1'b1;
914
//    else
915
      Wrap = 1'b0;    // At the moment no wrap bit is set
916
 
917
    // Writing buffer pointer
918
    TempAddr = {22'h01, ((TxBDIndex + 1'b1)<<2)};
919
    TempData = 32'h78563411;
920
    WishboneWrite(TempData, TempAddr); // buffer pointer
921
 
922
 
923 49 mohor
    TempAddr = {22'h01, (TxBDIndex<<2)};
924 41 mohor
 
925
    TempData = {Length[15:0], 1'b1, 1'b0, Wrap, 3'h0, ControlFrame, 1'b0, TxBDIndex[7:0]};  // Ready and Wrap = 1
926
 
927
    #1;
928
//    if(TxBDIndex == 6)    // Only 4 buffer descriptors are used
929
//      TxBDIndex = 0;
930
//    else
931
      TxBDIndex = TxBDIndex + 2;
932
 
933
    WishboneWrite(TempData, TempAddr); // Writing status to TxBD
934
  end
935
endtask
936
 
937
 
938
 
939
task ReceivePacket;    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
940
  input [15:0] LengthRx;
941
  input        RxControlFrame;
942
  input        Abort;
943
  reg        WrapRx;
944
  reg [31:0] TempRxAddr;
945
  reg [31:0] TempRxData;
946
  reg abc;
947
  begin
948
//    if(RxBDIndex == 6)    // Only 3 buffer descriptors are used
949
//      WrapRx = 1'b1;
950
//    else
951
      WrapRx = 1'b0;
952
 
953
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex + 1'b1)<<2)};
954
    TempRxData = 32'h73507350 + RxBDIndex;
955
    WishboneWrite(TempRxData, TempRxAddr); // Writing Rx pointer
956
 
957
 
958
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex)<<2)};
959
//    TempRxData = {LengthRx[15:0], 1'b1, 1'b0, WrapRx, 5'h0, RxBDIndex[7:0]};  // Ready and WrapRx = 1 or 0
960
    TempRxData = {16'h0, 1'b1, 1'b0, WrapRx, 5'h0, RxBDIndex[7:0]};  // Ready and WrapRx = 1 or 0
961
 
962
    #1;
963
//    if(RxBDIndex == 6)    // Only 4 buffer descriptors are used
964
//      RxBDIndex = 0;
965
//    else
966
      RxBDIndex = RxBDIndex + 2;
967
 
968
    abc=1;
969
    WishboneWrite(TempRxData, TempRxAddr); // Writing status to RxBD
970
    abc=0;
971
 
972
      begin
973
        #200;
974
        if(RxControlFrame)
975
          GetControlDataOnMRxD(LengthRx); // LengthRx = PAUSE timer value.
976
        else
977
          GetDataOnMRxD(LengthRx, Abort); // LengthRx bytes is comming on MRxD[3:0] signals
978
      end
979
 
980
  end
981
endtask
982
 
983
 
984
task GetDataOnMRxD;
985
  input [15:0] Len;
986
  input abort;
987
  integer tt;
988
 
989 49 mohor
//  reg [87:0] ddata;
990
 
991 41 mohor
  begin
992 49 mohor
//    ddata = 88'h50727196edcba987654321;
993
 
994 41 mohor
    @ (posedge MRxClk);
995
    MRxDV=1'b1;
996
 
997
    for(tt=0; tt<15; tt=tt+1)
998
    begin
999
      MRxD=4'h5;              // preamble
1000
      @ (posedge MRxClk);
1001
    end
1002
    MRxD=4'hd;                // SFD
1003 49 mohor
 
1004 41 mohor
    for(tt=1; tt<(Len+1); tt=tt+1)
1005
    begin
1006
      @ (posedge MRxClk);
1007
      MRxD=tt[3:0];
1008
      if(tt==9)
1009
        RxAbort<=#1 abort;
1010
      @ (posedge MRxClk);
1011
      MRxD=tt[7:4];
1012
      RxAbort<=#1 0;
1013
    end
1014 49 mohor
/*
1015
    for(tt=0; tt<Len; tt=tt+1)
1016
    begin
1017
      @ (posedge MRxClk);
1018
      MRxD=ddata[3:0];
1019
      $display("MRxD=0x%0x", MRxD);
1020
      if(tt==9)
1021
        RxAbort<=#1 abort;
1022
      @ (posedge MRxClk);
1023
      MRxD=ddata[7:4];
1024
      $display("MRxD=0x%0x", MRxD);
1025
      ddata[87:0] = {8'h0, ddata[87:8]};
1026
 
1027
      RxAbort<=#1 0;
1028
    end
1029
*/
1030 41 mohor
    @ (posedge MRxClk);
1031
    MRxDV=1'b0;
1032
  end
1033
endtask
1034
 
1035
 
1036
task GetControlDataOnMRxD;
1037
  input [15:0] Timer;
1038
  reg [127:0] Packet;
1039
  reg [127:0] Data;
1040
  reg [31:0] Crc;
1041
  integer tt;
1042
 
1043
  begin
1044
  Packet = 128'h10082C000010_deadbeef0013_8880_0010; // 0180c2000001 + 8808 + 0001
1045
  Crc = 32'h6014fe08; // not a correct value
1046
 
1047
    @ (posedge MRxClk);
1048
    MRxDV=1'b1;
1049
 
1050
    for(tt=0; tt<15; tt=tt+1)
1051
    begin
1052
      MRxD=4'h5;              // preamble
1053
      @ (posedge MRxClk);
1054
    end
1055
    MRxD=4'hd;                // SFD
1056
 
1057
    for(tt=0; tt<32; tt=tt+1)
1058
    begin
1059
      Data = Packet << (tt*4);
1060
      @ (posedge MRxClk);
1061
      MRxD=Data[127:124];
1062
    end
1063
 
1064
    for(tt=0; tt<2; tt=tt+1)    // timer
1065
    begin
1066
      Data[15:0] = Timer << (tt*8);
1067
      @ (posedge MRxClk);
1068
      MRxD=Data[11:8];
1069
      @ (posedge MRxClk);
1070
      MRxD=Data[15:12];
1071
    end
1072
 
1073
    for(tt=0; tt<42; tt=tt+1)   // padding
1074
    begin
1075
      Data[7:0] = 8'h0;
1076
      @ (posedge MRxClk);
1077
      MRxD=Data[3:0];
1078
      @ (posedge MRxClk);
1079
      MRxD=Data[3:0];
1080
    end
1081
 
1082
    for(tt=0; tt<4; tt=tt+1)    // crc
1083
    begin
1084
      Data[31:0] = Crc << (tt*8);
1085
      @ (posedge MRxClk);
1086
      MRxD=Data[27:24];
1087
      @ (posedge MRxClk);
1088
      MRxD=Data[31:28];
1089
    end
1090
 
1091
 
1092
 
1093
    @ (posedge MRxClk);
1094
    MRxDV=1'b0;
1095
  end
1096
endtask
1097
`endif
1098
 
1099
 
1100 15 mohor
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.