1 |
2 |
tarookumic |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
----------------------------------------------------------------------------
|
6 |
|
|
-- This file is a part of the LEON VHDL model
|
7 |
|
|
-- Copyright (C) 1999 European Space Agency (ESA)
|
8 |
|
|
--
|
9 |
|
|
-- This library is free software; you can redistribute it and/or
|
10 |
|
|
-- modify it under the terms of the GNU Lesser General Public
|
11 |
|
|
-- License as published by the Free Software Foundation; either
|
12 |
|
|
-- version 2 of the License, or (at your option) any later version.
|
13 |
|
|
--
|
14 |
|
|
-- See the file COPYING.LGPL for the full details of the license.
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
-----------------------------------------------------------------------------
|
18 |
|
|
-- Entity: ahbarb
|
19 |
|
|
-- File: ahbarb.vhd
|
20 |
|
|
-- Author: Jiri Gaisler - Gaisler Research
|
21 |
|
|
-- Description: AMBA AHB arbiter and decoder
|
22 |
|
|
------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
library IEEE;
|
25 |
|
|
use IEEE.std_logic_1164.all;
|
26 |
|
|
use IEEE.std_logic_arith.all;
|
27 |
|
|
use work.leon_target.all;
|
28 |
|
|
use work.leon_config.all;
|
29 |
|
|
use work.leon_iface.all;
|
30 |
|
|
use work.amba.all;
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
entity ahbarb is
|
34 |
|
|
generic (
|
35 |
|
|
masters : integer := 2; -- number of masters
|
36 |
|
|
defmast : integer := 0 -- default master
|
37 |
|
|
);
|
38 |
|
|
port (
|
39 |
|
|
rst : in std_logic;
|
40 |
|
|
clk : in clk_type;
|
41 |
|
|
msti : out ahb_mst_in_vector(0 to masters-1);
|
42 |
|
|
msto : in ahb_mst_out_vector(0 to masters-1);
|
43 |
|
|
slvi : out ahb_slv_in_vector(0 to AHB_SLV_MAX-1);
|
44 |
|
|
slvo : in ahb_slv_out_vector(0 to AHB_SLV_MAX)
|
45 |
|
|
);
|
46 |
|
|
end;
|
47 |
|
|
|
48 |
|
|
architecture rtl of ahbarb is
|
49 |
|
|
|
50 |
|
|
type reg_type is record
|
51 |
|
|
hmaster : integer range 0 to masters-1;
|
52 |
|
|
hmasterd : integer range 0 to masters-1;
|
53 |
|
|
hslave : integer range 0 to AHB_SLV_MAX;
|
54 |
|
|
hready : std_logic; -- needed for two-cycle error response
|
55 |
|
|
hlock : std_logic;
|
56 |
|
|
hmasterlock : std_logic;
|
57 |
|
|
htrans : std_logic_vector(1 downto 0); -- transfer type
|
58 |
|
|
end record;
|
59 |
|
|
|
60 |
|
|
constant ahbmin : integer := AHB_SLV_ADDR_MSB-1;
|
61 |
|
|
type nmstarr is array ( 1 to 5) of integer range 0 to masters-1;
|
62 |
|
|
type nvalarr is array ( 1 to 5) of boolean;
|
63 |
|
|
signal r, rin : reg_type;
|
64 |
|
|
signal rsplit, rsplitin : std_logic_vector(masters-1 downto 0);
|
65 |
|
|
|
66 |
|
|
begin
|
67 |
|
|
|
68 |
|
|
comb : process(rst, msto, slvo, r, rsplit)
|
69 |
|
|
variable rv : reg_type;
|
70 |
|
|
variable nhmaster, hmaster : integer range 0 to masters -1;
|
71 |
|
|
variable haddr : std_logic_vector(31 downto 0); -- address bus
|
72 |
|
|
variable hrdata : std_logic_vector(31 downto 0); -- read data bus
|
73 |
|
|
variable htrans : std_logic_vector(1 downto 0); -- transfer type
|
74 |
|
|
variable hresp : std_logic_vector(1 downto 0); -- respons type
|
75 |
|
|
variable hwrite : std_logic; -- read/write
|
76 |
|
|
variable hsize : std_logic_vector(2 downto 0); -- transfer size
|
77 |
|
|
variable hprot : std_logic_vector(3 downto 0); -- protection info
|
78 |
|
|
variable hburst : std_logic_vector(2 downto 0); -- burst type
|
79 |
|
|
variable hwdata : std_logic_vector(31 downto 0); -- write data
|
80 |
|
|
variable hgrant : std_logic_vector(0 to masters-1); -- bus grant
|
81 |
|
|
variable hsel : std_logic_vector(0 to AHB_SLV_MAX); -- slave select
|
82 |
|
|
variable hready : std_logic; -- ready
|
83 |
|
|
variable hmastlock : std_logic;
|
84 |
|
|
variable nslave : natural range 0 to AHB_SLV_MAX;
|
85 |
|
|
variable ahbaddr : std_logic_vector(ahbmin downto 0);
|
86 |
|
|
variable vsplit : std_logic_vector(masters-1 downto 0);
|
87 |
|
|
variable nmst : nmstarr;
|
88 |
|
|
variable nvalid : nvalarr;
|
89 |
|
|
variable htmp : std_logic_vector(3 downto 0);
|
90 |
|
|
begin
|
91 |
|
|
|
92 |
|
|
rv := r; rv.hready := '0';
|
93 |
|
|
|
94 |
|
|
-- bus multiplexers
|
95 |
|
|
|
96 |
|
|
haddr := msto(r.hmaster).haddr;
|
97 |
|
|
htrans := msto(r.hmaster).htrans;
|
98 |
|
|
hwrite := msto(r.hmaster).hwrite;
|
99 |
|
|
hsize := msto(r.hmaster).hsize;
|
100 |
|
|
hprot := msto(r.hmaster).hprot;
|
101 |
|
|
hburst := msto(r.hmaster).hburst;
|
102 |
|
|
hmastlock := msto(r.hmaster).hlock;
|
103 |
|
|
hwdata := msto(r.hmasterd).hwdata;
|
104 |
|
|
hready := slvo(r.hslave).hready;
|
105 |
|
|
hrdata := slvo(r.hslave).hrdata;
|
106 |
|
|
hresp := slvo(r.hslave).hresp ;
|
107 |
|
|
|
108 |
|
|
if r.hslave = AHB_SLV_MAX then
|
109 |
|
|
-- default slave
|
110 |
|
|
if (r.htrans = HTRANS_IDLE) or (r.htrans = HTRANS_BUSY) then
|
111 |
|
|
hresp := HRESP_OKAY; hready := '1';
|
112 |
|
|
else
|
113 |
|
|
-- return two-cycle error in case of unimplemented slave access
|
114 |
|
|
hresp := HRESP_ERROR; hready := r.hready; rv.hready := not r.hready;
|
115 |
|
|
end if;
|
116 |
|
|
end if;
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
-- Find next master:
|
120 |
|
|
-- * priority is fixed, highest index has highest priority
|
121 |
|
|
-- * splitted masters are not granted
|
122 |
|
|
-- * burst transfers cannot be interrupted
|
123 |
|
|
-- * low-priority masters will be granted if they drive SEQ or NONSEQ
|
124 |
|
|
-- on HTRANS, and high-priority masters only drive IDLE
|
125 |
|
|
|
126 |
|
|
nvalid(1 to 4) := (others => false); nvalid(5) := true;
|
127 |
|
|
nmst(1 to 4) := (others => 0); nmst(5) := defmast; nhmaster := r.hmaster;
|
128 |
|
|
|
129 |
|
|
if (r.hmasterlock = '0') and (
|
130 |
|
|
(msto(r.hmaster).htrans = HTRANS_IDLE) or
|
131 |
|
|
( (msto(r.hmaster).htrans = HTRANS_NONSEQ) and
|
132 |
|
|
(msto(r.hmaster).hburst = HBURST_SINGLE) ) ) then
|
133 |
|
|
for i in 0 to (masters -1) loop
|
134 |
|
|
if ((rsplit(i) = '0') or not AHB_SPLIT) then
|
135 |
|
|
if (msto(i).hbusreq = '1') and (msto(i).htrans(1) = '1') then
|
136 |
|
|
nmst(2) := i; nvalid(2) := true;
|
137 |
|
|
end if;
|
138 |
|
|
if (msto(i).hbusreq = '1') then
|
139 |
|
|
nmst(3) := i; nvalid(3) := true;
|
140 |
|
|
end if;
|
141 |
|
|
if not ((nmst(4) = defmast) and nvalid(4)) then
|
142 |
|
|
nmst(4) := i; nvalid(4) := true;
|
143 |
|
|
end if;
|
144 |
|
|
end if;
|
145 |
|
|
end loop;
|
146 |
|
|
for i in 1 to 5 loop
|
147 |
|
|
if nvalid(i) then nhmaster := nmst(i); exit; end if;
|
148 |
|
|
end loop;
|
149 |
|
|
end if;
|
150 |
|
|
|
151 |
|
|
rv.hlock := msto(nhmaster).hlock;
|
152 |
|
|
|
153 |
|
|
hgrant := (others => '0'); hgrant(nhmaster) := '1';
|
154 |
|
|
|
155 |
|
|
-- select slave
|
156 |
|
|
ahbaddr := haddr(31 downto (31 - ahbmin));
|
157 |
|
|
-- pragma translate_off
|
158 |
|
|
if not is_x(haddr(31 downto (31 - AHB_SLV_ADDR_MSB +1))) then
|
159 |
|
|
-- pragma translate_on
|
160 |
|
|
nslave := AHBSLVADDR(conv_integer(unsigned(haddr(31 downto (31 - AHB_SLV_ADDR_MSB +1)))));
|
161 |
|
|
-- pragma translate_off
|
162 |
|
|
end if;
|
163 |
|
|
-- pragma translate_on
|
164 |
|
|
|
165 |
|
|
-- if htrans = HTRANS_IDLE then nslave := AHB_SLV_MAX; end if;
|
166 |
|
|
|
167 |
|
|
hsel := (others => '0'); hsel(nslave) := '1';
|
168 |
|
|
|
169 |
|
|
-- latch active master and slave
|
170 |
|
|
if hready = '1' then
|
171 |
|
|
rv.hmaster := nhmaster; rv.hmasterd := r.hmaster;
|
172 |
|
|
rv.hslave := nslave; rv.htrans := htrans; rv.hmasterlock := r.hlock;
|
173 |
|
|
end if;
|
174 |
|
|
|
175 |
|
|
-- latch HLOCK
|
176 |
|
|
|
177 |
|
|
-- split support
|
178 |
|
|
|
179 |
|
|
vsplit := (others => '0');
|
180 |
|
|
if AHB_SPLIT then
|
181 |
|
|
vsplit := rsplit;
|
182 |
|
|
if hresp = HRESP_SPLIT then vsplit(r.hmasterd) := '1'; end if;
|
183 |
|
|
for i in AHBSLVSPLIT'range loop --'
|
184 |
|
|
if AHBSLVSPLIT(i) = 1 then
|
185 |
|
|
vsplit := vsplit and not slvo(i).hsplit(masters-1 downto 0);
|
186 |
|
|
end if;
|
187 |
|
|
end loop;
|
188 |
|
|
end if;
|
189 |
|
|
|
190 |
|
|
-- reset operation
|
191 |
|
|
if (rst = '0') then
|
192 |
|
|
rv.hmaster := 0; rv.hmasterlock := '0'; rv.hslave := AHB_SLV_MAX;
|
193 |
|
|
hsel := (others => '0'); rv.htrans := HTRANS_IDLE;
|
194 |
|
|
hready := '1'; vsplit := (others => '0');
|
195 |
|
|
end if;
|
196 |
|
|
|
197 |
|
|
-- drive master inputs
|
198 |
|
|
for i in 0 to (masters -1) loop
|
199 |
|
|
msti(i).hgrant <= hgrant(i);
|
200 |
|
|
msti(i).hready <= hready;
|
201 |
|
|
msti(i).hrdata <= hrdata;
|
202 |
|
|
msti(i).hresp <= hresp;
|
203 |
|
|
end loop;
|
204 |
|
|
|
205 |
|
|
-- drive slave inputs
|
206 |
|
|
for i in 0 to (AHB_SLV_MAX-1) loop
|
207 |
|
|
slvi(i).haddr <= haddr;
|
208 |
|
|
slvi(i).htrans <= htrans;
|
209 |
|
|
slvi(i).hwrite <= hwrite;
|
210 |
|
|
slvi(i).hsize <= hsize;
|
211 |
|
|
slvi(i).hburst <= hburst;
|
212 |
|
|
slvi(i).hready <= hready;
|
213 |
|
|
slvi(i).hwdata <= hwdata;
|
214 |
|
|
slvi(i).hprot <= hprot;
|
215 |
|
|
slvi(i).hsel <= hsel(i);
|
216 |
|
|
slvi(i).hmaster <= std_logic_vector(conv_unsigned(r.hmaster, 4));
|
217 |
|
|
slvi(i).hmastlock <= r.hmasterlock;
|
218 |
|
|
end loop;
|
219 |
|
|
|
220 |
|
|
-- assign register inputs
|
221 |
|
|
|
222 |
|
|
rin <= rv;
|
223 |
|
|
rsplitin <= vsplit;
|
224 |
|
|
|
225 |
|
|
end process;
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
reg0 : process(clk)
|
229 |
|
|
begin if rising_edge(clk) then r <= rin; end if; end process;
|
230 |
|
|
|
231 |
|
|
splitreg : if AHB_SPLIT generate
|
232 |
|
|
reg1 : process(clk)
|
233 |
|
|
begin if rising_edge(clk) then rsplit <= rsplitin; end if; end process;
|
234 |
|
|
end generate;
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
end;
|
238 |
|
|
|