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

Subversion Repositories core_arm

[/] [core_arm/] [trunk/] [vhdl/] [peripherals/] [net/] [eth_oc.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 tarookumic
----------------------------------------------------------------------------
2
--  This file is a part of the LEON VHDL model
3
--  Copyright (C) 2003 Gaisler Research
4
--
5
--  This library is free software; you can redistribute it and/or
6
--  modify it under the terms of the GNU Lesser General Public
7
--  License as published by the Free Software Foundation; either
8
--  version 2 of the License, or (at your option) any later version.
9
--
10
--  See the file COPYING.LGPL for the full details of the license.
11
----------------------------------------------------------------------------
12
-- Entity:      eth_oc
13
-- File:        eth_oc.vhd
14
-- Description: Backend for Opencores PCI_IF
15
-- Author:      Daniel Hedberg, Jiri Gaisler - Gaisler Research
16
------------------------------------------------------------------------------
17
 
18
library ieee;
19
use ieee.std_logic_1164.all;
20
use work.amba.all;
21
use work.ambacomp.all;
22
use work.leon_iface.all;
23
 
24
entity eth_oc is
25
   port (
26
      rst  : in  std_logic;
27
      clk  : in  std_logic;
28
      ahbsi : in  ahb_slv_in_type;
29
      ahbso : out ahb_slv_out_type;
30
      ahbmi : in  ahb_mst_in_type;
31
      ahbmo : out ahb_mst_out_type;
32
      eneti : in eth_in_type;
33
      eneto : out eth_out_type;
34
      irq   : out std_logic
35
      );
36
end;
37
 
38
architecture rtl of eth_oc is
39
 
40
type wb_mst_in_type is record
41
  mdat_i : std_logic_vector(31 downto 0);      -- binary data bus
42
  rty_i  : std_logic;
43
  ack_i  : std_logic;                          -- data available
44
end record;
45
 
46
type wb_mst_out_type is record
47
  adr_o  : std_logic_vector(11 downto 2);       -- address bus (byte) 
48
  mdat_o : std_logic_vector(31 downto 0);        -- binary data bus    
49
  we_o   : std_logic;
50
  stb_o  : std_logic;
51
  cab_o  : std_logic;
52
end record;
53
 
54
type wb_slv_in_type is record
55
  adr_i  : std_logic_vector(31 downto 0);
56
  sdat_i : std_logic_vector(31 downto 0);
57
  we_i   : std_logic;
58
  stb_i  : std_logic;
59
  cab_i  : std_logic;
60
  cti_i  : std_logic_vector(2 downto 0);
61
end record;
62
 
63
type wb_slv_out_type is record
64
  ack_o  : std_logic;                           -- data available 
65
  rty_o  : std_logic;
66
  sdat_o : std_logic_vector(31 downto 0);        -- binary data bus    
67
end record;
68
 
69
type ahbslv_state_type is (idle, strobe, respond, rty, doreturn);
70
type ahbmst_state_type is (idle, req, respond);
71
 
72
type ahbslv_reg_type is record
73
  hresp      : std_logic_vector(1 downto 0);
74
  hready     : std_logic;
75
  adr_o      : std_logic_vector(11 downto 2);
76
  hrdata     : std_logic_vector(31 downto 0);
77
  mdat_o     : std_logic_vector(31 downto 0);
78
  mdat_i     : std_logic_vector(31 downto 0);
79
  ack_i      : std_logic;
80
  rty_i      : std_logic;
81
  we_o       : std_logic;
82
  hburst     : std_logic_vector(2 downto 0);
83
  htrans     : std_logic_vector(1 downto 0);
84
end record;
85
 
86
type wb_reg_type is record
87
  stb_i     : std_logic;
88
  we_i      : std_logic;
89
  cab_o     : std_logic;
90
end record;
91
 
92
type reg_type is record
93
  ahbslv_state   : ahbslv_state_type;
94
  ahbmst_state   : ahbmst_state_type;
95
  ahbslv         : ahbslv_reg_type;
96
  wb             : wb_reg_type;
97
  burst          : std_logic;
98
  start          : std_logic;
99
  rst            : std_logic;
100
  ocrst          : std_logic;
101
end record;
102
 
103
signal r, rin : reg_type;
104
signal highbits : std_logic_vector(31 downto 0);
105
signal lowbits : std_logic_vector(31 downto 0);
106
signal occlk : std_logic;
107
signal mdio_oe : std_logic;
108
 
109
signal cbe_en : std_logic_vector(3 downto 0);
110
signal wbmi : wb_mst_in_type;
111
signal wbmo : wb_mst_out_type;
112
signal wbsi : wb_slv_in_type;
113
signal wbso : wb_slv_out_type;
114
 
115
signal dmai : ahb_dma_in_type;
116
signal dmao : ahb_dma_out_type;
117
 
118
component eth_top
119
    port (
120
 
121
--      // WISHBONE common
122
      wb_clk_i : in std_logic;
123
      wb_rst_i : in std_logic;
124
      wb_dat_i : in std_logic_vector(31 downto 0);
125
      wb_dat_o : out std_logic_vector(31 downto 0);
126
 
127
--      // WISHBONE slave
128
      wb_adr_i : in std_logic_vector(11 downto 2);
129
      wb_sel_i : in std_logic_vector(3 downto 0);
130
      wb_we_i  : in std_logic;
131
      wb_cyc_i : in std_logic;
132
      wb_stb_i : in std_logic;
133
      wb_ack_o : out std_logic;
134
      wb_err_o : out std_logic;
135
 
136
--      // WISHBONE master
137
      m_wb_adr_o : out std_logic_vector(31 downto 0);
138
      m_wb_sel_o : out std_logic_vector(3 downto 0);
139
      m_wb_we_o  : out std_logic;
140
      m_wb_dat_o : out std_logic_vector(31 downto 0);
141
      m_wb_dat_i : in std_logic_vector(31 downto 0);
142
      m_wb_cyc_o : out std_logic;
143
      m_wb_stb_o : out std_logic;
144
      m_wb_ack_i : in std_logic;
145
      m_wb_err_i : in std_logic;
146
 
147
      m_wb_cti_o : out std_logic_vector(2 downto 0);
148
      m_wb_bte_o : out std_logic_vector(1 downto 0);
149
 
150
--      //TX
151
      mtx_clk_pad_i : in std_logic;
152
      mtxd_pad_o    : out std_logic_vector(3 downto 0);
153
      mtxen_pad_o   : out std_logic;
154
      mtxerr_pad_o  : out std_logic;
155
 
156
--      //RX
157
      mrx_clk_pad_i : in std_logic;
158
      mrxd_pad_i    : in std_logic_vector(3 downto 0);
159
      mrxdv_pad_i   : in std_logic;
160
      mrxerr_pad_i  : in std_logic;
161
      mcoll_pad_i   : in std_logic;
162
      mcrs_pad_i    : in std_logic;
163
 
164
--      // MIIM
165
      mdc_pad_o  : out std_logic;
166
      md_pad_i   : in std_logic;
167
      md_pad_o   : out std_logic;
168
      md_padoe_o : out std_logic;
169
 
170
      int_o : out std_logic
171
 
172
    );
173
end component;
174
 
175
begin
176
 
177
  lowbits <= (others => '0');
178
  highbits <= (others => '1');
179
 
180
  comb: process (r, ahbsi, wbmi, rst, cbe_en, ahbmi, wbsi, dmao)
181
  variable v : reg_type;
182
  variable vstb_o, vstart, vburst : std_logic;
183
  variable vprdata : std_logic_vector(31 downto 0);
184
  variable ack_o : std_logic;
185
  begin  -- process comb
186
    v := r;
187
    vstb_o  := '0';
188
    v.ahbslv.hready := '1';
189
 
190
    case r.ahbslv_state is
191
      when idle   =>
192
        v.ahbslv.ack_i := '0';
193
        v.ahbslv.hburst := ahbsi.hburst;
194
        v.ahbslv.htrans := ahbsi.htrans;
195
        v.ahbslv.adr_o  := ahbsi.haddr(11 downto 2);
196
        if (ahbsi.hsel and ahbsi.hready and ahbsi.htrans(1)) = '1' then
197
            v.ahbslv.hready := '0';
198
            v.ahbslv_state  := strobe;
199
            v.ahbslv.we_o   := ahbsi.hwrite;
200
        end if;
201
      when strobe  =>
202
        -- emulate the old reset bit in MODER(11) of the ethernet core
203
        if r.ahbslv.adr_o = "0000000000" and (r.ahbslv.we_o = '1') then
204
          v.rst := ahbsi.hwdata(11);
205
        end if;
206
        if (r.rst or v.rst) = '1' then v.ahbslv_state := idle; else
207
          v.ahbslv_state    := respond;
208
          v.ahbslv.mdat_o   := ahbsi.hwdata;  --write specific
209
          v.ahbslv.mdat_i   := wbmi.mdat_i;
210
          vstb_o            := '1';
211
          v.ahbslv.ack_i    := wbmi.ack_i;
212
          v.ahbslv.rty_i    := wbmi.rty_i;
213
          v.ahbslv.hready   := '0';
214
          if r.ahbslv.hburst = "001" then v.wb.cab_o := '1'; end if;
215
        end if;
216
      when respond =>
217
        if r.ahbslv.ack_i = '1' then
218
          v.ahbslv_state    := idle;
219
          v.ahbslv.hrdata   := r.ahbslv.mdat_i;  --read specific
220
        elsif r.ahbslv.rty_i = '1' then
221
          v.ahbslv_state    := rty;
222
          v.ahbslv.hready   := '0';
223
          v.ahbslv.hresp    := hresp_retry;
224
        else
225
          vstb_o     := '1';              --fix
226
          v.ahbslv.hready   := '0';
227
          v.ahbslv.mdat_i   := wbmi.mdat_i;  --read specific
228
          v.ahbslv.ack_i    := wbmi.ack_i;
229
          v.ahbslv.rty_i    := wbmi.rty_i;
230
        end if;
231
        if (r.wb.cab_o = '1' and ahbsi.htrans(0) = '0') then
232
          v.wb.cab_o := '0';
233
        end if;
234
      when rty =>
235
        v.ahbslv_state  := doreturn;
236
      when doreturn =>
237
        v.ahbslv_state  := idle;
238
        v.ahbslv.hresp  := hresp_okay;
239
      when others => null;
240
    end case;
241
 
242
----------------------------------------
243
----------------------------------------
244
 
245
    v.wb.stb_i := wbsi.stb_i;
246
    v.wb.we_i := wbsi.we_i;
247
 
248
    ack_o := '0';
249
 
250
    case r.ahbmst_state is
251
      when idle =>
252
        if r.wb.stb_i = '1' then
253
          v.ahbmst_state := req;
254
          v.start := '1';
255
          if wbsi.cti_i = "010" then
256
            v.burst := '1';
257
          end if;
258
        end if;
259
      when req  =>
260
        if (wbsi.cti_i = "111" or wbsi.cti_i = "000" or
261
            wbsi.adr_i(9 downto 2) = "11111111") and dmao.start = '1'
262
        then
263
            v.burst := '0';
264
            v.start := '0';
265
        end if;
266
        if dmao.active = '1' and dmao.ready = '1'  then
267
          ack_o := '1';
268
          if v.start = '0' then v.ahbmst_state := respond; end if;
269
        end if;
270
      when respond =>
271
          v.ahbmst_state := idle;
272
      when others => null;
273
    end case;
274
 
275
    v.ocrst := r.rst or not rst;
276
 
277
    if rst = '0' then
278
      v.ahbslv_state          := idle;
279
      v.ahbslv.hresp          := hresp_okay;
280
      v.ahbslv.hready         := '1';
281
      v.ahbslv.adr_o          := (others => '0');
282
      v.ahbslv.hrdata         := (others => '0');
283
      v.ahbslv.mdat_o         := (others => '0');
284
      v.ahbslv.mdat_i         := (others => '0');
285
      v.ahbslv.ack_i          := '0';
286
      v.ahbslv.rty_i          := '0';
287
      v.ahbslv.we_o           := '0';
288
 
289
      v.ahbmst_state          := idle;
290
      v.start                 := '0';
291
      v.burst                 := '0';
292
 
293
      v.wb.cab_o      := '0';
294
      v.rst := '0';
295
 
296
    end if;
297
 
298
    wbmo.adr_o         <= r.ahbslv.adr_o;
299
    wbmo.mdat_o        <= v.ahbslv.mdat_o;
300
    wbmo.we_o          <= r.ahbslv.we_o;
301
    wbmo.stb_o         <= vstb_o;
302
    ahbso.hready       <= r.ahbslv.hready;
303
    ahbso.hresp        <= r.ahbslv.hresp;
304
    wbmo.cab_o         <= v.wb.cab_o;
305
    ahbso.hrdata       <= v.ahbslv.hrdata;
306
    ahbso.hsplit       <= (others => '0');
307
    dmai.address       <= wbsi.adr_i;
308
    dmai.wdata         <= wbsi.sdat_i;
309
    dmai.start         <= v.start;
310
    dmai.burst         <= v.burst;
311
    dmai.write         <= r.wb.we_i;
312
    dmai.size          <= "10";         -- 32 bit
313
    wbso.ack_o         <= ack_o;
314
    wbso.sdat_o        <= dmao.rdata;
315
    wbso.rty_o         <= '0';
316
 
317
    rin <= v;
318
 
319
  end process comb;
320
 
321
  regs : process(clk)
322
  begin
323
    if rising_edge(clk) then
324
      r <= rin;
325
    end if;
326
  end process;
327
 
328
  ahbmst0 : ahbmst generic map (1) port map (rst, clk, dmai, dmao, ahbmi, ahbmo);
329
 
330
  oc : eth_top port map (
331
--      // WISHBONE common
332
      wb_clk_i =>    clk ,
333
      wb_rst_i =>    r.ocrst ,
334
      wb_dat_i =>    wbmo.mdat_o ,
335
      wb_dat_o =>    wbmi.mdat_i ,
336
 
337
--      // WISHBONE slave
338
      wb_adr_i =>     wbmo.adr_o(11 downto 2),
339
      wb_sel_i =>     highbits(3 downto 0),
340
      wb_we_i  =>     wbmo.we_o,
341
      wb_cyc_i =>     highbits(0),
342
      wb_stb_i =>     wbmo.stb_o,
343
      wb_ack_o =>     wbmi.ack_i  ,
344
      wb_err_o =>     Open  ,
345
 
346
--      // WISHBONE master
347
      m_wb_adr_o =>     wbsi.adr_i,
348
      m_wb_sel_o =>     Open,
349
      m_wb_we_o  =>     wbsi.we_i,
350
      m_wb_dat_o =>     wbsi.sdat_i,
351
      m_wb_dat_i =>     wbso.sdat_o,
352
      m_wb_cyc_o =>     Open,
353
      m_wb_stb_o =>     wbsi.stb_i,
354
      m_wb_ack_i =>     wbso.ack_o,
355
      m_wb_err_i =>     lowbits(0),
356
 
357
       m_wb_cti_o =>     wbsi.cti_i,
358
       m_wb_bte_o =>     open,
359
 
360
--       //TX
361
      mtx_clk_pad_i =>     eneti.tx_clk,
362
      mtxd_pad_o    =>     eneto.txd,
363
      mtxen_pad_o   =>     eneto.tx_en,
364
      mtxerr_pad_o  =>     eneto.tx_er,
365
 
366
--      //RX
367
      mrx_clk_pad_i =>     eneti.rx_clk,
368
      mrxd_pad_i    =>     eneti.rxd,
369
      mrxdv_pad_i   =>     eneti.rx_dv,
370
      mrxerr_pad_i  =>     eneti.rx_er,
371
      mcoll_pad_i   =>     eneti.rx_col,
372
      mcrs_pad_i    =>     eneti.rx_crs,
373
 
374
--      // MIIM
375
      mdc_pad_o  =>     eneto.mdc,
376
      md_pad_i   =>     eneti.mdio_i,
377
      md_pad_o   =>     eneto.mdio_o,
378
      md_padoe_o =>     mdio_oe,
379
 
380
      int_o      =>   irq
381
 
382
     );
383
 
384
       eneto.mdio_oe <= not mdio_oe;    -- invert output enable
385
       eneto.reset   <= rst;            -- reset PHY
386
end;

powered by: WebSVN 2.1.0

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