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

Subversion Repositories esoc

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

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

Line No. Rev Author Line
1 42 lmaarsen
-- -------------------------------------------------------------------------
2
-- -------------------------------------------------------------------------
3
--
4
-- Revision Control Information
5
--
6
-- $RCSfile: top_ethgen32.v,v $
7
-- $Source: /ipbu/cvs/sio/projects/TriSpeedEthernet/src/testbench/models/verilog/ethernet_model/gen/top_ethgen8.v,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 Generator for 8 bit fifoless MAC Atlantic client interface
19
-- Instantiates VHDL module: ethgenerator (ethgen.vhd)
20
--                           timing_adapter_8 (timing_adapter_8.vhd) 
21
-- ALTERA Confidential and Proprietary
22
-- Copyright 2006 (c) Altera Corporation
23
-- All rights reserved
24
--
25
-- -------------------------------------------------------------------------
26
-- -------------------------------------------------------------------------
27
 
28
library ieee ;
29
use     ieee.std_logic_1164.all ;
30
use     ieee.std_logic_unsigned.all ;
31
use     ieee.std_logic_arith.all;
32
 
33
 
34
 
35
entity top_ethgenerator_8 is
36
 
37
 
38
    generic (  THOLD           : time    := 1 ns;
39
               ENABLE_SHIFT16  : integer := 1;  --0 for false, 1 for true
40
               ZERO_LATENCY    : integer := 1   --0 for NON-ZERO read latency, etc.
41
 
42
            );
43
 
44
    port (
45
 
46
       reset            : in    std_logic;
47
       clk                      : in    std_logic;
48
       enable           : in    std_logic;
49
       dout             : out   std_logic_vector(7 downto 0);
50
       dval             : out   std_logic;
51
       derror           : out   std_logic;
52
       sop                      : out   std_logic;
53
       eop                      : out   std_logic;
54
       mac_reverse  : in        std_logic;
55
       dst                      : in    std_logic_vector (47 downto 0);
56
       src                      : in    std_logic_vector (47 downto 0);
57
       prmble_len       : in    integer range 0 to 40;
58
       pquant           : in    std_logic_vector (15 downto 0);
59
       vlan_ctl         : in    std_logic_vector (15 downto 0);
60
       len                      : in    std_logic_vector (15 downto 0);
61
       frmtype          : in    std_logic_vector (15 downto 0);
62
       cntstart         : in    integer range 0 to 255;
63
       cntstep          : in    integer range 0 to 255;
64
       ipg_len          : in    integer range 0 to 32768;
65
       payload_err  : in    std_logic;
66
       prmbl_err    : in    std_logic;
67
       crc_err      : in    std_logic;
68
       vlan_en      : in    std_logic;
69
       stack_vlan   : in    std_logic;
70
       pause_gen    : in    std_logic;
71
       pad_en       : in    std_logic;
72
       phy_err      : in    std_logic;
73
       end_err      : in    std_logic;
74
       data_only    : in    std_logic;
75
       start        : in    std_logic;
76
       done         : out   std_logic
77
     );
78
 
79
end top_ethgenerator_8;
80
 
81
architecture behav of top_ethgenerator_8 is
82
 
83
-- Component instantiated by Turbo autoplace on 21/02/2008 at 10:16:49
84
COMPONENT timing_adapter_8
85
port (
86
 
87
  -- Interface: clk                     
88
  clk                  : in std_logic;
89
  reset                : in std_logic;
90
  -- Interface: in
91
  in_ready              : out std_logic;
92
  in_valid              : in  std_logic;
93
  in_data               : in  std_logic_vector (7 downto 0);
94
  in_startofpacket      : in  std_logic;
95
  in_endofpacket        : in  std_logic;
96
  in_error              : in  std_logic;
97
  -- Interface: out
98
  out_ready             : in std_logic;
99
  out_valid             : out std_logic;
100
  out_data              : out std_logic_vector (7 downto 0);
101
  out_startofpacket     : out std_logic;
102
  out_endofpacket       : out std_logic;
103
  out_error             : out std_logic
104
);
105
END COMPONENT;
106
 
