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

Subversion Repositories esoc

[/] [esoc/] [trunk/] [Sources/] [altera/] [esoc_port_mac/] [testbench/] [model/] [top_ethmon32.vhd] - Blame information for rev 42

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 42 lmaarsen
-- -------------------------------------------------------------------------
2
-- -------------------------------------------------------------------------
3
--
4
-- Revision Control Information
5
--
6
-- $RCSfile: top_ethmon32.vhd,v $
7
-- $Source: /ipbu/cvs/sio/projects/TriSpeedEthernet/src/testbench/models/vhdl/ethernet_model/mon/top_ethmon32.vhd,v $
8
--
9
-- $Revision: #1 $
10
-- $Date: 2008/08/09 $
11
-- Check in by : $Author: sc-build $
12
-- Author      : SKNg/TTChong
13
--
14
-- Project     : Triple Speed Ethernet - 10/100/1000 MAC
15
--
16
-- Description : (Simulation only)
17
--
18
-- Ethernet Traffic Monitor/Decoder for 32 bit MAC Atlantic client interface
19
-- Instantiates ETHMONITOR_32 (ethmon_32.vhd)
20
--
21
-- 
22
-- ALTERA Confidential and Proprietary
23
-- Copyright 2006 (c) Altera Corporation
24
-- All rights reserved
25
--
26
-- -------------------------------------------------------------------------
27
-- -------------------------------------------------------------------------
28
 
29
 
30
 
31
library ieee ;
32
use ieee.std_logic_1164.all ;
33
use ieee.std_logic_arith.all ;
34
use ieee.std_logic_unsigned.all ;
35
use std.textio.all ;
36
 
37
entity TOP_ETHMONITOR32 is
38
 
39
    generic (
40
      BIG_ENDIAN      : integer := 1;  --0 for false, 1 for true
41
      ENABLE_SHIFT16  : integer := 0  --0 for false, 1 for true
42
 
43
    );
44
 
45
    port (
46
 
47
      reset       : in std_logic ;     -- active high
48
      clk         : in std_logic;
49
 
50
      -- Word Interface input
51
 
52
      din      : in  std_logic_vector(31 downto 0);
53
      dval     : in  std_logic;
54
      derror   : in  std_logic;
55
      sop      : in  std_logic;   -- pulse with first word
56
      eop      : in  std_logic;   -- pulse with last word (tmod valid)
57
      tmod     : in  std_logic_vector(1 downto 0);  -- last word modulo
58
 
59
        -- Frame Contents definitions
60
 
61
      dst           : out std_logic_vector(47 downto 0); -- destination address
62
      src           : out std_logic_vector(47 downto 0); -- source address
63
 
64
      prmble_len    : out integer range 0 to 10000;         -- length of preamble
65
      pquant        : out std_logic_vector(15 downto 0); -- Pause Quanta value
66
      vlan_ctl      : out std_logic_vector(15 downto 0); -- VLAN control info
67
      len           : out std_logic_vector(15 downto 0); -- Length of payload
68
      frmtype       : out std_logic_vector(15 downto 0); -- if non-null: type field instead length
69
 
70
      payload       : out std_logic_vector(7 downto 0);
71
      payload_vld   : out std_logic;
72
 
73
        -- Indicators
74
 
75
      is_vlan       : out std_logic;
76
      is_stack_vlan : out std_logic;
77
      is_pause      : out std_logic;
78
      crc_err       : out std_logic;
79
      prmbl_err     : out std_logic;
80
      len_err       : out std_logic;
81
      payload_err   : out std_logic;
82
      frame_err     : out std_logic;
83
      pause_op_err  : out std_logic;
84
      pause_dst_err : out std_logic;
85
      mac_err       : out std_logic;
86
      end_err       : out std_logic;
87
 
88
       -- Control
89
 
90
      jumbo_en      : in std_logic;
91
      data_only     : in std_logic;
92
 
93
        -- Receive indicator
94
 
95
      frm_rcvd     : out std_logic );
96
 
97
end TOP_ETHMONITOR32 ;
98
 
99
architecture behave of TOP_ETHMONITOR32 is
100
 
