1 |
2 |
federico.a |
library ieee;
|
2 |
|
|
use ieee.std_logic_1164.all;
|
3 |
|
|
use ieee.std_logic_arith.all;
|
4 |
|
|
|
5 |
|
|
package ahb_package is
|
6 |
|
|
|
7 |
|
|
-----------------------------------------------------------------------------
|
8 |
|
|
-- Generic contants
|
9 |
|
|
-----------------------------------------------------------------------------
|
10 |
|
|
--***************************************************************
|
11 |
|
|
constant dump_no: integer := 0;--no dump on memory write
|
12 |
|
|
constant dump_end: integer := 1;--memory dump at end of test
|
13 |
|
|
constant dump_all: integer := 2;--continuous memory dump
|
14 |
|
|
--***************************************************************
|
15 |
|
|
constant zeroes: std_logic_vector(31 downto 0):= (others => '0');
|
16 |
|
|
constant tie_zero: std_logic:= '0';
|
17 |
|
|
constant ones: std_logic_vector(31 downto 0):= (others => '1');
|
18 |
|
|
constant tie_one: std_logic:= '1';
|
19 |
|
|
--***************************************************************
|
20 |
|
|
|
21 |
|
|
-----------------------------------------------------------------------------
|
22 |
|
|
-- AHB system: for every slave define LOW and HIGH address
|
23 |
|
|
-----------------------------------------------------------------------------
|
24 |
|
|
type addr_t is
|
25 |
|
|
record
|
26 |
|
|
high: integer;
|
27 |
|
|
low: integer;
|
28 |
|
|
end record;
|
29 |
|
|
|
30 |
|
|
-----------------------------------------------------------------------------
|
31 |
|
|
-- AHB Master
|
32 |
|
|
-----------------------------------------------------------------------------
|
33 |
|
|
-- AHB master inputs
|
34 |
|
|
type mst_in_t is
|
35 |
|
|
record
|
36 |
|
|
hgrant: std_logic;
|
37 |
|
|
hready: std_logic;
|
38 |
|
|
hresp: std_logic_vector(1 downto 0);
|
39 |
|
|
hrdata: std_logic_vector(31 downto 0);
|
40 |
|
|
end record;
|
41 |
|
|
|
42 |
|
|
-- AHB master outputs
|
43 |
|
|
type mst_out_t is
|
44 |
|
|
record
|
45 |
|
|
hbusreq: std_logic;
|
46 |
|
|
hlock: std_logic;
|
47 |
|
|
htrans: std_logic_vector(1 downto 0);
|
48 |
|
|
haddr: std_logic_vector(31 downto 0);
|
49 |
|
|
hwrite: std_logic;
|
50 |
|
|
hsize: std_logic_vector(2 downto 0);
|
51 |
|
|
hburst: std_logic_vector(2 downto 0);
|
52 |
|
|
hprot: std_logic_vector(3 downto 0);
|
53 |
|
|
hwdata: std_logic_vector(31 downto 0);
|
54 |
|
|
end record;
|
55 |
|
|
|
56 |
|
|
-----------------------------------------------------------------------------
|
57 |
|
|
-- AHB Slave
|
58 |
|
|
-----------------------------------------------------------------------------
|
59 |
|
|
-- AHB slave inputs
|
60 |
|
|
type slv_in_t is
|
61 |
|
|
record
|
62 |
|
|
hsel: std_logic;
|
63 |
|
|
haddr: std_logic_vector(31 downto 0);
|
64 |
|
|
hwrite: std_logic;
|
65 |
|
|
htrans: std_logic_vector(1 downto 0);
|
66 |
|
|
hsize: std_logic_vector(2 downto 0);
|
67 |
|
|
hburst: std_logic_vector(2 downto 0);
|
68 |
|
|
hwdata: std_logic_vector(31 downto 0);
|
69 |
|
|
hprot: std_logic_vector(3 downto 0);
|
70 |
|
|
hready: std_logic;
|
71 |
|
|
hmaster: std_logic_vector(3 downto 0);
|
72 |
|
|
hmastlock: std_logic;
|
73 |
|
|
end record;
|
74 |
|
|
|
75 |
|
|
-- AHB slave outputs
|
76 |
|
|
type slv_out_t is
|
77 |
|
|
record
|
78 |
|
|
hready: std_logic;
|
79 |
|
|
hresp: std_logic_vector(1 downto 0);
|
80 |
|
|
hrdata: std_logic_vector(31 downto 0);
|
81 |
|
|
hsplit: std_logic_vector(15 downto 0);
|
82 |
|
|
end record;
|
83 |
|
|
|
84 |
|
|
-----------------------------------------------------------------------------
|
85 |
|
|
-- Definitions for AMBA APB Slaves constants and types
|
86 |
|
|
-----------------------------------------------------------------------------
|
87 |
|
|
constant apb_addr: integer range 8 to 32 := 32;-- address width
|
88 |
|
|
constant apb_data: integer range 8 to 32 := 32;-- data width
|
89 |
|
|
|
90 |
|
|
-- APB slave inputs
|
91 |
|
|
type apb_in_t is
|
92 |
|
|
record
|
93 |
|
|
psel: std_logic;
|
94 |
|
|
penable: std_logic;
|
95 |
|
|
paddr: std_logic_vector(apb_addr-1 downto 0);
|
96 |
|
|
pwrite: std_logic;
|
97 |
|
|
pwdata: std_logic_vector(apb_data-1 downto 0);
|
98 |
|
|
end record;
|
99 |
|
|
|
100 |
|
|
-- APB slave outputs
|
101 |
|
|
type apb_out_t is
|
102 |
|
|
record
|
103 |
|
|
prdata: std_logic_vector(apb_addr-1 downto 0);
|
104 |
|
|
end record;
|
105 |
|
|
|
106 |
|
|
-----------------------------------------------------------------------------
|
107 |
|
|
-- Definitions for AMBA AHB Arbiter/Decoder/Bridges
|
108 |
|
|
-----------------------------------------------------------------------------
|
109 |
|
|
-- supporting array types
|
110 |
|
|
|
111 |
|
|
type addr_in_v_t is array (15 downto 0) of addr_t;
|
112 |
|
|
type addr_matrix_t is array (natural range <> ) of addr_in_v_t;
|
113 |
|
|
|
114 |
|
|
type mst_in_v_t is array (natural Range <> ) of mst_in_t;
|
115 |
|
|
type mst_out_v_t is array (natural Range <> ) of mst_out_t;
|
116 |
|
|
|
117 |
|
|
type slv_in_v_t is array (natural Range <> ) of slv_in_t;
|
118 |
|
|
type slv_out_v_t is array (natural Range <> ) of slv_out_t;
|
119 |
|
|
|
120 |
|
|
type apb_in_v_t is array (natural range <> ) of apb_in_t;
|
121 |
|
|
type apb_out_v_t is array (natural range <> ) of apb_out_t;
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
--***************************************************************
|
125 |
|
|
-- definition of amba AHB protocol constants
|
126 |
|
|
--***************************************************************
|
127 |
|
|
|
128 |
|
|
--***************************************************************
|
129 |
|
|
--configuration register space addresses
|
130 |
|
|
--***************************************************************
|
131 |
|
|
constant dma_extadd_addr: std_logic_vector(3 downto 0):= "0000";
|
132 |
|
|
constant dma_intadd_addr: std_logic_vector(3 downto 0):= "0001";
|
133 |
|
|
constant dma_intmod_addr: std_logic_vector(3 downto 0):= "0010";
|
134 |
|
|
constant dma_type_addr: std_logic_vector(3 downto 0):= "0011";
|
135 |
|
|
constant dma_count_addr: std_logic_vector(3 downto 0):= "0100";
|
136 |
|
|
constant dma_go_addr: std_logic_vector(3 downto 0):= "0101";
|
137 |
|
|
|
138 |
|
|
--***************************************************************
|
139 |
|
|
-- hprot values
|
140 |
|
|
--***************************************************************
|
141 |
|
|
--constant opcode_fetch: std_logic_vector(3 downto 0):= "---0";
|
142 |
|
|
--constant data_access: std_logic_vector(3 downto 0):= "---1";
|
143 |
|
|
--constant user_access: std_logic_vector(3 downto 0):= "--0-";
|
144 |
|
|
--constant privileged_access: std_logic_vector(3 downto 0):= "--1-";
|
145 |
|
|
--constant not_bufferable: std_logic_vector(3 downto 0):= "-0--";
|
146 |
|
|
--constant bufferable: std_logic_vector(3 downto 0):= "-1--";
|
147 |
|
|
--constant not_cacheable: std_logic_vector(3 downto 0):= "0---";
|
148 |
|
|
--constant cacheable: std_logic_vector(3 downto 0):= "1---";
|
149 |
|
|
|
150 |
|
|
--***************************************************************
|
151 |
|
|
-- hburst values
|
152 |
|
|
--***************************************************************
|
153 |
|
|
constant single: std_logic_vector(2 downto 0):= "000";
|
154 |
|
|
constant incr: std_logic_vector(2 downto 0):= "001";
|
155 |
|
|
constant wrap4: std_logic_vector(2 downto 0):= "010";
|
156 |
|
|
constant incr4: std_logic_vector(2 downto 0):= "011";
|
157 |
|
|
constant wrap8: std_logic_vector(2 downto 0):= "100";
|
158 |
|
|
constant incr8: std_logic_vector(2 downto 0):= "101";
|
159 |
|
|
constant wrap16: std_logic_vector(2 downto 0):= "110";
|
160 |
|
|
constant incr16: std_logic_vector(2 downto 0):= "111";
|
161 |
|
|
|
162 |
|
|
--***************************************************************
|
163 |
|
|
-- hsize values
|
164 |
|
|
--***************************************************************
|
165 |
|
|
constant bits8: std_logic_vector(2 downto 0):= "000";
|
166 |
|
|
constant bits16: std_logic_vector(2 downto 0):= "001";
|
167 |
|
|
constant bits32: std_logic_vector(2 downto 0):= "010";
|
168 |
|
|
constant bits64: std_logic_vector(2 downto 0):= "011";
|
169 |
|
|
constant bits128: std_logic_vector(2 downto 0):= "100";
|
170 |
|
|
constant bits256: std_logic_vector(2 downto 0):= "101";
|
171 |
|
|
constant bits512: std_logic_vector(2 downto 0):= "110";
|
172 |
|
|
constant bits1024: std_logic_vector(2 downto 0):= "111";
|
173 |
|
|
|
174 |
|
|
--***************************************************************
|
175 |
|
|
-- htrans values
|
176 |
|
|
--***************************************************************
|
177 |
|
|
constant idle: std_logic_vector(1 downto 0):= "00";
|
178 |
|
|
constant busy: std_logic_vector(1 downto 0):= "01";
|
179 |
|
|
constant nonseq: std_logic_vector(1 downto 0):= "10";
|
180 |
|
|
constant seq: std_logic_vector(1 downto 0):= "11";
|
181 |
|
|
|
182 |
|
|
--***************************************************************
|
183 |
|
|
-- hresp values
|
184 |
|
|
--***************************************************************
|
185 |
|
|
constant ok_resp: std_logic_vector(1 downto 0):= "00";
|
186 |
|
|
constant error_resp: std_logic_vector(1 downto 0):= "01";
|
187 |
|
|
constant retry_resp: std_logic_vector(1 downto 0):= "10";
|
188 |
|
|
constant split_resp: std_logic_vector(1 downto 0):= "11";
|
189 |
|
|
|
190 |
|
|
-----------------------------------------------------------------------------
|
191 |
|
|
-- AHB system constants
|
192 |
|
|
-----------------------------------------------------------------------------
|
193 |
|
|
|
194 |
|
|
--***************************************************************
|
195 |
|
|
-- priority values
|
196 |
|
|
--***************************************************************
|
197 |
|
|
constant master: std_logic:= '1';
|
198 |
|
|
constant slave: std_logic:= '0';
|
199 |
|
|
|
200 |
|
|
--***************************************************************
|
201 |
|
|
-- split retry programmable slave response values
|
202 |
|
|
--***************************************************************
|
203 |
|
|
constant retry: std_logic:= '0';
|
204 |
|
|
constant split: std_logic:= '1';
|
205 |
|
|
|
206 |
|
|
--***************************************************************
|
207 |
|
|
-- locked/non locked ahb bus request programmable
|
208 |
|
|
--***************************************************************
|
209 |
|
|
constant nonlocked: std_logic:='0';
|
210 |
|
|
constant locked: std_logic:='1';
|
211 |
|
|
|
212 |
|
|
--***************************************************************
|
213 |
|
|
-- burst capability for masters and slaves
|
214 |
|
|
--***************************************************************
|
215 |
|
|
constant burst_support: integer:= 1;
|
216 |
|
|
constant no_burst_support: integer:= 0;
|
217 |
|
|
|
218 |
|
|
--***************************************************************
|
219 |
|
|
-- hprot values
|
220 |
|
|
--***************************************************************
|
221 |
|
|
constant hprot_posted: std_logic_vector(3 downto 0):= "1111";
|
222 |
|
|
constant hprot_nonposted: std_logic_vector(3 downto 0):= "0000";
|
223 |
|
|
|
224 |
|
|
-----------------------------------------------------------------------------
|
225 |
|
|
-- Definitions for test ports
|
226 |
|
|
-----------------------------------------------------------------------------
|
227 |
|
|
type conf_type_t is
|
228 |
|
|
record
|
229 |
|
|
write: std_logic;
|
230 |
|
|
addr: std_logic_vector(3 downto 0);
|
231 |
|
|
wdata: std_logic_vector(31 downto 0);
|
232 |
|
|
end record;
|
233 |
|
|
|
234 |
|
|
-----------------------------------------------------------------------------
|
235 |
|
|
-- Definitions for ahb master dma parameters passing
|
236 |
|
|
-----------------------------------------------------------------------------
|
237 |
|
|
type start_type_t is
|
238 |
|
|
record
|
239 |
|
|
start: std_logic;
|
240 |
|
|
extaddr: std_logic_vector(31 downto 0);
|
241 |
|
|
intaddr: std_logic_vector(15 downto 0);
|
242 |
|
|
intmod: std_logic_vector(15 downto 0);
|
243 |
|
|
count: std_logic_vector(15 downto 0);
|
244 |
|
|
hparams: std_logic_vector(15 downto 0);
|
245 |
|
|
end record;
|
246 |
|
|
|
247 |
|
|
-----------------------------------------------------------------------------
|
248 |
|
|
-- Handshake signals and data between master/slave and internal memories/registers
|
249 |
|
|
-----------------------------------------------------------------------------
|
250 |
|
|
type wrap_out_t is
|
251 |
|
|
record
|
252 |
|
|
addr: std_logic_vector(31 downto 0);
|
253 |
|
|
take: std_logic;
|
254 |
|
|
wdata: std_logic_vector(31 downto 0);
|
255 |
|
|
ask: std_logic;
|
256 |
|
|
end record;
|
257 |
|
|
|
258 |
|
|
type wrap_in_t is
|
259 |
|
|
record
|
260 |
|
|
take_ok: std_logic;
|
261 |
|
|
ask_ok: std_logic;
|
262 |
|
|
rdata: std_logic_vector(31 downto 0);
|
263 |
|
|
end record;
|
264 |
|
|
|
265 |
|
|
-----------------------------------------------------------------------------
|
266 |
|
|
-- Parameters for defining AHB STIMULATOR behaviour
|
267 |
|
|
-----------------------------------------------------------------------------
|
268 |
|
|
type uut_params_t is
|
269 |
|
|
record
|
270 |
|
|
hsize_tb: std_logic_vector(2 downto 0);
|
271 |
|
|
split_tb: std_logic;
|
272 |
|
|
prior_tb: std_logic;
|
273 |
|
|
hburst_cycle: std_logic;
|
274 |
|
|
hburst_tb: std_logic_vector(2 downto 0);
|
275 |
|
|
-- high_addr_tb:std_logic_vector(19 downto 0);
|
276 |
|
|
ext_addr_incr_tb: integer;
|
277 |
|
|
intmod_tb: integer;
|
278 |
|
|
hprot_tb: std_logic_vector(3 downto 0);
|
279 |
|
|
base_tb: integer;
|
280 |
|
|
int_addr_incr_tb: integer;
|
281 |
|
|
int_base_tb: integer;
|
282 |
|
|
locked_request: std_logic;
|
283 |
|
|
end record;
|
284 |
|
|
|
285 |
|
|
-----------------------------------------------------------------------------
|
286 |
|
|
-- Vector types (aggregates) of previous types
|
287 |
|
|
-----------------------------------------------------------------------------
|
288 |
|
|
type conf_type_v is array (Natural Range <> ) of conf_type_t;
|
289 |
|
|
|
290 |
|
|
type start_type_v is array (Natural Range <> ) of start_type_t;
|
291 |
|
|
|
292 |
|
|
type wrap_out_v is array (Natural Range <> ) of wrap_out_t;
|
293 |
|
|
type wrap_in_v is array (Natural Range <> ) of wrap_in_t;
|
294 |
|
|
|
295 |
|
|
type uut_params_v_t is array (Natural Range <> ) of uut_params_t;
|
296 |
|
|
|
297 |
|
|
--***************************************************************
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
--***************************************************************
|
301 |
|
|
--***************************************************************
|
302 |
|
|
--uut#0
|
303 |
|
|
--signal stim_0: uut_params_t:= (bits32,retry,master,'0',wrap4,"00000000000000000000",2,4,hprot_nonposted,2048,1,0,'1');
|
304 |
|
|
--uut#1
|
305 |
|
|
--signal stim_1: uut_params_t:= (bits32,retry,slave,'0',wrap4,"00000000000000000000",2,4,hprot_posted,2048+128,1,0,'1');
|
306 |
|
|
--uut#2
|
307 |
|
|
--signal stim_2: uut_params_t:= (bits32,retry,master,'0',wrap4,"00000000000000000000",2,4,hprot_posted,2048+256,1,0,'0');
|
308 |
|
|
--uut#3
|
309 |
|
|
--signal stim_3: uut_params_t:= (bits32,retry,master,'0',wrap4,"00010000001000000000",2,4,hprot_posted,2048,1,0,'0');
|
310 |
|
|
|
311 |
|
|
--signal stim_v: uut_params_v_t(3 downto 0) := (stim_3, stim_2, stim_1, stim_0);
|
312 |
|
|
--***************************************************************
|
313 |
|
|
--***************************************************************
|
314 |
|
|
end;
|
315 |
|
|
|
316 |
|
|
package body ahb_package is
|
317 |
|
|
end;
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|