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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_19/] [bench/] [verilog/] [tb_eth_top.v] - Blame information for rev 41

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

powered by: WebSVN 2.1.0

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