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 67

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

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

powered by: WebSVN 2.1.0

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