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

Subversion Repositories ethmac

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

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 108 mohor
// Revision 1.12  2002/02/26 17:01:09  mohor
45
// Small fixes for external/internal DMA missmatches.
46
//
47 80 mohor
// Revision 1.11  2002/02/16 13:06:59  mohor
48
// EXTERNAL_DMA used instead of WISHBONE_DMA.
49
//
50 67 mohor
// Revision 1.10  2002/02/16 07:22:15  mohor
51
// Testbench fixed, code simplified, unused signals removed.
52
//
53 66 mohor
// Revision 1.9  2002/02/14 20:14:38  billditt
54
// Added separate tests for Multicast, Unicast, Broadcast
55
//
56
// Revision 1.8  2002/02/12 20:24:00  mohor
57
// HASH0 and HASH1 register read/write added.
58
//
59 49 mohor
// Revision 1.7  2002/02/06 14:11:35  mohor
60
// non-DMA host interface added. Select the right configutation in eth_defines.
61
//
62 41 mohor
// Revision 1.6  2001/12/08 12:36:00  mohor
63
// TX_BD_NUM register added instead of the RB_BD_ADDR.
64
//
65 36 mohor
// Revision 1.5  2001/10/19 11:24:04  mohor
66
// Number of addresses (wb_adr_i) minimized.
67
//
68 23 mohor
// Revision 1.4  2001/10/19 08:46:53  mohor
69
// eth_timescale.v changed to timescale.v This is done because of the
70
// simulation of the few cores in a one joined project.
71
//
72 22 mohor
// Revision 1.3  2001/09/24 14:55:49  mohor
73
// Defines changed (All precede with ETH_). Small changes because some
74
// tools generate warnings when two operands are together. Synchronization
75
// between two clocks domains in eth_wishbonedma.v is changed (due to ASIC
76
// demands).
77
//
78 19 mohor
// Revision 1.2  2001/08/15 14:04:30  mohor
79
// Signal names changed on the top level for easier pad insertion (ASIC).
80
//
81 17 mohor
// Revision 1.1  2001/08/06 14:41:09  mohor
82
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
83
// Include files fixed to contain no path.
84
// File names and module names changed ta have a eth_ prologue in the name.
85
// File eth_timescale.v is used to define timescale
86
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
87
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
88
// and Mdo_OE. The bidirectional signal must be created on the top level. This
89
// is done due to the ASIC tools.
90
//
91 15 mohor
// Revision 1.1  2001/07/30 21:46:09  mohor
92
// Directory structure changed. Files checked and joind together.
93
//
94
//
95
//
96
//
97
//
98
 
99
 
100
 
101 108 mohor
`include "tb_eth_defines.v"
102 15 mohor
`include "eth_defines.v"
103 22 mohor
`include "timescale.v"
104 15 mohor
 
105
module tb_eth_top();
106
 
107
 
108
parameter Tp = 1;
109
 
110
 
111
reg           WB_CLK_I;
112
reg           WB_RST_I;
113
reg   [31:0]  WB_DAT_I;
114
 
115
reg   [31:0]  WB_ADR_I;
116
reg    [3:0]  WB_SEL_I;
117
reg           WB_WE_I;
118
reg           WB_CYC_I;
119
reg           WB_STB_I;
120
 
121
wire  [31:0]  WB_DAT_O;
122
wire          WB_ACK_O;
123
wire          WB_ERR_O;
124 41 mohor
reg    [1:0]  WB_ACK_I;
125
 
126 67 mohor
`ifdef EXTERNAL_DMA
127 15 mohor
wire   [1:0]  WB_REQ_O;
128
wire   [1:0]  WB_ND_O;
129
wire          WB_RD_O;
130 41 mohor
`else
131
// WISHBONE master
132
wire    [31:0]    m_wb_adr_o;
133
wire     [3:0]    m_wb_sel_o;
134
wire              m_wb_we_o;
135
reg     [31:0]    m_wb_dat_i;
136
wire    [31:0]    m_wb_dat_o;
137
wire              m_wb_cyc_o;
138
wire              m_wb_stb_o;
139
reg               m_wb_ack_i;
140
reg               m_wb_err_i;
141
`endif
142 15 mohor
 
143
reg           MTxClk;
144
wire   [3:0]  MTxD;
145
wire          MTxEn;
146
wire          MTxErr;
147
 
148
reg           MRxClk;
149
reg    [3:0]  MRxD;
150
reg           MRxDV;
151
reg           MRxErr;
152
reg           MColl;
153
reg           MCrs;
154
 
155
reg           Mdi_I;
156
wire          Mdo_O;
157
wire          Mdo_OE;
158
wire          Mdc_O;
159
 
160
 
161 108 mohor
reg [7:0] memory0 [0:65535];
162
reg [7:0] memory1 [0:65535];
163
reg [7:0] memory2 [0:65535];
164
reg [7:0] memory3 [0:65535];
165 15 mohor
 
166
reg WishboneBusy;
167
reg StartTB;
168
reg [9:0] TxBDIndex;
169
reg [9:0] RxBDIndex;
170
 
171 108 mohor
reg LogEnable;
172
 
173 67 mohor
`ifdef EXTERNAL_DMA
174 41 mohor
`else
175
  integer mcd1;
176
  integer mcd2;
177
`endif
178 15 mohor
 
179
// Connecting Ethernet top module
180
 
181
eth_top ethtop
182
(
183
  // WISHBONE common
184 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),
185 15 mohor
 
186
  // WISHBONE slave
187 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),
188 80 mohor
        .wb_stb_i(WB_STB_I),       .wb_ack_o(WB_ACK_O), .wb_err_o(WB_ERR_O),
189 41 mohor
 
190 67 mohor
`ifdef EXTERNAL_DMA
191 80 mohor
        .wb_ack_i(WB_ACK_I), .wb_req_o(WB_REQ_O), .wb_nd_o(WB_ND_O),   .wb_rd_o(WB_RD_O),
192 41 mohor
`else
193
// WISHBONE master
194
  .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),
195
  .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),
196
  .m_wb_err_i(m_wb_err_i),
197
`endif
198 15 mohor
 
199
  //TX
200 19 mohor
  .mtx_clk_pad_i(MTxClk), .mtxd_pad_o(MTxD), .mtxen_pad_o(MTxEn), .mtxerr_pad_o(MTxErr),
201 15 mohor
 
202
  //RX
203 19 mohor
  .mrx_clk_pad_i(MRxClk), .mrxd_pad_i(MRxD), .mrxdv_pad_i(MRxDV), .mrxerr_pad_i(MRxErr),
204 17 mohor
  .mcoll_pad_i(MColl), .mcrs_pad_i(MCrs),
205 15 mohor
 
206
  // MIIM
207 108 mohor
  .mdc_pad_o(Mdc_O), .md_pad_i(Mdi_I), .md_pad_o(Mdo_O), .md_padoe_o(Mdo_OE),
208 22 mohor
 
209
  .int_o()
210 15 mohor
);
211
 
212
 
213
 
214
 
215
 
216
 
217
 
218
initial
219
begin
220
  WB_CLK_I  =  1'b0;
221 19 mohor
  WB_DAT_I  = 32'h0;
222
  WB_ADR_I  = 32'h0;
223
  WB_SEL_I  =  4'h0;
224
  WB_WE_I   =  1'b0;
225 15 mohor
  WB_CYC_I  =  1'b0;
226
  WB_STB_I  =  1'b0;
227 41 mohor
 
228 67 mohor
`ifdef EXTERNAL_DMA
229 15 mohor
  WB_ACK_I  =  2'h0;
230 41 mohor
`else
231
  m_wb_ack_i = 0;
232
  m_wb_err_i = 0;
233
`endif
234 15 mohor
  MTxClk    =  1'b0;
235
  MRxClk    =  1'b0;
236
  MRxD      =  4'h0;
237
  MRxDV     =  1'b0;
238
  MRxErr    =  1'b0;
239
  MColl     =  1'b0;
240
  MCrs      =  1'b0;
241
  Mdi_I     =  1'b0;
242
 
243
  WishboneBusy = 1'b0;
244
  TxBDIndex = 10'h0;
245
  RxBDIndex = 10'h0;
246 108 mohor
  LogEnable = 1'b1;
247 15 mohor
end
248
 
249
 
250
// Reset pulse
251
initial
252
begin
253 67 mohor
`ifdef EXTERNAL_DMA
254 41 mohor
`else
255
  mcd1 = $fopen("ethernet_tx.log");
256
  mcd2 = $fopen("ethernet_rx.log");
257
`endif
258
  WB_RST_I =  1'b1;
259 15 mohor
  #100 WB_RST_I =  1'b0;
260
  #100 StartTB  =  1'b1;
261
end
262
 
263
 
264
 
