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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gleichmann/] [sim/] [phy_ext.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
--------------------------------------------------------------------------------
2
--  Project:         LEON-ARC
3
--  Entity:          phy_ext
4
--  Architecture(s): behav
5
--  Author:          tame@msc-ge.com
6
--  Company:         Gleichmann Electronics
7
--
8
--  Description:
9
--    This file is based upon the PHY simulation model by Gaisler Research,
10
--    which is part of the GNU GPL-licensed GRLIB. For details on the GRLIB, go
11
--    to www.gaisler.com.
12
--
13
--    The original design has been extended in respect to logging signals.
14
--
15
--------------------------------------------------------------------------------
16
--
17
--  Gaisler original comment:
18
--  Entity:      phy
19
--  File:            phy.vhd
20
--  Description: Simulation model of the Intel LXT971A Ethernet PHY
21
--               Only the MII interface is implemented.
22
--               Stimuli is read from a file "indata" and response is
23
--               written to "outdata"
24
--  Author:      Marko Isomaki
25
------------------------------------------------------------------------------
26
 
27
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use std.textio.all;
31
 
32
library work;
33
use work.txt_util.all;
34
 
35
 
36
entity phy_ext is
37
  generic (
38
    infile_name : string := "indata";
39
    outfile_name : string := "outdata";
40
    logfile_name : string := "logfile";
41
    win_size : natural := 3);           -- number of packages that form a window
42
  port (
43
    resetn    : in    std_logic;
44
    led_cfg   : in    std_logic_vector(2 downto 0);
45
    log_en    : in    std_logic := '1';
46
    cycle_num : in    integer;
47
    mdio      : inout std_logic;
48
    tx_clk    : out   std_logic;
49
    rx_clk    : out   std_logic;
50
    rxd       : out   std_logic_vector(3 downto 0);
51
    rx_dv     : out   std_logic;
52
    rx_er     : out   std_logic;
53
    rx_col    : out   std_logic;
54
    rx_crs    : out   std_logic;
55
    txd       : in    std_logic_vector(3 downto 0);
56
    tx_en     : in    std_logic;
57
    tx_er     : in    std_logic;
58
    mdc       : in    std_logic);
59
end entity;
60
 
61
 
62
architecture behav of phy_ext is
63
  --type declarations
64
  type state_type is (base10h, base10f, base100h, base100f);
65
 
66
  type reg_type is
67
    record
68
      crs       : std_logic;
69
      tx_count  : integer range 0 to 1;
70
      tx_output : std_logic_vector(3 downto 0);
71
      rx_dv     : std_logic;
72
      rx_er     : std_logic;
73
      prev_txd  : std_logic;
74
      state     : state_type;
75
      new_data  : std_logic;
76
      new_txd   : std_logic;
77
      counter   : integer range 0 to 400000;
78
      pcount    : integer range 0 to 64;
79
    end record;
80
 
81
  --signal declarations
82
  signal clk_fast : std_logic := '0';
83
  signal clk_slow : std_logic := '0';
84
  signal temp_clk : std_logic;
85
  signal r, rin   : reg_type;
86
 
87
  file indata     : text open read_mode is infile_name;
88
  file outdata    : text open write_mode is outfile_name;
89
 
90
  -- logfile contains read and write accesses
91
  file logfile            : text open write_mode is logfile_name;
92
  shared variable logline : line;
93
  shared variable logstring : string(1 to 80);
94
 
95
  signal temp_col : std_logic;
96
 
97
begin
98
  --clock generation
99
  clk_fast <= not clk_fast after 20 ns;
100
  clk_slow <= not clk_slow after 200 ns;
101
 
102
  temp_clk <= clk_fast when r.state = base100h or r.state = base100f else
103
              clk_slow;
104
 
105
  rx_clk <= temp_clk;
106
  tx_clk <= temp_clk;
107
 
108
  --unused signals
109
  mdio <= 'Z';
110
 
111
  comb : process(r, txd, tx_en, tx_er)
112
    variable v   : reg_type;
113
    variable col : std_logic;
114
  begin
115
    v          := r;
116
    v.prev_txd := r.new_txd;
117
    v.crs      := '0';
118
    v.new_data := '0';
119
    --transmitter part
120
    v.new_txd  := tx_en;
121
    if tx_er = '1' then
122
      v.tx_output := X"F";
123
    elsif tx_en = '1' then
124
      v.tx_output := txd;
125
    end if;
126
 
127
    if (r.state = base10h or r.state = base100h) and tx_en = '1' then
128
      v.crs := '1';
129
    end if;
130
    --receiver part
131
    if r.counter > 0 then
132
      v.counter := r.counter-1;
133
    end if;
134
 
135
    v.rx_dv := '0';
136
    v.rx_er := '0';
137
 
138
    if r.counter = 0 then
139
      if(tx_en = '0' or (r.new_txd = '0' and tx_en = '1') or
140
          r.state = base100f or r.state = base10f) then
141
        v.rx_dv    := '1';
142
        v.new_data := '1';
143
        v.crs      := '1';
144
      end if;
145
    end if;
146
 
147
    --control signals
148
    if (r.state = base10h or r.state = base100h) and
149
      tx_en = '1' and r.rx_dv = '1' then
150
      col := '1';
151
    else
152
      col := '0';
153
    end if;
154
    --output
155
 
156
    rx_col <= col;
157
    temp_col <= col;
158
 
159
    rx_crs <= r.crs;
160
    rx_dv  <= r.rx_dv;
161
    rx_er  <= r.rx_er;
162
    --registers
163
    rin    <= v;
164
  end process comb;
165
 
166
  log_start : process is
167
  begin
168
    if log_en = '1' then
169
      print(logfile, "#");
170
      print(logfile, "# RX_TRANSFER CYCLE_NUMBER RX_CLK RX_DV RX_ER COL CRS RXD MDC MDIO");
171
      print(logfile, "# TX_TRANSFER CYCLE_NUMBER TX_CLK TX_EN TX_ER TXD");
172
      print(logfile, "#");
173
    end if;
174
    wait;
175
  end process;
176
 
177
  regs : process(resetn, temp_clk)
178
    variable textline : line;
179
    variable wline    : line;
180
    variable din_tmp  : bit_vector(3 downto 0);
181
    variable din_ok   : boolean;
182
  begin
183
    if resetn = '0' then
184
      case led_cfg is
185
        when "000"  => r.state <= base10h;
186
        when "001"  => r.state <= base10f;
187
        when "010"  => r.state <= base100h;
188
        when "011"  => r.state <= base100f;
189
        when others => r.state <= base10h;
190
      end case;
191
      r.crs      <= '0';
192
      r.tx_count <= 0;
193
      r.new_txd  <= '0';
194
      r.rx_dv    <= '0';
195
      r.rx_er    <= '0';
196
      r.new_data <= '0';
197
      r.counter  <= 2000;
198
      r.pcount   <= 0;
199
    elsif rising_edge(temp_clk) then
200
      r <= rin;
201
      if rin.new_data = '1' and not endfile(indata) then
202
        readline(indata, textline);
203
        read(textline, din_tmp, din_ok);
204
        if din_ok then
205
          rxd <= to_stdlogicvector(din_tmp);
206
          -- write RX data to logfile
207
          if log_en = '1' then
208
            print(logfile,
209
                  string'("RX ") &
210
                  str(cycle_num) & " " &  -- current clock cycle number
211
                  str(temp_clk) & " " &  -- equivalent to rx_clk
212
                  str(r.rx_dv) & " " &  -- receive data valid
213
                  str(r.rx_er) & " " &  -- receive error
214
                  str(temp_col) & " " &  -- equivalent to rx_col
215
                  str(r.crs) & " " &    -- receive carrier sense
216
                  hstr(to_stdlogicvector(din_tmp)) & " " &  -- receive data
217
                  str(mdc) & " " &
218
                  str(mdio));
219
          end if;
220
        else
221
          report "new-packet" severity note;
222
          r.pcount <= rin.pcount + 1;
223
          if rin.pcount + 1 /= win_size then
224
            if r.state = base100h or r.state = base100f then
225
              r.counter <= 500;
226
            else
227
              r.counter <= 50;
228
            end if;
229
          else
230
            r.counter <= 1000;
231
            r.pcount  <= 0;
232
          end if;
233
          rxd     <= (others => 'U');
234
          r.rx_dv <= '0';
235
          r.crs   <= '0';
236
        end if;
237
      else
238
        rxd     <= (others => 'U');
239
        r.rx_dv <= '0';
240
        r.crs   <= '0';
241
      end if;
242
 
243
      if rin.new_txd = '1' then
244
        write(wline, to_bitvector(rin.tx_output), left, 4);
245
        writeline(outdata, wline);
246
        -- write TX data to logfile
247
        if log_en = '1' then
248
          print(logfile,
249
                string'("TX ") &
250
                str(cycle_num) & " " &  -- current clock cycle number
251
                str(temp_clk) & " " &   -- equivalent to tx_clk
252
                str(tx_en) & " " &      -- always enabled here
253
                str(tx_er) & " " &      -- transmit error
254
                hstr(txd));             -- transmit data
255
        end if;
256
        if r.state = base10h or r.state = base100h then
257
          r.crs <= '1';
258
        end if;
259
      elsif rin.prev_txd = '1' then
260
        write(wline, string'("end"), left, 3);
261
        writeline(outdata, wline);
262
      end if;
263
    end if;
264
  end process regs;
265
 
266
end architecture;

powered by: WebSVN 2.1.0

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