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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [actel/] [ordb1a3pe1500/] [bench/] [verilog/] [include/] [eth_stim.v] - Blame information for rev 409

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

Line No. Rev Author Line
1 408 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Ethernet MAC Stimulus                                       ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Ethernet MAC stimulus tasks. Taken from the project         ////
7
////  testbench in the ethmac core.                               ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////                                                              ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Tadej Markovic, tadej@opencores.org                   ////
14
////      - Igor Mohor,     igorM@opencores.org                   ////
15
////      - Julius Baxter   julius.baxter@orsoc.se                ////
16
////                                                              ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
`define TIME $display("Time: %0t", $time)
45
 
46
// Defines for ethernet test to trigger sending/receiving
47
// Is straight forward when using RTL design, but if using netlist then paths to
48
// the RX/TX enabled bits depend on synthesis tool, etc, but ones here appear to
49
// work with design put through Synplify, with hierarchy maintained.
50 409 julius
`define ETH_TOP dut.ethmac0
51 408 julius
`define ETH_BD_RAM_PATH `ETH_TOP.wishbone.bd_ram
52
`define ETH_MODER_PATH `ETH_TOP.ethreg1.MODER_0
53
 
54
`ifdef RTL_SIM
55
 `ifdef eth_IS_GATELEVEL
56
  `define ETH_MODER_TXEN_BIT `ETH_MODER_PATH.r_TxEn;
57
  `define ETH_MODER_RXEN_BIT `ETH_MODER_PATH.r_RxEn;
58
 `else
59
  `define ETH_MODER_TXEN_BIT `ETH_MODER_PATH.DataOut[1];
60
  `define ETH_MODER_RXEN_BIT `ETH_MODER_PATH.DataOut[0];
61
 `endif
62
`endif
63
 
64
`ifdef GATE_SIM
65
 `define ETH_MODER_TXEN_BIT `ETH_MODER_PATH.r_TxEn;
66
 `define ETH_MODER_RXEN_BIT `ETH_MODER_PATH.r_RxEn;