101
component ETHMONITOR_32
102
 
103
    generic (
104
        ENABLE_SHIFT16 : integer := 0  --0 for false, 1 for true
105
 
106
    );
107
 
108
    port (
109
 
110
      reset       : in std_logic ;     -- active high
111
 
112
        -- GMII transmit interface: To be connected to MAC TX
113
 
114
      tx_clk      : in std_logic ;
115
      txd         : in std_logic_vector(7 downto 0);
116
      tx_dv       : in std_logic;
117
      tx_er       : in std_logic;
118
 
119
        -- Frame Contents definitions
120
 
121
      dst           : out std_logic_vector(47 downto 0); -- destination address
122
      src           : out std_logic_vector(47 downto 0); -- source address
123
 
124
      prmble_len    : out integer range 0 to 10000;         -- length of preamble
125
      pquant        : out std_logic_vector(15 downto 0); -- Pause Quanta value
126
      vlan_ctl      : out std_logic_vector(15 downto 0); -- VLAN control info
127
      len           : out std_logic_vector(15 downto 0); -- Length of payload
128
      frmtype       : out std_logic_vector(15 downto 0); -- if non-null: type field instead length
129
 
130
      payload       : out std_logic_vector(7 downto 0);
131
      payload_vld   : out std_logic;
132
 
133
        -- Indicators
134
 
135
      is_vlan       : out std_logic;
136
      is_stack_vlan : out std_logic;
137
      is_pause      : out std_logic;
138
      crc_err       : out std_logic;
139
      prmbl_err     : out std_logic;
140
      len_err       : out std_logic;
141
      payload_err   : out std_logic;
142
      frame_err     : out std_logic;
143
      pause_op_err  : out std_logic;
144
      pause_dst_err : out std_logic;
145
      mac_err       : out std_logic;
146
      end_err       : out std_logic;
147
 
148
       -- Control
149
 
150
      jumbo_en      : in std_logic;
151
      data_only     : in std_logic;
152
 
153
        -- Receive indicator
154
 
155
      frm_rcvd     : out std_logic );
156
 
157
   end component ;
158
 
159
    -- Monitor port signals 
160
    -- ----------------------------------
161
 
162
    signal frm_rcvd_i : std_logic;   -- from gen
163
    signal frm_rcvd_d : std_logic;   -- delayed for handshake
164
    signal frm_rcvd_ex: std_logic;   -- external
165
 
166
    -- GMII Monitor signals
167
 
168
    signal tx_clk   : std_logic;                      -- 8 times the XGMII
169
    signal txd      : std_logic_vector(7 downto 0);
170
    signal tx_dv    : std_logic;
171
    signal tx_er    : std_logic;
172
 
173
    -- internal
174
 
175
    signal fast_clk       : std_logic;
176
    signal fast_clk_cnt   : integer;
177
    signal fast_clk_gate  : std_logic;
178
    signal clk_d          : std_logic;
179
 
180
    -- captured word data 
181
 
182
    signal    din_int    : std_logic_vector(31 downto 0);
183
    signal    dval_int   : std_logic;
184
    signal    derror_int : std_logic;
185
    signal    sop_int    : std_logic;   -- pulse with first word             
186
    signal    eop_int    : std_logic;   -- pulse with last word (tmod valid) 
187
    signal    tmod_int   : std_logic_vector(1 downto 0);  -- last word modulo
188
 
189
    -- shift registers to feed GMII Monitor
190
 
191
    signal eop_int_d    : std_logic;
192
    signal eop_done     : std_logic;
193
    signal txd_shift    : std_logic_vector(31 downto 0);
194
    signal txdv_shift   : std_logic_vector(3 downto 0);
195
 
196
 
197
    -- internal 
198
 
199
    signal   l_dst           : std_logic_vector(47 downto 0); -- destination address
200
    signal   l_src           : std_logic_vector(47 downto 0); -- source address
201
    signal   l_prmble_len    : integer range 0 to 10000;         -- length of preamble
202
    signal   l_pquant        : std_logic_vector(15 downto 0); -- Pause Quanta value
203
    signal   l_vlan_ctl      : std_logic_vector(15 downto 0); -- VLAN control info
