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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_11/] [bench/] [verilog/] [tb_ethernet.v] - Blame information for rev 156

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

Line No. Rev Author Line
1 116 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  tb_ethernet.v                                               ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6
////  http://www.opencores.org/projects/ethmac/                   ////
7
////                                                              ////
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, 2002 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 156 mohor
// Revision 1.3  2002/07/23 16:34:31  mohor
45
// gsr added for use when ETH_XILINX_RAMB4 define is set.
46
//
47 121 mohor
// Revision 1.2  2002/07/19 14:02:47  mohor
48
// Clock mrx_clk set to 2.5 MHz.
49
//
50 117 mohor
// Revision 1.1  2002/07/19 13:57:53  mohor
51
// Testing environment also includes traffic cop, memory interface and host
52
// interface.
53 116 mohor
//
54
//
55
//
56
//
57 117 mohor
//
58 116 mohor
 
59
 
60
 
61
`include "tb_eth_defines.v"
62
`include "eth_defines.v"
63
`include "timescale.v"
64
 
65
module tb_ethernet();
66
 
67
 
68
parameter Tp = 1;
69
 
70
 
71
reg           wb_clk_o;
72
reg           wb_rst_o;
73
 
74
reg           mtx_clk;
75
reg           mrx_clk;
76
 
77
wire   [3:0]  MTxD;
78
wire          MTxEn;
79
wire          MTxErr;
80
 
81
reg    [3:0]  MRxD;     // This goes to PHY
82
reg           MRxDV;    // This goes to PHY
83
reg           MRxErr;   // This goes to PHY
84
reg           MColl;    // This goes to PHY
85
reg           MCrs;     // This goes to PHY
86
 
87
wire          Mdi_I;
88
wire          Mdo_O;
89
wire          Mdo_OE;
90
wire          Mdc_O;
91
 
92
integer tx_log;
93
integer rx_log;
94
 
95
reg StartTB;
96
 
97 121 mohor
`ifdef ETH_XILINX_RAMB4
98
  reg gsr;
