-- Address decode logic for ipbus fabric
--
-- This file has been AUTOGENERATED from the address table - do not hand edit
--
-- We assume the synthesis tool is clever enough to recognise exclusive conditions
-- in the if statement.
--
-- Dave Newbold, February 2011

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
use work.ipbus.all;

package ipbus_addr_decode is

  function ipbus_addr_sel(signal addr : in std_logic_vector(31 downto 0)) return integer;

end ipbus_addr_decode;

package body ipbus_addr_decode is

  function ipbus_addr_sel(signal addr : in std_logic_vector(31 downto 0)) return integer is
    variable sel : integer;
  begin
		if    std_match(addr, "-----------------------0001-----") then
			sel := 0; -- DUTInterfaces / base 00000020 / mask 0000001f
		elsif std_match(addr, "-----------------------0010-----") then
			sel := 1; -- triggerInputs / base 00000040 / mask 0000001f
		elsif std_match(addr, "-----------------------0011-----") then
			sel := 2; -- triggerLogic / base 00000060 / mask 0000001f
		elsif std_match(addr, "-----------------------0100-----") then
			sel := 3; -- eventBuffer / base 00000080 / mask 0000001f
		elsif std_match(addr, "-----------------------0101-----") then
			sel := 4; -- logic_clocks / base 000000a0 / mask 0000001f
		elsif std_match(addr, "-----------------------0110-----") then
			sel := 5; -- i2c_master / base 000000c0 / mask 00000007
		elsif std_match(addr, "-----------------------1010-----") then
                        sel := 6; -- Event_Formatter / base 00000140 / mask 0000001f
                elsif std_match(addr, "-----------------------1011-----") then
                        sel := 7; -- TPix3_iface   / base 00000160 / mask 0000001f
		elsif std_match(addr, "-----------------------0000-----") then
			sel := 8; -- version / base 00000000 / mask 00000000
		else
			sel := 99;
		end if;
		return sel;
	end ipbus_addr_sel;
 
end ipbus_addr_decode;
