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 |
|
|
-- Package: amba
|
20 |
|
|
-- File: amba.vhd
|
21 |
|
|
-- Author: Jiri Gaisler, Gaisler Research
|
22 |
|
|
-- Description: AMBA 2.0 bus signal definitions + support for plug&play
|
23 |
|
|
------------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
library ieee;
|
26 |
|
|
use ieee.std_logic_1164.all;
|
27 |
|
|
use ieee.numeric_std.all;
|
28 |
|
|
-- pragma translate_off
|
29 |
|
|
use std.textio.all;
|
30 |
|
|
-- pragma translate_on
|
31 |
|
|
library grlib;
|
32 |
|
|
use grlib.stdlib.all;
|
33 |
|
|
|
34 |
|
|
package amba is
|
35 |
|
|
|
36 |
|
|
constant NAHBMST : integer := 16; -- maximum AHB masters
|
37 |
|
|
constant NAHBSLV : integer := 16; -- maximum AHB slaves
|
38 |
|
|
constant NAPBSLV : integer := 16; -- maximum APB slaves
|
39 |
|
|
constant NAHBIRQ : integer := 32; -- maximum interrupts
|
40 |
|
|
constant NAHBAMR : integer := 4; -- maximum address mapping registers
|
41 |
|
|
constant NAHBIR : integer := 4; -- maximum AHB identification registers
|
42 |
|
|
constant NAHBCFG : integer := NAHBIR + NAHBAMR; -- words in AHB config block
|
43 |
|
|
constant NAPBIR : integer := 1; -- maximum APB configuration words
|
44 |
|
|
constant NAPBAMR : integer := 1; -- maximum APB configuration words
|
45 |
|
|
constant NAPBCFG : integer := NAPBIR + NAPBAMR; -- words in APB config block
|
46 |
|
|
constant NBUS : integer := 4;
|
47 |
|
|
|
48 |
|
|
subtype amba_config_word is std_logic_vector(31 downto 0);
|
49 |
|
|
type ahb_config_type is array (0 to NAHBCFG-1) of amba_config_word;
|
50 |
|
|
type apb_config_type is array (0 to NAPBCFG-1) of amba_config_word;
|
51 |
|
|
|
52 |
|
|
-- AHB master inputs
|
53 |
|
|
type ahb_mst_in_type is record
|
54 |
|
|
hgrant : std_logic_vector(0 to NAHBMST-1); -- bus grant
|
55 |
|
|
hready : std_ulogic; -- transfer done
|
56 |
|
|
hresp : std_logic_vector(1 downto 0); -- response type
|
57 |
|
|
hrdata : std_logic_vector(31 downto 0); -- read data bus
|
58 |
|
|
hcache : std_ulogic; -- cacheable
|
59 |
|
|
hirq : std_logic_vector(NAHBIRQ-1 downto 0); -- interrupt result bus
|
60 |
|
|
testen : std_ulogic; -- scan test enable
|
61 |
|
|
testrst : std_ulogic; -- scan test reset
|
62 |
|
|
scanen : std_ulogic; -- scan enable
|
63 |
|
|
testoen : std_ulogic; -- test output enable
|
64 |
|
|
end record;
|
65 |
|
|
|
66 |
|
|
-- AHB master outputs
|
67 |
|
|
type ahb_mst_out_type is record
|
68 |
|
|
hbusreq : std_ulogic; -- bus request
|
69 |
|
|
hlock : std_ulogic; -- lock request
|
70 |
|
|
htrans : std_logic_vector(1 downto 0); -- transfer type
|
71 |
|
|
haddr : std_logic_vector(31 downto 0); -- address bus (byte)
|
72 |
|
|
hwrite : std_ulogic; -- read/write
|
73 |
|
|
hsize : std_logic_vector(2 downto 0); -- transfer size
|
74 |
|
|
hburst : std_logic_vector(2 downto 0); -- burst type
|
75 |
|
|
hprot : std_logic_vector(3 downto 0); -- protection control
|
76 |
|
|
hwdata : std_logic_vector(31 downto 0); -- write data bus
|
77 |
|
|
hirq : std_logic_vector(NAHBIRQ-1 downto 0); -- interrupt bus
|
78 |
|
|
hconfig : ahb_config_type; -- memory access reg.
|
79 |
|
|
hindex : integer range 0 to NAHBMST-1; -- diagnostic use only
|
80 |
|
|
end record;
|
81 |
|
|
|
82 |
|
|
-- AHB slave inputs
|
83 |
|
|
type ahb_slv_in_type is record
|
84 |
|
|
hsel : std_logic_vector(0 to NAHBSLV-1); -- slave select
|
85 |
|
|
haddr : std_logic_vector(31 downto 0); -- address bus (byte)
|
86 |
|
|
hwrite : std_ulogic; -- read/write
|
87 |
|
|
htrans : std_logic_vector(1 downto 0); -- transfer type
|
88 |
|
|
hsize : std_logic_vector(2 downto 0); -- transfer size
|
89 |
|
|
hburst : std_logic_vector(2 downto 0); -- burst type
|
90 |
|
|
hwdata : std_logic_vector(31 downto 0); -- write data bus
|
91 |
|
|
hprot : std_logic_vector(3 downto 0); -- protection control
|
92 |
|
|
hready : std_ulogic; -- transfer done
|
93 |
|
|
hmaster : std_logic_vector(3 downto 0); -- current master
|
94 |
|
|
hmastlock : std_ulogic; -- locked access
|
95 |
|
|
hmbsel : std_logic_vector(0 to NAHBAMR-1); -- memory bank select
|
96 |
|
|
hcache : std_ulogic; -- cacheable
|
97 |
|
|
hirq : std_logic_vector(NAHBIRQ-1 downto 0); -- interrupt result bus
|
98 |
|
|
testen : std_ulogic; -- scan test enable
|
99 |
|
|
testrst : std_ulogic; -- scan test reset
|
100 |
|
|
scanen : std_ulogic; -- scan enable
|
101 |
|
|
testoen : std_ulogic; -- test output enable
|
102 |
|
|
end record;
|
103 |
|
|
|
104 |
|
|
-- AHB slave outputs
|
105 |
|
|
type ahb_slv_out_type is record
|
106 |
|
|
hready : std_ulogic; -- transfer done
|
107 |
|
|
hresp : std_logic_vector(1 downto 0); -- response type
|
108 |
|
|
hrdata : std_logic_vector(31 downto 0); -- read data bus
|
109 |
|
|
hsplit : std_logic_vector(15 downto 0); -- split completion
|
110 |
|
|
hcache : std_ulogic; -- cacheable
|
111 |
|
|
hirq : std_logic_vector(NAHBIRQ-1 downto 0); -- interrupt bus
|
112 |
|
|
hconfig : ahb_config_type; -- memory access reg.
|
113 |
|
|
hindex : integer range 0 to NAHBSLV-1; -- diagnostic use only
|
114 |
|
|
end record;
|
115 |
|
|
|
116 |
|
|
-- array types
|
117 |
|
|
type ahb_mst_out_vector_type is array (natural range <>) of ahb_mst_out_type;
|
118 |
|
|
type ahb_slv_out_vector_type is array (natural range <>) of ahb_slv_out_type;
|
119 |
|
|
subtype ahb_mst_out_vector is ahb_mst_out_vector_type(NAHBMST-1 downto 0);
|
120 |
|
|
subtype ahb_slv_out_vector is ahb_slv_out_vector_type(NAHBSLV-1 downto 0);
|
121 |
|
|
type ahb_mst_out_bus_vector is array (0 to NBUS-1) of ahb_mst_out_vector;
|
122 |
|
|
type ahb_slv_out_bus_vector is array (0 to NBUS-1) of ahb_slv_out_vector;
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
-- constants
|
126 |
|
|
constant HTRANS_IDLE: std_logic_vector(1 downto 0) := "00";
|
127 |
|
|
constant HTRANS_BUSY: std_logic_vector(1 downto 0) := "01";
|
128 |
|
|
constant HTRANS_NONSEQ: std_logic_vector(1 downto 0) := "10";
|
129 |
|
|
constant HTRANS_SEQ: std_logic_vector(1 downto 0) := "11";
|
130 |
|
|
|
131 |
|
|
constant HBURST_SINGLE: std_logic_vector(2 downto 0) := "000";
|
132 |
|
|
constant HBURST_INCR: std_logic_vector(2 downto 0) := "001";
|
133 |
|
|
constant HBURST_WRAP4: std_logic_vector(2 downto 0) := "010";
|
134 |
|
|
constant HBURST_INCR4: std_logic_vector(2 downto 0) := "011";
|
135 |
|
|
constant HBURST_WRAP8: std_logic_vector(2 downto 0) := "100";
|
136 |
|
|
constant HBURST_INCR8: std_logic_vector(2 downto 0) := "101";
|
137 |
|
|
constant HBURST_WRAP16: std_logic_vector(2 downto 0) := "110";
|
138 |
|
|
constant HBURST_INCR16: std_logic_vector(2 downto 0) := "111";
|
139 |
|
|
|
140 |
|
|
constant HSIZE_BYTE: std_logic_vector(2 downto 0) := "000";
|
141 |
|
|
constant HSIZE_HWORD: std_logic_vector(2 downto 0) := "001";
|
142 |
|
|
constant HSIZE_WORD: std_logic_vector(2 downto 0) := "010";
|
143 |
|
|
constant HSIZE_DWORD: std_logic_vector(2 downto 0) := "011";
|
144 |
|
|
constant HSIZE_4WORD: std_logic_vector(2 downto 0) := "100";
|
145 |
|
|
constant HSIZE_8WORD: std_logic_vector(2 downto 0) := "101";
|
146 |
|
|
constant HSIZE_16WORD: std_logic_vector(2 downto 0) := "110";
|
147 |
|
|
constant HSIZE_32WORD: std_logic_vector(2 downto 0) := "111";
|
148 |
|
|
|
149 |
|
|
constant HRESP_OKAY: std_logic_vector(1 downto 0) := "00";
|
150 |
|
|
constant HRESP_ERROR: std_logic_vector(1 downto 0) := "01";
|
151 |
|
|
constant HRESP_RETRY: std_logic_vector(1 downto 0) := "10";
|
152 |
|
|
constant HRESP_SPLIT: std_logic_vector(1 downto 0) := "11";
|
153 |
|
|
|
154 |
|
|
-- APB slave inputs
|
155 |
|
|
type apb_slv_in_type is record
|
156 |
|
|
psel : std_logic_vector(0 to NAPBSLV-1); -- slave select
|
157 |
|
|
penable : std_ulogic; -- strobe
|
158 |
|
|
paddr : std_logic_vector(31 downto 0); -- address bus (byte)
|
159 |
|
|
pwrite : std_ulogic; -- write
|
160 |
|
|
pwdata : std_logic_vector(31 downto 0); -- write data bus
|
161 |
|
|
pirq : std_logic_vector(NAHBIRQ-1 downto 0); -- interrupt result bus
|
162 |
|
|
testen : std_ulogic; -- scan test enable
|
163 |
|
|
testrst : std_ulogic; -- scan test reset
|
164 |
|
|
scanen : std_ulogic; -- scan enable
|
165 |
|
|
testoen : std_ulogic; -- test output enable
|
166 |
|
|
end record;
|
167 |
|
|
|
168 |
|
|
-- APB slave outputs
|
169 |
|
|
type apb_slv_out_type is record
|
170 |
|
|
prdata : std_logic_vector(31 downto 0); -- read data bus
|
171 |
|
|
pirq : std_logic_vector(NAHBIRQ-1 downto 0); -- interrupt bus
|
172 |
|
|
pconfig : apb_config_type; -- memory access reg.
|
173 |
|
|
pindex : integer range 0 to NAPBSLV -1; -- diag use only
|
174 |
|
|
end record;
|
175 |
|
|
|
176 |
|
|
-- array types
|
177 |
|
|
type apb_slv_out_vector is array (0 to NAPBSLV-1) of apb_slv_out_type;
|
178 |
|
|
|
179 |
|
|
-- support for plug&play configuration
|
180 |
|
|
|
181 |
|
|
constant AMBA_CONFIG_VER0 : std_logic_vector(1 downto 0) := "00";
|
182 |
|
|
|
183 |
|
|
subtype amba_vendor_type is integer range 0 to 16#ff#;
|
184 |
|
|
subtype amba_device_type is integer range 0 to 16#3ff#;
|
185 |
|
|
subtype amba_version_type is integer range 0 to 16#3f#;
|
186 |
|
|
subtype amba_cfgver_type is integer range 0 to 3;
|
187 |
|
|
subtype amba_irq_type is integer range 0 to NAHBIRQ-1;
|
188 |
|
|
subtype ahb_addr_type is integer range 0 to 16#fff#;
|
189 |
|
|
constant zx : std_logic_vector(31 downto 0) := (others => '0');
|
190 |
|
|
constant zxirq : std_logic_vector(NAHBIRQ-1 downto 0) := (others => '0');
|
191 |
|
|
constant zy : std_logic_vector(0 to 31) := (others => '0');
|
192 |
|
|
|
193 |
|
|
constant apb_none : apb_slv_out_type :=
|
194 |
|
|
(zx, zxirq(NAHBIRQ-1 downto 0), (others => zx), 0);
|
195 |
|
|
constant ahbm_none : ahb_mst_out_type := ( '0', '0', "00", zx,
|
196 |
|
|
'0', "000", "000", "0000", zx, zxirq(NAHBIRQ-1 downto 0), (others => zx), 0);
|
197 |
|
|
constant ahbs_none : ahb_slv_out_type := (
|
198 |
|
|
'1', "00", zx, zx(15 downto 0), '0', zxirq(NAHBIRQ-1 downto 0), (others => zx), 0);
|
199 |
|
|
constant ahbs_in_none : ahb_slv_in_type := (
|
200 |
|
|
zy(0 to NAHBSLV-1), zx, '0', "00", "000", "000", zx,
|
201 |
|
|
"0000", '1', "0000", '0', zy(0 to NAHBAMR-1), '0', zxirq(NAHBIRQ-1 downto 0),
|
202 |
|
|
'0', '0', '0', '0');
|
203 |
|
|
|
204 |
|
|
constant ahbsv_none : ahb_slv_out_vector := (others => ahbs_none);
|
205 |
|
|
|
206 |
|
|
function ahb_device_reg(vendor : amba_vendor_type; device : amba_device_type;
|
207 |
|
|
cfgver : amba_cfgver_type; version : amba_version_type;
|
208 |
|
|
interrupt : amba_irq_type)
|
209 |
|
|
return std_logic_vector;
|
210 |
|
|
|
211 |
|
|
function ahb_membar(memaddr : ahb_addr_type; prefetch, cache : std_ulogic;
|
212 |
|
|
addrmask : ahb_addr_type)
|
213 |
|
|
return std_logic_vector;
|
214 |
|
|
|
215 |
|
|
function ahb_membar_opt(memaddr : ahb_addr_type; prefetch, cache : std_ulogic;
|
216 |
|
|
addrmask : ahb_addr_type; enable : integer)
|
217 |
|
|
return std_logic_vector;
|
218 |
|
|
|
219 |
|
|
function ahb_iobar(memaddr : ahb_addr_type; addrmask : ahb_addr_type)
|
220 |
|
|
return std_logic_vector;
|
221 |
|
|
|
222 |
|
|
function apb_iobar(memaddr : ahb_addr_type; addrmask : ahb_addr_type)
|
223 |
|
|
return std_logic_vector;
|
224 |
|
|
|
225 |
|
|
function ahb_slv_dec_cache(haddr : std_logic_vector(31 downto 0);
|
226 |
|
|
ahbso : ahb_slv_out_vector; cached : integer)
|
227 |
|
|
return std_ulogic;
|
228 |
|
|
|
229 |
|
|
function ahb_slv_dec_pfetch(haddr : std_logic_vector(31 downto 0);
|
230 |
|
|
ahbso : ahb_slv_out_vector)
|
231 |
|
|
return std_ulogic;
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
component ahbctrl
|
235 |
|
|
generic (
|
236 |
|
|
defmast : integer := 0; -- default master
|
237 |
|
|
split : integer := 0; -- split support
|
238 |
|
|
rrobin : integer := 0; -- round-robin arbitration
|
239 |
|
|
timeout : integer range 0 to 255 := 0; -- HREADY timeout
|
240 |
|
|
ioaddr : ahb_addr_type := 16#fff#; -- I/O area MSB address
|
241 |
|
|
iomask : ahb_addr_type := 16#fff#; -- I/O area address mask
|
242 |
|
|
cfgaddr : ahb_addr_type := 16#ff0#; -- config area MSB address
|
243 |
|
|
cfgmask : ahb_addr_type := 16#ff0#; -- config area address mask
|
244 |
|
|
nahbm : integer range 1 to NAHBMST := NAHBMST; -- number of masters
|
245 |
|
|
nahbs : integer range 1 to NAHBSLV := NAHBSLV; -- number of slaves
|
246 |
|
|
ioen : integer range 0 to 15 := 1; -- enable I/O area
|
247 |
|
|
disirq : integer range 0 to 1 := 0; -- disable interrupt routing
|
248 |
|
|
fixbrst : integer range 0 to 1 := 0; -- support fix-length bursts
|
249 |
|
|
debug : integer range 0 to 2 := 2; -- print config to console
|
250 |
|
|
fpnpen : integer range 0 to 1 := 0; -- full PnP configuration decoding
|
251 |
|
|
icheck : integer range 0 to 1 := 1;
|
252 |
|
|
devid : integer := 0; -- unique device ID
|
253 |
|
|
enbusmon : integer range 0 to 1 := 0; --enable bus monitor
|
254 |
|
|
assertwarn : integer range 0 to 1 := 0; --enable assertions for warnings
|
255 |
|
|
asserterr : integer range 0 to 1 := 0; --enable assertions for errors
|
256 |
|
|
hmstdisable : integer := 0; --disable master checks
|
257 |
|
|
hslvdisable : integer := 0; --disable slave checks
|
258 |
|
|
arbdisable : integer := 0; --disable arbiter checks
|
259 |
|
|
mprio : integer := 0; --master with highest priority
|
260 |
|
|
enebterm : integer range 0 to 1 := 0 --enable early burst termination
|
261 |
|
|
);
|
262 |
|
|
port (
|
263 |
|
|
rst : in std_ulogic;
|
264 |
|
|
clk : in std_ulogic;
|
265 |
|
|
msti : out ahb_mst_in_type;
|
266 |
|
|
msto : in ahb_mst_out_vector;
|
267 |
|
|
slvi : out ahb_slv_in_type;
|
268 |
|
|
slvo : in ahb_slv_out_vector;
|
269 |
|
|
testen : in std_ulogic := '0';
|
270 |
|
|
testrst : in std_ulogic := '1';
|
271 |
|
|
scanen : in std_ulogic := '0';
|
272 |
|
|
testoen : in std_ulogic := '1'
|
273 |
|
|
);
|
274 |
|
|
end component;
|
275 |
|
|
|
276 |
|
|
component apbctrl
|
277 |
|
|
generic (
|
278 |
|
|
hindex : integer := 0;
|
279 |
|
|
haddr : integer := 0;
|
280 |
|
|
hmask : integer := 16#fff#;
|
281 |
|
|
nslaves : integer range 1 to NAPBSLV := NAPBSLV;
|
282 |
|
|
debug : integer range 0 to 2 := 2; -- print config to console
|
283 |
|
|
icheck : integer range 0 to 1 := 1;
|
284 |
|
|
enbusmon : integer range 0 to 1 := 0;
|
285 |
|
|
asserterr : integer range 0 to 1 := 0;
|
286 |
|
|
assertwarn : integer range 0 to 1 := 0;
|
287 |
|
|
pslvdisable : integer := 0
|
288 |
|
|
);
|
289 |
|
|
port (
|
290 |
|
|
rst : in std_ulogic;
|
291 |
|
|
clk : in std_ulogic;
|
292 |
|
|
ahbi : in ahb_slv_in_type;
|
293 |
|
|
ahbo : out ahb_slv_out_type;
|
294 |
|
|
apbi : out apb_slv_in_type;
|
295 |
|
|
apbo : in apb_slv_out_vector
|
296 |
|
|
);
|
297 |
|
|
end component;
|
298 |
|
|
|
299 |
|
|
component ahbctrl_mb
|
300 |
|
|
generic (
|
301 |
|
|
defmast : integer := 0; -- default master
|
302 |
|
|
split : integer := 0; -- split support
|
303 |
|
|
rrobin : integer := 0; -- round-robin arbitration
|
304 |
|
|
timeout : integer range 0 to 255 := 0; -- HREADY timeout
|
305 |
|
|
ioaddr : ahb_addr_type := 16#fff#; -- I/O area MSB address
|
306 |
|
|
iomask : ahb_addr_type := 16#fff#; -- I/O area address mask
|
307 |
|
|
cfgaddr : ahb_addr_type := 16#ff0#; -- config area MSB address
|
308 |
|
|
cfgmask : ahb_addr_type := 16#ff0#; -- config area address mask
|
309 |
|
|
nahbm : integer range 1 to NAHBMST := NAHBMST; -- number of masters
|
310 |
|
|
nahbs : integer range 1 to NAHBSLV := NAHBSLV; -- number of slaves
|
311 |
|
|
ioen : integer range 0 to 15 := 1; -- enable I/O area
|
312 |
|
|
disirq : integer range 0 to 1 := 0; -- disable interrupt routing
|
313 |
|
|
fixbrst : integer range 0 to 1 := 0; -- support fix-length bursts
|
314 |
|
|
debug : integer range 0 to 2 := 2; -- report cores to console
|
315 |
|
|
fpnpen : integer range 0 to 1 := 0; -- full PnP configuration decoding
|
316 |
|
|
busndx : integer range 0 to 3 := 0;
|
317 |
|
|
icheck : integer range 0 to 1 := 1;
|
318 |
|
|
devid : integer := 0; -- unique device ID
|
319 |
|
|
enbusmon : integer range 0 to 1 := 0; --enable bus monitor
|
320 |
|
|
assertwarn : integer range 0 to 1 := 0; --enable assertions for warnings
|
321 |
|
|
asserterr : integer range 0 to 1 := 0; --enable assertions for errors
|
322 |
|
|
hmstdisable : integer := 0; --disable master checks
|
323 |
|
|
hslvdisable : integer := 0; --disable slave checks
|
324 |
|
|
arbdisable : integer := 0; --disable arbiter checks
|
325 |
|
|
mprio : integer := 0; --master with highest priority
|
326 |
|
|
enebterm : integer range 0 to 1 := 0 --enable early burst termination
|
327 |
|
|
);
|
328 |
|
|
port (
|
329 |
|
|
rst : in std_ulogic;
|
330 |
|
|
clk : in std_ulogic;
|
331 |
|
|
msti : out ahb_mst_in_type;
|
332 |
|
|
msto : in ahb_mst_out_bus_vector;
|
333 |
|
|
slvi : out ahb_slv_in_type;
|
334 |
|
|
slvo : in ahb_slv_out_bus_vector;
|
335 |
|
|
testen : in std_ulogic := '0';
|
336 |
|
|
testrst : in std_ulogic := '1';
|
337 |
|
|
scanen : in std_ulogic := '0';
|
338 |
|
|
testoen : in std_ulogic := '1'
|
339 |
|
|
);
|
340 |
|
|
end component;
|
341 |
|
|
|
342 |
|
|
component ahbdefmst
|
343 |
|
|
generic ( hindex : integer range 0 to NAHBMST-1 := 0);
|
344 |
|
|
port ( ahbmo : out ahb_mst_out_type);
|
345 |
|
|
end component;
|
346 |
|
|
|
347 |
|
|
-- pragma translate_off
|
348 |
|
|
|
349 |
|
|
component ahbmon is
|
350 |
|
|
generic(
|
351 |
|
|
asserterr : integer range 0 to 1 := 1;
|
352 |
|
|
assertwarn : integer range 0 to 1 := 1;
|
353 |
|
|
hmstdisable : integer := 0;
|
354 |
|
|
hslvdisable : integer := 0;
|
355 |
|
|
arbdisable : integer := 0;
|
356 |
|
|
nahbm : integer range 0 to NAHBMST := NAHBMST;
|
357 |
|
|
nahbs : integer range 0 to NAHBSLV := NAHBSLV
|
358 |
|
|
);
|
359 |
|
|
port(
|
360 |
|
|
rst : in std_ulogic;
|
361 |
|
|
clk : in std_ulogic;
|
362 |
|
|
ahbmi : in ahb_mst_in_type;
|
363 |
|
|
ahbmo : in ahb_mst_out_vector;
|
364 |
|
|
ahbsi : in ahb_slv_in_type;
|
365 |
|
|
ahbso : in ahb_slv_out_vector;
|
366 |
|
|
err : out std_ulogic);
|
367 |
|
|
end component;
|
368 |
|
|
|
369 |
|
|
component apbmon is
|
370 |
|
|
generic(
|
371 |
|
|
asserterr : integer range 0 to 1 := 1;
|
372 |
|
|
assertwarn : integer range 0 to 1 := 1;
|
373 |
|
|
pslvdisable : integer := 0;
|
374 |
|
|
napb : integer range 0 to NAPBSLV := NAPBSLV
|
375 |
|
|
);
|
376 |
|
|
port(
|
377 |
|
|
rst : in std_ulogic;
|
378 |
|
|
clk : in std_ulogic;
|
379 |
|
|
apbi : in apb_slv_in_type;
|
380 |
|
|
apbo : in apb_slv_out_vector;
|
381 |
|
|
err : out std_ulogic);
|
382 |
|
|
end component;
|
383 |
|
|
|
384 |
|
|
component ambamon is
|
385 |
|
|
generic(
|
386 |
|
|
asserterr : integer range 0 to 1 := 1;
|
387 |
|
|
assertwarn : integer range 0 to 1 := 1;
|
388 |
|
|
hmstdisable : integer := 0;
|
389 |
|
|
hslvdisable : integer := 0;
|
390 |
|
|
pslvdisable : integer := 0;
|
391 |
|
|
arbdisable : integer := 0;
|
392 |
|
|
nahbm : integer range 0 to NAHBMST := NAHBMST;
|
393 |
|
|
nahbs : integer range 0 to NAHBSLV := NAHBSLV;
|
394 |
|
|
napb : integer range 0 to NAPBSLV := NAPBSLV
|
395 |
|
|
);
|
396 |
|
|
port(
|
397 |
|
|
rst : in std_ulogic;
|
398 |
|
|
clk : in std_ulogic;
|
399 |
|
|
ahbmi : in ahb_mst_in_type;
|
400 |
|
|
ahbmo : in ahb_mst_out_vector;
|
401 |
|
|
ahbsi : in ahb_slv_in_type;
|
402 |
|
|
ahbso : in ahb_slv_out_vector;
|
403 |
|
|
apbi : in apb_slv_in_type;
|
404 |
|
|
apbo : in apb_slv_out_vector;
|
405 |
|
|
err : out std_ulogic);
|
406 |
|
|
end component;
|
407 |
|
|
|
408 |
|
|
subtype vendor_description is string(1 to 24);
|
409 |
|
|
subtype device_description is string(1 to 31);
|
410 |
|
|
type device_table_type is array (0 to 1023) of device_description;
|
411 |
|
|
type vendor_library_type is record
|
412 |
|
|
vendorid : amba_vendor_type;
|
413 |
|
|
vendordesc : vendor_description;
|
414 |
|
|
device_table : device_table_type;
|
415 |
|
|
end record;
|
416 |
|
|
type device_array is array (0 to 255) of vendor_library_type;
|
417 |
|
|
|
418 |
|
|
-- pragma translate_on
|
419 |
|
|
|
420 |
|
|
end;
|
421 |
|
|
|
422 |
|
|
package body amba is
|
423 |
|
|
|
424 |
|
|
function ahb_device_reg(vendor : amba_vendor_type; device : amba_device_type;
|
425 |
|
|
cfgver : amba_cfgver_type; version : amba_version_type;
|
426 |
|
|
interrupt : amba_irq_type)
|
427 |
|
|
return std_logic_vector is
|
428 |
|
|
variable cfg : std_logic_vector(31 downto 0);
|
429 |
|
|
begin
|
430 |
|
|
case cfgver is
|
431 |
|
|
when 0 =>
|
432 |
|
|
cfg(31 downto 24) := std_logic_vector(to_unsigned(vendor, 8));
|
433 |
|
|
cfg(23 downto 12) := std_logic_vector(to_unsigned(device, 12));
|
434 |
|
|
cfg(11 downto 10) := std_logic_vector(to_unsigned(cfgver, 2));
|
435 |
|
|
cfg( 9 downto 5) := std_logic_vector(to_unsigned(version, 5));
|
436 |
|
|
cfg( 4 downto 0) := std_logic_vector(to_unsigned(interrupt, 5));
|
437 |
|
|
when others => cfg := (others => '0');
|
438 |
|
|
end case;
|
439 |
|
|
return(cfg);
|
440 |
|
|
end;
|
441 |
|
|
|
442 |
|
|
function ahb_membar(memaddr : ahb_addr_type; prefetch, cache : std_ulogic;
|
443 |
|
|
addrmask : ahb_addr_type)
|
444 |
|
|
return std_logic_vector is
|
445 |
|
|
variable cfg : std_logic_vector(31 downto 0);
|
446 |
|
|
begin
|
447 |
|
|
cfg(31 downto 20) := std_logic_vector(to_unsigned(memaddr, 12));
|
448 |
|
|
cfg(19 downto 16) := "00" & prefetch & cache;
|
449 |
|
|
cfg(15 downto 4) := std_logic_vector(to_unsigned(addrmask, 12));
|
450 |
|
|
cfg( 3 downto 0) := "0010";
|
451 |
|
|
return(cfg);
|
452 |
|
|
end;
|
453 |
|
|
|
454 |
|
|
function ahb_membar_opt(memaddr : ahb_addr_type; prefetch, cache : std_ulogic;
|
455 |
|
|
addrmask : ahb_addr_type; enable : integer)
|
456 |
|
|
return std_logic_vector is
|
457 |
|
|
variable cfg : std_logic_vector(31 downto 0);
|
458 |
|
|
begin
|
459 |
|
|
cfg := (others => '0');
|
460 |
|
|
if enable /= 0 then
|
461 |
|
|
return (ahb_membar(memaddr, prefetch, cache, addrmask));
|
462 |
|
|
else return(cfg); end if;
|
463 |
|
|
end;
|
464 |
|
|
|
465 |
|
|
function ahb_iobar(memaddr : ahb_addr_type; addrmask : ahb_addr_type)
|
466 |
|
|
return std_logic_vector is
|
467 |
|
|
variable cfg : std_logic_vector(31 downto 0);
|
468 |
|
|
begin
|
469 |
|
|
cfg(31 downto 20) := std_logic_vector(to_unsigned(memaddr, 12));
|
470 |
|
|
cfg(19 downto 16) := "0000";
|
471 |
|
|
cfg(15 downto 4) := std_logic_vector(to_unsigned(addrmask, 12));
|
472 |
|
|
cfg( 3 downto 0) := "0011";
|
473 |
|
|
return(cfg);
|
474 |
|
|
end;
|
475 |
|
|
|
476 |
|
|
function apb_iobar(memaddr : ahb_addr_type; addrmask : ahb_addr_type)
|
477 |
|
|
return std_logic_vector is
|
478 |
|
|
variable cfg : std_logic_vector(31 downto 0);
|
479 |
|
|
begin
|
480 |
|
|
cfg(31 downto 20) := std_logic_vector(to_unsigned(memaddr, 12));
|
481 |
|
|
cfg(19 downto 16) := "0000";
|
482 |
|
|
cfg(15 downto 4) := std_logic_vector(to_unsigned(addrmask, 12));
|
483 |
|
|
cfg( 3 downto 0) := "0001";
|
484 |
|
|
return(cfg);
|
485 |
|
|
end;
|
486 |
|
|
|
487 |
|
|
function ahb_slv_dec_cache(haddr : std_logic_vector(31 downto 0);
|
488 |
|
|
ahbso : ahb_slv_out_vector; cached : integer)
|
489 |
|
|
return std_ulogic is
|
490 |
|
|
variable hcache : std_ulogic;
|
491 |
|
|
variable ctbl : std_logic_vector(15 downto 0);
|
492 |
|
|
begin
|
493 |
|
|
hcache := '0'; ctbl := (others => '0');
|
494 |
|
|
if cached = 0 then
|
495 |
|
|
for i in 0 to NAHBSLV-1 loop
|
496 |
|
|
for j in NAHBAMR to NAHBCFG-1 loop
|
497 |
|
|
if (ahbso(i).hconfig(j)(16) = '1') and
|
498 |
|
|
(ahbso(i).hconfig(j)(15 downto 4) /= "000000000000")
|
499 |
|
|
then
|
500 |
|
|
if (haddr(31 downto 20) and ahbso(i).hconfig(j)(15 downto 4)) =
|
501 |
|
|
(ahbso(i).hconfig(j)(31 downto 20) and ahbso(i).hconfig(j)(15 downto 4)) then
|
502 |
|
|
hcache := '1';
|
503 |
|
|
end if;
|
504 |
|
|
end if;
|
505 |
|
|
end loop;
|
506 |
|
|
end loop;
|
507 |
|
|
else
|
508 |
|
|
ctbl := conv_std_logic_vector(cached, 16);
|
509 |
|
|
hcache := ctbl(conv_integer(haddr(31 downto 28)));
|
510 |
|
|
end if;
|
511 |
|
|
return(hcache);
|
512 |
|
|
end;
|
513 |
|
|
|
514 |
|
|
function ahb_slv_dec_pfetch(haddr : std_logic_vector(31 downto 0);
|
515 |
|
|
ahbso : ahb_slv_out_vector)
|
516 |
|
|
return std_ulogic is
|
517 |
|
|
variable pfetch : std_ulogic;
|
518 |
|
|
begin
|
519 |
|
|
pfetch := '0';
|
520 |
|
|
for i in 0 to NAHBSLV-1 loop
|
521 |
|
|
for j in NAHBAMR to NAHBCFG-1 loop
|
522 |
|
|
if ahbso(i).hconfig(j)(17) = '1' then
|
523 |
|
|
if (haddr(31 downto 20) and ahbso(i).hconfig(j)(15 downto 4)) =
|
524 |
|
|
(ahbso(i).hconfig(j)(31 downto 20) and ahbso(i).hconfig(j)(15 downto 4)) then
|
525 |
|
|
pfetch := '1';
|
526 |
|
|
end if;
|
527 |
|
|
end if;
|
528 |
|
|
end loop;
|
529 |
|
|
end loop;
|
530 |
|
|
return(pfetch);
|
531 |
|
|
end;
|
532 |
|
|
|
533 |
|
|
end;
|