107
-- Component instantiated by Turbo autoplace on 21/02/2008 at 10:16:17
108
COMPONENT ETHGENERATOR
109
 
110
    generic (  THOLD          : time    := 1 ns;
111
                           ENABLE_SHIFT16 : integer := 0  --0 for false, 1 for true
112
                        );
113
    port (
114
 
115
      reset       : in std_logic ;     -- active high
116
 
117
        -- GMII receive interface: To be connected to MAC RX
118
 
119
      rx_clk      : in std_logic ;
120
      enable      : in std_logic ;
121
      rxd         : out std_logic_vector(7 downto 0);
122
      rx_dv       : out std_logic;
123
      rx_er       : out std_logic;
124
 
125
        -- Additional FIFO controls for FIFO test scenarios
126
 
127
      sop         : out std_logic;   -- pulse with first character
128
      eop         : out std_logic;   -- pulse with last  character
129
 
130
        -- Frame Contents definitions
131
 
132
      mac_reverse   : in std_logic;                     -- 1: dst/src are sent MSB first
133
      dst           : in std_logic_vector(47 downto 0); -- destination address
134
      src           : in std_logic_vector(47 downto 0); -- source address
135
 
136
      prmble_len    : in integer range 0 to 40;         -- length of preamble
137
      pquant        : in std_logic_vector(15 downto 0); -- Pause Quanta value
138
      vlan_ctl      : in std_logic_vector(15 downto 0); -- VLAN control info
139
      len           : in std_logic_vector(15 downto 0); -- Length of payload
140
      frmtype       : in std_logic_vector(15 downto 0); -- if non-null: type field instead length
141
 
142
      cntstart      : in integer range 0 to 255;  -- payload data counter start (first byte of payload)
143
      cntstep       : in integer range 0 to 255;  -- payload counter step (2nd byte in paylaod)
144
 
145
      ipg_len       : in integer range 0 to 32768;  -- inter packet gap (delay after CRC)
146
      wrong_pause_op : in std_logic ;                    -- Generate Pause Frame with Wrong Opcode       
147
      wrong_pause_lgth : in std_logic ;                    -- Generate Pause Frame with Wrong Opcode       
148
       -- Control
149
 
150
      payload_err   : in std_logic;  -- generate payload pattern error (last payload byte is wrong)
151
      prmbl_err     : in std_logic;
152
      crc_err       : in std_logic;
153
      vlan_en       : in std_logic;
154
      pause_gen     : in std_logic;
155
      pad_en        : in std_logic;
156
      phy_err       : in std_logic;
157
      end_err       : in std_logic;  -- keep rx_dv high one cycle after end of frame
158
      magic         : in std_logic;
159
      stack_vlan    : in std_logic;
160
 
161
      data_only     : in std_logic;  -- if set omits preamble, padding, CRC
162
 
163
      start         : in  std_logic;
164
      done          : out std_logic );
165
 
166
END COMPONENT;
167
 
168
 
169
--  internal GMII from generator
170
signal    rxd           : std_logic_vector (7 downto 0);
171
signal    rx_dv         : std_logic;
172
signal    rx_er         : std_logic;
173
signal    sop_gen       : std_logic;
174
signal    eop_gen       : std_logic;
175
signal    start_gen : std_logic;
176
signal    done_gen      : std_logic;
177
--  captured signals from generator (lasting 1 word clock cycle)
178
signal    enable_int: std_logic;
179
signal    enable_reg: std_logic;
180
signal    sop_int       : std_logic; --  captured sop_gen
181
signal    sop_int_d : std_logic; --  captured sop_gen
182
signal    eop_int       : std_logic; --  captured eop_gen
183
signal    eop_i         : std_logic; --  captured eop_gen
184
signal    rx_er_int : std_logic; --  captured rx_er
185
--  external signals
186
signal    sop_ex    : std_logic;
187
signal    eop_ex    : std_logic;
188
--  captured command signals 
189
signal  ipg_len_i       :  integer range 0 to 32768; -- inter packet gap
190
--  internal
191
signal    data8     : std_logic_vector(7 downto 0);
192
signal    clkcnt        : std_logic_vector(2 downto 0);
193
signal    bytecnt_eop: std_logic_vector(1 downto 0); --  captured count for last word
194
signal    count         : integer;
195
 
