2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.all;
4 use ieee.numeric_std.all;
7 use work.lx_rocon_pkg.all;
9 -- Main unit in the IRC cooprocessor
10 -- This could be written as generic (n IRC axes)
12 entity irc_proc_main is
15 num_irc_g : positive := 4
21 reset_i : in std_logic;
23 irc_i : in IRC_COUNT_OUTPUT_Array_Type((num_irc_g-1) downto 0);
25 irc_index_reset_o : out std_logic_vector((num_irc_g-1) downto 0);
27 mem_clk_i : in std_logic;
28 mem_en_i : in std_logic;
29 mem_we_i : in std_logic_vector(3 downto 0);
30 mem_addr_i : in std_logic_vector(ceil_log2(num_irc_g) downto 0);
31 mem_data_i : in std_logic_vector(31 downto 0);
32 mem_data_o : out std_logic_vector(31 downto 0)
36 architecture Behavioral of irc_proc_main is
38 signal op_s : std_logic_vector(1 downto 0);
39 signal axis_s : std_logic_vector((ceil_log2(num_irc_g)-1) downto 0);
41 signal op_r : std_logic_vector(1 downto 0);
42 signal axis_r : std_logic_vector((ceil_log2(num_irc_g)-1) downto 0);
44 signal ram_en_s : std_logic;
45 signal ram_addr_s : std_logic_vector((mem_addr_i'length-1) downto 0);
46 signal ram_write_s : std_logic_vector(3 downto 0);
47 signal ram_data_i_s : std_logic_vector(31 downto 0);
48 signal ram_data_o_s : std_logic_vector(31 downto 0);
53 generic map (num_irc_g)
62 -- FIXME: Template needs to support 1-bit WE enabling, getting KEEP conflicts on wea here
63 ram: xilinx_dualport_bram_no_change
68 address_width => ram_addr_s'length
79 douta => ram_data_o_s,
91 ram_addr_s <= axis_s & op_s(1);
94 process (irc_i, op_r, axis_r, ram_data_o_s, reset_i)
95 variable skip_v : std_logic;
96 variable irc_v : IRC_COUNT_OUTPUT_Type;
97 variable res_v : std_logic_vector(31 downto 0);
98 variable count_v : std_logic_vector(31 downto 0);
101 -- Init (reset the index reset events)
102 irc_index_reset_o <= (others => '0');
104 ram_write_s <= "0000";
105 ram_data_i_s <= (others => '0');
107 count_v := (others => '0');
111 if reset_i = '0' then
114 if op_r(1) = '0' then
116 irc_v := irc_i(to_integer(unsigned(axis_r)));
118 if op_r(0) = '0' then
119 count_v(7 downto 0) := irc_v.qcount;
122 if irc_v.index_event = '1' then
123 irc_index_reset_o(to_integer(unsigned(axis_r))) <= '1';
124 count_v(7 downto 0) := irc_v.index;
131 if count_v(7) = '1' then
132 count_v(31 downto 8) := (others => '1');
134 count_v(31 downto 8) := (others => '0');
138 ep_add32nc(count_v, not ram_data_o_s, '1', res_v);
141 count_v(7 downto 0) := res_v(7 downto 0);
143 if res_v(7) = '1' then
144 count_v(31 downto 8) := (others => '1');
146 count_v(31 downto 8) := (others => '0');
150 ep_add32nc(ram_data_o_s, count_v, '0', res_v);
154 ram_write_s <= "1111";
155 ram_data_i_s <= res_v;
160 -- Read next stored IRC
172 wait until clk_i'event and clk_i = '1';