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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [sim/] [BFMs/] [SGMII_altera/] [testbench/] [model/] [ethmon.v] - Blame information for rev 9

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

Line No. Rev Author Line
1 9 jefflieu
// -------------------------------------------------------------------------
2
// -------------------------------------------------------------------------
3
//
4
// Revision Control Information
5
//
6
// $RCSfile: ethmon.v,v $
7
// $Source: /ipbu/cvs/sio/projects/TriSpeedEthernet/src/testbench/models/verilog/ethernet_model/mon/ethmon.v,v $
8
//
9
// $Revision: #1 $
10
// $Date: 2011/11/10 $
11
// Check in by : $Author: max $
12
// Author      : SKNg/TTChong
13
//
14
// Project     : Triple Speed Ethernet - 10/100/1000 MAC
15
//
16
// Description : (Simulation only)
17
//
18
// GMII Interface Ethernet Traffic Monitor/Decoder
19
// Ethernet Traffic Monitor for 8 bit MAC Atlantic client interface
20
//
21
// 
22
// ALTERA Confidential and Proprietary
23
// Copyright 2006 (c) Altera Corporation
24
// All rights reserved
25
//
26
// -------------------------------------------------------------------------
27
// -------------------------------------------------------------------------
28
 
29
`timescale 1 ns / 1 ns
30
 
31
 
32
module ethmonitor (
33
 
34
   reset,
35
   tx_clk,
36
   txd,
37
   tx_dv,
38
   tx_er,
39
   tx_sop,
40
   tx_eop,
41
   dst,
42
   src,
43
   prmble_len,
44
   pquant,
45
   vlan_ctl,
46
   len,
47
   frmtype,
48
   payload,
49
   payload_vld,
50
   is_vlan,
51
   is_stack_vlan,
52
   is_pause,
53
   crc_err,
54
   prmbl_err,
55
   len_err,
56
   payload_err,
57
   frame_err,
58
   pause_op_err,
59
   pause_dst_err,
60
   mac_err,
61
   end_err,
62
   jumbo_en,
63
   data_only,
64
   frm_rcvd);
65
 
66
parameter ENABLE_SHIFT16 = 1'b 0;
67
 
68
 
69
input   reset; //  active high
70
input   tx_clk;
71
input   [7:0] txd;
72
input   tx_dv;
73
input   tx_er;
74
input   tx_sop;
75
input   tx_eop;
76
output   [47:0] dst; //  destination address
77
output   [47:0] src; //  source address
78
output   [13:0] prmble_len; //  length of preamble
79
output   [15:0] pquant; //  Pause Quanta value
80
output   [15:0] vlan_ctl; //  VLAN control info
81
output   [15:0] len; //  Length of payload
82
output   [15:0] frmtype; //  if non-null: type field instead length
83
output   [7:0] payload;
84
output   payload_vld;
85
output   is_vlan;
86
output   is_stack_vlan;
87
output   is_pause;
88
output   crc_err;
89
output   prmbl_err;
90
output   len_err;
91
output   payload_err;
92
output   frame_err;
93
output   pause_op_err;
94
output   pause_dst_err;
95
output   mac_err;
96
output   end_err;
97
input   jumbo_en;
98
input   data_only;
99
output   frm_rcvd;
100
//  GMII transmit interface: To be connected to MAC TX
101
wire    [47:0] dst;
102
reg     [47:0] src;
103
wire    [13:0] prmble_len;
104
reg     [15:0] pquant;
105
reg     [15:0] vlan_ctl;
106
wire    [15:0] len;
107
wire    [15:0] frmtype;
108
reg     [7:0] payload;
109
//  Indicators
110
reg     payload_vld;
111
wire    is_vlan;
112
wire    is_stack_vlan;
113
wire    is_pause;
114
reg     crc_err;
115
reg     prmbl_err;
116
reg     len_err;
117
reg     payload_err;
118
reg     frame_err;
119
reg     pause_op_err;
120
reg     pause_dst_err;
121
reg     mac_err;
122
//  Control
123
reg     end_err;
124
reg     frm_rcvd;
125
reg     frm_in;
126
reg     tx_clk_int;
127
reg     tx_eop_reg;
128
//  port signals internally reused
129
reg     [13:0] iprmble_len; //  length of preamble
130
reg     [15:0] ifrmtype;
131
reg     [15:0] ilen;
132
reg     [47:0] idst;
133
reg     iis_vlan;
134
reg     iis_stack_vlan;
135
reg     iis_pause;
136
reg     tx_clk_dly;
137
//  internal
138
 
139
// TYPE state_typ:
140
parameter state_typ_s_idle = 0;
141
parameter state_typ_s_prmbl = 1;
142
parameter state_typ_s_dst = 2;
143
parameter state_typ_s_src = 3;
144
parameter state_typ_s_typelen = 4;
145
parameter state_typ_s_pause = 5;
146
parameter state_typ_s_tag = 6;
147
parameter state_typ_s_len = 7;
148
parameter state_typ_s_data = 8;
149
parameter state_typ_s_pad = 9;
150
parameter state_typ_s_crc = 10;
151
parameter state_typ_s_abort = 11;
152
parameter state_typ_s_utype = 12;
153
parameter state_typ_s_Dword32Aligned = 13;
154
 
155
reg     [3:0] state;
156
reg     [3:0] last_state;
157
reg     last_tx_dv; //  follows tx_dv with one cycle delay
158
reg     [31:0] crc32;
159
reg     [31:0] count;
160
reg     [31:0] poscnt; //  position in frame starts at first dst byte
161
reg     [7:0] datacnt; //  counter to verify payload
162
reg     [7:0] datainc; //  counter increment
163
reg     tx_sof; //  start of frame indicator for 1 clk cycle with 1st byte
164
reg     tx_dst; //  start of frame indicator for 1 clk cycle with 1st byte
165
reg     [31:0]  process_6_crctmp;
166
reg     [3:0]  V2V_process_6_i;
167
integer  process_11_ix;
168
integer  process_12_ix;
169
reg      process_12_ln;
170
integer  process_14_hi;
171
integer  process_14_lo;
172
reg     [31:0]  process_14_cnttmp;
173
integer  process_14_i;
174
integer  process_14_flen;
175
 
176
always @(posedge reset or posedge tx_clk)
177
   begin : process_1
178
   if (reset == 1'b 1)
179
      begin
180
      tx_eop_reg <= 1'b 0;
181
      end
182
   else
183
      begin
184
      tx_eop_reg <= tx_eop;
185
      end
186
   end
187
 
188
always @(tx_sop or tx_eop_reg)
189
   begin : process_2
190
   if (tx_sop == 1'b 1 & data_only == 1'b 1)
191
      begin
192
      frm_in <= 1'b 1;
193
      end
194
   else if (tx_eop_reg == 1'b 1 )
195
      begin
196
      frm_in <= 1'b 0;
197
      end
198
   end
199
 
200
always@(tx_clk)
201
begin
202
 
203
        tx_clk_dly <= #(1)tx_clk ;
204
 
205
end
206
 
207
always @(frm_in or tx_dv or tx_clk_dly)
208
   begin : process_3
209
   if (frm_in == 1'b 1 && tx_dv == 1'b 1 )
210
      begin
211
      tx_clk_int <= #(1) tx_clk_dly;
212
      end
213
   else if (frm_in==1'b1 && tx_dv == 1'b 0)
214
      begin
215
      tx_clk_int <= #(1) 1'b 0;
216
      end
217
   else
218
      begin
219
      tx_clk_int <= #(1) tx_clk_dly;
220
      end
221
   end
222
 
223
//  connect permanent port signals
224
//  ------------------------------
225
assign prmble_len = iprmble_len;
226
assign frmtype = ifrmtype;
227
assign len = ilen;
228
assign dst = idst;
229
assign is_vlan = iis_vlan;
230
assign is_stack_vlan = iis_stack_vlan;
231
assign is_pause = iis_pause;
232
//  generate tx start pulse
233
//  ----------------------
234
 
235
always@(last_tx_dv or tx_dv or tx_sop)
236
begin
237
 
238
        if (data_only==1'b0)
239
        begin
240
 
241
                tx_sof <= ~last_tx_dv & tx_dv; //  pulse with first byte 0 to 1 change
242
 
243
        end
244
        else
245
        begin
246
 
247
                tx_sof <= tx_sop ;
248
 
249
        end
250
 
251
end
252
 
253
//  generate pulse start of destination address
254
//  --------------------
255
always @(last_state or state)
256
   begin : process_4
257
   if (last_state != state_typ_s_dst & state == state_typ_s_dst)
258
      begin
259
      tx_dst <= 1'b 1;
260
      end
261
   else
262
      begin
263
      tx_dst <= 1'b 0;
264
      end
265
   end
266
//  ------------------------------------------
267
//  capture tx_er indicator
268
//  ------------------------------------------
269
always @(posedge tx_clk_int or posedge reset)
270
   begin : process_5
271
   if (reset == 1'b 1)
272
      begin
273
      mac_err <= 1'b 0;
274
      last_tx_dv <= 1'b 0;
275
      end
276
   else
277
      begin
278
      if (tx_sof == 1'b 1)
279
         begin
280
         mac_err <= 1'b 0;  //  reset indicator at start of new receive
281
         end
282
      else if (tx_er == 1'b 1 )
283
         begin
284
         mac_err <= 1'b 1;  //  capture one or many
285
         end
286
      last_tx_dv <= tx_dv;
287
      end
288
   end
289
//  ----------------------------------------------
290
//  CRC calculation over all bytes except preamble
291
//  ----------------------------------------------
292
always @(posedge tx_clk_int or posedge reset)
293
   begin : process_6
294
   if (reset == 1'b 1)
295
      begin
296
      crc32 <= {32{1'b 1}};
297
      crc_err <= 1'b 0;
298
      end
299
   else
300
      begin
301
//  need it ahead
302
      if (tx_dst == 1'b 1 | state != state_typ_s_idle &
303
    state != state_typ_s_prmbl & state != state_typ_s_utype |
304
    state == state_typ_s_utype & tx_dv == 1'b 1)
305
         begin
306
//  push all inclusive CRC bytes
307
//  preset CRC or load current value
308
         if (tx_dst == 1'b 1)
309
            begin
310
//  first data, preset CRC
311
            process_6_crctmp = {32{1'b 1}};
312
            end
313
         else
314
            begin
315
            process_6_crctmp = crc32;
316
            end
317
//  calculate next step
318
 
319
         for (V2V_process_6_i = 0; V2V_process_6_i <= 7; V2V_process_6_i = V2V_process_6_i + 1)
320
            begin
321
            if ((txd[V2V_process_6_i] ^ process_6_crctmp[31]) == 1'b 1)
322
               begin
323
               process_6_crctmp = (process_6_crctmp << 1);  //  shift in a 0, will be xor'ed to 1 by the polynom
324
               process_6_crctmp = process_6_crctmp ^ 32'h 04C11DB7;
325
               end
326
            else
327
               begin
328
               process_6_crctmp = (process_6_crctmp << 1);  //  shift in a 0
329
               end
330
            end
331
//  process all bits we have here
332
         crc32 <= process_6_crctmp; //  remember current value
333
//  check if CRC is valid
334
         if (process_6_crctmp == 32'h C704DD7B)
335
            begin
336
            crc_err <= 1'b 0;
337
            end
338
         else
339
            begin
340
            crc_err <= 1'b 1;
341
            end
342
         end
343
      end
344
   end
345
//  ----------------------------------------------
346
//  Extract RX Payload on payload bus and check payload errors:
347
//  * first byte is counter initialization
348
//  * second byte is counter increment
349
//  * data begins from 3rd byte on 
350
//  ----------------------------------------------
351
always @(posedge tx_clk_int or posedge reset)
352
   begin : process_7
353
   if (reset == 1'b 1)
354
      begin
355
      payload <= {8{1'b 0}};
356
      payload_vld <= 1'b 0;
357
      payload_err <= 1'b 0;
358
      datacnt <= 0;
359
      end
360
   else
361
      begin
362
      if (state == state_typ_s_typelen)
363
         begin
364
         payload_err <= 1'b 0;  //  reset as a frame of length 0 will not get into S_DATA.
365
         end
366
      if (state == state_typ_s_data)
367
         begin
368
         payload <= txd;
369
         payload_vld <= 1'b 1;
370
         if (count == 0)
371
            begin
372
            datacnt <= ({1'b 0, txd});  //  load counter
373
            payload_err <= 1'b 0;
374
            end
375
         else if (count == 1 )
376
            begin
377
            datainc <= ({1'b 0, txd});  //  load increment
378
//  verify payload contents
379
            end
380
         else
381
            begin
382
            datacnt <= (datacnt + datainc) % 256;
383
            if (datacnt != ({1'b 0, txd}))
384
               begin
385
               payload_err <= 1'b 1;
386
               end
387
            end
388
         end
389
      else
390
         begin
391
         payload <= {8{1'b 0}};
392
         payload_vld <= 1'b 0;
393
         end
394
      end
395
   end
396
//  ----------------------------------------------
397
//  Position Counter: Starts with first octet of destination address
398
//  ----------------------------------------------
399
always @(posedge tx_clk_int or posedge reset)
400
   begin : process_8
401
   if (reset == 1'b 1)
402
      begin
403
      poscnt <= 0;
404
      end
405
   else
406
      begin
407
      if (tx_dst == 1'b 1)
408
         begin
409
//  reset at start of DST 
410
         poscnt <= 1;
411
         end
412
      else
413
         begin
414
         if (poscnt < 65535)
415
            begin
416
            poscnt <= poscnt + 1'b 1;
417
            end
418
         end
419
      end
420
   end
421
//  ----------------------------------------------
422
//  End of Frame:
423
//  change from non-idle to idle indicates something was received
424
//  if dv is still asserted this is an end error
425
//  ----------------------------------------------
426
always @(posedge tx_clk_int or posedge reset)
427
   begin : process_9
428
   if (reset == 1'b 1)
429
      begin
430
      frm_rcvd <= 1'b 0;
431
      end_err <= 1'b 0;
432
      end
433
   else
434
      begin
435
      if (last_state != state_typ_s_idle & state == state_typ_s_idle)
436
         begin
437
         frm_rcvd <= 1'b 1;
438
         end
439
      else
440
         begin
441
         frm_rcvd <= 1'b 0;
442
         end
443
      if (tx_sof == 1'b 1)
444
         begin
445
         end_err <= 1'b 0;
446
         end
447
      else if (last_state != state_typ_s_idle & state == state_typ_s_idle &
448
    tx_dv == 1'b 1 )
449
         begin
450
         end_err <= 1'b 1;  //  dv still asserted even after nothing more expected
451
         end
452
      end
453
   end
454
//  ----------------------------------------------
455
//  Preamble check
456
//  ----------------------------------------------
457
always @(posedge tx_clk_int or posedge reset)
458
   begin : process_10
459
   if (reset == 1'b 1)
460
      begin
461
      prmbl_err <= 1'b 0;
462
      iprmble_len <= 0;
463
      end
464
   else
465
      begin
466
      if (tx_sof == 1'b 1)
467
         begin
468
         if (txd != 8'h 55)
469
            begin
470
            prmbl_err <= 1'b 1;
471
            end
472
         else
473
            begin
474
            prmbl_err <= 1'b 0; //  reset usually
475
            end
476
         if (data_only == 1'b 1)
477
            begin
478
            iprmble_len <= 0;
479
            end
480
         else
481
            begin
482
            iprmble_len <= 1;
483
            end
484
         end
485
      else if (state == state_typ_s_prmbl )
486
         begin
487
         if (txd != 8'h 55 & txd != 8'h D5)
488
            begin
489
            prmbl_err <= 1'b 1;
490
            end
491
         iprmble_len <= iprmble_len + 1'b 1;
492
         end
493
      end
494
   end
495
//  ----------------------------------------------
496
//  Extract Source and Destination addresses
497
//  ----------------------------------------------
498
always @(posedge tx_clk_int or posedge reset)
499
   begin : process_11
500
   if (reset == 1'b 1)
501
      begin
502
      idst <= {48{1'b 0}};
503
      src <= {48{1'b 0}};
504
      end
505
   else
506
      begin
507
      process_11_ix = count * 8;
508
      if (tx_sof == 1'b 1)
509
         begin
510
         process_11_ix = 1'b 0;
511
         end
512
 
513
         if (tx_sof == 1'b 1 & data_only == 1'b 1 & state == state_typ_s_Dword32Aligned & ENABLE_SHIFT16 == 1'b1)
514
            begin
515
                case (count)
516
                1'b 0 : ;
517
                1'b 1 : ;
518
                default:;
519
                endcase
520
             end
521
         if (tx_sof == 1'b 0 & data_only == 1'b 1 & ENABLE_SHIFT16 == 1'b1 & state == state_typ_s_dst)
522
            begin
523
            case (count)
524
            1'b 0:
525
               begin
526
               idst[7:0] <= txd[7:0];
527
               end
528
            1'b 1:
529
               begin
530
               idst[15:8] <= txd[7:0];
531
               end
532
            2'b 10:
533
               begin
534
               idst[23:16] <= txd[7:0];
535
               end
536
            2'b 11:
537
               begin
538
               idst[31:24] <= txd[7:0];
539
               end
540
            3'b 100:
541
               begin
542
               idst[39:32] <= txd[7:0];
543
               end
544
            3'b 101:
545
               begin
546
               idst[47:40] <= txd[7:0];
547
               end
548
            default:
549
               ;
550
            endcase
551
           end
552
 
553
      if (tx_sof == 1'b 1 & data_only == 1'b 1 & ENABLE_SHIFT16 == 1'b0| state == state_typ_s_dst)
554
         begin
555
         case (count)
556
         1'b 0:
557
            begin
558
            idst[7:0] <= txd[7:0];
559
            end
560
         1'b 1:
561
            begin
562
            idst[15:8] <= txd[7:0];
563
            end
564
         2'b 10:
565
            begin
566
            idst[23:16] <= txd[7:0];
567
            end
568
         2'b 11:
569
            begin
570
            idst[31:24] <= txd[7:0];
571
            end
572
         3'b 100:
573
            begin
574
            idst[39:32] <= txd[7:0];
575
            end
576
         3'b 101:
577
            begin
578
            idst[47:40] <= txd[7:0];
579
            end
580
         default:
581
            ;
582
         endcase         end
583
      if (state == state_typ_s_src)
584
         begin
585
        case (count)
586
         1'b 0:
587
            begin
588
            src[7:0] <= txd[7:0];
589
            end
590
         1'b 1:
591
            begin
592
            src[15:8] <= txd[7:0];
593
            end
594
         2'b 10:
595
            begin
596
            src[23:16] <= txd[7:0];
597
            end
598
         2'b 11:
599
            begin
600
            src[31:24] <= txd[7:0];
601
            end
602
         3'b 100:
603
            begin
604
            src[39:32] <= txd[7:0];
605
            end
606
         3'b 101:
607
            begin
608
            src[47:40] <= txd[7:0];
609
            end
610
         default:
611
            ;
612
         endcase         end
613
      end
614
   end
615
//  ----------------------------------------------
616
//  Extract Length/Type field and VLAN Tag identifier
617
//  ----------------------------------------------
618
always @(posedge tx_clk_int or posedge reset)
619
   begin : process_12
620
   if (reset == 1'b 1)
621
      begin
622
      ilen <= {16{1'b 0}};
623
      ifrmtype <= {16{1'b 0}};
624
      vlan_ctl <= {16{1'b 0}};
625
      iis_vlan <= 1'b 0;
626
      len_err <= 1'b 0;
627
      iis_stack_vlan <= 1'b0;
628
      end
629
   else
630
      begin
631
      process_12_ix = 4'b 1000 - count * 8;
632
// if( tx_sof_d = '1' ) then              -- clear all on start of every frame
633
// 
634
//     ilen     <= (others => '0');
635
//     ifrmtype <= (others => '0');
636
//     vlan_ctl <= (others => '0');
637
//     iis_vlan  <= '0';
638
//     
639
// end if;
640
      if (state == state_typ_s_typelen)
641
         begin
642
//  if in type/len set both
643
        case (count)
644
         1'b 0:
645
            begin
646
            ifrmtype[15:8] <= txd;
647
            ilen[15:8] <= txd;
648
            end
649
         1'b 1:
650
            begin
651
            ifrmtype[7:0] <= txd;
652
            ilen[7:0] <= txd;
653
            end
654
         default:
655
            ;
656
         endcase
657
         vlan_ctl <= {16{1'b 0}};   //  clear at start of new frame (at SOF it is too early)
658
         iis_vlan <= 1'b 0;
659
         len_err  <= 1'b 0;
660
         end
661
 
662
         if(state==state_typ_s_typelen)
663
         begin
664
 
665
                iis_stack_vlan <= 1'b0 ;
666
 
667
         end
668
         else if (last_state == state_typ_s_len & state == state_typ_s_tag)
669
         begin
670
 
671
                iis_stack_vlan <= 1'b1 ;
672
 
673
         end
674
 
675
      else if (state == state_typ_s_len )
676
         begin
677
//  in len again, set len independently
678
         case (count)
679
         1'b 0:
680
            begin
681
            ifrmtype[15:8] <= txd;
682
            ilen[15:8] <= txd;
683
            end
684
         1'b 1:
685
            begin
686
            ifrmtype[7:0] <= txd;
687
            ilen[7:0] <= txd;
688
            end
689
         default:
690
            ;
691
         endcase
692
         end
693
      else if (state == state_typ_s_tag )
694
         begin
695
         iis_vlan <= 1'b 1;
696
        case (count)
697
         1'b 0:
698
            begin
699
            vlan_ctl[15:8] <= txd;  // ilen(ix+7 downto ix)     <= txd;
700
            end
701
         1'b 1:
702
            begin
703
            vlan_ctl[7:0] <= txd;
704
            end
705
         default:
706
            ;
707
         endcase         end
708
//  verify length at end of frame for normal frames (length 46... max and not a type)
709
      if (last_state == state_typ_s_crc & state == state_typ_s_idle &
710
    iis_pause == 1'b 0 & (iis_vlan == 1'b 0 &
711
    ilen > 45 | iis_vlan == 1'b 1 &
712
    ilen > 41))
713
         begin
714
//  verify integrity of length field 
715
         if (tx_dv == 1'b 1 |
716
             iis_stack_vlan == 1'b 1 & ilen != poscnt - 5'b 11010 |
717
             (iis_vlan == 1'b 1 & iis_stack_vlan == 1'b 0) & ilen != poscnt - 5'b 10110 |
718
             iis_vlan == 1'b 0 & ilen != poscnt - 5'b 10010)
719
            begin
720
            len_err <= 1'b 1;
721
            end
722
         else
723
            begin
724
            len_err <= 1'b 0;
725
            end
726
         end
727
      end
728
   end
729
//  ----------------------------------------------
730
//  Extract Pause frame indication,
731
//                opcode error,
732
//                destination address error,
733
//                and Pause Quanta
734
//  ----------------------------------------------
735
always @(posedge tx_clk_int or posedge reset)
736
   begin : process_13
737
   if (reset == 1'b 1)
738
      begin
739
      pquant <= {16{1'b 0}};
740
      iis_pause <= 1'b 0;
741
      pause_op_err <= 1'b 0;
742
      pause_dst_err <= 1'b 0;
743
      end
744
   else
745
      begin
746
 
747
      if (tx_sof == 1'b 1)
748
         begin
749
         iis_pause <= 1'b 0;    //  clear at start of frame
750
         pause_op_err <= 1'b 0;
751
         pause_dst_err <= 1'b 0;
752
         end
753
 
754
      if (state == state_typ_s_pause)
755
         begin
756
         iis_pause <= 1'b 1;
757
         //if (count >= 2)
758
            //begin
759
//  pick octets after opcode
760
        case (count)
761
            2'b 10:
762
               begin
763
               pquant[15:8] <= txd;
764
               end
765
            2'b 11:
766
               begin
767
               pquant[7:0] <= txd;
768
               end
769
            default:
770
               ;
771
            endcase
772
            //end
773
        if (count == 0 & txd != 8'h 00 | count == 1 & txd != 8'h 01 )
774
            begin
775
            pause_op_err <= 1'b 1;
776
            end
777
         if (idst != 48'h 010000c28001)
778
            begin
779
//  01-80-c2-00-00-01 is standard !
780
            pause_dst_err <= 1'b 1;
781
            end
782
         end
783
      end
784
   end
785
//  ----------------------------------------------
786
//  Monitor State Machine
787
//  ----------------------------------------------
788
always @(posedge tx_clk_int or posedge reset)
789
   begin : process_14
790
   if (reset == 1'b 1)
791
      begin
792
      state <= state_typ_s_idle;
793
      last_state <= state_typ_s_idle;
794
      count <= 0;
795
      frame_err <= 1'b 0;   //  state machine abort indicator
796
      end
797
   else
798
      begin
799
//  remember last state and increment internal counter
800
      last_state <= state;
801
      if (count < 65535)
802
         begin
803
         process_14_cnttmp = count + 1'b 1;
804
         end
805
      else
806
         begin
807
         process_14_cnttmp = count;
808
         end
809
//  Abort detection: If enable goes low in middle of frame
810
      if (state != state_typ_s_idle & state != state_typ_s_abort &
811
    state != state_typ_s_utype & tx_dv == 1'b 0)
812
         begin
813
         state <= state_typ_s_abort;
814
         end
815
      else
816
         begin
817
         case (state)
818
         state_typ_s_abort:
819
            begin
820
            if (tx_dv == 1'b 1)
821
               begin
822
               if (last_tx_dv == 1'b 0 & data_only == 1'b 1)
823
                  begin
824
//  only 1 clock cycle inbetween
825
                  if (ENABLE_SHIFT16 == 1'b0)
826
                  state <= state_typ_s_dst;
827
                  else
828
                   state <= state_typ_s_Dword32Aligned;
829
 
830
                  process_14_cnttmp = 1'b 1;
831
                  frame_err <= 1'b 0;
832
                  end
833
               else
834
                  begin
835
                  state <= state_typ_s_abort;   //  wait til tx stops transmission
836
                  end
837
               end
838
            else
839
               begin
840
               state <= state_typ_s_idle;
841
               end
842
            frame_err <= 1'b 1;
843
            end
844
         state_typ_s_idle:
845
            begin
846
            if (tx_sof == 1'b 1)
847
               begin
848
//  we miss the very first !
849
               process_14_cnttmp = 1'b 1;   //  therefore need to count to 1 immediately
850
               frame_err <= 1'b 0;
851
               if (data_only == 1'b 1)
852
                  begin
853
//  no preamble checking ?
854
                  if (ENABLE_SHIFT16 == 1'b0)
855
                  state <= state_typ_s_dst;
856
                  else
857
                   state <= state_typ_s_Dword32Aligned;
858
 
859
                  end
860
               else
861
                  begin
862
                  state <= state_typ_s_prmbl;
863
                  end
864
               end
865
            else
866
               begin
867
               process_14_cnttmp = 1'b 0;   //  keep it to zero always 
868
               end
869
            end
870
         state_typ_s_prmbl:
871
            begin
872
            if (txd == 8'h D5)
873
               begin
874
               state <= state_typ_s_dst;
875
               process_14_cnttmp = 1'b 0;
876
               end
877
            end
878
 
879
         state_typ_s_Dword32Aligned:
880
           begin
881
           if (count == 1)
882
              begin
883
              state <= state_typ_s_dst;
884
              process_14_cnttmp = 1'b 0;
885
              end
886
           end
887
 
888
         state_typ_s_dst:
889
            begin
890
            if (count == 5)
891
               begin
892
               state <= state_typ_s_src;
893
               process_14_cnttmp = 1'b 0;
894
               end
895
            end
896
         state_typ_s_src:
897
            begin
898
            if (count == 5)
899
               begin
900
               state <= state_typ_s_typelen;
901
               process_14_cnttmp = 1'b 0;
902
               end
903
            end
904
         state_typ_s_typelen:
905
            begin
906
            if (count != 0)
907
               begin
908
//  second half of 2-octet field
909
               process_14_cnttmp = 1'b 0;
910
               process_14_flen = ({1'b 0, ilen[15:8], txd});    //  need it NOW
911
               if (process_14_flen <= 1500)
912
                  begin
913
//  ok normal user frame. check if data or 0 length
914
                  if (process_14_flen != 0)
915
                     begin
916
                     state <= state_typ_s_data;
917
//  no data, PAD or finished
918
                     end
919
                  else
920
                     begin
921
                     if (data_only == 1'b 1)
922
                        begin
923
                        state <= state_typ_s_idle;  //  Ok, we are done dont expect anything more
924
                        end
925
                     else
926
                        begin
927
                        state <= state_typ_s_pad;   //  zero-length frame needs padding
928
                        end
929
                     end
930
//  not normal frame
931
                  end
932
               else
933
                  begin
934
                  if (process_14_flen == 16'h 8808)
935
                     begin
936
                     state <= state_typ_s_pause;
937
                     end
938
                  else if (process_14_flen == 16'h 8100 )
939
                     begin
940
                     state <= state_typ_s_tag;
941
                     end
942
                  else
943
                     begin
944
                     state <= state_typ_s_utype;    //  S_ABORT;    -- unknown type
945
                     end
946
                  end
947
               end
948
            end
949
         state_typ_s_pause:
950
            begin
951
            if (count >= 3)
952
               begin
953
//  need to overread opcode
954
               state <= state_typ_s_pad;
955
               process_14_cnttmp = 1'b 0;
956
               end
957
            end
958
         state_typ_s_tag:
959
            begin
960
            if (count >= 1)
961
               begin
962
               state <= state_typ_s_len;
963
               process_14_cnttmp = 1'b 0;
964
               end
965
            end
966
         state_typ_s_len:
967
            begin
968
            if (count >= 1)
969
               begin
970
//  Length after VLAN TAG
971
               process_14_cnttmp = 1'b 0;
972
               process_14_flen = ({1'b 0, ilen[15:8], txd});    //  need it NOW
973
 
974
               if ( process_14_flen == 16'h8100)
975
               begin
976
 
977
                state <= state_typ_s_tag;
978
 
979
               end
980
               else if (process_14_flen != 0)
981
                  begin
982
                  state <= state_typ_s_data;
983
//  no data, PAD or finished
984
                  end
985
               else
986
                  begin
987
                  if (data_only == 1'b 1)
988
                     begin
989
                     state <= state_typ_s_idle; //  Ok, we are done dont expect CRC
990
                     end
991
                  else
992
                     begin
993
                     state <= state_typ_s_pad;
994
                     end
995
                  end
996
               end
997
            end
998
         state_typ_s_data:
999
            begin
1000
            if (count >= ilen - 1'b 1)
1001
               begin
1002
               process_14_cnttmp = 1'b 0;
1003
               if (data_only == 1'b 1)
1004
                  begin
1005
//  no PAD and no CRC ?
1006
                  state <= state_typ_s_idle;
1007
                  end
1008
               else if (poscnt < 6'b 111100 - 1'b 1 )
1009
                  begin
1010
//  expect padding ?
1011
                  state <= state_typ_s_pad;
1012
                  end
1013
               else
1014
                  begin
1015
                  state <= state_typ_s_crc;
1016
                  end
1017
               end
1018
            end
1019
         state_typ_s_pad:
1020
            begin
1021
            if (poscnt >= 6'b 111100 - 1'b 1)
1022
               begin
1023
               state <= state_typ_s_crc;
1024
               process_14_cnttmp = 1'b 0;
1025
               end
1026
            end
1027
         state_typ_s_crc:
1028
            begin
1029
            if (count >= 3)
1030
               begin
1031
               state <= state_typ_s_idle;
1032
               process_14_cnttmp = 1'b 0;
1033
               end
1034
            end
1035
         state_typ_s_utype:
1036
            begin
1037
            if (tx_dv == 1'b 0)
1038
               begin
1039
//  unknown type... wait for end of frame
1040
               state <= state_typ_s_idle;
1041
               process_14_cnttmp = 1'b 0;
1042
               end
1043
            end
1044
         endcase
1045
         end
1046
//  abort                    
1047
//  load the counter with the new value                   
1048
      count <= process_14_cnttmp;
1049
      end
1050
   end
1051
 
1052
 
1053
endmodule // module ethmonitor
1054
 

powered by: WebSVN 2.1.0

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