196
--assign output
197
signal dout_reg       : std_logic_vector(7 downto 0);
198
signal dval_reg       : std_logic;
199
signal derror_reg     : std_logic;
200
signal done_reg       : std_logic;
201
 
202
signal  dout_temp   : std_logic_vector (7 downto 0);
203
signal  dval_temp   : std_logic;
204
signal  derror_temp : std_logic;
205
signal  sop_temp    : std_logic;
206
signal  eop_temp    : std_logic;
207
signal  done_temp   : std_logic;
208
 
209
signal  dout_before_delay       : std_logic_vector (7 downto 0);
210
signal  dval_before_delay       : std_logic;
211
signal  derror_before_delay     : std_logic;
212
signal  sop_before_delay        : std_logic;
213
signal  eop_before_delay        : std_logic;
214
signal  done_before_delay       : std_logic;
215
 
216
 
217
-- TYPE stm_typ:
218
type  stm_typ is (S_IDLE, S_DATA, S_IPG, S_IPG0, S_WAIT);
219
 
220
signal  state          : stm_typ;
221
signal  last_state     : stm_typ;
222
 
223
signal  clk_d          : std_logic;
224
signal  fast_clk       : std_logic;
225
signal  fast_clk_gate  : std_logic;
226
signal  bytecnt        : std_logic_vector(2 downto 0);
227
signal  tx_clk         : std_logic;
228
 
229
begin
230
 
231
 
232
 
233
--  ---------------------------------------
234
--  Generate internal fast clock synchronized to external input clock
235
--  ---------------------------------------
236
 
237
process
238
 begin
239
   fast_clk <= '0' after 0.1 ns;
240
   wait for 0.4 ns;
241
   fast_clk <= '1' after 0.1 ns;
242
   wait for 0.4 ns;
243
end process;
244
 
245
 
246
process (fast_clk,reset)
247
begin
248
   if (reset = '1') then
249
      fast_clk_gate <= '0';
250
      clk_d         <= '0';
251
   elsif (falling_edge(fast_clk)) then
252
--  work on neg edge
253
      clk_d <= clk;
254
      if ((rx_dv = '0' or done_gen = '1') and
255
                    (enable_int = '1' or start_gen = '1')) then
256
 
257
--  generator not running, enable it permanently
258
         fast_clk_gate <= '1';
259
      elsif (clk_d = '0' and clk = '1' and
260
                            state /= S_WAIT and (enable_int = '1' or
261
                            state = S_IPG0) ) then
262
--  wait for rising edge
263
         fast_clk_gate <= '1';
264
      else
265
         fast_clk_gate <= '0';
266
      end if;
267
   end if;
268
end process;
269
 
270
 
271
--  DDR process to generate gated clock
272
process (fast_clk,reset)
273
   begin
274
           if (reset = '1') then
275
              tx_clk <= '0';
276
           elsif ( fast_clk = '1' ) then
277
              if (fast_clk_gate ='1') then
278
                 tx_clk <= '1';
279
              end if;
280
           elsif ( fast_clk = '0' ) then
281
              tx_clk <= '0';
282
           end if;
283
 
284
end process;
285
 
286
 
287
 
288
--  capture generator signals with word clock domain handshake
289
--  ----------------------------------------------------------
290
process (tx_clk,reset)
291
  begin
292
   if (reset = '1') then
293
      eop_int   <= '0';
294
      sop_int   <= '0';
295
      rx_er_int <= '0';
296
 
297
   elsif (rising_edge(tx_clk)) then
298
 
299
      if (sop_gen = '1') then
300
         sop_int <= '1';
301
      elsif (sop_ex = '1' ) then
302
         sop_int <= '0';
303
      end if;
304
 
305
      if (eop_gen = '1') then
306
         eop_int <= '1';
307
      elsif (eop_ex = '1' ) then
308
         eop_int <= '0';
309
          end if;
310
 
311
      if (rx_er = '1') then
312
         rx_er_int <= '1';
