VME_Funct_Match.vhd 4.98 KB
Newer Older
Tom Levens's avatar
Tom Levens committed
1 2 3 4 5
--------------------------------------------------------------------------------
-- CERN (BE-CO-HT)
-- VME64x Core
-- http://www.ohwr.org/projects/vme64x-core
--------------------------------------------------------------------------------
dpedrett's avatar
dpedrett committed
6
--
Tom Levens's avatar
Tom Levens committed
7
-- unit name:     VME_Funct_Match (VME_Funct_Match.vhd)
8
--
Tom Levens's avatar
Tom Levens committed
9 10
-- author:        Pablo Alvarez Sanchez <pablo.alvarez.sanchez@cern.ch>
--                Davide Pedretti       <davide.pedretti@cern.ch>
dpedrett's avatar
dpedrett committed
11
--
Tom Levens's avatar
Tom Levens committed
12
-- description:
dpedrett's avatar
dpedrett committed
13
--
Tom Levens's avatar
Tom Levens committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
-- dependencies:
--
--------------------------------------------------------------------------------
-- GNU LESSER GENERAL PUBLIC LICENSE
--------------------------------------------------------------------------------
-- This source file is free software; you can redistribute it and/or modify it
-- under the terms of the GNU Lesser General Public License as published by the
-- Free Software Foundation; either version 2.1 of the License, or (at your
-- option) any later version. This source is distributed in the hope that it
-- will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- See the GNU Lesser General Public License for more details. You should have
-- received a copy of the GNU Lesser General Public License along with this
-- source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
--------------------------------------------------------------------------------
-- last changes: see log.
--------------------------------------------------------------------------------
-- TODO: -
--------------------------------------------------------------------------------
dpedrett's avatar
dpedrett committed
33

Tom Levens's avatar
Tom Levens committed
34 35 36 37
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.vme64x_pack.all;
dpedrett's avatar
dpedrett committed
38 39

entity VME_Funct_Match is
Tom Levens's avatar
Tom Levens committed
40
  generic (
41
    g_ADEM      : t_adem_array(0 to 7);
42 43
    g_AMCAP     : t_amcap_array(0 to 7);
    g_DECODE_AM : boolean
Tom Levens's avatar
Tom Levens committed
44
  );
Tom Levens's avatar
Tom Levens committed
45
  port (
46 47
    clk_i          : in  std_logic;
    rst_n_i        : in  std_logic;
Tom Levens's avatar
Tom Levens committed
48

49 50
    -- Input address (to be decoded).
    addr_i         : in  std_logic_vector(31 downto 0);
51
    -- Sub-address of the function (the part not masked by adem).
52 53 54
    addr_o         : out std_logic_vector(31 downto 0);
    decode_start_i : in  std_logic;
    am_i           : in  std_logic_vector( 5 downto 0);
Tom Levens's avatar
Tom Levens committed
55

56
    ader_i         : in  t_ader_array(0 to 7);
Tom Levens's avatar
Tom Levens committed
57

Tristan Gingold's avatar
Tristan Gingold committed
58
    -- Set when a function is selected.
59 60
    decode_sel_o   : out std_logic;
    -- Set when sel_o is valid (decoding is done).
Tristan Gingold's avatar
Tristan Gingold committed
61
    decode_done_o  : out std_logic
Tom Levens's avatar
Tom Levens committed
62
  );
dpedrett's avatar
dpedrett committed
63
end VME_Funct_Match;
Tom Levens's avatar
Tom Levens committed
64

Tom Levens's avatar
Tom Levens committed
65 66
architecture rtl of VME_Funct_Match is
  -- Function index and ADEM from priority encoder
67 68 69
  signal s_function_sel : natural range 0 to 7;
  signal s_function_sel_valid : std_logic;
  signal s_decode_start_1 : std_logic;
70

Tom Levens's avatar
Tom Levens committed
71
  -- Selected function
72 73
  signal s_function      : std_logic_vector( 7 downto 0);
  signal s_ader_am_valid : std_logic_vector( 7 downto 0);
Tom Levens's avatar
Tom Levens committed
74 75
begin
  ------------------------------------------------------------------------------
76
  -- Address and AM comparators
Tom Levens's avatar
Tom Levens committed
77 78
  ------------------------------------------------------------------------------
  gen_match_loop : for i in 0 to 7 generate
79
    -- True in case of match
80 81 82
    s_function(i) <=
      '1' when (((addr_i(c_ADEM_M) and g_ADEM(i)(c_ADEM_M))
                 = ader_i(i)(c_ADEM_M))
83 84
                and ((am_i = ader_i(i)(c_ADER_AM))
                     or not g_DECODE_AM))
85
      else '0';
86 87 88
    -- True if the AM part of ADER is enabled by AMCAP
    s_ader_am_valid(i) <=
      g_AMCAP(i)(to_integer(unsigned(ader_i(i)(c_ADER_AM))));
Tom Levens's avatar
Tom Levens committed
89 90 91 92 93
  end generate;

  ------------------------------------------------------------------------------
  -- Function priority encoder
  ------------------------------------------------------------------------------
94 95
  process (clk_i)
  begin
Tom Levens's avatar
Tom Levens committed
96
    if rising_edge(clk_i) then
97 98 99
      s_function_sel <= 0;
      s_function_sel_valid <= '0';
      s_decode_start_1 <= '0';
100

Tom Levens's avatar
Tom Levens committed
101
      if rst_n_i = '0' then
102 103 104
        null;
      elsif decode_start_i = '1' then
        s_decode_start_1 <= '1';
105 106
        for i in 0 to 7 loop
          if s_function(i) = '1' then
107 108
            s_function_sel <= i;
            s_function_sel_valid <= s_ader_am_valid(i);
109 110 111
            exit;
          end if;
        end loop;
Tom Levens's avatar
Tom Levens committed
112 113 114 115 116 117 118
      end if;
    end if;
  end process;

  ------------------------------------------------------------------------------
  -- Address output latch
  ------------------------------------------------------------------------------
119 120 121
  process (clk_i) is
    variable mask : std_logic_vector(31 downto 0);
  begin
Tom Levens's avatar
Tom Levens committed
122
    if rising_edge(clk_i) then
123
      if rst_n_i = '0' or s_decode_start_1 = '0' then
Tom Levens's avatar
Tom Levens committed
124
        addr_o <= (others => '0');
125 126
        decode_done_o <= '0';
        decode_sel_o <= '0';
127
      else
128 129
        -- s_decode_start_1 is set.
        decode_done_o <= '1';
130

131 132
        if s_function_sel_valid = '1' then
          mask := (others => '0');
Tristan Gingold's avatar
Tristan Gingold committed
133
          mask(c_ADEM_M) := g_ADEM(s_function_sel)(c_ADEM_M);
134 135 136 137
          addr_o <= addr_i and not mask;
          decode_sel_o <= '1';
        else
          decode_sel_o <= '0';
Tom Levens's avatar
Tom Levens committed
138 139
        end if;
      end if;
140 141
    end if;
  end process;
Tom Levens's avatar
Tom Levens committed
142
end rtl;