67
`endif
68
 
69
reg [15:0] eth_stim_rx_packet_length;
70
reg [7:0] st_data;
71
reg [31:0] lfsr;
72
integer lfsr_last_byte;
73
 
74
// Is number of ethernet packets to send if doing the eth-rx test.
75
parameter eth_stim_num_rx_only_tests = 256;
76
 
77
 
78
parameter num_tx_bds = 16;
79
parameter num_tx_bds_mask = 4'hf;
80
parameter num_rx_bds = 16;
81
parameter num_rx_bds_mask = 4'hf;
82
parameter max_eth_packet_size = 16'h0600;
83
// If running eth-rxtxbig test (sending and receiving maximum packets), then
84
// set this parameter to the max packet size, otherwise min packet size
85
//parameter rx_while_tx_min_packet_size = max_eth_packet_size;
86
parameter rx_while_tx_min_packet_size = 32;
87
 
88
// Use the smallest possible IPG
89
parameter eth_stim_use_min_IPG = 0;
90
parameter eth_stim_IPG_delay_max = 500_000; // Maximum 500uS ga
91
//parameter eth_stim_IPG_delay_max = 100_000_000; // Maximum 100mS between packets
92
parameter eth_stim_IPG_min_10mb = 9600; // 9.6 uS
93
parameter eth_stim_IPG_min_100mb = 800; // 860+~100 = 960 nS 100MBit min IPG
94
parameter eth_stim_check_rx_packet_contents = 1;
95
parameter eth_stim_check_tx_packet_contents = 1;
96
 
97
parameter eth_inject_errors = 0;
98
 
99
// When running simulations where you don't want to feed packets to the design
100
// like this...
101
parameter eth_stim_disable_rx_stim = 0;
102
 
103
// Delay between seeing that the buffer descriptor for an RX packet says it's
104
// been received and ending up in the memory.
105
// For 25MHz sdram controller, use following:
106
//parameter  Td_rx_packet_check = (`BOARD_CLOCK_PERIOD * 2000);
107
// For 64MHz sdram controller, use following:
108
parameter  Td_rx_packet_check = (`BOARD_CLOCK_PERIOD * 500);
109
 
110
 
111
 
112
integer expected_rxbd;// init to 0
113
integer expected_txbd;
114
 
115
wire ethmac_rxen;
116
wire ethmac_txen;
117
assign ethmac_rxen = eth_stim_disable_rx_stim ? 0 : `ETH_MODER_RXEN_BIT;
118
assign ethmac_txen = `ETH_MODER_TXEN_BIT;
119
 
120
integer eth_rx_num_packets_sent = 0;
121
integer eth_rx_num_packets_checked = 0;
122
integer num_tx_packets = 1;
123
 
124
integer rx_packet_lengths [0:1023]; // Array of packet lengths
125
 
126
 
127
integer speed_loop;
128
 
129
// When txen is (re)enabled, the tx bd pointer goes back to 0
130
always @(posedge ethmac_txen)
131
  expected_txbd = 0;
132
 
133
   reg  eth_stim_waiting;
134
 
135
initial
136
  begin
137
     #1;
138
     //lfsr = 32'h84218421; // Init pseudo lfsr
139
     lfsr = 32'h00700001; // Init pseudo lfsr
140
     lfsr_last_byte = 0;
141
 
142
     eth_stim_waiting = 1;
143
 
144
     while (eth_stim_waiting) // Loop, waiting for enabling of MAC by software
145
       begin
146
          #100;
147
          // If RX enable and not TX enable...
148
          if(ethmac_rxen === 1'b1 & !(ethmac_txen===1'b1))
149
            begin
150
               if (eth_inject_errors)
151
                 begin
152
                    do_rx_only_stim(16, 0, 0);
153
                    do_rx_only_stim(128, 1'b1, 8);
154
                    do_rx_only_stim(256, 1'b1, 4);
155
                    eth_stim_waiting = 0;
156
                 end
157
               else
158
                 begin
159
                    do_rx_only_stim(eth_stim_num_rx_only_tests, 0, 0);
160
                    eth_stim_waiting = 0;
161
                 end
162
            end // if (ethmac_rxen === 1'b1 & !(ethmac_txen===1'b1))
163
          // If both RX and TX enabled
164
          else if (ethmac_rxen === 1'b1 & ethmac_txen===1'b1)
165
            begin
166
               // If RX enable and TX enable
167
               do_rx_while_tx_stim(1400);
168
               eth_stim_waiting = 0;
169
            end
170
       end // while (eth_stim_waiting)     
171
 
172
  end // initial begin
173
 
174
   // Main Ethernet RX testing stimulus task.
175
   // Sends a set of packets at both speeds
176
   task do_rx_only_stim;
177
      input [31:0] num_packets;
178
      input        inject_errors;
179
      input [31:0] inject_errors_mod;
180
 
181
      begin
182
         expected_rxbd = num_tx_bds; // init this here
183
 
184
         for(speed_loop=1;speed_loop<3;speed_loop=speed_loop+1)
185
           begin
186
 
187
              send_packet_loop(num_packets, 64, 2'b01, 1, speed_loop[0], 10000,
188
                               48'h0012_3456_789a, 48'h0708_090A_0B0C, 1,
189
                               inject_errors, inject_errors_mod);
190
 
191
           end
192
 
193
      end
194
   endtask // do_rx_stim
195
 
196
   // Generate RX packets while there's TX going on
197
   // Sends a set of packets at both speeds
198
   task do_rx_while_tx_stim;
199
      input [31:0] num_packets;
200
      reg [31:0] IPG; // Inter-packet gap
201
      reg [31:0] packet_size;
202
 
203
      integer    j;
204
      begin
205
         expected_rxbd = num_tx_bds; // init this here
206
 
207
         for(j=0;j<num_packets;j=j+1)
208
           begin
209
              // Determine delay between RX packets:
210
 
211
              if (eth_stim_use_min_IPG)
212
                begin
213
                   // Assign based on whether we're in 100mbit or 10mbit mode
214
                   IPG = eth_phy0.eth_speed ? eth_stim_IPG_min_100mb :
215
                         eth_stim_IPG_min_10mb;
216
                   // Add a little bit of variability
217
                   // Add up to 15
218
                   IPG = IPG + ($random & 32'h000000f);
219
                end
220
              else
221
                begin
222
                   IPG = $random;
223
 
224
                   while (IPG > eth_stim_IPG_delay_max)
225
                     IPG = IPG / 2;
226
 
227
 
228
                end
229
              $display("do_rx_while_tx IPG = %0d", IPG);
230
              // Determine size of next packet:
231
              if (rx_while_tx_min_packet_size == max_eth_packet_size)
232
                // We want to transmit biggest packets possible, easy case
233
                packet_size = max_eth_packet_size - 4;
234
              else
235
                begin
236
                   // Constrained random sized packets
237
                   packet_size = $random;
238
 
239
                   while (packet_size > (max_eth_packet_size-4))
240
                     packet_size = packet_size / 2;
241
 
242
                   // Now divide by least significant bits of j
243
                   packet_size = packet_size / {29'd0,j[1:0],1'b1};
244
                   if (packet_size < 60)
245
                     packet_size = packet_size + 60;
246
                end
247
 
248
              $display("do_rx_while_tx packet_size = %0d", packet_size);
249
              send_packet_loop(1, packet_size, 2'b01, 1, eth_phy0.eth_speed,
250
                               IPG, 48'h0012_3456_789a,
251
                               48'h0708_090A_0B0C, 1, 1'b0, 0);
252
 
253
              // If RX enable went low, wait for it go high again
254
              if (ethmac_rxen===1'b0)
255
                begin
256
 
257
                   while (ethmac_rxen===1'b0)
258
                     begin
259
                        @(posedge ethmac_rxen);
260
                        #10000;
261
                     end
262
 
263
                   // RX disabled and when re-enabled we reset the buffer descriptor number
264
                   expected_rxbd = num_tx_bds;
265
 
266
                end
267
 
268
           end // for (j=0;j<num_packets;j=j+1)
269
      end
270
   endtask // do_rx_stim
271
 
272
   //
273
   // always@() to check the TX buffer descriptors
274
   //
275
      reg keep_polling;
276
      reg [31:0] txbd_lenstat, last_txbd_lenstat;
277
      reg        detected_packet_tx;
278
   always @(posedge ethmac_txen)
279
     begin
280
         last_txbd_lenstat = 0;
281
         keep_polling=1;
282
         // Wait on the TxBD Ready bit
283
         while(keep_polling)
284
           begin
285
              #10;
286
              get_bd_lenstat(expected_txbd, txbd_lenstat);
287
              // Check if we've finished transmitting this BD
288
              if (!txbd_lenstat[15] & last_txbd_lenstat[15])
289
                // Falling edge of TX BD Ready
290
                detected_packet_tx = 1;
291
 
292
              last_txbd_lenstat = txbd_lenstat;
293
 
294
              // If TX en goes low then exit
295
              if (!ethmac_txen)
296
                keep_polling = 0;
297
              else if (detected_packet_tx)
298
                begin
299
                   // Wait until the eth_phy has finished receiving it
300
                   while (eth_phy0.mtxen_i === 1'b1)
301
                     #10;
302
 
303
                   $display("(%t) Check TX packet: bd %d: 0x%h",$time,
304
                            expected_txbd, txbd_lenstat);
305
 
306
                   // Check the TXBD, see if the packet transmitted OK
307
                   if (txbd_lenstat[8] | txbd_lenstat[3])
308
                     begin
309
                        // Error occured
310
                        `TIME;
311
                        $display("*E TX Error of packet %0d detected.",
312
                                 num_tx_packets);
313
                        $display(" TX BD %0d = 0x%h", expected_txbd,
314
                                 txbd_lenstat);
315
                        if (txbd_lenstat[8])
316
                          $display(" Underrun in MAC during TX");
317
                        if (txbd_lenstat[3])
318
                          $display(" Retransmission limit hit");
319
 
320
                        $finish;
321
                     end
322
                   else
323
                     begin
324
                        // Packet was OK, let's compare the contents we received
325
                        // with those that were meant to be transmitted
326
                        if (eth_stim_check_tx_packet_contents)
327
                          begin
328
                             check_tx_packet(expected_txbd);
329
                             expected_txbd = (expected_txbd + 1) &
330
                                             num_tx_bds_mask;
331
                             num_tx_packets = num_tx_packets + 1;
332
                             detected_packet_tx = 0;
333
                          end
334
                     end
335
                end
336
           end // while (keep_polling)
337
     end // always @ (posedge ethmac_txen)
338
 
339
 
340
 
341
   //
342
   // Check packet TX'd by MAC was good
343
   // 
344
   task check_tx_packet;
345
      input [31:0] tx_bd_num;
346
 
347
      reg [31:0]   tx_bd_addr;
348
      reg [7:0]    phy_byte;
349
 
350
      reg [31:0]   txpnt_wb; // Pointer in array to where data should be
351
      reg [24:0]   txpnt_sdram; // Index in array of shorts for data in SDRAM part
352
      reg [21:0]   buffer;
353
      reg [7:0]    sdram_byte;
354
      reg [31:0]   tx_len_bd;
355
 
356
      integer      i;
357
      integer      failure;
358
      begin
359
         failure = 0;
360
 
361
         get_bd_lenstat(tx_bd_num, tx_len_bd);
362
 
363
         tx_len_bd = {15'd0,tx_len_bd[31:16]};
364
 
365
         // Check, if length didn't have to be padded, that
366
         // amount transmitted was correct
367
         if ((tx_len_bd > 60)&(tx_len_bd != (eth_phy0.tx_len-4)))
368
           begin
369
              $display("*E TX packet sent length, %0d != length in TX BD, %0d",
370
                       eth_phy0.tx_len-4, tx_len_bd);
371
              #100;
372
              $finish;
373
           end
374
 
375
         get_bd_addr(tx_bd_num, tx_bd_addr);
376
 
377
         // We're never going to be using more than about 256K of receive buffer
378
         // so let's lop off the top bit of the address pointer - we only want
379
         // the offset from the base of the memory bank
380
         txpnt_wb = {14'd0,tx_bd_addr[17:0]};
381
         txpnt_sdram = tx_bd_addr[24:0];
382
 
383
         // Variable we'll use for index in the PHY's TX buffer
384
         buffer = 0; // Start of TX data
385
`ifdef VERSATILE_SDRAM
386
         for (i=0;i<tx_len_bd;i=i+1)
387
           begin
388
              //$display("Checking address in tx bd 0x%0h",txpnt_sdram);
389
 
390
              sdram0.get_byte(txpnt_sdram,sdram_byte);
391
 
392
              phy_byte = eth_phy0.tx_mem[buffer];
393
              // Debugging output
394
              //$display("txpnt_sdram = 0x%h, sdram_byte = 0x%h, buffer = 0x%h, phy_byte = 0x%h", txpnt_sdram,  sdram_byte, buffer, phy_byte);
395
              if (phy_byte !== sdram_byte)
396
                begin
397
                   `TIME;
398
                   $display("*E Wrong byte (%d) of TX packet! ram = %h, phy = %h",buffer, sdram_byte, phy_byte);
399
                   failure = 1;
400
                end
401
 
402
              buffer = buffer + 1;
403
 
404
              txpnt_sdram = txpnt_sdram+1;
405
 
406
           end // for (i=0;i<tx_len_bd;i=i+1)
407
 
408
`else
409
         $display("SET ME UP TO LOOK IN ANOTHER MEMORY!");
410
         $display("RAM pointer for BD is 0x%h, bank offset we'll use is 0x%h",
411
                  tx_bd_addr, txpnt_wb);
412
         $finish;
413
`endif // !`ifdef VERSATILE_SDRAM
414
         if (failure)
415
           begin
416
              #100
417
                `TIME;
418
              $display("*E Error transmitting packet %0d (%0d bytes). Finishing simulation", num_tx_packets, tx_len_bd);
419
              get_bd_lenstat(tx_bd_num, tx_len_bd);
420
              $display("   TXBD lenstat: 0x%0h",tx_len_bd);
421
              $display("   TXBD address: 0x%0h",tx_bd_addr);
422
              $finish;
423
           end
424
         else
425
           begin
426
              #1 $display( "(%0t)(%m) TX packet %0d: %0d bytes in memory OK!",$time,num_tx_packets, tx_len_bd);
427
 
428
           end
429
 
430
 
431
      end
432
   endtask // check_tx_packet
433
 
434
   //
435
   // Task to send a set of packets
436
   //
437
   task send_packet_loop;
438
      input [31:0] num_packets;
439
      input [31:0] length;
440
      input [1:0]  length_change; // 0 = none, 1 = incr, 2 = decrement
441
      input [31:0] length_change_size; // Size to change by
442
      input        speed;
443
      input [31:0] back_to_back_delay; // #delay setting between packets
444
      input [47:0] dst_mac;
445
      input [47:0] src_mac;
446
      input        random_fill;
447
      input        random_errors;
448
      input [31:0] random_error_mod;
449
      integer      j;
450
      reg          error_this_time;
451
      integer      error_type; // 0 = rxerr, 1=bad preamble 2=bad crc 3=TODO
452
      reg [31:0]   rx_bd_lenstat;
453
      begin
454
         error_type = 0;
455
         error_this_time = 0;
456
 
457
         if (speed & !(eth_phy0.control_bit14_10[13] === 1'b1))
458
           begin
459
              // write to phy's control register for 100Mbps
460
              eth_phy0.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
461
              // Swapping speeds, give some delay
462
              #10000;
463
           end
464
         else if (!speed & !(eth_phy0.control_bit14_10[13] === 1'b0))
465
           begin
466
              eth_phy0.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
467
              // Swapping speeds, give some delay
468
              #10000;
469
           end
470
 
471
         eth_phy0.control_bit8_0   = 9'h1_00;
472
 
473
         for(j=0;j<num_packets | length <32;j=j+1)
474
           begin
475
              eth_stim_rx_packet_length = length[15:0]; // Bytes
476
              st_data = 8'h0F;
477
 
478
              // setup RX packet in buffer - length is without CRC
479
              set_rx_packet(0, eth_stim_rx_packet_length, 1'b0, dst_mac,
480
                            src_mac, 16'h0D0E, st_data, random_fill);
481
 
482
              set_rx_addr_type(0, dst_mac, src_mac, 16'h0D0E);
483
 
484
              // Error type 2 is cause CRC error
485
              append_rx_crc(0, eth_stim_rx_packet_length, 1'b0,
486
                            (error_type==2));
487
 
488
              if (error_this_time)
489
                begin
490
                   if (error_type == 0)
491
                     // RX ERR assert during transmit
492
                     eth_phy0.send_rx_packet(64'h0055_5555_5555_5555, 4'h7,
493
                                             8'hD5, 0,
494
                                             eth_stim_rx_packet_length+4,
495
                                             1'b0, 1'b1);
496
                   else if (error_type == 1)
497
                     // Incorrect preamble
498
                     eth_phy0.send_rx_packet(64'h0055_5f55_5555_5555, 4'h7,
499
                                             8'hD5, 0,
500
                                             eth_stim_rx_packet_length+4,
501
                                             1'b0, 1'b0);
502
                   else
503
                     // Normal datapacket
504
                     eth_phy0.send_rx_packet(64'h0055_5555_5555_5555, 4'h7,
505
                                             8'hD5, 0,
506
                                             eth_stim_rx_packet_length+4,
507
                                             1'b0, 1'b0);
508
                end
509
              else
510
                eth_phy0.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5,
511
                                        0, eth_stim_rx_packet_length+4, 1'b0,
512
                                        1'b0);
513
 
514
 
515
              // if RX enable still set (might have gone low during this packet
516
              if (ethmac_rxen)
517
                begin
518
                   if (error_this_time)
519
                     // Put in dummy length, checking function will skip...
520
                     rx_packet_lengths[(eth_rx_num_packets_sent& 12'h3ff)]=32'heeeeeeee;
521
                   else
522
                     rx_packet_lengths[(eth_rx_num_packets_sent & 12'h3ff)] = length;
523
 
524
                   eth_rx_num_packets_sent = eth_rx_num_packets_sent + 1;
525
 
526
                end // if (ethmac_rxen)
527
              else
528
                begin
529
                   // Force the loop to finish up                  
530
                   j = num_packets;
531
                end
532
 
533
 
534
              // Inter-packet gap
535
              #back_to_back_delay;
536
 
537
              // Update length
538
              if (length_change == 2'b01)
539
                length = length + length_change_size;
540
 
541
              if ((length_change == 2'b10) &&
542
                  ((length - length_change_size) > 32))
543
                length = length - length_change_size;
544
 
545
              // Increment error type
546
              if (error_this_time)
547
                error_type = error_type + 1;
548
              if (error_type > 3)
549
                error_type = 0;
550
 
551
 
552
              // Check if we should put in an error this time
553
              if (j%random_error_mod == 0)
554
                error_this_time = 1;
555
              else
556
                error_this_time = 0;
557
 
558
              eth_phy0.rx_err(0);
559
 
560
              // Now wait to check if we have filled up all the RX BDs and
561
              // the this packet would start writing over them. Only really an
562
              // issue when doing minimum IPG tests.
563
              while(((eth_rx_num_packets_sent+1) - eth_rx_num_packets_checked)
564
                    == num_rx_bds)
565
                #100;
566
 
567
 
568
           end // for (j=0;j<num_packets | length <32;j=j+1)
569
      end
570
   endtask // send_packet_loop
571
 
572
   // Local buffer of "sent" data to the ethernet MAC, we will check against
573
   // Size of our local buffer in bytes
574
   parameter eth_rx_sent_circbuf_size = (16*1024);
575
   parameter eth_rx_sent_circbuf_size_mask = eth_rx_sent_circbuf_size - 1;
576
   integer eth_rx_sent_circbuf_fill_ptr = 0;
577
   integer eth_rx_sent_circbuf_read_ptr = 0;
578
   // The actual buffer
579
   reg [7:0] eth_rx_sent_circbuf [0:eth_rx_sent_circbuf_size-1];
580
 
581
   /*
582
    TASKS for set and check RX packets:
583
    -----------------------------------
584
    set_rx_packet
585
    (rxpnt[31:0], len[15:0], plus_nibble, d_addr[47:0], s_addr[47:0], type_len[15:0], start_data[7:0]);
586
    check_rx_packet
587
    (rxpnt_phy[31:0], rxpnt_wb[31:0], len[15:0], plus_nibble, successful_nibble, failure[31:0]);
588
    */
589
   task set_rx_packet;
590
      input  [31:0] rxpnt; // pointer to place in in the phy rx buffer we'll start at
591
      input [15:0]  len;
592
      input         plus_dribble_nibble; // if length is longer for one nibble
593
      input [47:0]  eth_dest_addr;
594
      input [47:0]  eth_source_addr;
595
      input [15:0]  eth_type_len;
596
      input [7:0]   eth_start_data;
597
      input         random_fill;
598
      integer       i, sd;
599
      reg [47:0]    dest_addr;
600
      reg [47:0]    source_addr;
601
      reg [15:0]    type_len;
602
      reg [21:0]    buffer;
603
      reg           delta_t;
604
 
605
      begin
606
         buffer = rxpnt[21:0];
607
         dest_addr = eth_dest_addr;
608
         source_addr = eth_source_addr;
609
         type_len = eth_type_len;
610
         sd = eth_start_data;
611
         delta_t = 0;
612
         for(i = 0; i < len; i = i + 1)
613
           begin
614
              if (i < 6)
615
                begin
616
                   eth_phy0.rx_mem[buffer] = dest_addr[47:40];
617
                   dest_addr = dest_addr << 8;
618
                end
619
              else if (i < 12)
620
                begin
621
                   eth_phy0.rx_mem[buffer] = source_addr[47:40];
622
                   source_addr = source_addr << 8;
623
                end
624
              else if (i < 14)
625
                begin
626
                   eth_phy0.rx_mem[buffer] = type_len[15:8];
627
                   type_len = type_len << 8;
628
                end
629
              else
630
                begin
631
                   if (random_fill)
632
                     begin
633
                        if (lfsr_last_byte == 0)
634
                          eth_phy0.rx_mem[buffer] = lfsr[15:8];
635
                        if (lfsr_last_byte == 1)
636
                          eth_phy0.rx_mem[buffer] = lfsr[23:16];
637
                        if (lfsr_last_byte == 2)
638
                          eth_phy0.rx_mem[buffer] = lfsr[31:24];
639
                        if (lfsr_last_byte == 3)
640
                          begin
641
                             eth_phy0.rx_mem[buffer] = lfsr[7:0];
642
                             lfsr = {lfsr[30:0],(((lfsr[31] ^ lfsr[6]) ^
643
                                                  lfsr[5]) ^ lfsr[1])};
644
                             lfsr_last_byte =  0;
645
                          end
646
                        else
647
                          lfsr_last_byte = lfsr_last_byte + 1;
648
 
649
                     end // if (random_fill)               
650
                   else
651
                     eth_phy0.rx_mem[buffer] = sd[7:0];
652
                   sd = sd + 1;
653
                end // else: !if(i < 14)
654
 
655
              // Update our local buffer
656
              eth_rx_sent_circbuf[eth_rx_sent_circbuf_fill_ptr]
657
                = eth_phy0.rx_mem[buffer];
658
              eth_rx_sent_circbuf_fill_ptr = (eth_rx_sent_circbuf_fill_ptr+1)&
659
                                             eth_rx_sent_circbuf_size_mask;
660
 
661
              buffer = buffer + 1;
662
           end // for (i = 0; i < len; i = i + 1)
663
 
664
         delta_t = !delta_t;
665
         if (plus_dribble_nibble)
666
           eth_phy0.rx_mem[buffer] = {4'h0, 4'hD /*sd[3:0]*/};
667
         delta_t = !delta_t;
668
      end
669
   endtask // set_rx_packet
670
 
671
 
672
 
673
 
674
   task set_rx_addr_type;
675
      input  [31:0] rxpnt;
676
      input [47:0]  eth_dest_addr;
677
      input [47:0]  eth_source_addr;
678
      input [15:0]  eth_type_len;
679
      integer       i;
680
      reg [47:0]    dest_addr;
681
      reg [47:0]    source_addr;
682
      reg [15:0]    type_len;
683
      reg [21:0]    buffer;
684
      reg           delta_t;
685
      begin
686
         buffer = rxpnt[21:0];
687
         dest_addr = eth_dest_addr;
688
         source_addr = eth_source_addr;
689
         type_len = eth_type_len;
690
         delta_t = 0;
691
         for(i = 0; i < 14; i = i + 1)
692
           begin
693
              if (i < 6)
694
                begin
695
                   eth_phy0.rx_mem[buffer] = dest_addr[47:40];
696
                   dest_addr = dest_addr << 8;
697
                end
698
              else if (i < 12)
699
                begin
700
                   eth_phy0.rx_mem[buffer] = source_addr[47:40];
701
                   source_addr = source_addr << 8;
702
                end
703
              else // if (i < 14)
704
                begin
705
                   eth_phy0.rx_mem[buffer] = type_len[15:8];
706
                   type_len = type_len << 8;
707
                end
708
              buffer = buffer + 1;
709
           end
710
         delta_t = !delta_t;
711
      end
712
   endtask // set_rx_addr_type
713
 
714
 
715
`ifdef eth_IS_GATELEVEL // Check if we're using a synthesized version of eth module
716
   // Get the length/status register of the ethernet buffer descriptor
717
   task get_bd_lenstat;
718
      input [31:0] bd_num;// Number of ethernet BD to check
719
      output [31:0] bd_lenstat;
720
 `ifdef ACTEL
721
      reg [8:0]    tmp;
722
      integer      raddr;
723
 `endif
724
      begin
725
 `ifdef ACTEL
726
 
727
         // Pull from the Actel memory model
728
         raddr = `ETH_BD_RAM_PATH.\mem_tile.I_1 .get_address((bd_num*2));
729
 
730
         tmp = `ETH_BD_RAM_PATH.\mem_tile.I_1 .MEM_512_9[(raddr*2)];
731
         bd_lenstat[8:0] = tmp[8:0];
732
 
733
         tmp = `ETH_BD_RAM_PATH.\mem_tile.I_1 .MEM_512_9[(raddr*2)+1];
734
         bd_lenstat[17:9] = tmp[8:0];
735
 
736
         raddr = `ETH_BD_RAM_PATH.\mem_tile_0.I_1 .get_address((bd_num*2));
737
 
738
         tmp = `ETH_BD_RAM_PATH.\mem_tile_0.I_1 .MEM_512_9[(raddr*2)];
739
         bd_lenstat[26:18] = tmp[8:0];
740
 
741
         tmp = `ETH_BD_RAM_PATH.\mem_tile_0.I_1 .MEM_512_9[(raddr*2)+1];
742
         bd_lenstat[31:27] = tmp[4:0];
743
 
744
         //$display("(%t) read eth bd lenstat %h",$time, bd_lenstat);
745
 `endif
746
      end
747
   endtask // get_bd_lenstat
748
 
749
   // Get the length/status register of the ethernet buffer descriptor
750
   task get_bd_addr;
751
      input [31:0] bd_num;// Number of the ethernet BD to check
752
      output [31:0] bd_addr;
753
 `ifdef ACTEL
754
      reg [8:0]    tmp;
755
      integer       raddr;
756
 `endif
757
      begin
758
 `ifdef ACTEL
759
         // Pull from the Actel memory model
760
         raddr = `ETH_BD_RAM_PATH.\mem_tile.I_1 .get_address((bd_num*2)+1);
761
 
762
         tmp = `ETH_BD_RAM_PATH.\mem_tile.I_1 .MEM_512_9[(raddr*2)];
763
         bd_addr[8:0] = tmp[8:0];
764
 
765
         tmp = `ETH_BD_RAM_PATH.\mem_tile.I_1 .MEM_512_9[(raddr*2)+1];
766
         bd_addr[17:9] = tmp[8:0];
767
 
768
         raddr = `ETH_BD_RAM_PATH.\mem_tile_0.I_1 .get_address((bd_num*2)+1);
769
 
770
         tmp = `ETH_BD_RAM_PATH.\mem_tile_0.I_1 .MEM_512_9[(raddr*2)];
771
         bd_addr[26:18] = tmp[8:0];
772
 
773
         tmp = `ETH_BD_RAM_PATH.\mem_tile_0.I_1 .MEM_512_9[(raddr*2)+1];
774
         bd_addr[31:27] = tmp[4:0];
775
 
776
         //$display("(%t) read eth bd%d addr %h",$time,bd_num, bd_addr);
777
 `endif
778
      end
779
   endtask // get_bd_addr
780
 
781
`else // !`ifdef eth_IS_GATELEVEL
782
 
783
   // Get the length/status register of the ethernet buffer descriptor
784
   task get_bd_lenstat;
785
      input [31:0] bd_num;// Number of ethernet BD to check
786
      output [31:0] bd_lenstat;
787
      begin
788
         bd_lenstat = `ETH_BD_RAM_PATH.mem[(bd_num*2)];
789
      end
790
   endtask // get_bd_lenstat
791
 
792
   // Get the length/status register of the ethernet buffer descriptor
793
   task get_bd_addr;
794
      input [31:0] bd_num;// Number of the ethernet BD to check
795
      output [31:0] bd_addr;
796
      begin
797
         bd_addr = `ETH_BD_RAM_PATH.mem[((bd_num*2)+1)];
798
         //$display("(%t) read eth bd%d addr %h",$time,bd_num, bd_addr);
799
      end
800
   endtask // get_bd_addr
801
`endif
802
 
803
   // Always block triggered by finishing of transmission of new packet from 
804
   // send_packet_loop
805
   integer eth_rx_packet_length_to_check;
806
 
807
   always @*
808
     begin
809
        // Loop here waiting for a packet to be sent, or if we shouldn't
810
        // check them at all.
811
        while((eth_rx_num_packets_sent == eth_rx_num_packets_checked) ||
812
              !eth_stim_check_rx_packet_contents)
813
          #1000;
814
 
815
        eth_rx_packet_length_to_check
816
          = rx_packet_lengths[(eth_rx_num_packets_checked & 12'h3ff)];
817
 
818
        if ( eth_rx_packet_length_to_check !==  32'heeeeeeee)
819
          check_rx_packet(expected_rxbd, 0, eth_rx_packet_length_to_check);
820
 
821
        eth_rx_num_packets_checked = eth_rx_num_packets_checked + 1;
822
 
823
        expected_rxbd = expected_rxbd + 1;
824
 
825
        // Wrap
826
        if (expected_rxbd == (num_tx_bds + num_rx_bds))
827
          expected_rxbd = num_tx_bds;
828
     end
829
 
830
   task check_rx_packet;
831
 
832
      input [31:0] rx_bd_num;
833
      input [31:0] rxpnt_phy; // Pointer in array of data in PHY
834
      input [31:0] len;
835
 
836
      reg [31:0]   rx_bd_lenstat;
837
      reg [31:0]   rx_bd_addr;
838
      reg [7:0]    phy_byte;
839
 
840
      reg [31:0]   rxpnt_wb; // Pointer in array to where data should be
841
      reg [24:0]   rxpnt_sdram; // byte address from CPU in RAM
842
      reg [15:0]   sdram_short;
843
      reg [7:0]    sdram_byte;
844
      //reg [7:0]    phy_rx_mem [0:2000];
845
 
846
      integer      i;
847
      integer      failure;
848
 
849
      begin
850
 
851
         failure = 0;
852
 
853
         // Wait until the buffer descriptor indicates the packet has been 
854
         // received...
855
         get_bd_lenstat(rx_bd_num, rx_bd_lenstat);
856
         while (rx_bd_lenstat & 32'h00008000)// Check Empty bit
857
           begin
858
              #10;
859
              get_bd_lenstat(rx_bd_num, rx_bd_lenstat);
860
              //$display("(%t) check_rx_packet: poll bd %d: 0x%h",$time,
861
                //        rx_bd_num, rx_bd_lenstat);
862
           end
863
 
864
 
865
         // Delay some time - takes a bit for the Wishbone FSM to pipe out the
866
         // packet over Wishbone and into whatever memory it's going into
867
         #Td_rx_packet_check;
868
 
869
         // Ok, buffer filled, let's get its offset in memory
870
         get_bd_addr(rx_bd_num, rx_bd_addr);
871
 
872
         $display("(%t) Check RX packet: bd %d: 0x%h, addr 0x%h",$time,
873
                  rx_bd_num, rx_bd_lenstat, rx_bd_addr);
874
 
875
 
876
         // We're never going to be using more than about 256KB of receive buffer
877
         // so let's lop off the top bit of the address pointer - we only want
878
         // the offset from the base of the memory bank
879
 
880
         rxpnt_wb = {14'd0,rx_bd_addr[17:0]};
881
         rxpnt_sdram = rx_bd_addr[24:0];
882
 
883
`ifdef VERSATILE_SDRAM
884
         // We'll look inside the SDRAM array
885
         // Hard coded for the SDRAM buffer area to be from the halfway mark in
886
         // memory (so starting in Bank2)
887
         // We'll be passed the offset from the beginning of the buffer area
888
         // in rxpnt_wb. This value will be in bytes.
889
 
890
         //$display("RAM pointer for BD is 0x%h, SDRAM addr is 0x%h", rx_bd_addr, rxpnt_sdram);
891
 
892
 
893
         for (i=0;i<len;i=i+1)
894
           begin
895
 
896
              sdram0.get_byte(rxpnt_sdram,sdram_byte);
897
 
898
              phy_byte = eth_rx_sent_circbuf[eth_rx_sent_circbuf_read_ptr];//phy_rx_mem[buffer]; //eth_phy0.rx_mem[buffer];
899
 
900
              if (phy_byte !== sdram_byte)
901
                begin
902
                   `TIME;
903
                   $display("*E Wrong byte (%d) of RX packet! phy = %h, ram = %h",
904
                            i, phy_byte, sdram_byte);
905
                   failure = 1;
906
                end
907
 
908
              eth_rx_sent_circbuf_read_ptr = (eth_rx_sent_circbuf_read_ptr+1)&
909
                                             eth_rx_sent_circbuf_size_mask;
910
 
911
              rxpnt_sdram = rxpnt_sdram+1;
912
 
913
           end // for (i=0;i<len;i=i+2)
914
`else
915
 
916
         $display("SET ME UP TO LOOK IN ANOTHER MEMORY!");
917
         $display("RAM pointer for BD is 0x%h, bank offset we'll use is 0x%h",
918
                  rx_bd_addr, rxpnt_wb);
919
         $finish;
920
 
921
 
922
`endif // !`ifdef VERSATILE_SDRAM
923
 
924
         if (failure)
925
           begin
926
              #100
927
                `TIME;
928
              $display("*E Recieved packet %0d, length %0d bytes, had an error. Finishing simulation.", eth_rx_num_packets_checked, len);
929
              $finish;
930
           end
931
         else
932
           begin
933
              #1 $display( "(%0t)(%m) RX packet %0d: %0d bytes in memory OK!",$time,eth_rx_num_packets_checked, len);
934
 
935
           end
936
      end
937
   endtask // check_rx_packet
938
 
939
 
940
   //////////////////////////////////////////////////////////////
941
   // Ethernet CRC Basic tasks
942
   //////////////////////////////////////////////////////////////
943
 
944
   task append_rx_crc;
945
      input  [31:0] rxpnt_phy; // source
946
      input [15:0]  len; // length in bytes without CRC
947
      input         plus_dribble_nibble; // if length is longer for one nibble
948
      input         negated_crc; // if appended CRC is correct or not
949
      reg [31:0]    crc;
950
      reg [7:0]     tmp;
951
      reg [31:0]    addr_phy;
952
      reg           delta_t;
953
      begin
954
         addr_phy = rxpnt_phy + len;
955
         delta_t = 0;
956
         // calculate CRC from prepared packet
957
         paralel_crc_phy_rx(rxpnt_phy, {16'h0, len}, plus_dribble_nibble, crc);
958
         if (negated_crc)
959
           crc = ~crc;
960
         delta_t = !delta_t;
961
 
962
         if (plus_dribble_nibble)
963
           begin
964
              tmp = eth_phy0.rx_mem[addr_phy];
965
              eth_phy0.rx_mem[addr_phy]     = {crc[27:24], tmp[3:0]};
966
              eth_phy0.rx_mem[addr_phy + 1] = {crc[19:16], crc[31:28]};
967
              eth_phy0.rx_mem[addr_phy + 2] = {crc[11:8], crc[23:20]};
968
              eth_phy0.rx_mem[addr_phy + 3] = {crc[3:0], crc[15:12]};
969
              eth_phy0.rx_mem[addr_phy + 4] = {4'h0, crc[7:4]};
970
           end
971
         else
972
           begin
973
              eth_phy0.rx_mem[addr_phy]     = crc[31:24];
974
              eth_phy0.rx_mem[addr_phy + 1] = crc[23:16];
975
              eth_phy0.rx_mem[addr_phy + 2] = crc[15:8];
976
              eth_phy0.rx_mem[addr_phy + 3] = crc[7:0];
977
           end
978
      end
979
   endtask // append_rx_crc
980
 
981
   task append_rx_crc_delayed;
982
      input  [31:0] rxpnt_phy; // source
983
      input [15:0]  len; // length in bytes without CRC
984
      input         plus_dribble_nibble; // if length is longer for one nibble
985
      input         negated_crc; // if appended CRC is correct or not
986
      reg [31:0]    crc;
987
      reg [7:0]     tmp;
988
      reg [31:0]    addr_phy;
989
      reg           delta_t;
990
      begin
991
         addr_phy = rxpnt_phy + len;
992
         delta_t = 0;
993
         // calculate CRC from prepared packet
994
         paralel_crc_phy_rx(rxpnt_phy+4, {16'h0, len}-4, plus_dribble_nibble, crc);
995
         if (negated_crc)
996
           crc = ~crc;
997
         delta_t = !delta_t;
998
 
999
         if (plus_dribble_nibble)
1000
           begin
1001
              tmp = eth_phy0.rx_mem[addr_phy];
1002
              eth_phy0.rx_mem[addr_phy]     = {crc[27:24], tmp[3:0]};
1003
              eth_phy0.rx_mem[addr_phy + 1] = {crc[19:16], crc[31:28]};
1004
              eth_phy0.rx_mem[addr_phy + 2] = {crc[11:8], crc[23:20]};
1005
              eth_phy0.rx_mem[addr_phy + 3] = {crc[3:0], crc[15:12]};
1006
              eth_phy0.rx_mem[addr_phy + 4] = {4'h0, crc[7:4]};
1007
           end
1008
         else
1009
           begin
1010
              eth_phy0.rx_mem[addr_phy]     = crc[31:24];
1011
              eth_phy0.rx_mem[addr_phy + 1] = crc[23:16];
1012
              eth_phy0.rx_mem[addr_phy + 2] = crc[15:8];
1013
              eth_phy0.rx_mem[addr_phy + 3] = crc[7:0];
1014
           end
1015
      end
1016
   endtask // append_rx_crc_delayed
1017
 
1018
 
1019
   // paralel CRC calculating for PHY RX
1020
   task paralel_crc_phy_rx;
1021
      input  [31:0] start_addr; // start address
1022
      input [31:0]  len; // length of frame in Bytes without CRC length
1023
      input         plus_dribble_nibble; // if length is longer for one nibble
1024
      output [31:0] crc_out;
1025
      reg [21:0]    addr_cnt; // only 22 address lines
1026
      integer       word_cnt;
1027
      integer       nibble_cnt;
1028
      reg [31:0]    load_reg;
1029
      reg           delta_t;
1030
      reg [31:0]    crc_next;
1031
      reg [31:0]    crc;
1032
      reg           crc_error;
1033
      reg [3:0]     data_in;
1034
      integer       i;
1035
      begin
1036
         #1 addr_cnt = start_addr[21:0];
1037
         word_cnt = 24; // 27; // start of the frame - nibble granularity (MSbit first)
1038
         crc = 32'hFFFF_FFFF; // INITIAL value
1039
         delta_t = 0;
1040
         // length must include 4 bytes of ZEROs, to generate CRC
1041
         // get number of nibbles from Byte length (2^1 = 2)
1042
         if (plus_dribble_nibble)
1043
           nibble_cnt = ((len + 4) << 1) + 1'b1; // one nibble longer
1044
         else
1045
           nibble_cnt = ((len + 4) << 1);
1046
         // because of MAGIC NUMBER nibbles are swapped [3:0] -> [0:3]
1047
         load_reg[31:24] = eth_phy0.rx_mem[addr_cnt];
1048
         addr_cnt = addr_cnt + 1;
1049
         load_reg[23:16] = eth_phy0.rx_mem[addr_cnt];
1050
         addr_cnt = addr_cnt + 1;
1051
         load_reg[15: 8] = eth_phy0.rx_mem[addr_cnt];
1052
         addr_cnt = addr_cnt + 1;
1053
         load_reg[ 7: 0] = eth_phy0.rx_mem[addr_cnt];
1054
         addr_cnt = addr_cnt + 1;
1055
         while (nibble_cnt > 0)
1056
           begin
1057
              // wait for delta time
1058
              delta_t = !delta_t;
1059
              // shift data in
1060
 
1061
              if(nibble_cnt <= 8) // for additional 8 nibbles shift ZEROs in!
1062
                data_in[3:0] = 4'h0;
1063
              else
1064
 
1065
                data_in[3:0] = {load_reg[word_cnt], load_reg[word_cnt+1], load_reg[word_cnt+2], load_reg[word_cnt+3]};
1066
              crc_next[0]  = (data_in[0] ^ crc[28]);
1067
              crc_next[1]  = (data_in[1] ^ data_in[0] ^ crc[28]    ^ crc[29]);
1068
              crc_next[2]  = (data_in[2] ^ data_in[1] ^ data_in[0] ^ crc[28]  ^ crc[29] ^ crc[30]);
1069
              crc_next[3]  = (data_in[3] ^ data_in[2] ^ data_in[1] ^ crc[29]  ^ crc[30] ^ crc[31]);
1070
              crc_next[4]  = (data_in[3] ^ data_in[2] ^ data_in[0] ^ crc[28]  ^ crc[30] ^ crc[31]) ^ crc[0];
1071
              crc_next[5]  = (data_in[3] ^ data_in[1] ^ data_in[0] ^ crc[28]  ^ crc[29] ^ crc[31]) ^ crc[1];
1072
              crc_next[6]  = (data_in[2] ^ data_in[1] ^ crc[29]    ^ crc[30]) ^ crc[ 2];
1073
              crc_next[7]  = (data_in[3] ^ data_in[2] ^ data_in[0] ^ crc[28]  ^ crc[30] ^ crc[31]) ^ crc[3];
1074
              crc_next[8]  = (data_in[3] ^ data_in[1] ^ data_in[0] ^ crc[28]  ^ crc[29] ^ crc[31]) ^ crc[4];
1075
              crc_next[9]  = (data_in[2] ^ data_in[1] ^ crc[29]    ^ crc[30]) ^ crc[5];
1076
              crc_next[10] = (data_in[3] ^ data_in[2] ^ data_in[0] ^ crc[28]  ^ crc[30] ^ crc[31]) ^ crc[6];
1077
              crc_next[11] = (data_in[3] ^ data_in[1] ^ data_in[0] ^ crc[28]  ^ crc[29] ^ crc[31]) ^ crc[7];
1078
              crc_next[12] = (data_in[2] ^ data_in[1] ^ data_in[0] ^ crc[28]  ^ crc[29] ^ crc[30]) ^ crc[8];
1079
              crc_next[13] = (data_in[3] ^ data_in[2] ^ data_in[1] ^ crc[29]  ^ crc[30] ^ crc[31]) ^ crc[9];
1080
              crc_next[14] = (data_in[3] ^ data_in[2] ^ crc[30]    ^ crc[31]) ^ crc[10];
1081
              crc_next[15] = (data_in[3] ^ crc[31])   ^ crc[11];
1082
              crc_next[16] = (data_in[0] ^ crc[28])   ^ crc[12];
1083
              crc_next[17] = (data_in[1] ^ crc[29])   ^ crc[13];
1084
              crc_next[18] = (data_in[2] ^ crc[30])   ^ crc[14];
1085
              crc_next[19] = (data_in[3] ^ crc[31])   ^ crc[15];
1086
              crc_next[20] =  crc[16];
1087
              crc_next[21] =  crc[17];
1088
              crc_next[22] = (data_in[0] ^ crc[28])   ^ crc[18];
1089
              crc_next[23] = (data_in[1] ^ data_in[0] ^ crc[29]    ^ crc[28]) ^ crc[19];
1090
              crc_next[24] = (data_in[2] ^ data_in[1] ^ crc[30]    ^ crc[29]) ^ crc[20];
1091
              crc_next[25] = (data_in[3] ^ data_in[2] ^ crc[31]    ^ crc[30]) ^ crc[21];
1092
              crc_next[26] = (data_in[3] ^ data_in[0] ^ crc[31]    ^ crc[28]) ^ crc[22];
1093
              crc_next[27] = (data_in[1] ^ crc[29])   ^ crc[23];
1094
              crc_next[28] = (data_in[2] ^ crc[30])   ^ crc[24];
1095
              crc_next[29] = (data_in[3] ^ crc[31])   ^ crc[25];
1096
              crc_next[30] =  crc[26];
1097
              crc_next[31] =  crc[27];
1098
 
1099
              crc = crc_next;
1100
              crc_error = crc[31:0] != 32'hc704dd7b;  // CRC not equal to magic number
1101
              case (nibble_cnt)
1102
                9: crc_out = {!crc[24], !crc[25], !crc[26], !crc[27], !crc[28], !crc[29], !crc[30], !crc[31],
1103
                              !crc[16], !crc[17], !crc[18], !crc[19], !crc[20], !crc[21], !crc[22], !crc[23],
1104
                              !crc[ 8], !crc[ 9], !crc[10], !crc[11], !crc[12], !crc[13], !crc[14], !crc[15],
1105
                              !crc[ 0], !crc[ 1], !crc[ 2], !crc[ 3], !crc[ 4], !crc[ 5], !crc[ 6], !crc[ 7]};
1106
                default: crc_out = crc_out;
1107
              endcase
1108
              // wait for delta time
1109
              delta_t = !delta_t;
1110
              // increment address and load new data
1111
              if ((word_cnt+3) == 7)//4)
1112
                begin
1113
                   // because of MAGIC NUMBER nibbles are swapped [3:0] -> [0:3]
1114
                   load_reg[31:24] = eth_phy0.rx_mem[addr_cnt];
1115
                   addr_cnt = addr_cnt + 1;
1116
                   load_reg[23:16] = eth_phy0.rx_mem[addr_cnt];
1117
                   addr_cnt = addr_cnt + 1;
1118
                   load_reg[15: 8] = eth_phy0.rx_mem[addr_cnt];
1119
                   addr_cnt = addr_cnt + 1;
1120
                   load_reg[ 7: 0] = eth_phy0.rx_mem[addr_cnt];
1121
                   addr_cnt = addr_cnt + 1;
1122
                end
1123
              // set new load bit position
1124
              if((word_cnt+3) == 31)
1125
                word_cnt = 16;
1126
              else if ((word_cnt+3) == 23)
1127
                word_cnt = 8;
1128
              else if ((word_cnt+3) == 15)
1129
                word_cnt = 0;
1130
              else if ((word_cnt+3) == 7)
1131
                word_cnt = 24;
1132
              else
1133
                word_cnt = word_cnt + 4;// - 4;
1134
              // decrement nibble counter
1135
              nibble_cnt = nibble_cnt - 1;
1136
              // wait for delta time
1137
              delta_t = !delta_t;
1138
           end // while
1139
         #1;
1140
      end
1141
   endtask // paralel_crc_phy_rx
1142
 
1143
 
1144
 
1145
 

powered by: WebSVN 2.1.0

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