265
// Generating WB_CLK_I clock
266
always
267
begin
268 41 mohor
//  forever #2.5 WB_CLK_I = ~WB_CLK_I;  // 2*2.5 ns -> 200.0 MHz    
269 19 mohor
//  forever #5 WB_CLK_I = ~WB_CLK_I;  // 2*5 ns -> 100.0 MHz    
270 15 mohor
//  forever #10 WB_CLK_I = ~WB_CLK_I;  // 2*10 ns -> 50.0 MHz    
271 108 mohor
//  forever #15 WB_CLK_I = ~WB_CLK_I;  // 2*10 ns -> 33.3 MHz    
272
  forever #18 WB_CLK_I = ~WB_CLK_I;  // 2*18 ns -> 27.7 MHz    
273 41 mohor
//  forever #25 WB_CLK_I = ~WB_CLK_I;  // 2*25 ns -> 20.0 MHz
274 108 mohor
//  forever #31.25 WB_CLK_I = ~WB_CLK_I;  // 2*31.25 ns -> 16.0 MHz    
275 41 mohor
//  forever #50 WB_CLK_I = ~WB_CLK_I;  // 2*50 ns -> 10.0 MHz
276
//  forever #55 WB_CLK_I = ~WB_CLK_I;  // 2*55 ns ->  9.1 MHz    
277 15 mohor
end
278
 
279
// Generating MTxClk clock
280
always
281
begin
282 108 mohor
//  #3 forever #20 MTxClk = ~MTxClk;   // 2*20 ns -> 25 MHz
283
  #3 forever #200 MTxClk = ~MTxClk;   // 2*200 ns -> 2.5 MHz
284 15 mohor
end
285
 
286
// Generating MRxClk clock
287
always
288
begin
289 108 mohor
//  #16 forever #20 MRxClk = ~MRxClk;   // 2*20 ns -> 25 MHz
290
//  #16 forever #200 MRxClk = ~MRxClk;   // 2*200 ns -> 2.5 MHz
291
  #16 forever #62.5 MRxClk = ~MRxClk;   // 2*62.5 ns -> 8 MHz       // just for testing purposes
292 15 mohor
end
293
 
294 67 mohor
`ifdef EXTERNAL_DMA
295 15 mohor
initial
296
begin
297
  wait(StartTB);  // Start of testbench
298
 
299 22 mohor
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 1
300
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 0
301 36 mohor
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR<<2}); // r_RxBDAddress = 0x80
302 22 mohor
  WishboneWrite(32'h0002A443, {26'h0, `ETH_MODER_ADR<<2});     // RxEn, Txen, FullD, CrcEn, Pad, DmaEn, r_IFG
303
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR<<2}); //r_TxFlow = 1
304 15 mohor
 
305
  SendPacket(16'h0015, 1'b0);
306
  SendPacket(16'h0043, 1'b1);   // Control frame
307
  SendPacket(16'h0025, 1'b0);
308
  SendPacket(16'h0045, 1'b0);
309
  SendPacket(16'h0025, 1'b0);
310
 
311
  ReceivePacket(16'h0012, 1'b1);    // Initializes RxBD and then Sends a control packet on the MRxD[3:0] signals.
312
  ReceivePacket(16'h0011, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
313
  ReceivePacket(16'h0016, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
314
  ReceivePacket(16'h0017, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
315
  ReceivePacket(16'h0018, 1'b0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
316
 
317
 
318 22 mohor
  WishboneRead({26'h0, `ETH_MODER_ADR});   // Read from MODER register
319 15 mohor
 
320 23 mohor
  WishboneRead({24'h04, (8'h0<<2)});       // Read from TxBD register
321
  WishboneRead({24'h04, (8'h1<<2)});       // Read from TxBD register
322
  WishboneRead({24'h04, (8'h2<<2)});       // Read from TxBD register
323
  WishboneRead({24'h04, (8'h3<<2)});       // Read from TxBD register
324
  WishboneRead({24'h04, (8'h4<<2)});       // Read from TxBD register
325 15 mohor
 
326 23 mohor
  WishboneRead({22'h01, (10'h80<<2)});       // Read from RxBD register
327
  WishboneRead({22'h01, (10'h81<<2)});       // Read from RxBD register
328
  WishboneRead({22'h01, (10'h82<<2)});       // Read from RxBD register
329
  WishboneRead({22'h01, (10'h83<<2)});       // Read from RxBD register
330
  WishboneRead({22'h01, (10'h84<<2)});       // Read from RxBD register
331 15 mohor
 
332
  #10000 $stop;
333
end
334
 
335
 
336
 
337
 
338
 
339
 
340
 
341
task WishboneWrite;
342
  input [31:0] Data;
343
  input [31:0] Address;
344
  integer ii;
345
 
346
  begin
347
    wait (~WishboneBusy);
348
    WishboneBusy = 1;
349
    @ (posedge WB_CLK_I);
350
    #1;
351
    WB_ADR_I = Address;
352
    WB_DAT_I = Data;
353
    WB_WE_I  = 1'b1;
354
    WB_CYC_I = 1'b1;
355
    WB_STB_I = 1'b1;
356
    WB_SEL_I = 4'hf;
357
 
358 19 mohor
    wait(WB_ACK_O);   // waiting for acknowledge response
359
 
360
    // Writing information about the access to the screen
361 15 mohor
    @ (posedge WB_CLK_I);
362 23 mohor
      if(~Address[11] & ~Address[10])
363 22 mohor
        $write("\nWrite to register (Data: 0x%x, Reg. Addr: 0x%0x)", Data, Address);
364 15 mohor
      else
365 23 mohor
      if(~Address[11] & Address[10])
366 36 mohor
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
367 15 mohor
          begin
368 22 mohor
            $write("\nWrite to TxBD (Data: 0x%x, TxBD Addr: 0x%0x)\n", Data, Address);
369 23 mohor
            if(Data[9])
370 15 mohor
              $write("Send Control packet (PAUSE = 0x%0h)\n", Data[31:16]);
371
          end
372
        else
373 22 mohor
          $write("\nWrite to RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", Data, Address);
374 15 mohor
      else
375 22 mohor
        $write("\nWB write ??????????????     Data: 0x%x      Addr: 0x%0x", Data, Address);
376 15 mohor
    #1;
377
    WB_ADR_I = 32'hx;
378
    WB_DAT_I = 32'hx;
379
    WB_WE_I  = 1'bx;
380
    WB_CYC_I = 1'b0;
381
    WB_STB_I = 1'b0;
382
    WB_SEL_I = 4'hx;
383
    #5 WishboneBusy = 0;
384
  end
385
endtask
386
 
387
 
388
task WishboneRead;
389
  input [31:0] Address;
390
  reg   [31:0] Data;
391
  integer ii;
392
 
393
  begin
394
    wait (~WishboneBusy);
395
    WishboneBusy = 1;
396
    @ (posedge WB_CLK_I);
397
    #1;
398
    WB_ADR_I = Address;
399
    WB_WE_I  = 1'b0;
400
    WB_CYC_I = 1'b1;
401
    WB_STB_I = 1'b1;
402
    WB_SEL_I = 4'hf;
403
 
404
    for(ii=0; (ii<20 & ~WB_ACK_O); ii=ii+1)   // Response on the WISHBONE is limited to 20 WB_CLK_I cycles
405
    begin
406
      @ (posedge WB_CLK_I);
407
      Data = WB_DAT_O;
408
    end
409
 
410
    if(ii==20)
411
      begin
412
        $display("\nERROR: Task WishboneRead(Address=0x%0h): Too late or no appeariance of the WB_ACK_O signal, (Time=%0t)",
413
          Address, $time);
414
        #50 $stop;
415
      end
416
 
417
    @ (posedge WB_CLK_I);
418 23 mohor
      if(~Address[11] & ~Address[10])
419 22 mohor
        $write("\nRead from register (Data: 0x%x, Reg. Addr: 0x%0x)", Data, Address);
420 15 mohor
      else
421 23 mohor
      if(~Address[11] & Address[10])
422 36 mohor
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
423 15 mohor
          begin
424 22 mohor
            $write("\nRead from TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", Data, Address);
425 15 mohor
          end
426
        else
427 22 mohor
          $write("\nRead from RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", Data, Address);
428 15 mohor
      else
429 22 mohor
        $write("\nWB read  ?????????    Data: 0x%x      Addr: 0x%0x", Data, Address);
430 15 mohor
    #1;
431
    WB_ADR_I = 32'hx;
432
    WB_WE_I  = 1'bx;
433
    WB_CYC_I = 1'b0;
434
    WB_STB_I = 1'b0;
435
    WB_SEL_I = 4'hx;
436
    #5 WishboneBusy = 0;
437
  end
438
endtask
439
 
440
 
441
 
442
 
443
task SendPacket;
444
  input [15:0]  Length;
445
  input         ControlFrame;
446
  reg           Wrap;
447
  reg [31:0]    TempAddr;
448
  reg [31:0]    TempData;
449
 
450
  begin
451
    if(TxBDIndex == 3)    // Only 4 buffer descriptors are used
452
      Wrap = 1'b1;
