2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.all;
4 use ieee.numeric_std.all;
6 use work.lx_rocon_pkg.all;
8 -- Main unit in the IRC cooprocessor
9 -- This could be written as generic (n IRC axes)
11 entity irc_proc_main is
16 reset_i : in std_logic;
18 irc_i : in IRC_COUNT_OUTPUT_Array_Type(3 downto 0);
20 irc_index_reset_o : out std_logic_vector(3 downto 0);
22 mem_clk_i : in std_logic;
23 mem_en_i : in std_logic;
24 mem_we_i : in std_logic_vector(3 downto 0);
25 mem_addr_i : in std_logic_vector(2 downto 0);
26 mem_data_i : in std_logic_vector(31 downto 0);
27 mem_data_o : out std_logic_vector(31 downto 0)
31 architecture Behavioral of irc_proc_main is
33 signal op_s : std_logic_vector(1 downto 0);
34 signal axis_s : std_logic_vector(1 downto 0);
36 signal op_r : std_logic_vector(1 downto 0);
37 signal axis_r : std_logic_vector(1 downto 0);
39 signal ram_en_s : std_logic;
40 signal ram_addr_s : std_logic_vector(2 downto 0);
41 signal ram_write_s : std_logic_vector(3 downto 0);
42 signal ram_data_i_s : std_logic_vector(31 downto 0);
43 signal ram_data_o_s : std_logic_vector(31 downto 0);
56 ram: xilinx_dualport_bram_no_change
72 douta => ram_data_o_s,
83 -- RAM address (delayed by a cycle when writing)
84 ram_addr_s <= (axis_r & op_r(1)) when ram_write_s = "1111" else (axis_s & op_s(1));
89 variable skip_v : std_logic;
90 variable irc_v : IRC_COUNT_OUTPUT_Type;
91 variable res_v : std_logic_vector(31 downto 0);
92 variable count_v : std_logic_vector(31 downto 0);
96 wait until clk_i'event and clk_i = '1';
98 -- Init (reset the index reset events)
99 irc_index_reset_o <= (others => '0');
101 if reset_i = '1' then
104 ram_write_s <= "0000";
105 ram_data_i_s <= (others => '0');
107 op_r <= (others => '0');
108 axis_r <= (others => '0');
114 ram_write_s <= "0000";
117 if op_r(1) = '0' then
119 irc_v := irc_i(to_integer(unsigned(axis_s)));
121 if op_r(0) = '0' then
122 count_v(7 downto 0) := irc_v.qcount;
125 if irc_v.index_event = '1' then
126 irc_index_reset_o(to_integer(unsigned(axis_s))) <= '1';
127 count_v(7 downto 0) := irc_v.index;
134 if count_v(7) = '1' then
135 count_v(31 downto 8) := (others => '1');
137 count_v(31 downto 8) := (others => '0');
141 ep_add32nc(count_v, not ram_data_o_s, '1', res_v);
144 count_v(7 downto 0) := res_v(7 downto 0);
146 if res_v(7) = '1' then
147 count_v(31 downto 8) := (others => '1');
149 count_v(31 downto 8) := (others => '0');
153 ep_add32nc(ram_data_o_s, count_v, '0', res_v);
157 ram_write_s <= "1111";
158 ram_data_i_s <= res_v;
163 -- Read next stored IRC
164 -- FIXME: Wire the enabling directly so it takes one cycle less,
165 -- although op_r = "11" is reserved for potential extesion for 2nd index,
166 -- so not very important