204
    signal   l_len           : std_logic_vector(15 downto 0); -- Length of payload
205
    signal   l_frmtype       : std_logic_vector(15 downto 0); -- if non-null: type field instead length
206
    signal   l_is_vlan       : std_logic;
207
    signal   l_is_stack_vlan : std_logic;
208
    signal   l_is_pause      : std_logic;
209
    signal   l_crc_err       : std_logic;
210
    signal   l_prmbl_err     : std_logic;
211
    signal   l_len_err       : std_logic;
212
    signal   l_payload_err   : std_logic;
213
    signal   l_frame_err     : std_logic;
214
    signal   l_pause_op_err  : std_logic;
215
    signal   l_pause_dst_err : std_logic;
216
    signal   l_mac_err       : std_logic;
217
    signal   l_end_err       : std_logic;
218
 
219
    signal din_reg            : std_logic_vector(31 downto 0);
220
    signal dval_reg           : std_logic;
221
    signal derror_reg         : std_logic;
222
    signal sop_reg            : std_logic;   -- pulse with first word
223
    signal eop_reg            : std_logic;   -- pulse with last word (tmod valid)
224
    signal tmod_reg           : std_logic_vector(1 downto 0);  -- last word modulo
225
 
226
begin
227
 
228
   -- Capture word data input
229
   -- ----------------------------------
230
 
231
   process( clk, reset )
232
   begin
233
 
234
        if( reset='1' ) then
235
 
236
                din_int   <= (others => '0');
237
                dval_int  <= '0';
238
                derror_int<= '0';
239
                sop_int   <= '0';
240
                eop_int   <= '0';
241
                tmod_int  <= (others => '0');
242
 
243
                frm_rcvd_ex <= '0';
244
                eop_int_d <= '0';
245
 
