Belle II KLM Scint Firmware  1
SamplingMask.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.all;
4 use ieee.numeric_std.all;
5 library work;
6 use work.klm_scint_pkg.all;
7 
8 
9 entity SamplingMask is
10  generic (N_WINS_PADDING : std_logic_vector(8 downto 0) := "000000010");
11  port (
12  clk : in std_logic;
13  rst : in std_logic := '0';
14  ena : in std_logic := '0';
15  new_bit : in std_logic := '1';
16  win_start : in std_logic_vector(8 downto 0) := (others=>'0');
17  N_win : in std_logic_vector(3 downto 0) := (others=>'0');
18  wr_ena_mask : out std_logic_vector(511 downto 0) := (others=>'1')
19  );
20 end SamplingMask;
21 architecture Behavioral of SamplingMask is
22 
23 
24  signal ena_i : std_logic_vector(1 downto 0) := "00";
25  signal i_win : std_logic_vector(8 downto 0) := (others=>'0');
26  signal n_win_i : std_logic_vector(3 downto 0) := (others=>'0');
27  signal new_bit_i : std_logic := '1';
28 
29  type masking_state_machine is (
30  IDLE,
31  MODIFY_MASK
32  );
33  signal masking_state : masking_state_machine := IDLE;
34 
35 
36 begin
37 
38  ena_i(0) <= ena;
39  process (clk, ena)
40  begin
41  if rising_edge(clk) then
42  ena_i(1) <= ena;
43  end if;
44  end process;
45 
46 
47  process(clk, rst, ena_i, new_bit, win_start, n_win, n_win_i)
48  -- variable i_win : std_logic_vector(8 downto 0);
49  variable count : std_logic_vector(3 downto 0);
50  begin
51  if rising_edge(clk) then
52  if rst = '1' then
53  masking_state <= IDLE;
54  wr_ena_mask <= (others=>'1');
55  else
56  case( masking_state ) is
57 
58  when IDLE =>
59  if ena_i = "01" then
60  count := "0000";
61  i_win <= win_start - N_WINS_PADDING;
62  n_win_i <= n_win;
63  new_bit_i <= new_bit;
64  masking_state <= MODIFY_MASK;
65  else
66  masking_state <= IDLE;
67  end if;
68 
69  when MODIFY_MASK =>
70  wr_ena_mask(to_integer(unsigned(i_win))) <= new_bit_i;
71  if count = n_win_i + 2*to_integer(unsigned(N_WINS_PADDING)) then
72  masking_state <= IDLE;
73  else
74  count := count + '1';
75  i_win <= i_win + '1';
76  masking_state <= MODIFY_MASK;
77  end if;
78  end case;
79  end if;
80  end if;
81  end process;
82 
83 
84 
85 end Behavioral;