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/] [gaisler/] [can/] [can_rd.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
-----------------------------------------------------------------------------   
19
-- Entity:      can_oc
20
-- File:        can_oc.vhd
21
-- Author:      Jiri Gaisler - Gaisler Research
22
-- Description: AHB interface for the OpenCores CAN MAC
23
------------------------------------------------------------------------------ 
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
library grlib;
28
use grlib.amba.all;
29
use grlib.stdlib.all;
30
use grlib.devices.all;
31
library techmap;
32
use techmap.gencomp.all;
33
library gaisler;
34
use gaisler.can.all;
35
 
36
entity can_rd is
37
   generic (
38
    slvndx    : integer := 0;
39
    ioaddr    : integer := 16#000#;
40
    iomask    : integer := 16#FF0#;
41
    irq       : integer := 0;
42
    memtech   : integer := DEFMEMTECH;
43
    syncrst   : integer := 0;
44
    dmap      : integer := 0);
45
   port (
46
      resetn  : in  std_logic;
47
      clk     : in  std_logic;
48
      ahbsi   : in  ahb_slv_in_type;
49
      ahbso   : out ahb_slv_out_type;
50
      can_rxi : in  std_logic_vector(1 downto 0);
51
      can_txo : out std_logic_vector(1 downto 0)
52
   );
53
end;
54
 
55
architecture rtl of can_rd is
56
 
57
constant ncores : integer := 1;
58
constant sepirq : integer := 0;
59
constant REVISION : amba_version_type := ncores-1;
60
 
61
constant hconfig : ahb_config_type := (
62
 
63
  4 => ahb_iobar(ioaddr, iomask), others => zero32);
64
 
65
type ahbregs is record
66
  hsel      : std_ulogic;
67
  hwrite    : std_ulogic;
68
  hwrite2   : std_ulogic;
69
  htrans    : std_logic_vector(1 downto 0);
70
  haddr     : std_logic_vector(10 downto 0);
71
  hwdata    : std_logic_vector(7 downto 0);
72
  herr      : std_ulogic;
73
  hready    : std_ulogic;
74
  ws        : std_logic_vector(1 downto 0);
75
  irqi      : std_logic_vector(ncores-1 downto 0);
76
  irqo      : std_logic_vector(ncores-1 downto 0);
77
  muxsel    : std_logic;
78
  writemux  : std_logic;
79
end record;
80
 
81
subtype cdata is std_logic_vector(7 downto 0);
82
type cdataarr is array (0 to 7) of cdata;
83
signal data_out : cdataarr;
84
signal reset : std_logic;
85
signal irqo : std_logic_vector(ncores-1 downto 0);
86
signal addr : std_logic_vector(7 downto 0);
87
 
88
signal vcc, gnd : std_ulogic;
89
 
90
signal r, rin : ahbregs;
91
signal can_lrxi, can_ltxo : std_logic;
92
begin
93
 
94
  gnd <= '0'; vcc <= '1'; reset <= not resetn;
95
 
96
  comb : process(ahbsi, r, resetn, data_out, irqo)
97
  variable v : ahbregs;
98
  variable hresp : std_logic_vector(1 downto 0);
99
  variable dataout : std_logic_vector(7 downto 0);
100
  variable irqvec : std_logic_vector(NAHBIRQ-1 downto 0);
101
  variable vmuxreg : std_logic;
102
  begin
103
 
104
    v := r;
105
    if (r.hsel = '1' ) and (r.ws /= "11") then v.ws := r.ws + 1; end if;
106
 
107
    if ahbsi.hready = '1' then
108
      v.hsel := ahbsi.hsel(slvndx);
109
      v.haddr := ahbsi.haddr(10 downto 0);
110
      v.htrans := ahbsi.htrans;
111
      v.hwrite := ahbsi.hwrite;
112
      v.herr := orv(ahbsi.hsize) and ahbsi.hwrite;
113
      v.ws := "00";
114
    end if;
115
 
116
    v.hready := (r.hsel and r.ws(1) and not r.ws(0)) or not resetn
117
        or (ahbsi.hready and not ahbsi.htrans(1));
118
 
119
    vmuxreg := not r.haddr(7) and r.haddr(6);
120
 
121
    --v.hwrite2 := r.hwrite and r.hsel and r.htrans(1) and r.ws(1) 
122
--      and not r.ws(0) and not r.herr;
123
    v.hwrite2 := r.hwrite and r.hsel and r.htrans(1) and r.ws(1)
124
        and not r.ws(0) and not r.herr and not vmuxreg;
125
    v.writemux := r.hwrite and r.hsel and r.htrans(1) and r.ws(1)
126
        and not r.ws(0) and vmuxreg;
127
 
128
    if (r.herr and r.ws(1)) = '1' then hresp := HRESP_ERROR;
129
    else hresp := HRESP_OKAY; end if;
130
 
131
    case r.haddr(1 downto 0) is
132
    when "00" => v.hwdata := ahbsi.hwdata(31 downto 24);
133
    when "01" => v.hwdata := ahbsi.hwdata(23 downto 16);
134
    when "10" => v.hwdata := ahbsi.hwdata(15 downto 8);
135
    when others => v.hwdata := ahbsi.hwdata(7 downto 0);
136
    end case;
137
 
138
    --dataout := data_out(0);
139
    if r.haddr(7 downto 6) = "01" then
140
       dataout := (others => r.muxsel);
141
       if r.writemux = '1' then
142
          v.muxsel := r.hwdata(0);
143
       end if;
144
    else
145
       dataout := data_out(0);
146
    end if;
147
 
148
    -- Interrupt goes to low when appeard and is normal high
149
    -- but the irq controller from leon is active high and the interrupt should appear only
150
    -- for 1 Clk cycle,
151
 
152
    v.irqi := irqo; v.irqo:= (r.irqi and not irqo);
153
    irqvec := (others => '0');
154
    if sepirq = 1 then irqvec(ncores-1+irq downto irq) := r.irqo;
155
    else irqvec(irq) := orv(r.irqo); end if;
156
 
157
 
158
    ahbso.hirq <= irqvec;
159
    ahbso.hrdata  <= dataout & dataout & dataout & dataout;
160
    ahbso.hresp <= hresp; rin <= v;
161
 
162
  end process;
163
 
164
  -- Double mapping of registers [byte (offset 0), word (offset 0x80)]
165
  dmap0 : if dmap = 0 generate
166
    addr <= r.haddr(7 downto 0);
167
  end generate;
168
  dmap1 : if dmap = 1 generate
169
    addr <= "000"&r.haddr(6 downto 2) when r.haddr(7) = '1' else
170
            r.haddr(7 downto 0);
171
  end generate;
172
 
173
  reg : process(clk)
174
  begin if clk'event and clk = '1' then r <= rin; end if; end process;
175
 
176
  cmod : can_mod generic map (memtech, syncrst)
177
    --port map (reset, clk, r.hsel, r.hwrite2, r.haddr(7 downto 0), r.hwdata, 
178
    port map (reset, clk, r.hsel, r.hwrite2, addr, r.hwdata,
179
        data_out(0), irqo(0), can_lrxi, can_ltxo, ahbsi.testen);
180
 
181
  cmux : canmux port map (r.muxsel, can_lrxi, can_ltxo, can_rxi, can_txo);
182
 
183
    ahbso.hconfig <= hconfig;
184
    ahbso.hindex  <= slvndx;
185
    ahbso.hsplit  <= (others => '0');
186
    ahbso.hcache  <= '0';
187
    ahbso.hready  <= r.hready;
188
 
189
 
190
-- pragma translate_off
191
  bootmsg : report_version
192
  generic map (
193
        "can_oc" & tost(slvndx) &
194
        ": SJA1000 Compatible CAN MAC, revision " & tost(REVISION) &
195
        ", irq " & tost(irq));
196
-- pragma translate_on
197
 
198
end;

powered by: WebSVN 2.1.0

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