library IEEE; use IEEE.std_logic_1164.all; use IEEE.MATH_REAL.all; library work; use work.io_types.all; entity control_unit is port ( clk, rst : in std_logic; ext_control_in : in ext_control_unit_in_t; ext_control_out : out ext_control_unit_out_t; int_control_in : in int_control_unit_in_t; int_control_out : out int_control_unit_out_t; ); end entity control_unit; architecture behave of control_unit is type state_t is record address: std_logic_vector(address_width - 1 downto 0); seq_mem_access_count: std_logic_vector(seq_vector_length - 1 downto 0); curr_driver: std_logic_vector(number_of_drivers - 1 downto 0); --one-hot encoded, 0 means disabled ready: std_logic; instruction: std_logic_vector(inst_word_width - 1 downto 0); end record state_t; signal state: state_t; shared variable ored: std_logic; begin comb_proc: process(control_in, state) begin ored := '0'; ready_reduction: for i in 0 to number_of_drivers - 1 loop ored := ored or int_control_in.active_driver(i); end loop ready_reduction; int_control_out.driver_id <= state.curr_driver; int_control_out.address <= state.address; int_control_out.seq_mem_access_count <= state.seq_mem_access_count; int_control_out.ready <= state.ready; int_control_out.instruction <= state.instruction; end process comb_proc; sync_proc: process(clk, state) begin if rising_edge(clk) then if rst = '1' then state <= ((others => '0'), (others => '0'), (others => '0'), '1', x"00"); else state.ready <= not ored; if ored = '0' then state.address <= ext_control_in.address; state.seq_mem_access_count <= ext_control_in.seq_mem_access_count; state.curr_driver <= ext_control_in.driver_id; state.instruction <= ext_control_in.instruction; end if; end if; end if; end process sync_proc; end architecture behave;