453
    else
454
      Wrap = 1'b0;
455
 
456 23 mohor
    TempAddr = {22'h01, (TxBDIndex<<2)};
457 22 mohor
    TempData = {Length[15:0], 1'b1, 1'b0, Wrap, 3'h0, ControlFrame, 1'b0, TxBDIndex[7:0]};  // Ready and Wrap = 1
458 15 mohor
 
459
    #1;
460
    if(TxBDIndex == 3)    // Only 4 buffer descriptors are used
461
      TxBDIndex = 0;
462
    else
463
      TxBDIndex = TxBDIndex + 1;
464
 
465
    fork
466
      begin
467
        WishboneWrite(TempData, TempAddr); // Writing status to TxBD
468
      end
469
 
470
      begin
471
        if(~ControlFrame)
472
        WaitingForTxDMARequest(4'h1, Length); // Delay, DMALength
473
      end
474
    join
475
  end
476
endtask
477
 
478
 
479
 
480
task ReceivePacket;    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
481
  input [15:0] LengthRx;
482
  input        RxControlFrame;
483
  reg        WrapRx;
484
  reg [31:0] TempRxAddr;
485
  reg [31:0] TempRxData;
486
  reg abc;
487
  begin
488
    if(RxBDIndex == 3)    // Only 4 buffer descriptors are used
489
      WrapRx = 1'b1;
490
    else
491
      WrapRx = 1'b0;
492
 
493 36 mohor
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex)<<2)};
494 15 mohor
 
495 22 mohor
    TempRxData = {LengthRx[15:0], 1'b1, 1'b0, WrapRx, 5'h0, RxBDIndex[7:0]};  // Ready and WrapRx = 1 or 0
496 15 mohor
 
497
    #1;
498
    if(RxBDIndex == 3)    // Only 4 buffer descriptors are used
499
      RxBDIndex = 0;
500
    else
501
      RxBDIndex = RxBDIndex + 1;
502
 
503
    abc=1;
504
    WishboneWrite(TempRxData, TempRxAddr); // Writing status to RxBD
505
    abc=0;
506
    fork
507
      begin
508
        #200;
509
        if(RxControlFrame)
510
          GetControlDataOnMRxD(LengthRx); // LengthRx = PAUSE timer value.
511
        else
512
          GetDataOnMRxD(LengthRx); // LengthRx bytes is comming on MRxD[3:0] signals
513
      end
514
 
515
      begin
516
        if(RxControlFrame)
517
          WaitingForRxDMARequest(4'h1, 16'h40); // Delay, DMALength = 64 bytes.
518
        else
519
          WaitingForRxDMARequest(4'h1, LengthRx); // Delay, DMALength
520
      end
521
    join
522
  end
523
endtask
524
 
525
 
526
 
527
task WaitingForTxDMARequest;
528
  input [3:0] Delay;
529
  input [15:0] DMALength;
530
  integer pp;
531
  reg [7:0]a, b, c, d;
532
 
533
  for(pp=0; pp*4<DMALength; pp=pp+1)
534
  begin
535
    a = 4*pp[7:0]+3;
536
    b = 4*pp[7:0]+2;
537
    c = 4*pp[7:0]+1;
538
    d = 4*pp[7:0]  ;
539
    @ (posedge WB_REQ_O[0]);
540
    repeat(Delay) @(posedge WB_CLK_I);
541
 
542
    wait (~WishboneBusy);
543
    WishboneBusy = 1;
544
    #1;
545
    WB_DAT_I = {a, b, c, d};
546 23 mohor
    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 = {22'h02, rr[9:0]};
583 15 mohor
    $display("task WaitingForRxDMARequest: rr=%0d, WB_ADR_I=0x%0h, WB_DAT_O=0x%0h", rr, WB_ADR_I, WB_DAT_O);
584
 
585
    WB_WE_I  = 1'b1;
586
    WB_CYC_I = 1'b1;
587
    WB_STB_I = 1'b1;
588
    WB_SEL_I = 4'hf;
589
    WB_ACK_I[1] = 1'b1;
590
 
591
    @ (posedge WB_CLK_I);
592
    #1;
593
    WB_ADR_I = 32'hx;
594
    WB_WE_I  = 1'bx;
595
    WB_CYC_I = 1'b0;
596
    WB_STB_I = 1'b0;
597
    WB_SEL_I = 4'hx;
598
    WB_ACK_I[1] = 1'b0;
599
    #5 WishboneBusy = 0;
600
  end
601
endtask
602
 
603
 
604
 
605
task GetDataOnMRxD;
606
  input [15:0] Len;
607
  integer tt;
608
 
609
  begin
610
    @ (posedge MRxClk);
611
    MRxDV=1'b1;
612
 
613
    for(tt=0; tt<15; tt=tt+1)
614
    begin
615
      MRxD=4'h5;              // preamble
616
      @ (posedge MRxClk);
617
    end
618
    MRxD=4'hd;                // SFD
619
 
620
    for(tt=0; tt<Len; tt=tt+1)
621
    begin
622
      @ (posedge MRxClk);
623
      MRxD=tt[3:0];
624
      @ (posedge MRxClk);
625
      MRxD=tt[7:4];
626
    end
627
    @ (posedge MRxClk);
628
    MRxDV=1'b0;
629
  end
630
endtask
631
 
632
 
633
task GetControlDataOnMRxD;
634
  input [15:0] Timer;
635
  reg [127:0] Packet;
636
  reg [127:0] Data;
637
  reg [31:0] Crc;
638
  integer tt;
639
 
640
  begin
641
  Packet = 128'h10082C000010_deadbeef0013_8880_0010; // 0180c2000001 + 8808 + 0001
642
  Crc = 32'h6014fe08; // not a correct value
643
 
644
    @ (posedge MRxClk);
645
    MRxDV=1'b1;
646
 
647
    for(tt=0; tt<15; tt=tt+1)
648
    begin
649
      MRxD=4'h5;              // preamble
650
      @ (posedge MRxClk);
651
    end
652
    MRxD=4'hd;                // SFD
653
 
654
    for(tt=0; tt<32; tt=tt+1)
655
    begin
656
      Data = Packet << (tt*4);
657
      @ (posedge MRxClk);
658
      MRxD=Data[127:124];
659
    end
660
 
661
    for(tt=0; tt<2; tt=tt+1)    // timer
662
    begin
663
      Data[15:0] = Timer << (tt*8);
664
      @ (posedge MRxClk);
665
      MRxD=Data[11:8];
666
      @ (posedge MRxClk);
667
      MRxD=Data[15:12];
668
    end
669
 
670
    for(tt=0; tt<42; tt=tt+1)   // padding
671
    begin
672
      Data[7:0] = 8'h0;
673
      @ (posedge MRxClk);
674
      MRxD=Data[3:0];
675
      @ (posedge MRxClk);
676
      MRxD=Data[3:0];
677
    end
678
 
679
    for(tt=0; tt<4; tt=tt+1)    // crc
680
    begin
681
      Data[31:0] = Crc << (tt*8);
682
      @ (posedge MRxClk);
683
      MRxD=Data[27:24];
684
      @ (posedge MRxClk);
685
      MRxD=Data[31:28];
686
    end
687
 
688
 
689
 
690
    @ (posedge MRxClk);
691
    MRxDV=1'b0;
692
  end
693
endtask
694
 
695 67 mohor
`else // No EXTERNAL_DMA
696 15 mohor
 
697 41 mohor
initial
698
begin
699
  wait(StartTB);  // Start of testbench
700 66 mohor
 
701 108 mohor
  // Reset eth MAC core
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
 
705 66 mohor
  InitializeMemory;
706
 
707
// Select which test you want to run:
708
    TestTxAndRx;
709
  //  TestUnicast;
710
  //  TestBroadcast;
711
  //  TestMulticast;
712 51 billditt
end
713 66 mohor
 
714
task TestTxAndRx;
715 108 mohor
 
716
 integer ii, jj;
717
 integer data_in, bd, pointer;
718
 
719 51 billditt
 begin
720 66 mohor
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 1
721
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR<<2});     // r_Rst = 0
722
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR<<2}); // r_RxBDAddress = 0x80
723 51 billditt
 
724 108 mohor
//  WishboneWrite(32'h0000a06b, {26'h0, `ETH_MODER_ADR<<2});     // RxEn, Txen, CrcEn, Pad en, half duplex, 
725
  WishboneWrite(32'h0000a46b, {26'h0, `ETH_MODER_ADR<<2});     // RxEn, Txen, CrcEn, Pad en, full duplex, 
726
//  WishboneWrite(32'h0001a06b, {26'h0, `ETH_MODER_ADR<<2});     // r_RecSmall, RxEn, Txen, CrcEn, Pad en, half duplex, 
727
                                                               // r_IPG, promisc On, reject broadcast 
728 51 billditt
 
729 66 mohor
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR<<2}); //r_TxFlow = 1
730 51 billditt
 