99
`endif
100
 
101
 
102 116 mohor
integer packet_ready_cnt, send_packet_cnt;
103
 
104
 
105
// Ethernet Slave Interface signals
106
wire [31:0] eth_sl_wb_adr_i, eth_sl_wb_dat_o, eth_sl_wb_dat_i;
107
wire  [3:0] eth_sl_wb_sel_i;
108
wire        eth_sl_wb_we_i, eth_sl_wb_cyc_i, eth_sl_wb_stb_i, eth_sl_wb_ack_o, eth_sl_wb_err_o;
109
 
110
// Memory Slave Interface signals
111
wire [31:0] mem_sl_wb_adr_i, mem_sl_wb_dat_o, mem_sl_wb_dat_i;
112
wire  [3:0] mem_sl_wb_sel_i;
113
wire        mem_sl_wb_we_i, mem_sl_wb_cyc_i, mem_sl_wb_stb_i, mem_sl_wb_ack_o, mem_sl_wb_err_o;
114
 
115
// Ethernet Master Interface signals
116
wire [31:0] eth_ma_wb_adr_o, eth_ma_wb_dat_i, eth_ma_wb_dat_o;
117
wire  [3:0] eth_ma_wb_sel_o;
118
wire        eth_ma_wb_we_o, eth_ma_wb_cyc_o, eth_ma_wb_stb_o, eth_ma_wb_ack_i, eth_ma_wb_err_i;
119
 
120
// Host Master Interface signals
121
wire [31:0] host_ma_wb_adr_o, host_ma_wb_dat_i, host_ma_wb_dat_o;
122
wire  [3:0] host_ma_wb_sel_o;
123
wire        host_ma_wb_we_o, host_ma_wb_cyc_o, host_ma_wb_stb_o, host_ma_wb_ack_i, host_ma_wb_err_i;
124
 
125
 
126
 
127
eth_cop i_eth_cop
128
(
129
  // WISHBONE common
130
  .wb_clk_i(wb_clk_o), .wb_rst_i(wb_rst_o),
131
 
132
  // WISHBONE MASTER 1  Ethernet Master Interface is connected here
133
  .m1_wb_adr_i(eth_ma_wb_adr_o),  .m1_wb_sel_i(eth_ma_wb_sel_o),  .m1_wb_we_i (eth_ma_wb_we_o),
134
  .m1_wb_dat_o(eth_ma_wb_dat_i),  .m1_wb_dat_i(eth_ma_wb_dat_o),  .m1_wb_cyc_i(eth_ma_wb_cyc_o),
135
  .m1_wb_stb_i(eth_ma_wb_stb_o),  .m1_wb_ack_o(eth_ma_wb_ack_i),  .m1_wb_err_o(eth_ma_wb_err_i),
136
 
137
  // WISHBONE MASTER 2  Host Interface is connected here
138
  .m2_wb_adr_i(host_ma_wb_adr_o), .m2_wb_sel_i(host_ma_wb_sel_o), .m2_wb_we_i (host_ma_wb_we_o),
139
  .m2_wb_dat_o(host_ma_wb_dat_i), .m2_wb_dat_i(host_ma_wb_dat_o), .m2_wb_cyc_i(host_ma_wb_cyc_o),
140
  .m2_wb_stb_i(host_ma_wb_stb_o), .m2_wb_ack_o(host_ma_wb_ack_i), .m2_wb_err_o(host_ma_wb_err_i),
141
 
142
  // WISHBONE slave 1   Ethernet Slave Interface is connected here
143
        .s1_wb_adr_o(eth_sl_wb_adr_i),  .s1_wb_sel_o(eth_sl_wb_sel_i),  .s1_wb_we_o (eth_sl_wb_we_i),
144
        .s1_wb_cyc_o(eth_sl_wb_cyc_i),  .s1_wb_stb_o(eth_sl_wb_stb_i),  .s1_wb_ack_i(eth_sl_wb_ack_o),
145
        .s1_wb_err_i(eth_sl_wb_err_o),  .s1_wb_dat_i(eth_sl_wb_dat_o),  .s1_wb_dat_o(eth_sl_wb_dat_i),
146
 
147
  // WISHBONE slave 2   Memory Interface is connected here
148
        .s2_wb_adr_o(mem_sl_wb_adr_i),  .s2_wb_sel_o(mem_sl_wb_sel_i),  .s2_wb_we_o (mem_sl_wb_we_i),
149
        .s2_wb_cyc_o(mem_sl_wb_cyc_i),  .s2_wb_stb_o(mem_sl_wb_stb_i),  .s2_wb_ack_i(mem_sl_wb_ack_o),
150
        .s2_wb_err_i(mem_sl_wb_err_o),  .s2_wb_dat_i(mem_sl_wb_dat_o),  .s2_wb_dat_o(mem_sl_wb_dat_i)
151
);
152
 
153
 
154
 
155
 
156
// Connecting Ethernet top module
157
eth_top ethtop
158
(
159
  // WISHBONE common
160
  .wb_clk_i(wb_clk_o),              .wb_rst_i(wb_rst_o),
161
 
162
  // WISHBONE slave
163
        .wb_adr_i(eth_sl_wb_adr_i[11:2]), .wb_sel_i(eth_sl_wb_sel_i),   .wb_we_i(eth_sl_wb_we_i),
164
        .wb_cyc_i(eth_sl_wb_cyc_i),       .wb_stb_i(eth_sl_wb_stb_i),   .wb_ack_o(eth_sl_wb_ack_o),
165
        .wb_err_o(eth_sl_wb_err_o),       .wb_dat_i(eth_sl_wb_dat_i),   .wb_dat_o(eth_sl_wb_dat_o),
166
 
167
  // WISHBONE master
168
  .m_wb_adr_o(eth_ma_wb_adr_o),     .m_wb_sel_o(eth_ma_wb_sel_o), .m_wb_we_o(eth_ma_wb_we_o),
169
  .m_wb_dat_i(eth_ma_wb_dat_i),     .m_wb_dat_o(eth_ma_wb_dat_o), .m_wb_cyc_o(eth_ma_wb_cyc_o),
170
  .m_wb_stb_o(eth_ma_wb_stb_o),     .m_wb_ack_i(eth_ma_wb_ack_i), .m_wb_err_i(eth_ma_wb_err_i),
171
 
172
  //TX
173
  .mtx_clk_pad_i(mtx_clk), .mtxd_pad_o(MTxD), .mtxen_pad_o(MTxEn), .mtxerr_pad_o(MTxErr),
174
 
175
  //RX
176
  .mrx_clk_pad_i(mrx_clk), .mrxd_pad_i(MRxD), .mrxdv_pad_i(MRxDV), .mrxerr_pad_i(MRxErr),
177
  .mcoll_pad_i(MColl),    .mcrs_pad_i(MCrs),
178
 
179
  // MIIM
180
  .mdc_pad_o(Mdc_O), .md_pad_i(Mdi_I), .md_pad_o(Mdo_O), .md_padoe_o(Mdo_OE),
181
 
182
  .int_o()
183
);
184
 
185
 
186
 
187
// Connecting Memory Interface Module
188
eth_memory i_eth_memory
189
(
190
  // WISHBONE common
191
        .wb_clk_i(wb_clk_o),         .wb_rst_i(wb_rst_o),
192
 
193
  // WISHBONE slave:   Memory Interface is connected here
194
        .wb_adr_i(mem_sl_wb_adr_i),  .wb_sel_i(mem_sl_wb_sel_i),  .wb_we_i (mem_sl_wb_we_i),
195
        .wb_cyc_i(mem_sl_wb_cyc_i),  .wb_stb_i(mem_sl_wb_stb_i),  .wb_ack_o(mem_sl_wb_ack_o),
196
        .wb_err_o(mem_sl_wb_err_o),  .wb_dat_o(mem_sl_wb_dat_o),  .wb_dat_i(mem_sl_wb_dat_i)
197
);
198
 
199
 
200
// Connecting Host Interface
201
eth_host eth_host
202
(
203
  // WISHBONE common
204
  .wb_clk_i(wb_clk_o),         .wb_rst_i(wb_rst_o),
205
 
206
  // WISHBONE master
207
  .wb_adr_o(host_ma_wb_adr_o), .wb_sel_o(host_ma_wb_sel_o), .wb_we_o (host_ma_wb_we_o),
208
  .wb_dat_i(host_ma_wb_dat_i), .wb_dat_o(host_ma_wb_dat_o), .wb_cyc_o(host_ma_wb_cyc_o),
209
  .wb_stb_o(host_ma_wb_stb_o), .wb_ack_i(host_ma_wb_ack_i), .wb_err_i(host_ma_wb_err_i)
210
);
211
 
212
 
213
 
214
 
215
 
216
// Reset pulse
217
initial
218
begin
219
  MCrs=0;                                     // This should come from PHY
220
  MColl=0;                                    // This should come from PHY
221
  MRxD=0;                                     // This should come from PHY
222
  MRxDV=0;                                    // This should come from PHY
223
  MRxErr=0;                                   // This should come from PHY
224
  packet_ready_cnt = 0;
225
  send_packet_cnt = 0;
226
  tx_log = $fopen("ethernet_tx.log");
227
  rx_log = $fopen("ethernet_rx.log");
228
  wb_rst_o =  1'b1;
229 121 mohor
`ifdef ETH_XILINX_RAMB4
230
  gsr           =  1'b0;
