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: pciahbmst
|
20 |
|
|
-- File: pciahbmst.vhd
|
21 |
|
|
-- Author: Jiri Gaisler - Gaisler Research
|
22 |
|
|
-- Description: Generic AHB master interface
|
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 gaisler;
|
32 |
|
|
use gaisler.misc.all;
|
33 |
|
|
|
34 |
|
|
entity pciahbmst is
|
35 |
|
|
generic (
|
36 |
|
|
hindex : integer := 0;
|
37 |
|
|
hirq : integer := 0;
|
38 |
|
|
venid : integer := VENDOR_GAISLER;
|
39 |
|
|
devid : integer := 0;
|
40 |
|
|
version : integer := 0;
|
41 |
|
|
chprot : integer := 3;
|
42 |
|
|
incaddr : integer := 0);
|
43 |
|
|
port (
|
44 |
|
|
rst : in std_ulogic;
|
45 |
|
|
clk : in std_ulogic;
|
46 |
|
|
dmai : in ahb_dma_in_type;
|
47 |
|
|
dmao : out ahb_dma_out_type;
|
48 |
|
|
ahbi : in ahb_mst_in_type;
|
49 |
|
|
ahbo : out ahb_mst_out_type
|
50 |
|
|
);
|
51 |
|
|
end;
|
52 |
|
|
|
53 |
|
|
architecture rtl of pciahbmst is
|
54 |
|
|
|
55 |
|
|
constant hconfig : ahb_config_type := (
|
56 |
|
|
|
57 |
|
|
others => zero32);
|
58 |
|
|
|
59 |
|
|
type reg_type is record
|
60 |
|
|
start : std_ulogic;
|
61 |
|
|
retry : std_ulogic;
|
62 |
|
|
grant : std_ulogic;
|
63 |
|
|
active : std_ulogic;
|
64 |
|
|
end record;
|
65 |
|
|
|
66 |
|
|
signal r, rin : reg_type;
|
67 |
|
|
|
68 |
|
|
begin
|
69 |
|
|
|
70 |
|
|
comb : process(ahbi, dmai, rst, r)
|
71 |
|
|
variable v : reg_type;
|
72 |
|
|
variable ready : std_ulogic;
|
73 |
|
|
variable retry : std_ulogic;
|
74 |
|
|
variable mexc : std_ulogic;
|
75 |
|
|
variable inc : std_logic_vector(3 downto 0); -- address increment
|
76 |
|
|
|
77 |
|
|
variable haddr : std_logic_vector(31 downto 0); -- AHB address
|
78 |
|
|
variable hwdata : std_logic_vector(31 downto 0); -- AHB write data
|
79 |
|
|
variable htrans : std_logic_vector(1 downto 0); -- transfer type
|
80 |
|
|
variable hwrite : std_ulogic; -- read/write
|
81 |
|
|
variable hburst : std_logic_vector(2 downto 0); -- burst type
|
82 |
|
|
variable newaddr : std_logic_vector(10 downto 0); -- next sequential address
|
83 |
|
|
variable hbusreq : std_ulogic; -- bus request
|
84 |
|
|
variable hprot : std_logic_vector(3 downto 0); -- transfer type
|
85 |
|
|
variable xhirq : std_logic_vector(NAHBIRQ-1 downto 0);
|
86 |
|
|
variable kblimit : std_logic; -- 1 kB limit indicator
|
87 |
|
|
begin
|
88 |
|
|
|
89 |
|
|
v := r; ready := '0'; mexc := '0'; retry := '0'; inc := (others => '0');
|
90 |
|
|
hprot := conv_std_logic_vector(chprot, 4); -- non-cached supervisor data
|
91 |
|
|
xhirq := (others => '0'); xhirq(hirq) := dmai.irq; kblimit := '0';
|
92 |
|
|
|
93 |
|
|
haddr := dmai.address; hbusreq := dmai.start; hwdata := dmai.wdata;
|
94 |
|
|
newaddr := dmai.address(10 downto 0);
|
95 |
|
|
|
96 |
|
|
if INCADDR > 0 then
|
97 |
|
|
inc(conv_integer(dmai.size)) := '1';
|
98 |
|
|
newaddr := haddr(10 downto 0) + inc;
|
99 |
|
|
if (newaddr(10) xor haddr(10)) = '1' then kblimit := '1'; end if;
|
100 |
|
|
end if;
|
101 |
|
|
|
102 |
|
|
-- hburst := HBURST_SINGLE;
|
103 |
|
|
if dmai.burst = '0' then hburst := HBURST_SINGLE;
|
104 |
|
|
else hburst := HBURST_INCR; end if;
|
105 |
|
|
|
106 |
|
|
if dmai.start = '1' then
|
107 |
|
|
-- hburst := HBURST_INCR;
|
108 |
|
|
if (r.active and dmai.burst and not r.retry) = '1' then
|
109 |
|
|
haddr(9 downto 0) := newaddr(9 downto 0);
|
110 |
|
|
if dmai.busy = '1' then htrans := HTRANS_BUSY;
|
111 |
|
|
elsif kblimit = '1' then htrans := HTRANS_IDLE;
|
112 |
|
|
else htrans := HTRANS_SEQ; end if;
|
113 |
|
|
else htrans := HTRANS_NONSEQ; end if;
|
114 |
|
|
else htrans := HTRANS_IDLE; end if;
|
115 |
|
|
|
116 |
|
|
if r.active = '1' then
|
117 |
|
|
if ahbi.hready = '1' then
|
118 |
|
|
case ahbi.hresp is
|
119 |
|
|
when HRESP_OKAY => ready := '1';
|
120 |
|
|
when HRESP_RETRY | HRESP_SPLIT=> retry := '1';
|
121 |
|
|
when others => ready := '1'; mexc := '1';
|
122 |
|
|
end case;
|
123 |
|
|
end if;
|
124 |
|
|
if ((ahbi.hresp = HRESP_RETRY) or (ahbi.hresp = HRESP_SPLIT)) then
|
125 |
|
|
v.retry := not ahbi.hready;
|
126 |
|
|
else v.retry := '0'; end if;
|
127 |
|
|
end if;
|
128 |
|
|
|
129 |
|
|
if r.retry = '1' then htrans := HTRANS_IDLE; end if;
|
130 |
|
|
|
131 |
|
|
v.start := '0';
|
132 |
|
|
if ahbi.hready = '1' then
|
133 |
|
|
v.grant := ahbi.hgrant(hindex);
|
134 |
|
|
if (htrans = HTRANS_NONSEQ) or (htrans = HTRANS_SEQ) or (htrans = HTRANS_BUSY) then
|
135 |
|
|
v.active := r.grant; v.start := r.grant;
|
136 |
|
|
else
|
137 |
|
|
v.active := '0';
|
138 |
|
|
end if;
|
139 |
|
|
end if;
|
140 |
|
|
|
141 |
|
|
if rst = '0' then v.retry := '0'; v.active := '0'; end if;
|
142 |
|
|
|
143 |
|
|
rin <= v;
|
144 |
|
|
|
145 |
|
|
ahbo.haddr <= haddr;
|
146 |
|
|
ahbo.htrans <= htrans;
|
147 |
|
|
ahbo.hbusreq <= hbusreq;
|
148 |
|
|
ahbo.hwdata <= dmai.wdata;
|
149 |
|
|
ahbo.hconfig <= hconfig;
|
150 |
|
|
ahbo.hlock <= '0';
|
151 |
|
|
ahbo.hwrite <= dmai.write;
|
152 |
|
|
ahbo.hsize <= '0' & dmai.size;
|
153 |
|
|
ahbo.hburst <= hburst;
|
154 |
|
|
ahbo.hprot <= hprot;
|
155 |
|
|
ahbo.hirq <= xhirq;
|
156 |
|
|
ahbo.hindex <= hindex;
|
157 |
|
|
|
158 |
|
|
dmao.start <= r.start;
|
159 |
|
|
dmao.active <= r.active;
|
160 |
|
|
dmao.ready <= ready;
|
161 |
|
|
dmao.mexc <= mexc;
|
162 |
|
|
dmao.retry <= retry;
|
163 |
|
|
dmao.haddr <= newaddr(9 downto 0);
|
164 |
|
|
dmao.rdata <= ahbi.hrdata;
|
165 |
|
|
|
166 |
|
|
end process;
|
167 |
|
|
|
168 |
|
|
regs : process(clk)
|
169 |
|
|
begin if rising_edge(clk) then r <= rin; end if; end process;
|
170 |
|
|
|
171 |
|
|
end;
|