731 108 mohor
  WishboneWrite(32'h00000002, {26'h0, `ETH_MAC_ADDR1_ADR<<2}); // MAC = 000203040506
732
  WishboneWrite(32'h03040506, {26'h0, `ETH_MAC_ADDR0_ADR<<2});
733
 
734
/*
735
// Just few reads
736
  WishboneRead({26'h0, `ETH_MODER_ADR<<2}, data_in);       // Read from ETH_MODER register
737
  WishboneRead({26'h0, `ETH_TX_BD_NUM_ADR<<2}, data_in);       // Read from ETH_TX_BD_NUM_ADR register
738
  WishboneRead({26'h0, `ETH_MAC_ADDR1_ADR<<2}, data_in);       // Read from ETH_MAC_ADDR1_ADR register
739
  WishboneRead({26'h0, `ETH_MAC_ADDR0_ADR<<2}, data_in);       // Read from ETH_MAC_ADDR0_ADR register
740
*/
741
 
742
 
743
 
744
 
745
    for(jj=0; jj<8; jj=jj+4)
746
    begin
747
      WishboneWriteData(`TX_BUF_BASE + jj, 32'hffffffff, 4'hf); // Initializing data to ff
748
    end
749
 
750
    for(jj=0; jj<8; jj=jj+4)
751
    begin
752
      WishboneWriteData(`RX_BUF_BASE + jj, 32'hffffffff, 4'hf); // Initializing data to ff
753
    end
754
 
755
//  SendPacketX(16'h0064, 1'b0, 2'h3);
756
//  SendPacketX(16'h0064, 1'b0, 2'h2);
757
//  SendPacketX(16'h0064, 1'b0, 2'h1);
758
//  SendPacketX(16'h0064, 1'b0, 2'h0);
759
//  SendPacket(16'h0064, 1'b0);
760
//  SendPacket(16'h0011, 1'b0);
761
//  SendPacket(16'h0012, 1'b0);
762
 
763
fork
764
  begin
765
    SendPacketX(16'h264, 1'b0, 2'h3);
766
    SendPacketX(16'h64, 1'b0, 2'h3);
767
  end
768
 
769
  begin
770
    ReceivePacketX(16'h0030, 1'b0, `UNICAST_XFR, 2'h0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
771
    ReceivePacketX(16'h0035, 1'b0, `UNICAST_XFR, 2'h0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
772
    ReceivePacketX(16'h0040, 1'b0, `UNICAST_XFR, 2'h0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
773
    ReceivePacketX(16'h0035, 1'b0, `UNICAST_XFR, 2'h0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
774
    ReceivePacketX(16'h0062, 1'b0, `UNICAST_XFR, 2'h0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
775
  end
776
join
777
 
778
fork
779
  begin
780
    wait(tb_eth_top.ethtop.wishbone.TxStatusWrite);   // wait until tx status is written
781
  end
782
 
783
  begin
784
    wait(tb_eth_top.ethtop.wishbone.RxStatusWrite);   // wait until rx status is written
785
  end
786
join
787
 
788
 
789
/*
790 51 billditt
  SendPacket(16'h0013, 1'b0);
791
  SendPacket(16'h0014, 1'b0);
792 15 mohor
 
793 51 billditt
  SendPacket(16'h0030, 1'b0);
794
  SendPacket(16'h0031, 1'b0);
795
  SendPacket(16'h0032, 1'b0);
796
  SendPacket(16'h0033, 1'b0);
797
  SendPacket(16'h0025, 1'b0);
798 108 mohor
  SendPacket(16'h0045, 1'b0);
799 51 billditt
  SendPacket(16'h0025, 1'b0);
800
  SendPacket(16'h0017, 1'b0);
801 108 mohor
*/
802 41 mohor
 
803 108 mohor
//  ReceivePacketX(16'h0050, 1'b0, `MULTICAST_XFR, 2'h3);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
804
//  ReceivePacketX(16'h0050, 1'b0, `MULTICAST_XFR, 2'h2);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
805
//  ReceivePacketX(16'h0050, 1'b0, `MULTICAST_XFR, 2'h1);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
806
//  ReceivePacketX(16'h0050, 1'b0, `MULTICAST_XFR, 2'h0);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
807 41 mohor
 
808 108 mohor
//  ReceivePacket(16'h0050, 1'b0, `MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
809
//  ReceivePacket(16'h0051, 1'b0, `UNICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
810
//  ReceivePacket(16'h0052, 1'b0, `MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
811
//  ReceivePacket(16'h0053, 1'b0, `BROADCAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
812
//  ReceivePacket(16'h0054, 1'b0, `UNICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
813
//  ReceivePacket(16'h0055, 1'b0, `MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
814
//  ReceivePacket(16'h0056, 1'b0, `UNICAST_WRONG_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
815 49 mohor
 
816 51 billditt
 
817 108 mohor
  repeat(1000) @ (posedge MRxClk);        // Waiting some time for all accesses to finish before reading out the statuses.
818 51 billditt
 
819 108 mohor
//  WishboneRead({24'h04, (8'h0<<2)}, RxBD);       // Read from TxBD register
820
//  WishboneRead({24'h04, (8'h1<<2)}, RxBD);       // Read from TxBD register
821
//  WishboneRead({24'h04, (8'h2<<2)}, RxBD);       // Read from TxBD register
822
//  WishboneRead({24'h04, (8'h3<<2)}, RxBD);       // Read from TxBD register
823
//  WishboneRead({24'h04, (8'h4<<2)}, RxBD);       // Read from TxBD register
824 66 mohor
 
825 108 mohor
  for(jj=0; jj<3; jj=jj+1)    // How many TxBD do we want to read?
826
  begin
827
 
828
      WishboneRead({22'h01, ((10'h0+jj[4:0]*2'h2)<<2)}, bd);       // Read from TxBD
829
      $display("\n(%0t)\t\tRead TxBD %0x = 0x%x", $time, jj, bd);
830
      if(~bd[15]) // Ready = 0?
831
        begin
832
          WishboneRead({22'h01, ((10'h0+jj[4:0]*2'h2+1'h1)<<2)}, pointer);  // Read TxBD pointer
833
          $display("\t\t\tRead TxBDPointer 0x=%x", pointer);
834
          $write("\t\t\tData:");
835
          for(ii=0; ii<bd[31:16]; ii=ii+4)
836
            begin
837
              WishboneReadData({pointer[31:2], 2'h0}+ii, data_in);        // Read data from Tx Pointer
838
              $write("\t0x%x", data_in);
839
            end
840
        end
841
  end
842
 
843
 
844
  for(jj=0; jj<3; jj=jj+1)    // How many RxBD do we want to read?
845
  begin
846
 
847
      WishboneRead({22'h01, ((10'h80+jj[4:0]*2'h2)<<2)}, bd);       // Read from RxBD
848
      $display("\n(%0t)\t\tRead RxBD %0x = 0x%x", $time, jj, bd);
849
      if(~bd[15]) // Empty = 0?
850
        begin
851
          WishboneRead({22'h01, ((10'h80+jj[4:0]*2'h2+1'h1)<<2)}, pointer);  // Read RxBD pointer
852
          $display("\t\t\tRead RxBDPointer 0x=%x", pointer);
853
          $write("\t\t\tData:");
854
          for(ii=0; ii<bd[31:16]+4; ii=ii+4)
855
            begin
856
              WishboneReadData({pointer[31:2], 2'h0} + ii, data_in);        // Read data from Rx Pointer
857
              $write("\t0x%x", data_in);
858
            end
859
        end
860
  end
861
 
862
  WishboneRead({22'h01, (10'h81<<2)}, data_in);       // Read from RxBD register
863
  WishboneRead({22'h01, (10'h82<<2)}, data_in);       // Read from RxBD register
864
  WishboneRead({22'h01, (10'h83<<2)}, data_in);       // Read from RxBD register
865
  WishboneRead({22'h01, (10'h84<<2)}, data_in);       // Read from RxBD register
866
  WishboneRead({22'h01, (10'h85<<2)}, data_in);       // Read from RxBD register
867
  WishboneRead({22'h01, (10'h86<<2)}, data_in);       // Read from RxBD register
868
  WishboneRead({22'h01, (10'h87<<2)}, data_in);       // Read from RxBD register
869
 
870
 
871
 
872 51 billditt
  #100000 $stop;
873 66 mohor
 end
874
endtask //TestTxAndRx
875 51 billditt
 
876 66 mohor
 
877 108 mohor
reg [7:0] LateCollisionCounter;
878
reg EnableCollisionCounter;
879
// Making a late collision
880
 
881
initial
882
EnableCollisionCounter =0;  // Collision = OFF
883
 
884
always @ (posedge MTxClk)
885
begin
886
  if(tb_eth_top.ethtop.wishbone.TxStartFrm)
887
    begin
888
      LateCollisionCounter = 0;
889
    end
890
  else
891
  if(EnableCollisionCounter)
892
    LateCollisionCounter = LateCollisionCounter + 1;
893
end
894
 
895
// Making a late collision
896
always @ (posedge MTxClk)
897
begin
898
  if(LateCollisionCounter==0)
899
    MColl = 0;
900
  else
901
  if(LateCollisionCounter==150)
902
    MColl = 1;
903
  else
904
  if(LateCollisionCounter==155)
905
    begin
906
      MColl = 0;
907
      MCrs = 0;
908
      EnableCollisionCounter=0;
909
      LateCollisionCounter=1;
910
    end
911
end
912
 
913
 
914
// Switching Carrier Sense ON and OFF
915
always @ (posedge MTxClk)
916
begin
917
  wait(tb_eth_top.ethtop.wishbone.TxStartFrm);
918
  MCrs=1;
919
  wait(tb_eth_top.ethtop.wishbone.TxEndFrm || !MCrs);
920
  MCrs=0;
921
end
922
 
923
 
924 51 billditt
task TestUnicast;
925 108 mohor
 
926
 integer ii, jj;
927
 integer data_in, bd, pointer;
928
 
929 51 billditt
 begin
930
  $display("\nBegin TestUnicast \n");
931
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR, 2'h0});     // r_Rst = 1
932
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR, 2'h0});     // r_Rst = 0
933
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR, 2'h0}); // r_RxBDAddress = 0x80
934 108 mohor
  WishboneWrite(32'h0000204b, {26'h0, `ETH_MODER_ADR, 2'h0});     // RxEn, Txen, CrcEn, no Pad, r_IFG, promisc off, broadcast off
935
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR, 2'h0}); // r_TxFlow = 1
936 51 billditt
 
937 66 mohor
  $display("\n This Uniicast packet will be rejected, wrong address in MAC Address Regs\n");
938 51 billditt
 
939 66 mohor
  ReceivePacket(16'h0014, 1'b0,`UNICAST_XFR);
940 51 billditt
 
941 108 mohor
  WishboneWrite(32'h03040506, {26'h0,`ETH_MAC_ADDR0_ADR ,2'h0}); // Mac Address 
942
  WishboneWrite(32'h00000002, {26'h0,`ETH_MAC_ADDR1_ADR ,2'h0}); // Mac Address
943 51 billditt
 
944
  $display("\n Set Proper Unicast Address in MAC_ADDRESS regs, resend packet\n");
945
 
946 66 mohor
  ReceivePacket(16'h0015, 1'b0,`UNICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
947 108 mohor
  ReceivePacket(16'h0016, 1'b0,`MULTICAST_XFR);  // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
948 66 mohor
  ReceivePacket(16'h0017, 1'b0,`UNICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
949 108 mohor
  ReceivePacket(16'h0018, 1'b0,`BROADCAST_XFR);  // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
950
  ReceivePacket(16'h0019, 1'b0,`UNICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
951 41 mohor
 
952
  repeat(5000) @ (posedge MRxClk);        // Waiting some time for all accesses to finish before reading out the statuses.
953
 
954 108 mohor
  WishboneRead({26'h0, `ETH_MODER_ADR}, data_in);   // Read from MODER register
955 41 mohor
 
956 108 mohor
  WishboneRead({22'h01, (10'h80<<2)}, data_in);       // Read from RxBD register
957
  WishboneRead({22'h01, (10'h81<<2)}, data_in);       // Read from RxBD register