231
  #100 gsr      =  1'b1;
232
  #100 gsr      =  1'b0;
233
`endif
234 116 mohor
  #100 wb_rst_o =  1'b0;
235
  #100 StartTB  =  1'b1;
236
end
237
 
238 121 mohor
`ifdef ETH_XILINX_RAMB4
239
  assign glbl.GSR = gsr;
240
`endif
241 116 mohor
 
242
 
243 121 mohor
 
244 116 mohor
// Generating wb_clk_o clock
245
initial
246
begin
247
  wb_clk_o=0;
248
//  forever #2.5 wb_clk_o = ~wb_clk_o;  // 2*2.5 ns -> 200.0 MHz    
249
//  forever #5 wb_clk_o = ~wb_clk_o;  // 2*5 ns -> 100.0 MHz    
250
//  forever #10 wb_clk_o = ~wb_clk_o;  // 2*10 ns -> 50.0 MHz    
251 156 mohor
//  forever #12.5 wb_clk_o = ~wb_clk_o;  // 2*12.5 ns -> 40 MHz    
252 116 mohor
//  forever #15 wb_clk_o = ~wb_clk_o;  // 2*10 ns -> 33.3 MHz    
253 156 mohor
  forever #20 wb_clk_o = ~wb_clk_o;  // 2*20 ns -> 25 MHz    
254 116 mohor
//  forever #25 wb_clk_o = ~wb_clk_o;  // 2*25 ns -> 20.0 MHz
255
//  forever #31.25 wb_clk_o = ~wb_clk_o;  // 2*31.25 ns -> 16.0 MHz    
256
//  forever #50 wb_clk_o = ~wb_clk_o;  // 2*50 ns -> 10.0 MHz
257
//  forever #55 wb_clk_o = ~wb_clk_o;  // 2*55 ns ->  9.1 MHz    
258
end
259
 
260
// Generating mtx_clk clock
261
initial
262
begin
263
  mtx_clk=0;
264 156 mohor
  #3 forever #20 mtx_clk = ~mtx_clk;   // 2*20 ns -> 25 MHz
265
//  #3 forever #200 mtx_clk = ~mtx_clk;   // 2*200 ns -> 2.5 MHz
266 116 mohor
end
267
 
268
// Generating mrx_clk clock
269
initial
270
begin
271
  mrx_clk=0;
272 156 mohor
  #16 forever #20 mrx_clk = ~mrx_clk;   // 2*20 ns -> 25 MHz
273
//  #16 forever #200 mrx_clk = ~mrx_clk;   // 2*200 ns -> 2.5 MHz
274 116 mohor
end
275
 
276
reg [31:0] tmp;
277
initial
278
begin
279
  wait(StartTB);  // Start of testbench
280
 
281
 
282
  eth_host.wb_write(`ETH_MODER, 4'hf, 32'h0); // Reset OFF
