| 1 |
145 |
lanttu |
-----------------------------------------------------------------
|
| 2 |
|
|
-- File : allocator.vhd
|
| 3 |
|
|
-- Description : Allocates one-sided crossbar buses
|
| 4 |
|
|
-- Designer : Hannu Penttinen 28.08.2006
|
| 5 |
|
|
--
|
| 6 |
|
|
-- Last modified
|
| 7 |
|
|
-----------------------------------------------------------------
|
| 8 |
|
|
-------------------------------------------------------------------------------
|
| 9 |
|
|
-- Copyright (c) 2011 Tampere University of Technology
|
| 10 |
|
|
-------------------------------------------------------------------------------
|
| 11 |
|
|
-- This file is part of Transaction Generator.
|
| 12 |
|
|
--
|
| 13 |
|
|
-- Transaction Generator is free software: you can redistribute it and/or
|
| 14 |
|
|
-- modify it under the terms of the Lesser GNU General Public License as
|
| 15 |
|
|
-- published by the Free Software Foundation, either version 3 of the License,
|
| 16 |
|
|
-- or (at your option) any later version.
|
| 17 |
|
|
--
|
| 18 |
|
|
-- Transaction Generator is distributed in the hope that it will be useful,
|
| 19 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
-- Lesser GNU General Public License for more details.
|
| 22 |
|
|
--
|
| 23 |
|
|
-- You should have received a copy of the Lesser GNU General Public License
|
| 24 |
|
|
-- along with Transaction Generator. If not, see
|
| 25 |
|
|
-- <http://www.gnu.org/licenses/>.
|
| 26 |
|
|
-------------------------------------------------------------------------------
|
| 27 |
|
|
|
| 28 |
|
|
library ieee;
|
| 29 |
|
|
use ieee.std_logic_1164.all;
|
| 30 |
|
|
use ieee.numeric_std.all;
|
| 31 |
|
|
--use Work.txt_util.all;
|
| 32 |
|
|
|
| 33 |
|
|
entity allocator is
|
| 34 |
|
|
generic (
|
| 35 |
|
|
n_ag_g : integer;
|
| 36 |
|
|
addr_width_g : integer;
|
| 37 |
|
|
switch_addr_width_g : integer
|
| 38 |
|
|
);
|
| 39 |
|
|
port(
|
| 40 |
|
|
clk : in std_logic;
|
| 41 |
|
|
rst_n : in std_logic;
|
| 42 |
|
|
req_addr_in : in std_logic_vector(n_ag_g * addr_width_g - 1 downto 0);
|
| 43 |
|
|
req_in : in std_logic_vector(n_ag_g - 1 downto 0);
|
| 44 |
|
|
hold_in : in std_logic_vector(n_ag_g - 1 downto 0);
|
| 45 |
|
|
grant_out : out std_logic_vector(n_ag_g - 1 downto 0);
|
| 46 |
|
|
src_id_out : out std_logic_vector(n_ag_g * switch_addr_width_g - 1 downto 0)
|
| 47 |
|
|
);
|
| 48 |
|
|
end allocator;
|
| 49 |
|
|
|
| 50 |
|
|
architecture rtl of allocator is
|
| 51 |
|
|
|
| 52 |
|
|
component arbiter
|
| 53 |
|
|
generic (
|
| 54 |
|
|
arb_width_g : integer
|
| 55 |
|
|
);
|
| 56 |
|
|
port (
|
| 57 |
|
|
clk : in std_logic;
|
| 58 |
|
|
rst_n : in std_logic;
|
| 59 |
|
|
req_in : in std_logic_vector(arb_width_g - 1 downto 0);
|
| 60 |
|
|
hold_in : in std_logic_vector(arb_width_g - 1 downto 0);
|
| 61 |
|
|
grant_out : out std_logic_vector(arb_width_g - 1 downto 0)
|
| 62 |
|
|
);
|
| 63 |
|
|
end component;
|
| 64 |
|
|
|
| 65 |
|
|
type req_vec_type is array (0 to n_ag_g - 1)
|
| 66 |
|
|
of std_logic_vector(n_ag_g - 1 downto 0);
|
| 67 |
|
|
|
| 68 |
|
|
signal grant_from_arb : req_vec_type;
|
| 69 |
|
|
signal grant_tmp : std_logic_vector(n_ag_g - 1 downto 0);
|
| 70 |
|
|
signal req : req_vec_type;
|
| 71 |
|
|
|
| 72 |
|
|
type src_id_type is array (0 to n_ag_g - 1) of std_logic_vector(switch_addr_width_g - 1 downto 0);
|
| 73 |
|
|
signal src_id_r : src_id_type;
|
| 74 |
|
|
|
| 75 |
|
|
begin -- rtl
|
| 76 |
|
|
|
| 77 |
|
|
-- generate arbiters for each dst
|
| 78 |
|
|
gen_arbs : for i in n_ag_g - 1 downto 0 generate
|
| 79 |
|
|
arb : arbiter
|
| 80 |
|
|
generic map (
|
| 81 |
|
|
arb_width_g => n_ag_g
|
| 82 |
|
|
)
|
| 83 |
|
|
port map (
|
| 84 |
|
|
clk => clk,
|
| 85 |
|
|
rst_n => rst_n,
|
| 86 |
|
|
req_in => req(i),
|
| 87 |
|
|
hold_in => hold_in,
|
| 88 |
|
|
grant_out => grant_from_arb(i)
|
| 89 |
|
|
);
|
| 90 |
|
|
end generate gen_arbs;
|
| 91 |
|
|
|
| 92 |
|
|
-- maps req_addr_in from input port to 2-D req for arbs
|
| 93 |
|
|
-- req(1)(2) <=> src 2 requests dst 1
|
| 94 |
|
|
map_requests : process (req_in, req_addr_in)
|
| 95 |
|
|
begin -- process map_requests
|
| 96 |
|
|
|
| 97 |
|
|
for i in n_ag_g - 1 downto 0 loop
|
| 98 |
|
|
for j in n_ag_g - 1 downto 0 loop
|
| 99 |
|
|
|
| 100 |
|
|
if req_addr_in((i+1) * addr_width_g - 1 downto i * addr_width_g) =
|
| 101 |
|
|
std_logic_vector(to_unsigned(j, addr_width_g))
|
| 102 |
|
|
then
|
| 103 |
|
|
req(j)(i) <= req_in(i);
|
| 104 |
|
|
else
|
| 105 |
|
|
req(j)(i) <= '0';
|
| 106 |
|
|
end if;
|
| 107 |
|
|
end loop; -- j
|
| 108 |
|
|
|
| 109 |
|
|
|
| 110 |
|
|
end loop; -- i
|
| 111 |
|
|
|
| 112 |
|
|
end process map_requests;
|
| 113 |
|
|
|
| 114 |
|
|
-- maps grant from arb to output port
|
| 115 |
|
|
-- grant_from_arb(1)(2) <=> dst 1 granted for src 2
|
| 116 |
|
|
map_grants : process (grant_from_arb)
|
| 117 |
|
|
begin -- process map_grants
|
| 118 |
|
|
|
| 119 |
|
|
grant_tmp <= (others => '0');
|
| 120 |
|
|
|
| 121 |
|
|
for i in n_ag_g - 1 downto 0 loop
|
| 122 |
|
|
for j in n_ag_g - 1 downto 0 loop
|
| 123 |
|
|
if grant_from_arb (i)(j) = '1' then
|
| 124 |
|
|
grant_tmp(j) <= '1';
|
| 125 |
|
|
end if;
|
| 126 |
|
|
end loop; -- j
|
| 127 |
|
|
end loop; -- i
|
| 128 |
|
|
|
| 129 |
|
|
end process map_grants;
|
| 130 |
|
|
|
| 131 |
|
|
-- register grant_out
|
| 132 |
|
|
reg_grant_out : process (clk, rst_n)
|
| 133 |
|
|
begin -- process reg_grant_out
|
| 134 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
| 135 |
|
|
grant_out <= (others => '0');
|
| 136 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
| 137 |
|
|
grant_out <= grant_tmp;
|
| 138 |
|
|
end if;
|
| 139 |
|
|
end process reg_grant_out;
|
| 140 |
|
|
|
| 141 |
|
|
|
| 142 |
|
|
|
| 143 |
|
|
ctrl_switches : process (clk, rst_n)
|
| 144 |
|
|
variable req_addr_v : integer;
|
| 145 |
|
|
begin -- process ctrl_switches
|
| 146 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
| 147 |
|
|
src_id_r <= (others => std_logic_vector(to_unsigned(n_ag_g, switch_addr_width_g)));
|
| 148 |
|
|
|
| 149 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
| 150 |
|
|
|
| 151 |
|
|
-- Default assigment: Illegal src_id
|
| 152 |
|
|
|
| 153 |
|
|
-- a) osoite vakio koko siirron ajan
|
| 154 |
|
|
src_id_r <= (others => std_logic_vector (to_unsigned(n_ag_g, switch_addr_width_g)));
|
| 155 |
|
|
|
| 156 |
|
|
for i in n_ag_g - 1 downto 0 loop
|
| 157 |
|
|
|
| 158 |
|
|
if grant_tmp(i) = '1' then
|
| 159 |
|
|
req_addr_v := to_integer (unsigned(req_addr_in((i+1)*addr_width_g - 1 downto i*addr_width_g)));
|
| 160 |
|
|
src_id_r (req_addr_v) <= std_logic_vector(to_unsigned(i, switch_addr_width_g));
|
| 161 |
|
|
end if; -- grant_tmp
|
| 162 |
|
|
end loop; -- i
|
| 163 |
|
|
|
| 164 |
|
|
-- -- b) uus yritys, osoite ei tarvi olla vakio koko siirron ajan
|
| 165 |
|
|
-- for i in n_ag_g - 1 downto 0 loop
|
| 166 |
|
|
-- if grant_tmp(i) = '1' then
|
| 167 |
|
|
-- if req_in (i) = '1' then
|
| 168 |
|
|
-- assert false report "Start of tx, store addr" severity note;
|
| 169 |
|
|
-- -- Start of the transfer
|
| 170 |
|
|
-- -- set dst mux to receive src
|
| 171 |
|
|
-- req_addr_v := to_integer (unsigned(req_addr_in((i+1)*addr_width_g - 1 downto i*addr_width_g)));
|
| 172 |
|
|
-- src_id_r (req_addr_v) <= std_logic_vector(to_unsigned(i, switch_addr_width_g));
|
| 173 |
|
|
-- else
|
| 174 |
|
|
-- assert false report "keep old addr" severity note;
|
| 175 |
|
|
-- end if;
|
| 176 |
|
|
-- else
|
| 177 |
|
|
-- -- No grant
|
| 178 |
|
|
-- -- -- src_id_r (mikä indeksi??) <= std_logic_vector (to_unsigned(n_ag_g, switch_addr_width_g));
|
| 179 |
|
|
|
| 180 |
|
|
-- for dst in 0 to n_ag_g-1 loop
|
| 181 |
|
|
-- if src_id_r( dst) = std_logic_vector(to_unsigned(i, switch_addr_width_g)) then
|
| 182 |
|
|
-- assert false report "reset src_id_r" severity note;
|
| 183 |
|
|
-- src_id_r (dst) <= std_logic_vector(to_unsigned(n_ag_g, switch_addr_width_g));
|
| 184 |
|
|
-- end if;
|
| 185 |
|
|
-- end loop; -- dst
|
| 186 |
|
|
|
| 187 |
|
|
-- end if; -- grant_tmp
|
| 188 |
|
|
-- end loop; -- i
|
| 189 |
|
|
-- b) loppuu
|
| 190 |
|
|
|
| 191 |
|
|
|
| 192 |
|
|
|
| 193 |
|
|
end if;
|
| 194 |
|
|
end process ctrl_switches;
|
| 195 |
|
|
|
| 196 |
|
|
|
| 197 |
|
|
-- map src_id_r to std_logic_vector and to out port
|
| 198 |
|
|
map_src_id_out : process (src_id_r)
|
| 199 |
|
|
begin -- process map_src_id_out
|
| 200 |
|
|
for i in n_ag_g - 1 downto 0 loop
|
| 201 |
|
|
src_id_out((i+1)* switch_addr_width_g - 1 downto i*switch_addr_width_g) <= src_id_r(i);
|
| 202 |
|
|
end loop; -- i
|
| 203 |
|
|
end process map_src_id_out;
|
| 204 |
|
|
|
| 205 |
|
|
end rtl;
|