958
  WishboneRead({22'h01, (10'h82<<2)}, data_in);       // Read from RxBD register
959
  WishboneRead({22'h01, (10'h83<<2)}, data_in);       // Read from RxBD register
960
  WishboneRead({22'h01, (10'h84<<2)}, data_in);       // Read from RxBD register
961
  WishboneRead({22'h01, (10'h85<<2)}, data_in);       // Read from RxBD register
962
  WishboneRead({22'h01, (10'h86<<2)}, data_in);       // Read from RxBD register
963
  WishboneRead({22'h01, (10'h87<<2)}, data_in);       // Read from RxBD register
964
  WishboneRead({22'h01, (10'h88<<2)}, data_in);       // Read from RxBD register
965
  WishboneRead({22'h01, (10'h89<<2)}, data_in);       // Read from RxBD register
966
 
967
 
968
  for(jj=0; jj<5; jj=jj+1)    // How many RxBD do we want to read?
969
  begin
970
 
971
      WishboneRead({22'h01, ((10'h80+jj[4:0]*2'h2)<<2)}, bd);       // Read from RxBD
972
      $display("\n(%0t)\t\tRead RxBD %0x = 0x%x", $time, jj, bd);
973
      if(~bd[15]) // Empty = 0?
974
        begin
975
          WishboneRead({22'h01, ((10'h80+jj[4:0]*2'h2+1'h1)<<2)}, pointer);  // Read RxBD pointer
976
          $display("\t\t\tRead RxBDPointer 0x=%x", pointer);
977
          $write("\t\t\tData:");
978
          for(ii=0; ii<bd[31:16]+4; ii=ii+4)
979
            begin
980
              WishboneReadData({pointer[31:2], 2'h0} + ii, data_in);        // Read data from Rx Pointer
981
              $write("\t0x%x", data_in);
982
            end
983
        end
984
  end
985
 
986
 
987 51 billditt
 
988
  #100000 $stop;
989
  $display("\nEnd TestUnicast \n");
990
end
991
endtask //TestUnicast
992 41 mohor
 
993 51 billditt
task TestMulticast;
994 108 mohor
 
995
  integer data_in;
996
 
997 51 billditt
 begin
998
  $display("\nBegin TestMulticast \n");
999
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR, 2'h0});     // r_Rst = 1
1000
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR, 2'h0});     // r_Rst = 0
1001
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR, 2'h0}); // r_RxBDAddress = 0x80
1002 66 mohor
  WishboneWrite(32'h00002043, {26'h0, `ETH_MODER_ADR, 2'h0});     // RxEn, Txen, CrcEn, No Pad, r_IFG, promiscuos off, broadcast enable
1003
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR, 2'h0}); // r_TxFlow = 1
1004 51 billditt
 
1005 66 mohor
  $display("\n This Multicast packet will be rejected by Hash Filter\n");
1006 51 billditt
 
1007 66 mohor
  ReceivePacket(16'h0014, 1'b0,`MULTICAST_XFR);
1008 51 billditt
 
1009
  WishboneWrite(32'h00400000, {26'h0, `ETH_HASH1_ADR,2'h0}); // set bit 16, multicast hash 36
1010 108 mohor
  WishboneRead({26'h0, `ETH_HASH1_ADR, 2'h0}, data_in);  // read back
1011 51 billditt
 
1012
  $display("\n Set Hash Filter to accept this Multicast packet, resend packet\n");
1013
 
1014 66 mohor
  ReceivePacket(16'h0015, 1'b0,`MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1015
  ReceivePacket(16'h0016, 1'b0,`MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1016
  ReceivePacket(16'h0017, 1'b0,`MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1017
  ReceivePacket(16'h0018, 1'b0,`MULTICAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1018 51 billditt
 
1019
  repeat(5000) @ (posedge MRxClk);        // Waiting some time for all accesses to finish before reading out the statuses.
1020
 
1021 108 mohor
  WishboneRead({26'h0, `ETH_MODER_ADR}, data_in);   // Read from MODER register
1022 51 billditt
 
1023 108 mohor
  WishboneRead({22'h01, (10'h80<<2)}, data_in);       // Read from RxBD register
1024
  WishboneRead({22'h01, (10'h81<<2)}, data_in);       // Read from RxBD register
1025
  WishboneRead({22'h01, (10'h82<<2)}, data_in);       // Read from RxBD register
1026
  WishboneRead({22'h01, (10'h83<<2)}, data_in);       // Read from RxBD register
1027
  WishboneRead({22'h01, (10'h84<<2)}, data_in);       // Read from RxBD register
1028
  WishboneRead({22'h01, (10'h85<<2)}, data_in);       // Read from RxBD register
1029
  WishboneRead({22'h01, (10'h86<<2)}, data_in);       // Read from RxBD register
1030
  WishboneRead({22'h01, (10'h87<<2)}, data_in);       // Read from RxBD register
1031
 
1032 66 mohor
  $display("\nEnd TestMulticast \n");
1033 108 mohor
  #100000 $stop;
1034 41 mohor
end
1035 51 billditt
endtask //TestMulticast
1036 41 mohor
 
1037
 
1038 51 billditt
task TestBroadcast;
1039 108 mohor
 
1040
  integer data_in;
1041
 
1042 51 billditt
 begin
1043 66 mohor
  $display("\n\n\nBegin TestBroadcast");