283
  eth_host.wb_read(`ETH_MODER, 4'hf, tmp);
284 156 mohor
  eth_host.wb_write(`ETH_MAC_ADDR1, 4'hf, 32'h0002); // Set ETH_MAC_ADDR1 register
285
  eth_host.wb_write(`ETH_MAC_ADDR0, 4'hf, 32'h03040506); // Set ETH_MAC_ADDR0 register
286 116 mohor
 
287
  initialize_txbd(3);
288 156 mohor
  initialize_rxbd(2);
289 116 mohor
 
290 156 mohor
//  eth_host.wb_write(`ETH_MODER, 4'hf, `ETH_MODER_RXEN  | `ETH_MODER_TXEN | `ETH_MODER_PRO | 
291
//                                      `ETH_MODER_CRCEN | `ETH_MODER_PAD); // Set MODER register
292
//  eth_host.wb_write(`ETH_MODER, 4'hf, `ETH_MODER_RXEN  | `ETH_MODER_TXEN | 
293
//                                      `ETH_MODER_CRCEN | `ETH_MODER_PAD); // Set MODER register
294
  eth_host.wb_write(`ETH_MODER, 4'hf, `ETH_MODER_RXEN  | `ETH_MODER_TXEN | `ETH_MODER_BRO |
295
                                      `ETH_MODER_CRCEN | `ETH_MODER_PAD); // Set MODER register
296
//  eth_host.wb_write(`ETH_MODER, 4'hf, `ETH_MODER_RXEN  | `ETH_MODER_TXEN | `ETH_MODER_PRO | 
297
//                                      `ETH_MODER_CRCEN | `ETH_MODER_PAD | `ETH_MODER_LOOPBCK); // Set MODER register
298
//  eth_host.wb_write(`ETH_MODER, 4'hf, `ETH_MODER_RXEN  | `ETH_MODER_TXEN | `ETH_MODER_PRO | 
299
//                                      `ETH_MODER_CRCEN | `ETH_MODER_PAD | `ETH_MODER_LOOPBCK | 
300
//                                      `ETH_MODER_FULLD); // Set MODER register
301
  eth_host.wb_read(`ETH_MODER, 4'hf, tmp);
302
 
303
  set_packet(16'h64, 8'h1);
304 116 mohor
  set_packet(16'h34, 8'h11);
305
  send_packet;
306
  set_packet(16'h34, 8'h21);
307
  set_packet(16'h34, 8'h31);
308 156 mohor
/*
309
  eth_host.wb_write(`ETH_CTRLMODER, 4'hf, 32'h4);   // Enable Tx Flow control
310
  eth_host.wb_write(`ETH_CTRLMODER, 4'hf, 32'h5);   // Enable Tx Flow control
311
  eth_host.wb_write(`ETH_TX_CTRL, 4'hf, 32'h10013); // Send Control frame with PAUSE_TV=0x0013
312
*/
313 116 mohor
  send_packet;
314 156 mohor
*/
315 116 mohor
 
316 156 mohor
  GetDataOnMRxD(100, `UNICAST_XFR); // LengthRx bytes is comming on MRxD[3:0] signals
317 116 mohor
 
318 156 mohor
  repeat (1000) @(posedge wb_clk_o);   // Waiting for TxEthMac to finish transmit
319 116 mohor
 
320 156 mohor
  GetDataOnMRxD(500, `BROADCAST_XFR); // LengthRx bytes is comming on MRxD[3:0] signals
321 116 mohor
 
322 156 mohor
  repeat (1000) @(posedge mrx_clk);   // Waiting for TxEthMac to finish transmit
323 116 mohor
 
324
 
325 156 mohor
  GetDataOnMRxD(1200, `BROADCAST_XFR); // LengthRx bytes is comming on MRxD[3:0] signals
326
 
327
 
328
  GetDataOnMRxD(1000, `UNICAST_XFR); // LengthRx bytes is comming on MRxD[3:0] signals
329
 
330 116 mohor
  repeat (10000) @(posedge wb_clk_o);   // Waiting for TxEthMac to finish transmit
331
 
332 156 mohor
  // Reading and printing interrupts
333
  eth_host.wb_read(`ETH_INT, 4'hf, tmp);
334
  $display("Print irq = 0x%0x", tmp);
335
 
336
  //Clearing all interrupts
337
  eth_host.wb_write(`ETH_INT, 4'hf, 32'h60);
338
 
339
  // Reading and printing interrupts
340
  eth_host.wb_read(`ETH_INT, 4'hf, tmp);
341
  $display("Print irq = 0x%0x", tmp);
342
 
343 116 mohor
  $display("\n\n End of simulation");
344
  $stop;
345
 
346
 
347
 
348
end
349
 
350
 
351
 
352
task initialize_txbd;
353
  input [6:0] txbd_num;
354
 
355
  integer i;
356
  integer bd_status_addr, buf_addr, bd_ptr_addr;
357
 
358
  for(i=0; i<txbd_num; i=i+1) begin
359
    buf_addr = `TX_BUF_BASE + i * 32'h600;
360
    bd_status_addr = `TX_BD_BASE + i * 8;
361
    bd_ptr_addr = bd_status_addr + 4;
362
 
363
    // Initializing BD - status
364
    if(i==txbd_num-1)
365
      eth_host.wb_write(bd_status_addr, 4'hf, 32'h00007800);    // last BD: + WRAP
366
    else
367
      eth_host.wb_write(bd_status_addr, 4'hf, 32'h00005800);    // IRQ + PAD + CRC
368
 
369
    eth_host.wb_write(bd_ptr_addr, 4'hf, buf_addr);             // Initializing BD - pointer
370
  end
371
endtask // initialize_txbd
372
 
373
 
374
task initialize_rxbd;
375
  input [6:0] rxbd_num;
376
 
377
  integer i;
378
  integer bd_status_addr, buf_addr, bd_ptr_addr;
379
 
380
  for(i=0; i<rxbd_num; i=i+1) begin
381
    buf_addr = `RX_BUF_BASE + i * 32'h600;
382
    bd_status_addr = `RX_BD_BASE + i * 8;
383
    bd_ptr_addr = bd_status_addr + 4;
384
 
385
    // Initializing BD - status
386
    if(i==rxbd_num-1)
387
      eth_host.wb_write(bd_status_addr, 4'hf, 32'h0000e000);    // last BD: + WRAP
388
    else
389
      eth_host.wb_write(bd_status_addr, 4'hf, 32'h0000c000);    // IRQ + PAD + CRC
390
 
391
    eth_host.wb_write(bd_ptr_addr, 4'hf, buf_addr);             // Initializing BD - pointer
392
  end
393
endtask // initialize_rxbd
394
 
395
 
396
task set_packet;
397
  input  [15:0] len;
398
  input   [7:0] start_data;
399
 
400
  integer i, sd;
401
  integer bd_status_addr, bd_ptr_addr, buffer, bd;
402
 
403
  begin
404
    sd = start_data;
405
    bd_status_addr = `TX_BD_BASE + packet_ready_cnt * 8;
406
    bd_ptr_addr = bd_status_addr + 4;
407
 
408
    // Reading BD + buffer pointer
409
    eth_host.wb_read(bd_status_addr, 4'hf, bd);
410
    eth_host.wb_read(bd_ptr_addr, 4'hf, buffer);
411
 
412
    while(bd & `ETH_TX_BD_READY) begin  // Buffer is ready. Don't touch !!!
413
      repeat(100) @(posedge wb_clk_o);
414
      i=i+1;
415
      eth_host.wb_read(bd_status_addr, 4'hf, bd);
416
      if(i>1000)  begin
417
        $display("(%0t)(%m)Waiting for TxBD ready to clear timeout", $time);
418
        $stop;
419
      end
420
    end
421
 
422
    // First write might not be word allign.
423
    if(buffer[1:0]==1)  begin
424
      eth_host.wb_write(buffer-1, 4'h7, {8'h0, sd[7:0], sd[7:0]+3'h1, sd[7:0]+3'h2});
425
      sd=sd+3;
426
      i=3;
427
    end
428
    else if(buffer[1:0]==2)  begin
429
      eth_host.wb_write(buffer-2, 4'h3, {16'h0, sd[7:0], sd[7:0]+3'h1});
430
      sd=sd+2;
431
      i=2;
432
    end
433
    else if(buffer[1:0]==3)  begin
434
      eth_host.wb_write(buffer-3, 4'h1, {24'h0, sd[7:0]});
435
      sd=sd+1;
436
      i=1;
437
    end
438
    else
439
      i=0;
440
 
441
 
442
    for(i=i; i<len-4; i=i+4) begin   // Last 0-3 bytes are not written
443
      eth_host.wb_write(buffer+i, 4'hf, {sd[7:0], sd[7:0]+3'h1, sd[7:0]+3'h2, sd[7:0]+3'h3});
444
      sd=sd+4;
445
    end
446
 
447
 
448
    // Last word
449
    if(len-i==3)
450
      eth_host.wb_write(buffer+i, 4'he, {sd[7:0], sd[7:0]+3'h1, sd[7:0]+3'h2, 8'h0});
451
    else if(len-i==2)
452
      eth_host.wb_write(buffer+i, 4'hc, {sd[7:0], sd[7:0]+3'h1, 16'h0});
453
    else if(len-i==1)
454
      eth_host.wb_write(buffer+i, 4'h8, {sd[7:0], 24'h0});
455
    else if(len-i==4)
456
      eth_host.wb_write(buffer+i, 4'hf, {sd[7:0], sd[7:0]+3'h1, sd[7:0]+3'h2, sd[7:0]+3'h3});
457
    else
458
      $display("(%0t)(%m) ERROR", $time);
459
 
460
 
461
    // Checking WRAP bit
462
    if(bd & `ETH_TX_BD_WRAP)
463
      packet_ready_cnt = 0;
464
    else
465
      packet_ready_cnt = packet_ready_cnt+1;
466
 
467
    // Writing len to bd
468
    bd = bd | (len<<16);
469
    eth_host.wb_write(bd_status_addr, 4'hf, bd);
470
 
471
  end
472
endtask // set_packet
473
 
474
 
475
task send_packet;
476
 
477
  integer bd_status_addr, bd_ptr_addr, buffer, bd;
478
 
479
  begin
480
    bd_status_addr = `TX_BD_BASE + send_packet_cnt * 8;
481
    bd_ptr_addr = bd_status_addr + 4;
482
 
483
    // Reading BD + buffer pointer
484
    eth_host.wb_read(bd_status_addr, 4'hf, bd);
485
    eth_host.wb_read(bd_ptr_addr, 4'hf, buffer);
486
 
487
    if(bd & `ETH_TX_BD_WRAP)
488
      send_packet_cnt=0;
489
    else
490
      send_packet_cnt=send_packet_cnt+1;
491
 
492
    // Setting ETH_TX_BD_READY bit
493
    bd = bd | `ETH_TX_BD_READY;
494
    eth_host.wb_write(bd_status_addr, 4'hf, bd);
495
  end
496
 
497
 
498
endtask // send_packet
499
 
500
 
501
task GetDataOnMRxD;
502
  input [15:0] Len;
503
  input [31:0] TransferType;
504
  integer tt;
505
 
506
  begin
507
    @ (posedge mrx_clk);
508
    #1MRxDV=1'b1;
509
 
510
    for(tt=0; tt<15; tt=tt+1)
511
      begin
512
        MRxD=4'h5;              // preamble
513
        @ (posedge mrx_clk);
514
        #1;
515
      end
516
 
517
    MRxD=4'hd;                // SFD
518
 
519
    for(tt=1; tt<(Len+1); tt=tt+1)
520
      begin
521
        @ (posedge mrx_clk);
522
        #1;
523
            if(TransferType == `UNICAST_XFR && tt == 1)
524
                MRxD= 4'h0;   // Unicast transfer
525
              else if(TransferType == `BROADCAST_XFR && tt < 7)
526
                MRxD = 4'hf;
527
              else
528
          MRxD=tt[3:0]; // Multicast transfer
529
 
530
        @ (posedge mrx_clk);
531
              #1;
532
              if(TransferType == `BROADCAST_XFR && tt < 7)
533
                MRxD = 4'hf;
534
              else
535
          MRxD=tt[7:4];
536
      end
537
 
538
    @ (posedge mrx_clk);
539
    #1;
540
    MRxDV=1'b0;
541
  end
542
endtask // GetDataOnMRxD
543
 
544
 
545
endmodule

powered by: WebSVN 2.1.0

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