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_mc.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_mc 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
    ncores    : integer range 1 to 8 := 1;
44
    sepirq    : integer range 0 to 1 := 0;
45
    syncrst   : integer range 0 to 1 := 0;
46
    ft        : integer range 0 to 1 := 0);
47
   port (
48
      resetn  : in  std_logic;
49
      clk     : in  std_logic;
50
      ahbsi   : in  ahb_slv_in_type;
51
      ahbso   : out ahb_slv_out_type;
52
      can_rxi : in  std_logic_vector(0 to 7);
53
      can_txo : out std_logic_vector(0 to 7)
54
   );
55
end;
56
 
57
architecture rtl of can_mc is
58
 
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
end record;
78
 
79
subtype cdata is std_logic_vector(7 downto 0);
80
type cdataarr is array (0 to 7) of cdata;
81
signal data_out : cdataarr;
82
signal reset : std_logic;
83
signal irqo : std_logic_vector(ncores-1 downto 0);
84
 
85
signal cs : std_logic_vector(7 downto 0);
86
 
87
signal vcc, gnd : std_ulogic;
88
 
89
signal r, rin : ahbregs;
90
 
91
begin
92
 
93
  gnd <= '0'; vcc <= '1'; reset <= not resetn;
94
 
95
  comb : process(ahbsi, r, resetn, data_out, irqo)
96
  variable v : ahbregs;
97
  variable hresp : std_logic_vector(1 downto 0);
98
  variable lcs, dataout : std_logic_vector(7 downto 0);
99
  variable irqvec : std_logic_vector(NAHBIRQ-1 downto 0);
100
  begin
101
 
102
    v := r;
103
    if (r.hsel = '1' ) and (r.ws /= "11") then v.ws := r.ws + 1; end if;
104
 
105
    if ahbsi.hready = '1' then
106
      v.hsel := ahbsi.hsel(slvndx);
107
      v.haddr := ahbsi.haddr(10 downto 0);
108
      v.htrans := ahbsi.htrans;
109
      v.hwrite := ahbsi.hwrite;
110
      v.herr := orv(ahbsi.hsize) and ahbsi.hwrite;
111
      v.ws := "00";
112
    end if;
113
 
114
    v.hready := (r.hsel and r.ws(1) and not r.ws(0)) or not resetn
115
        or (ahbsi.hready and not ahbsi.htrans(1)) or not v.hsel;
116
 
117
    v.hwrite2 := r.hwrite and r.hsel and r.htrans(1) and r.ws(1)
118
        and not r.ws(0) and not r.herr;
119
 
120
    if (r.herr and r.ws(1)) = '1' then hresp := HRESP_ERROR;
121
    else hresp := HRESP_OKAY; end if;
122
 
123
    case r.haddr(1 downto 0) is
124
    when "00" => v.hwdata := ahbsi.hwdata(31 downto 24);
125
    when "01" => v.hwdata := ahbsi.hwdata(23 downto 16);
126
    when "10" => v.hwdata := ahbsi.hwdata(15 downto 8);
127
    when others => v.hwdata := ahbsi.hwdata(7 downto 0);
128
    end case;
129
 
130
    if ncores > 1 then
131
      if r.hsel = '1' then lcs := decode(r.haddr(10 downto 8));
132
      else lcs := (others => '0'); end if;
133
      dataout := data_out(conv_integer(r.haddr(10 downto 8)));
134
    else dataout := data_out(0); lcs := "0000000" & r.hsel; end if;
135
 
136
    -- Interrupt goes to low when appeard and is normal high
137
    -- but the irq controller from leon is active high and the interrupt should appear only
138
    -- for 1 Clk cycle,
139
 
140
    v.irqi := irqo; v.irqo:= (r.irqi and not irqo);
141
    irqvec := (others => '0');
142
    if sepirq = 1 then irqvec(ncores-1+irq downto irq) := r.irqo;
143
    else irqvec(irq) := orv(r.irqo); end if;
144
 
145
    ahbso.hirq <= irqvec;
146
    ahbso.hrdata  <= dataout & dataout & dataout & dataout;
147
    cs <= lcs;
148
    ahbso.hresp <= hresp; rin <= v;
149
 
150
  end process;
151
 
152
  reg : process(clk)
153
  begin if clk'event and clk = '1' then r <= rin; end if; end process;
154
 
155
  cgen : for i in 0 to ncores-1 generate
156
   c0 : if i < ncores generate
157
      cmod : can_mod generic map (memtech, syncrst, ft)
158
      port map (reset, clk, cs(i), r.hwrite2, r.haddr(7 downto 0), r.hwdata,
159
        data_out(i), irqo(i), can_rxi(i), can_txo(i), ahbsi.testen);
160
   end generate;
161
   c1 : if i >= ncores generate
162
      can_txo(i) <= '0'; data_out(i) <= (others => '0'); irqo(i) <= '1';
163
   end generate;
164
  end generate;
165
 
166
    ahbso.hconfig <= hconfig;
167
    ahbso.hindex  <= slvndx;
168
    ahbso.hsplit  <= (others => '0');
169
    ahbso.hcache  <= '0';
170
    ahbso.hready  <= r.hready;
171
 
172
 
173
-- pragma translate_off
174
  bootmsg : report_version
175
  generic map (
176
        "can_oc" & tost(slvndx) &
177
        ": SJA1000 Compatible CAN MAC, #cores " & tost(REVISION+1) & ", irq " & tost(irq));
178
-- pragma translate_on
179
 
180
end;

powered by: WebSVN 2.1.0

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