-- 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, "--------------------------000-00") then
			sel := 0; -- statusReg / base 00000000 / mask 00000000
		elsif std_match(addr, "--------------------------000-01") then
			sel := 1; -- controlReg / base 00000001 / mask 00000000
		elsif std_match(addr, "--------------------------000-10") then
			sel := 2; -- pulser / base 00000002 / mask 00000000
		elsif std_match(addr, "--------------------------001---") then
			sel := 3; -- cbcI2C / base 00000008 / mask 00000007
		elsif std_match(addr, "--------------------------010---") then
			sel := 4; -- mainI2C / base 00000010 / mask 00000007
		elsif std_match(addr, "--------------------------011---") then
			sel := 5; -- captureBuffer / base 00000018 / mask 00000007
		elsif std_match(addr, "--------------------------100-0-") then
			sel := 6; -- emac_hostbus / base 00000020 / mask 00000001
		else
			sel := 99;
		end if;
		return sel;
	end ipbus_addr_sel;
 
end ipbus_addr_decode;