1044 51 billditt
  WishboneWrite(32'h00000800, {26'h0, `ETH_MODER_ADR, 2'h0});     // r_Rst = 1
1045
  WishboneWrite(32'h00000000, {26'h0, `ETH_MODER_ADR, 2'h0});     // r_Rst = 0
1046
  WishboneWrite(32'h00000080, {26'h0, `ETH_TX_BD_NUM_ADR, 2'h0}); // r_RxBDAddress = 0x80
1047 41 mohor
 
1048 66 mohor
  WishboneWrite(32'h0000A04b, {26'h0, `ETH_MODER_ADR, 2'h0});     // PadEn, CrcEn, IFG=accept, Reject Broadcast, TxEn, RxEn
1049
  WishboneWrite(32'h00000004, {26'h0, `ETH_CTRLMODER_ADR, 2'h0}); // r_TxFlow = 1
1050 51 billditt
 
1051 66 mohor
  $display("\nThis Broadcast packet will be rejected, r_BRO = 1");
1052
  ReceivePacket(16'h0014, 1'b0,`BROADCAST_XFR);
1053 51 billditt
 
1054 66 mohor
  $display("\nSet r_Bro = 0, resend packet");
1055
  WishboneWrite(32'h0000A043, {26'h0, `ETH_MODER_ADR, 2'h0});  // PadEn, CrcEn, IFG=accept, Accept Broadcast, TxEn, RxEn
1056
  ReceivePacket(16'h0015, 1'b0,`BROADCAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1057 51 billditt
 
1058 66 mohor
  $display("\n This Broadcast packet will be rejected, r_BRO = 1");
1059
  WishboneWrite(32'h0000A04b, {26'h0, `ETH_MODER_ADR, 2'h0});     // PadEn, CrcEn, IFG=accept, Reject Broadcast, TxEn, RxEn
1060
  ReceivePacket(16'h0016, 1'b0,`BROADCAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1061
  ReceivePacket(16'h0017, 1'b0,`BROADCAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1062 51 billditt
 
1063 66 mohor
  $display("\n Set r_Bro = 0, resend packet");
1064
  WishboneWrite(32'h0000A043, {26'h0, `ETH_MODER_ADR, 2'h0});  // PadEn, CrcEn, IFG=accept, Accept Broadcast, TxEn, RxEn
1065
  ReceivePacket(16'h0018, 1'b0,`BROADCAST_XFR);    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1066 51 billditt
 
1067
  repeat(5000) @ (posedge MRxClk);        // Waiting some time for all accesses to finish before reading out the statuses.
1068
 
1069 108 mohor
  WishboneRead({26'h0, `ETH_MODER_ADR}, data_in);   // Read from MODER register
1070 51 billditt
 
1071 108 mohor
  WishboneRead({22'h01, (10'h80<<2)}, data_in);       // Read from RxBD register
1072
  WishboneRead({22'h01, (10'h81<<2)}, data_in);       // Read from RxBD register
1073
  WishboneRead({22'h01, (10'h82<<2)}, data_in);       // Read from RxBD register
1074
  WishboneRead({22'h01, (10'h83<<2)}, data_in);       // Read from RxBD register
1075
  WishboneRead({22'h01, (10'h84<<2)}, data_in);       // Read from RxBD register
1076
  WishboneRead({22'h01, (10'h85<<2)}, data_in);       // Read from RxBD register
1077
  WishboneRead({22'h01, (10'h86<<2)}, data_in);       // Read from RxBD register
1078
  WishboneRead({22'h01, (10'h87<<2)}, data_in);       // Read from RxBD register
1079 51 billditt
 
1080
  #100000 $stop;
1081
  $display("\nEnd TestBroadcast \n");
1082
end
1083
endtask //TestBroadcast
1084
 
1085
 
1086 41 mohor
always @ (posedge WB_CLK_I)
1087
begin
1088
  if(m_wb_cyc_o & m_wb_stb_o) // Add valid address range
1089
    begin
1090
      repeat(3) @ (posedge WB_CLK_I);
1091
        begin
1092 66 mohor
          m_wb_ack_i <=#Tp 1'b1;
1093 41 mohor
          if(~m_wb_we_o)
1094
            begin
1095 108 mohor
              #Tp;