313
      elsif (eop_ex = '1' ) then
314
         rx_er_int <= '0';
315
      end if;
316
 
317
   end if;
318
end process;
319
 
320
 
321
--  word clock, external signal generation
322
--  --------------------------------------
323
process (clk,reset)
324
   begin
325
   if (reset = '1') then
326
      eop_ex <= '0';
327
      sop_ex <= '0';
328
      dval_reg <= '0';
329
      dout_reg <= (others => '0');
330
      derror_reg <= '0';
331
      start_gen <= '0';
332
      ipg_len_i <= 0;
333
      done_reg <= '0';
334
   elsif (rising_edge(clk)) then
335
      eop_ex            <= eop_int;
336
      sop_ex            <= sop_int;
337
      dout_reg          <= data8 after THOLD;
338
      derror_reg        <= rx_er_int after THOLD;
339
 
340
     if( done_gen='1' and ((state=S_IDLE or state=S_IPG0) or
341
                                      (state=S_DATA and eop_int='1' and ipg_len_i<4 and start='1')) ) then  -- nextstate=S_IPG0
342
--  nextstate=S_IPG0
343
         start_gen <= start;
344
      else
345
         start_gen <= '0';
346
      end if;
347
 
348
 
349
      if( (state = S_DATA or state=S_IPG0 or sop_int='1') and enable_int='1') then
350
         dval_reg <= '1' after THOLD;
351
      else
352
         dval_reg <= '0' after THOLD;
353
      end if;
354
 
355
--  store input variables that could change until end of frame
356
      if (sop_int = '1') then
357
         ipg_len_i <= ipg_len;
358
      end if;
359
 
360
      done_reg <= done_gen;
361
   end if;
362
end process;
363
 
364
 
365
--  ------------------------
366
--  capture GMII data bytes
367
--  ------------------------
368
process (tx_clk,reset)
369
 begin
370
   if (reset = '1') then
371
      data8 <= (others => '0');
372
   elsif (rising_edge (tx_clk)) then
373
      if (sop_gen = '1' and rx_dv = '1') then
374
--  first byte
375
         data8 <= rxd;
376
      elsif (rx_dv = '1' ) then
377
--  during frame
378
         data8 <= rxd;
379
      end if;
380
   end if;
381
end process;
382
 
383
--  ------------------------
384
--  state machine
385
--  ------------------------
386
process (clk, reset)
387
   begin
388
   if (reset = '1') then
389
      state <= S_IDLE;
390
      count <= 8;
391
   elsif (rising_edge(clk)) then
392
      if (state = S_IPG) then
393
         count <= count + 4;
394
      else
395
         count <= 8;
396
      end if;
397
 
398
              case (state) is
399
                      when S_idle =>
400
                         if (done_gen = '0') then
401
                            state <= s_data;
402
                         else
403
                            state <= s_idle;
404
                         end if;
405
                      when s_data =>
406
                         if (eop_int = '0' and enable_int = '1') then
407
                            state <= s_data;
408
                         elsif (eop_int = '0' and enable_int = '0' ) then
409
                            state <= s_wait;
410
                         elsif (eop_int = '1') then
411
                            if (ipg_len_i < 4 and start = '1') then
412
                               state <= s_ipg0; --  no IPG
413
                            elsif (ipg_len_i < 8 ) then
414
                               state <= s_idle;
415
                            else
416
                               state <= s_ipg;
417
                            end if;
418
                         else
419
                            state <= s_data;
420
                         end if;
421
                      when s_ipg =>
422
                         if (count < ipg_len_i) then
423
                            state <= s_ipg;
424
                         else
425
                            state <= s_idle;
426
                         end if;
427
                      when s_ipg0 =>
428
                         state <= s_data;
429
 
430
                      when s_wait =>
431
                         if (enable_int = '1') then
432
                            state <= s_data;
433
                         else
434
                            state <= s_wait;
435
                         end if;
436
                      when others =>
437
                         state <= s_idle;
438
              end case;
439
 
440
   end if;
441
end process;
442
 
443
 
444
 
445
process (clk,reset)
446
 begin
447
   if (reset = '1') then
