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_oc.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_oc 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
    ft        : 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;
51
      can_txo : out std_logic
52
   );
53
end;
54
 
55
architecture rtl of can_oc 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
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 vcc, gnd : std_ulogic;
86
 
87
signal r, rin : ahbregs;
88
 
89
begin
90
 
91
  gnd <= '0'; vcc <= '1'; reset <= not resetn;
92
 
93
  comb : process(ahbsi, r, resetn, data_out, irqo)
94
  variable v : ahbregs;
95
  variable hresp : std_logic_vector(1 downto 0);
96
  variable dataout : std_logic_vector(7 downto 0);
97
  variable irqvec : std_logic_vector(NAHBIRQ-1 downto 0);
98
  begin
99
 
100
    v := r;
101
    if (r.hsel = '1' ) and (r.ws /= "11") then v.ws := r.ws + 1; end if;
102
 
103
    if ahbsi.hready = '1' then
104
      v.hsel := ahbsi.hsel(slvndx);
105
      v.haddr := ahbsi.haddr(10 downto 0);
106
      v.htrans := ahbsi.htrans;
107
      v.hwrite := ahbsi.hwrite;
108
      v.herr := orv(ahbsi.hsize) and ahbsi.hwrite;
109
      v.ws := "00";
110
    end if;
111
 
112
    v.hready := (r.hsel and r.ws(1) and not r.ws(0)) or not resetn
113
        or (ahbsi.hready and not ahbsi.htrans(1)) or not v.hsel;
114
 
115
    v.hwrite2 := r.hwrite and r.hsel and r.htrans(1) and r.ws(1)
116
        and not r.ws(0) and not r.herr;
117
 
118
    if (r.herr and r.ws(1)) = '1' then hresp := HRESP_ERROR;
119
    else hresp := HRESP_OKAY; end if;
120
 
121
    case r.haddr(1 downto 0) is
122
    when "00" => v.hwdata := ahbsi.hwdata(31 downto 24);
123
    when "01" => v.hwdata := ahbsi.hwdata(23 downto 16);
124
    when "10" => v.hwdata := ahbsi.hwdata(15 downto 8);
125
    when others => v.hwdata := ahbsi.hwdata(7 downto 0);
126
    end case;
127
 
128
    dataout := data_out(0);
129
 
130
    -- Interrupt goes to low when appeard and is normal high
131
    -- but the irq controller from leon is active high and the interrupt should appear only
132
    -- for 1 Clk cycle,
133
 
134
    v.irqi := irqo; v.irqo:= (r.irqi and not irqo);
135
    irqvec := (others => '0');
136
    if sepirq = 1 then irqvec(ncores-1+irq downto irq) := r.irqo;
137
    else irqvec(irq) := orv(r.irqo); end if;
138
 
139
    ahbso.hirq <= irqvec;
140
    ahbso.hrdata  <= dataout & dataout & dataout & dataout;
141
    ahbso.hresp <= hresp; rin <= v;
142
 
143
  end process;
144
 
145
  reg : process(clk)
146
  begin if clk'event and clk = '1' then r <= rin; end if; end process;
147
 
148
  cmod : can_mod generic map (memtech, syncrst, ft)
149
    port map (reset, clk, r.hsel, r.hwrite2, r.haddr(7 downto 0), r.hwdata,
150
        data_out(0), irqo(0), can_rxi, can_txo, ahbsi.testen);
151
 
152
    ahbso.hconfig <= hconfig;
153
    ahbso.hindex  <= slvndx;
154
    ahbso.hsplit  <= (others => '0');
155
    ahbso.hcache  <= '0';
156
    ahbso.hready  <= r.hready;
157
 
158
 
159
-- pragma translate_off
160
  bootmsg : report_version
161
  generic map (
162
        "can_oc" & tost(slvndx) &
163
        ": SJA1000 Compatible CAN MAC, revision " & tost(REVISION) &
164
        ", irq " & tost(irq));
165
-- pragma translate_on
166
 
167
end;

powered by: WebSVN 2.1.0

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