246
        elsif(clk='1' and clk'event ) then
247
 
248
                din_int    <= din_reg;
249
                dval_int   <= dval_reg;
250
                derror_int <= derror_reg;
251
                sop_int    <= sop_reg;
252
                eop_int    <= eop_reg;
253
                tmod_int   <= tmod_reg;
254
 
255
                frm_rcvd_ex <= frm_rcvd_d;
256
 
257
                eop_int_d <= eop_int and dval_int;
258
 
259
        end if;
260
 
261
   end process;
262
 
263
   -- Results in word clock domain
264
   -- ----------------------------------
265
 
266
   frm_rcvd <= frm_rcvd_ex;
267
 
268
   process( clk, reset )
269
   begin
270
 
271
        if( reset='1' ) then
272
 
273
                dst          <= (others => '0');
274
                src          <= (others => '0');
275
                prmble_len   <= 0;
276
                pquant       <= (others => '0');
277
                vlan_ctl     <= (others => '0');
278
                len          <= (others => '0');
279
                frmtype      <= (others => '0');
280
                is_vlan      <= '0';
281
                is_stack_vlan<= '0';
282
                is_pause     <= '0';
283
                crc_err      <= '0';
284
                prmbl_err    <= '0';
285
                len_err      <= '0';
286
                payload_err  <= '0';
287
                frame_err    <= '0';
288
                pause_op_err <= '0';
289
                pause_dst_err<= '0';
290
                mac_err      <= '0';
291
                end_err      <= '0';
292
 
293
        elsif(clk='1' and clk'event ) then
294
 
295
                dst           <= l_dst ;
296
                src           <= l_src ;
297
                prmble_len    <= l_prmble_len ;
298
                pquant        <= l_pquant ;
299
                vlan_ctl      <= l_vlan_ctl;
300
                len           <= l_len    ;
301
                frmtype       <= l_frmtype ;
302
                is_vlan       <= l_is_vlan ;
303
                is_stack_vlan <= l_is_stack_vlan ;
304
                is_pause      <= l_is_pause;
305
                crc_err       <= l_crc_err ;
306
                prmbl_err     <= l_prmbl_err ;
307
                len_err       <= l_len_err   ;
308
                payload_err   <= l_payload_err;
309
                frame_err     <= l_frame_err   ;
310
                pause_op_err  <= l_pause_op_err;
311
                pause_dst_err <= l_pause_dst_err;
312
                mac_err       <= l_mac_err      ;
313
                end_err       <= l_end_err    ;
314
 
315
        end if;
316
 
317
   end process;
318
 
319
 
320
   -- create fast clock synchronized to clk rising edge
321
   -- -------------------------------------------------
322
 
323
   process
324
   begin
325
        fast_clk <= '0';
326
        wait for 0.5 ns;
327
        fast_clk <= '1';
328
        wait for 0.5 ns;
329
   end process;
330
 
331
   process( fast_clk, reset )
332
   begin
333
 
334
        if( reset='1' ) then
335
 
336
                fast_clk_gate <= '0';
337
                fast_clk_cnt  <= 3;
338
                clk_d         <= '0';
339
                frm_rcvd_d    <= '0';
340
                txd_shift     <= (others => '0');
341
                txdv_shift    <= (others => '0');
342
                eop_done      <= '0'; -- remember when we added 2 extra cycles after EOP
343
 
344
        elsif( fast_clk'event and fast_clk='0' ) then   -- work on neg edge
345
 
346
                clk_d <= clk;
347
 
348
                if(clk_d='1' and clk='0' and fast_clk_cnt > 2 and dval_int='1') then  -- wait for neg edge
349
 
350
                        fast_clk_cnt  <= 0;
351
                        fast_clk_gate <= '1';
352
 
353
                        -- load shift registers
354
 
355
                        txd_shift <= din_int;
356
 
357
                        if( eop_int='1' and dval_int='1' ) then
358
 
359
                                case tmod_int is
360
 
361
                                when "00" => txdv_shift <= "1111";
362
                                when "01" => txdv_shift <= "0001";
363
                                when "10" => txdv_shift <= "0011";
364
                                when "11" => txdv_shift <= "0111";
365
                                when others => txdv_shift <= "0000";
366
 
367
                                end case;
368
 
369
                        elsif( dval_int='1' ) then
370
 
371
                                txdv_shift <= "1111";
372
 
373
                        end if;
374
 
375
 
376
                elsif( fast_clk_cnt < 3 ) then
377
 
378
                        fast_clk_cnt <= fast_clk_cnt+1;
379
 
380
                        txd_shift  <= X"00" & txd_shift(31 downto 8);  -- LSByte first
381
                        txdv_shift <= '0'   & txdv_shift(3 downto 1);
382
 
383
                        fast_clk_gate <= '1';
384
 
385
                elsif( fast_clk_cnt < 5 and eop_int_d='1' and eop_done='0') then  -- give 2 more at end of frame to generate the frm_rcvd
386
 
387
                        txdv_shift   <= "0000";
388
                        fast_clk_cnt <= fast_clk_cnt+1;
389
                        fast_clk_gate <= '1';
390
 
391
                else
392
 
393
                        fast_clk_gate <= '0';
394
 
395
                end if;
396
 
397
                -- indicate when we finished the old frame (giving extra cycles after last bytes) 
398
                -- to block eop_int_d indication in case b2b frames are received
399
 
400
                if( fast_clk_cnt=4 and eop_int_d='1' ) then
401
 
402
                        eop_done <= '1';
403
 
404
                elsif( eop_int_d='0' ) then
405
 
406
                        eop_done <= '0';
407
 
408
                end if;
409
 
410
 
411
 
412
                -- capture frame received indication and sync it to word clock (handshake)
413
 
414
                if( frm_rcvd_i='1' ) then
415
 
416
                        frm_rcvd_d <= '1';
417
 
418
                elsif( frm_rcvd_ex='1' ) then
419
 
420
                        frm_rcvd_d <= '0';
421
                end if;
422
 
423
 
424
        end if;
425
 
426
   end process;
427
 
428
   -- DDR process to generate gated clock
429
 
430
   process( fast_clk, reset )
431
   begin
432
 
433
        if( reset='1' ) then
434
 
435
                tx_clk <= '0';
436
 
437
        elsif( fast_clk'event and fast_clk='1' ) then
438
 
439
                if( fast_clk_gate = '1' ) then
440
 
441
                        tx_clk <= '1';
442
 
443
                end if;
444
 
445
        elsif( fast_clk'event and fast_clk='0' ) then
446
 
447
                tx_clk <= '0';
448
 
449
        end if;
450
 
451
    end process;
452
 
453
   --tx_clk <= fast_clk and fast_clk_gate;        
454
 
455
 
456
   -- Use shifted word data to generate GMII signals
457
   -- ----------------------------------------------------------
458
 
459
   txd   <= txd_shift(7 downto 0);
460
   tx_dv <= txdv_shift(0);
461
   tx_er <= derror_int;
462
 
463
 
464
-- endian adapter from Little endian to Big endian
465
--       din      : in  std_logic_vector(31 downto 0);
466
--       dval     : in  std_logic;
467
--       derror   : in  std_logic;
468
--       sop      : in  std_logic;   -- pulse with first word
469
--       eop      : in  std_logic;   -- pulse with last word (tmod valid)
470
--       tmod     : in  std_logic_vector(1 downto 0);  -- last word modulo
471
 
472
 process (clk, reset)
473
  begin
474
   if( reset = '1' ) then
475
       din_reg   <= (others => '0');
476
       dval_reg  <= '0';
477
       derror_reg<= '0';
478
       sop_reg   <= '0';
479
       eop_reg   <= '0';
480
       tmod_reg  <= (others => '0');
481
 
482
   elsif( clk'event and clk='1' ) then
483
 
484
     if (BIG_ENDIAN = 1) then
485
 
486
          din_reg   <= (din(7 downto 0) & din(15 downto 8) & din(23 downto 16) & din(31 downto 24));
487
          dval_reg  <= dval_reg ;
488
          derror_reg<= derror_reg;
489
          sop_reg   <= sop;
490
          eop_reg   <= eop;
491
 
492
          case (tmod) is
493
            when "00"   => tmod_reg <= "00";
494
            when "01"   => tmod_reg <= "11";
495
            when "10"   => tmod_reg <= "10";
496
            when "11"   => tmod_reg <= "01";
497
            when others => tmod_reg <= "00";
498
          end case;
499
     else
500
          din_reg            <= din ;
501
          dval_reg           <= dval ;
502
          derror_reg         <= derror;
503
          sop_reg            <= sop;
504
          eop_reg            <= eop;
505
          tmod_reg           <= tmod;
506
     end if;
507
   end if;
508
 
509
  end process;
510
 
511
 
512
   -- Monitor
513
   -- ---------
514
 
515
   MON1G: ETHMONITOR_32
516
 
517
   generic map (
518
     ENABLE_SHIFT16 => ENABLE_SHIFT16
519
   )
520
 
521
   port map (
522
 
523
      reset         =>  reset,         -- active high
524
      tx_clk        =>  tx_clk,
525
      txd           =>  txd,
526
      tx_dv         =>  tx_dv,
527
      tx_er         =>  tx_er,
528
      dst           =>  l_dst,
529
      src           =>  l_src,
530
      prmble_len    =>  l_prmble_len,
531
      pquant        =>  l_pquant,
532
      vlan_ctl      =>  l_vlan_ctl,
533
      len           =>  l_len,
534
      frmtype       =>  l_frmtype,
535
      payload       =>  payload,
536
      payload_vld   =>  payload_vld,
537
      is_vlan       =>  l_is_vlan,
538
      is_stack_vlan =>  l_is_stack_vlan,
539
      is_pause      =>  l_is_pause,
540
      crc_err       =>  l_crc_err,
541
      prmbl_err     =>  l_prmbl_err,
542
      len_err       =>  l_len_err,
543
      payload_err   =>  l_payload_err,
544
      frame_err     =>  l_frame_err,
545
      pause_op_err  =>  l_pause_op_err,
546
      pause_dst_err =>  l_pause_dst_err,
547
      mac_err       =>  l_mac_err,
548
      end_err       =>  l_end_err,
549
      jumbo_en      =>  jumbo_en,
550
      data_only     =>  data_only,
551
      frm_rcvd      =>  frm_rcvd_i );
552
 
553
end behave;
554
 
555
 

powered by: WebSVN 2.1.0

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