448
          dout_temp  <= (others => '0');
449
          dval_temp  <= '0';
450
          derror_temp<= '0';
451
          sop_temp   <= '0';
452
          eop_temp   <= '0';
453
          done_temp  <= '0';
454
   elsif (rising_edge(clk)) then
455
             dout_temp     <= dout_reg after THOLD;
456
             dval_temp     <= dval_reg after THOLD;
457
             derror_temp   <= derror_reg after THOLD;
458
             sop_temp      <= sop_ex after THOLD;
459
             eop_temp      <= eop_ex after THOLD;
460
             done_temp     <= done_reg after THOLD;
461
    end if;
462
end process;
463
 
464
GMII_ADAPTER_BLOCK: if (ZERO_LATENCY = 1) generate
465
 
466
    tb_adapter: timing_adapter_8
467
    port map(
468
 
469
          -- Interface: clk
470
          clk                           => clk,
471
          reset                         => reset,
472
          -- Interface: in 
473
          in_ready                      => enable_int,
474
          in_valid                      => dval_temp,
475
          in_data                       => dout_temp,
476
          in_startofpacket      => sop_temp,
477
          in_endofpacket        => eop_temp,
478
          in_error                      => derror_temp,
479
          -- Interface: out
480
          out_ready                     => enable,
481
          out_valid                     => dval,
482
          out_data                      => dout,
483
          out_startofpacket => sop,
484
          out_endofpacket       => eop,
485
          out_error                     => derror
486
 
487
    );
488
 
489
    done <= done_temp;
490
end generate;
491
 
492
NO_ADAPTER_BLOCK: if (ZERO_LATENCY = 0) generate
493
 
494
     process (clk,reset)
495
       begin
496
         if (reset = '1')  then
497
           enable_reg <= '0';
498
         elsif (rising_edge(clk)) then
499
           enable_reg <= enable;
500
        end if;
501
        end process;
502
 
503
        enable_int  <=  enable_reg;
504
    dout        <=  dout_temp;
505
    dval        <=  dval_temp;
506
    derror      <=  derror_temp;
507
    sop         <=  sop_temp;
508
    eop         <=  eop_temp;
509
    done        <=  done_temp;
510
end generate;
511
 
512
 
513
--  Generator
514
--  ---------
515
gen1g : ethgenerator
516
generic map (
517
                        ENABLE_SHIFT16 => ENABLE_SHIFT16,
518
                        THOLD          => 0.1 ns
519
         )
520
 
521
port map (
522
 
523
          reset                                 =>      reset,
524
          rx_clk                                =>      tx_clk,
525
          enable                                =>      '1',
526
          rxd                                   =>      rxd,
527
          rx_dv                                 =>      rx_dv,
528
          rx_er                                 =>      rx_er,
529
          sop                                   =>      sop_gen,
530
          eop                                   =>      eop_gen,
531
          mac_reverse                   =>      mac_reverse,
532
          dst                                   =>      dst,
533
          src                                   =>      src,
534
          prmble_len                    =>      prmble_len,
535
          pquant                                =>      pquant,
536
          vlan_ctl                              =>      vlan_ctl,
537
          len                                   =>      len,
538
          frmtype                               =>      frmtype,
539
          cntstart                              =>      cntstart,
540
          cntstep                               =>      cntstep,
541
          ipg_len                               =>      4,
542
          wrong_pause_op        => '0',
543
          wrong_pause_lgth      => '0',
544
          payload_err                   =>      payload_err,
545
          prmbl_err                             =>      prmbl_err,
546
          crc_err                               =>      crc_err,
547
          vlan_en                               =>      vlan_en,
548
          stack_vlan                    =>      stack_vlan,
549
          pause_gen                             =>      pause_gen,
550
          pad_en                                =>      pad_en,
551
          phy_err                               =>      phy_err,
552
          magic                =>      '0',
553
          end_err                               =>      end_err,
554
          data_only                             =>      data_only,
555
          start                                 =>      start_gen,
556
          done                                  =>      done_gen
557
        );
558
 
559
end behav;
560
 
561
 

powered by: WebSVN 2.1.0

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