1096
              if(m_wb_adr_o[1:0] == 2'b00)       // word access
1097
                begin
1098
                  m_wb_dat_i[31:24] = memory3[{m_wb_adr_o[31:2], 2'h0}];
1099
                  m_wb_dat_i[23:16] = memory2[{m_wb_adr_o[31:2], 2'h0}];
1100
                  m_wb_dat_i[15:08] = memory1[{m_wb_adr_o[31:2], 2'h0}];
1101
                  m_wb_dat_i[07:00] = memory0[{m_wb_adr_o[31:2], 2'h0}];
1102
                end
1103
              else if(m_wb_adr_o[1:0] == 2'b10)       // half access
1104
                begin
1105
                  m_wb_dat_i[31:24] = 0;
1106
                  m_wb_dat_i[23:16] = 0;
1107
                  m_wb_dat_i[15:08] = memory1[{m_wb_adr_o[31:2], 2'h0}];
1108
                  m_wb_dat_i[07:00] = memory0[{m_wb_adr_o[31:2], 2'h0}];
1109
                end
1110
              else if(m_wb_adr_o[1:0] == 2'b01)       // byte access
1111
                begin
1112
                  m_wb_dat_i[31:24] = 0;
1113
                  m_wb_dat_i[23:16] = memory2[{m_wb_adr_o[31:2], 2'h0}];
1114
                  m_wb_dat_i[15:08] = 0;
1115
                  m_wb_dat_i[07:00] = 0;
1116
                end
1117
              else if(m_wb_adr_o[1:0] == 2'b11)       // byte access
1118
                begin
1119
                  m_wb_dat_i[31:24] = 0;
1120
                  m_wb_dat_i[23:16] = 0;
1121
                  m_wb_dat_i[15:08] = 0;
1122
                  m_wb_dat_i[07:00] = memory0[{m_wb_adr_o[31:2], 2'h0}];
1123
                end
1124
 
1125 41 mohor
              $fdisplay(mcd1, "(%0t) master read (0x%0x) = 0x%0x", $time, m_wb_adr_o, m_wb_dat_i);
1126
            end
1127
          else
1128 108 mohor
            begin
1129
              $fdisplay(mcd2, "(%0t) master write (0x%0x) = 0x%0x", $time, m_wb_adr_o, m_wb_dat_o);
1130
              if(m_wb_sel_o[0])
1131
                memory0[m_wb_adr_o] = m_wb_dat_o[7:0];
1132
              if(m_wb_sel_o[1])
1133
                memory1[m_wb_adr_o] = m_wb_dat_o[15:8];
1134
              if(m_wb_sel_o[2])
1135
                memory2[m_wb_adr_o] = m_wb_dat_o[23:16];
1136
              if(m_wb_sel_o[3])
1137
                memory3[m_wb_adr_o] = m_wb_dat_o[31:24];
1138
            end
1139 41 mohor
        end
1140
      @ (posedge WB_CLK_I);
1141
      m_wb_ack_i <=#Tp 1'b0;
1142
    end
1143
end
1144
 
1145 108 mohor
 
1146
 
1147
// Detecting ram_oe and ram_we being active at the same time
1148 41 mohor
always @ (posedge WB_CLK_I)
1149
begin
1150 108 mohor
  if(tb_eth_top.ethtop.wishbone.ram_we & tb_eth_top.ethtop.wishbone.ram_oe)
1151
    begin
1152
      $display("\n\n(%0t)ERROR: ram_we and ram_oe both activated at the same time", $time);
1153
      #1000;
1154
      $stop;
1155
    end
1156 41 mohor
end
1157
 
1158 108 mohor
 
1159
 
1160
 
1161 41 mohor
always @ (posedge WB_CLK_I)
1162
  if(tb_eth_top.ethtop.wishbone.RxStatusWrite)
1163
    $fdisplay(mcd2, "");  // newline added
1164
 
1165
task WishboneWrite;
1166
  input [31:0] Data;
1167
  input [31:0] Address;
1168
  integer ii;
1169
 
1170
  begin
1171
    wait (~WishboneBusy);
1172
    WishboneBusy = 1;
1173
    @ (posedge WB_CLK_I);
1174
    #1;
1175
    WB_ADR_I = Address;
1176
    WB_DAT_I = Data;
1177
    WB_WE_I  = 1'b1;
1178
    WB_CYC_I = 1'b1;
1179
    WB_STB_I = 1'b1;
1180
    WB_SEL_I = 4'hf;
1181
 
1182
 
1183
    wait(WB_ACK_O);   // waiting for acknowledge response
1184
 
1185
    // Writing information about the access to the screen
1186
    @ (posedge WB_CLK_I);
1187 108 mohor
    if(LogEnable)
1188
    begin
1189 41 mohor
      if(~Address[11] & ~Address[10])
1190
        $write("\n(%0t) Write to register (Data: 0x%x, Reg. Addr: 0x%0x)", $time, Data, Address);
1191
      else
1192
      if(~Address[11] & Address[10])
1193
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
1194
          begin
1195
            $write("\n(%0t) Write to TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", $time, Data, Address);
1196 66 mohor
            if(Address[9:2] == tb_eth_top.ethtop.r_TxBDNum-2'h2)
1197
              $write("(%0t) Send Control packet\n", $time);
1198 41 mohor
          end
1199
        else
1200
          $write("\n(%0t) Write to RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", $time, Data, Address);
1201
      else
1202
        $write("\n(%0t) WB write ??????????????     Data: 0x%x      Addr: 0x%0x", $time, Data, Address);
1203 108 mohor
    end
1204
 
1205 41 mohor
    #1;
1206
    WB_ADR_I = 32'hx;
1207
    WB_DAT_I = 32'hx;
1208
    WB_WE_I  = 1'bx;
1209
    WB_CYC_I = 1'b0;
1210
    WB_STB_I = 1'b0;
1211
    WB_SEL_I = 4'hx;
1212
    #5 WishboneBusy = 0;
1213
  end
1214
endtask
1215
 
1216
 
1217
task WishboneRead;
1218
  input [31:0] Address;
1219 108 mohor
  output[31:0] data;
1220 41 mohor
 
1221
  begin
1222
    wait (~WishboneBusy);
1223
    WishboneBusy = 1;
1224
    @ (posedge WB_CLK_I);
1225
    #1;
1226
    WB_ADR_I = Address;
1227
    WB_WE_I  = 1'b0;
1228
    WB_CYC_I = 1'b1;
1229
    WB_STB_I = 1'b1;
1230
    WB_SEL_I = 4'hf;
1231 108 mohor
    #3;
1232 41 mohor
    wait(WB_ACK_O);   // waiting for acknowledge response
1233
    @ (posedge WB_CLK_I);
1234 108 mohor
      data = WB_DAT_O;
1235 41 mohor
      if(~Address[11] & ~Address[10])
1236 108 mohor
//        $write("\n(%0t) Read from register (Data: 0x%x, Reg. Addr: 0x%0x)", $time, WB_DAT_O, Address);
1237
        $write("\n(%0t) Read from register (Data: 0x%x, Reg. Addr: 0x%0x)", $time, data, Address);
1238 41 mohor
      else
1239
      if(~Address[11] & Address[10])
1240
        if(Address[9:2] < tb_eth_top.ethtop.r_TxBDNum)
1241 108 mohor
//          ; //$write("\n(%0t) Read from TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", $time, WB_DAT_O, Address);
1242
          ; //$write("\n(%0t) Read from TxBD (Data: 0x%x, TxBD Addr: 0x%0x)", $time, data, Address);
1243 41 mohor
        else
1244 108 mohor
//          ;//$write("\n(%0t) Read from RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", $time, WB_DAT_O, Address);
1245
          ;//$write("\n(%0t) Read from RxBD (Data: 0x%x, RxBD Addr: 0x%0x)", $time, data, Address);
1246 41 mohor
      else
1247 108 mohor
//        $write("\n(%0t) WB read  ?????????    Data: 0x%x      Addr: 0x%0x", $time, WB_DAT_O, Address);
1248
        $write("\n(%0t) WB read  ?????????    Data: 0x%x      Addr: 0x%0x", $time, data, Address);
1249 41 mohor
    #1;
1250
    WB_ADR_I = 32'hx;
1251
    WB_WE_I  = 1'bx;
1252
    WB_CYC_I = 1'b0;
1253
    WB_STB_I = 1'b0;
1254
    WB_SEL_I = 4'hx;
1255
    #5 WishboneBusy = 0;
1256
  end
1257
endtask
1258
 
1259
 
1260
 
1261 108 mohor
task WishboneReadData;
1262
  input [31:0] Address;
1263
  output[31:0] data;
1264 41 mohor
 
1265 108 mohor
  begin
1266
    @ (posedge WB_CLK_I);
1267
    data = {memory3[Address], memory2[Address], memory1[Address], memory0[Address]};
1268
    #5;
1269
  end
1270
endtask
1271
 
1272
 
1273
task WishboneWriteData;
1274
  input [31:0] Address;
1275
  input [31:0] data;
1276
  input [3:0]  Select;
1277
 
1278
  begin
1279
    @ (posedge WB_CLK_I);
1280
    if(Select[0])
1281
      memory0[Address] = data[7:0];
1282
    if(Select[1])
1283
      memory1[Address] = data[15:8];
1284
    if(Select[2])
1285
      memory2[Address] = data[23:16];
1286
    if(Select[3])
1287
      memory3[Address] = data[31:24];
1288
//    $display("\n(%0t) Write data to memory (Data: 0x%x, Addr: 0x%0x)", $time, data, Address);
1289
    #5;
1290
  end
1291
endtask
1292
 
1293
 
1294
 
1295
 
1296 41 mohor
task SendPacket;
1297
  input [15:0]  Length;
1298
  input         ControlFrame;
1299
  reg           Wrap;
1300
  reg [31:0]    TempAddr;
1301
  reg [31:0]    TempData;
1302 108 mohor
  reg [31:0]    kk;
1303 41 mohor
 
1304
  begin
1305
//    if(TxBDIndex == 6)    // Only 3 buffer descriptors are used 
1306
//      Wrap = 1'b1;
1307
//    else
1308
      Wrap = 1'b0;    // At the moment no wrap bit is set
1309
 
1310
 
1311 108 mohor
    // Writing data to buffer
1312
    for(kk=0; kk<Length; kk=kk+4)
1313
    begin
1314
      TempAddr = `TX_BUF_BASE + TxBDIndex * 32'h600 + kk;
1315
      TempData = {kk[7:0], kk[7:0]+2'h1, kk[7:0]+2'h2, kk[7:0]+2'h3};
1316
      WishboneWriteData(TempAddr, TempData, 4'hf); // Writing Data to buffer that is pointed by the BD
1317
    end
1318
 
1319 41 mohor
 
1320 108 mohor
    // Writing buffer pointer
1321
    TempAddr = {22'h01, ((TxBDIndex*2'h2 + 1'b1)<<2)};
1322
    TempData = `TX_BUF_BASE + TxBDIndex * 32'h600; // 1536 bytes is reserved for one frame
1323
    WishboneWrite(TempData, TempAddr); // Writing Tx pointer
1324 41 mohor
 
1325 108 mohor
    TempAddr = {22'h01, ((TxBDIndex*2'h2)<<2)};
1326 41 mohor
    TempData = {Length[15:0], 1'b1, 1'b0, Wrap, 3'h0, ControlFrame, 1'b0, TxBDIndex[7:0]};  // Ready and Wrap = 1
1327
 
1328
    #1;
1329
//    if(TxBDIndex == 6)    // Only 4 buffer descriptors are used
1330
//      TxBDIndex = 0;
1331
//    else
1332 108 mohor
      TxBDIndex = TxBDIndex + 1;
1333 41 mohor
 
1334
    WishboneWrite(TempData, TempAddr); // Writing status to TxBD
1335
  end
1336
endtask
1337
 
1338
 
1339
 
1340 108 mohor
task SendPacketX;
1341
  input [15:0]  Length;
1342
  input         ControlFrame;
1343
  input  [1:0]  AddrOffset;
1344
  reg           Wrap;
1345
  reg [31:0]    TempAddr;
1346
  reg [31:0]    TempData;
1347
  reg [31:0]    kk;
1348
  reg  [3:0]    Select;
1349
 
1350
  begin
1351
    Wrap = 1'b0;
1352
 
1353
    case(AddrOffset)
1354
      2'h0 : Select = 4'hf;
1355
      2'h1 : Select = 4'h7;
1356
      2'h2 : Select = 4'h3;
1357
      2'h3 : Select = 4'h1;
1358
    endcase
1359
 
1360
    // Writing data to buffer
1361
    for(kk=0; kk<Length+4; kk=kk+4)   // Length+4 is because we might start up to 3 bytes later
1362
    begin
1363
      if(kk>0)
1364
        Select = 4'hf;
1365
      TempAddr = `TX_BUF_BASE + TxBDIndex * 32'h600 + kk;
1366
      TempData = {kk[7:0]+3'h1, kk[7:0]+3'h2, kk[7:0]+3'h3, kk[7:0]+3'h4};
1367
      WishboneWriteData(TempAddr, TempData, Select); // Writing Data to buffer that is pointed by the BD
1368
    end
1369
 
1370
 
1371
    // Writing buffer pointer
1372
    TempAddr = {22'h01, ((TxBDIndex*2'h2 + 1'b1)<<2)};
1373
    TempData = `TX_BUF_BASE + TxBDIndex * 32'h600 + AddrOffset; // 1536 bytes is reserved for one frame
1374
    WishboneWrite(TempData, TempAddr); // Writing Tx pointer
1375
 
1376
    TempAddr = {22'h01, ((TxBDIndex*2'h2)<<2)};
1377
    TempData = {Length[15:0], 1'b1, 1'b1, Wrap, 3'h0, ControlFrame, 1'b0, TxBDIndex[7:0]};  // Ready, interrupt and Wrap = 1
1378
 
1379
    #1;
1380
    if(Wrap)
1381
      TxBDIndex = 0;
1382
    else
1383
      TxBDIndex = TxBDIndex + 1;
1384
 
1385
    WishboneWrite(TempData, TempAddr); // Writing status to TxBD
1386
  end
1387
endtask
1388
 
1389
 
1390
 
1391 41 mohor
task ReceivePacket;    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1392
  input [15:0] LengthRx;
1393
  input        RxControlFrame;
1394 51 billditt
  input [31:0] TransferType;  //Broadcast,Unicast,Multicast
1395 41 mohor
  reg        WrapRx;
1396
  reg [31:0] TempRxAddr;
1397 108 mohor
//  reg [31:0] TempRxData;
1398
  integer TempRxData;
1399 41 mohor
  reg abc;
1400
  begin
1401
//    if(RxBDIndex == 6)    // Only 3 buffer descriptors are used
1402
//      WrapRx = 1'b1;
1403
//    else
1404
      WrapRx = 1'b0;
1405
 
1406 108 mohor
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex*2'h2 + 1'b1)<<2)};
1407
    TempRxData = `RX_BUF_BASE + RxBDIndex * 32'h600; // 1536 bytes is reserved for one frame
1408 41 mohor
    WishboneWrite(TempRxData, TempRxAddr); // Writing Rx pointer
1409
 
1410 108 mohor
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex*2'h2)<<2)};
1411 41 mohor
    TempRxData = {16'h0, 1'b1, 1'b0, WrapRx, 5'h0, RxBDIndex[7:0]};  // Ready and WrapRx = 1 or 0
1412
 
1413
    #1;
1414
//    if(RxBDIndex == 6)    // Only 4 buffer descriptors are used
1415
//      RxBDIndex = 0;
1416
//    else
1417 108 mohor
      RxBDIndex = RxBDIndex + 1;
1418 41 mohor
 
1419
    abc=1;
1420
    WishboneWrite(TempRxData, TempRxAddr); // Writing status to RxBD
1421
    abc=0;
1422
 
1423
      begin
1424
        #200;
1425
        if(RxControlFrame)
1426
          GetControlDataOnMRxD(LengthRx); // LengthRx = PAUSE timer value.
1427
        else
1428 66 mohor
          GetDataOnMRxD(LengthRx, TransferType); // LengthRx bytes is comming on MRxD[3:0] signals
1429 41 mohor
      end
1430
 
1431
  end
1432
endtask
1433
 
1434
 
1435 108 mohor
task ReceivePacketX;    // Initializes RxBD and then generates traffic on the MRxD[3:0] signals.
1436
  input [15:0] LengthRx;
1437
  input        RxControlFrame;
1438
  input [31:0] TransferType;  //Broadcast,Unicast,Multicast
1439
  input  [1:0]  AddrOffset;
1440
  reg        WrapRx;
1441
  reg [31:0] TempRxAddr;
1442
  integer TempRxData;
1443
  reg abc;
1444
  begin
1445
    WrapRx = 1'b0;
1446
 
1447
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex*2'h2 + 1'b1)<<2)};
1448
    TempRxData = `RX_BUF_BASE + RxBDIndex * 32'h600 + AddrOffset; // 1536 bytes is reserved for one frame
1449
    WishboneWrite(TempRxData, TempRxAddr); // Writing Rx pointer
1450
 
1451
    TempRxAddr = {22'h01, ((tb_eth_top.ethtop.r_TxBDNum + RxBDIndex*2'h2)<<2)};
1452
    TempRxData = {16'h0, 1'b1, 1'b1, WrapRx, 5'h0, RxBDIndex[7:0]};  // Ready, interrupt and WrapRx = 1 or 0
1453
 
1454
    #1;
1455
      RxBDIndex = RxBDIndex + 1;
1456
 
1457
    abc=1;
1458
    WishboneWrite(TempRxData, TempRxAddr); // Writing status to RxBD
1459
    abc=0;
1460
 
1461
      begin
1462
        #200;
1463
        if(RxControlFrame)
1464
          GetControlDataOnMRxD(LengthRx); // LengthRx = PAUSE timer value.
1465
        else
1466
          GetDataOnMRxD(LengthRx, TransferType); // LengthRx bytes is comming on MRxD[3:0] signals
1467
      end
1468
 
1469
  end
1470
endtask
1471
 
1472
 
1473 41 mohor
task GetDataOnMRxD;
1474
  input [15:0] Len;
1475 51 billditt
  input [31:0] TransferType;
1476 41 mohor
  integer tt;
1477
 
1478
  begin
1479
    @ (posedge MRxClk);
1480
    MRxDV=1'b1;
1481
 
1482
    for(tt=0; tt<15; tt=tt+1)
1483
    begin
1484
      MRxD=4'h5;              // preamble
1485
      @ (posedge MRxClk);
1486
    end
1487
    MRxD=4'hd;                // SFD
1488 51 billditt
 
1489
  for(tt=1; tt<(Len+1); tt=tt+1)
1490
 
1491 41 mohor
    begin
1492 51 billditt
 
1493 41 mohor
      @ (posedge MRxClk);
1494 51 billditt
          if(TransferType == `UNICAST_XFR && tt == 1)
1495
           MRxD= 4'h0;   // Unicast transfer
1496
          else if(TransferType == `BROADCAST_XFR && tt < 7)
1497
           MRxD = 4'hf;
1498
          else
1499
       MRxD=tt[3:0]; // Multicast transfer
1500 66 mohor
 
1501
    @ (posedge MRxClk);
1502 51 billditt
 
1503
           if(TransferType == `BROADCAST_XFR && tt < 7)
1504
            MRxD = 4'hf;
1505
          else
1506
        MRxD=tt[7:4];
1507 41 mohor
    end
1508 51 billditt
 
1509 41 mohor
    @ (posedge MRxClk);
1510
    MRxDV=1'b0;
1511
  end
1512
endtask
1513
 
1514
 
1515
task GetControlDataOnMRxD;
1516
  input [15:0] Timer;
1517
  reg [127:0] Packet;
1518
  reg [127:0] Data;
1519
  reg [31:0] Crc;
1520
  integer tt;
1521
 
1522
  begin
1523 66 mohor
  Packet = 128'h10082C000010_deadbeef0013_8880_0010; // 0180c2000001 + 8808 + 0001
1524 41 mohor
  Crc = 32'h6014fe08; // not a correct value
1525
 
1526
    @ (posedge MRxClk);
1527
    MRxDV=1'b1;
1528
 
1529
    for(tt=0; tt<15; tt=tt+1)
1530
    begin
1531
      MRxD=4'h5;              // preamble
1532
      @ (posedge MRxClk);
1533
    end
1534
    MRxD=4'hd;                // SFD
1535
 
1536
    for(tt=0; tt<32; tt=tt+1)
1537
    begin
1538
      Data = Packet << (tt*4);
1539
      @ (posedge MRxClk);
1540
      MRxD=Data[127:124];
1541
    end
1542
 
1543
    for(tt=0; tt<2; tt=tt+1)    // timer
1544
    begin
1545
      Data[15:0] = Timer << (tt*8);
1546
      @ (posedge MRxClk);
1547
      MRxD=Data[11:8];
1548
      @ (posedge MRxClk);
1549
      MRxD=Data[15:12];
1550
    end
1551
 
1552
    for(tt=0; tt<42; tt=tt+1)   // padding
1553
    begin
1554
      Data[7:0] = 8'h0;
1555
      @ (posedge MRxClk);
1556
      MRxD=Data[3:0];
1557
      @ (posedge MRxClk);
1558
      MRxD=Data[3:0];
1559
    end
1560
 
1561
    for(tt=0; tt<4; tt=tt+1)    // crc
1562
    begin
1563
      Data[31:0] = Crc << (tt*8);
1564
      @ (posedge MRxClk);
1565
      MRxD=Data[27:24];
1566
      @ (posedge MRxClk);
1567
      MRxD=Data[31:28];
1568
    end
1569
 
1570
 
1571
 
1572
    @ (posedge MRxClk);
1573
    MRxDV=1'b0;
1574
  end
1575
endtask
1576 66 mohor
 
1577
task InitializeMemory;
1578
  reg [9:0] mem_addr;
1579
 
1580
  begin
1581 108 mohor
    LogEnable = 1'b0;
1582
    $display("\n\n(%0t) Initializing Memory...", $time);
1583 66 mohor
    for(mem_addr=0; mem_addr<=10'h0ff; mem_addr=mem_addr+1'b1)
1584
      WishboneWrite(32'h0, {22'h01, mem_addr<<2}); // Writing status to RxBD
1585 108 mohor
    LogEnable = 1'b1;
1586 66 mohor
  end
1587
endtask
1588
 
1589
 
1590 41 mohor
`endif
1591
 
1592
 
1593 15 mohor
endmodule

powered by: WebSVN 2.1.0

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