Line 81... |
Line 81... |
architecture Behavioral of mont_ctrl is
|
architecture Behavioral of mont_ctrl is
|
signal start_d : std_logic; -- delayed version of start input
|
signal start_d : std_logic; -- delayed version of start input
|
signal start_pulse : std_logic;
|
signal start_pulse : std_logic;
|
signal auto_start_pulse : std_logic;
|
signal auto_start_pulse : std_logic;
|
signal start_multiplier_i : std_logic;
|
signal start_multiplier_i : std_logic;
|
signal start_up_counter : std_logic_vector(2 downto 0) := "100"; -- used in op_sel at multiplier start
|
signal start_up_counter : std_logic_vector(3 downto 0) := "1000"; -- used in op_sel at multiplier start
|
|
|
signal calc_time_i : std_logic; -- high ('1') during multiplication
|
signal calc_time_i : std_logic; -- high ('1') during multiplication
|
|
|
signal x_sel : std_logic_vector(1 downto 0); -- the operand used as x input
|
signal x_sel : std_logic_vector(1 downto 0); -- the operand used as x input
|
signal y_sel : std_logic_vector(1 downto 0); -- the operand used as y input
|
signal y_sel : std_logic_vector(1 downto 0); -- the operand used as y input
|
signal x_sel_buffer : std_logic_vector(1 downto 0); -- x operand as specified by fifo buffer (autorun)
|
signal x_sel_buffer : std_logic_vector(1 downto 0); -- x operand as specified by fifo buffer (autorun)
|
|
|
signal auto_done : std_logic;
|
signal auto_done : std_logic;
|
signal start_auto : std_logic;
|
signal start_auto : std_logic;
|
signal auto_multiplier_done_i : std_logic;
|
signal auto_multiplier_done_i : std_logic;
|
|
signal multiplier_ready_d : std_logic;
|
begin
|
begin
|
|
|
-----------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------
|
-- Processes related to starting and stopping the multiplier
|
-- Processes related to starting and stopping the multiplier
|
-----------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------
|
Line 105... |
Line 105... |
begin
|
begin
|
if rising_edge(clk) then
|
if rising_edge(clk) then
|
start_d <= start;
|
start_d <= start;
|
end if;
|
end if;
|
end process START_PULSE_PROC;
|
end process START_PULSE_PROC;
|
|
|
start_pulse <= start and (not start_d);
|
start_pulse <= start and (not start_d);
|
start_auto <= start_pulse and run_auto;
|
start_auto <= start_pulse and run_auto;
|
|
|
-- to start the multiplier we first need to select the x_operand and
|
-- to start the multiplier we first need to select the x_operand and
|
-- clock it in the x shift register
|
-- clock it in the x shift register
|
-- the we select the y_operand and start the multiplier
|
-- the we select the y_operand and start the multiplier
|
|
|
-- start_up_counter
|
-- start_up_counter
|
-- default state : "100"
|
-- default state : "1000"
|
-- at start pulse counter resets to 0 and counts up to "100"
|
-- at start pulse counter resets to 0 and counts up to "1000"
|
START_MULT_PROC: process(clk, reset)
|
START_MULT_PROC: process(clk, reset)
|
begin
|
begin
|
if reset = '1' then
|
if reset = '1' then
|
start_up_counter <= "100";
|
start_up_counter <= "1000";
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
if start_pulse = '1' or auto_start_pulse = '1' then
|
if start_pulse = '1' or auto_start_pulse = '1' then
|
start_up_counter <= "000";
|
start_up_counter <= "0000";
|
elsif start_up_counter(2) /= '1' then
|
elsif start_up_counter(3) /= '1' then
|
start_up_counter <= start_up_counter + '1';
|
start_up_counter <= start_up_counter + '1';
|
else
|
else
|
start_up_counter <= "100";
|
start_up_counter <= "1000";
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
-- select operands (autorun/single run)
|
-- select operands (autorun/single run)
|
x_sel <= x_sel_buffer when (run_auto = '1') else x_sel_single;
|
x_sel <= x_sel_buffer when (run_auto = '1') else x_sel_single;
|
y_sel <= "11" when (run_auto = '1') else y_sel_single; -- y is operand3 in auto mode
|
y_sel <= "11" when (run_auto = '1') else y_sel_single; -- y is operand3 in auto mode
|
|
|
-- clock operands to operand_mem output (first x, then y)
|
-- clock operands to operand_mem output (first x, then y)
|
with start_up_counter(2 downto 1) select
|
with start_up_counter(3 downto 2) select
|
op_sel <= x_sel when "00", -- start_up_counter="00x" (first 2 cycles)
|
op_sel <= x_sel when "00", -- start_up_counter="00xx" (first 4 cycles)
|
y_sel when others; --
|
y_sel when others; --
|
load_x <= start_up_counter(0) and (not start_up_counter(1)); -- latch x operand if start_up_counter="x01"
|
load_x <= (not start_up_counter(2)) and start_up_counter(1) and start_up_counter(0); -- latch x operand if start_up_counter="x011"
|
|
|
-- start multiplier when start_up_counter="x11"
|
-- start multiplier when start_up_counter="x111"
|
start_multiplier_i <= start_up_counter(1) and start_up_counter(0);
|
start_multiplier_i <= start_up_counter(2) and start_up_counter(1) and start_up_counter(0);
|
start_multiplier <= start_multiplier_i;
|
start_multiplier <= start_multiplier_i;
|
|
|
-- signal calc time is high during multiplication
|
-- signal calc time is high during multiplication
|
CALC_TIME_PROC: process(clk, reset)
|
CALC_TIME_PROC: process(clk, reset)
|
begin
|
begin
|
Line 162... |
Line 163... |
end if;
|
end if;
|
end process CALC_TIME_PROC;
|
end process CALC_TIME_PROC;
|
calc_time <= calc_time_i;
|
calc_time <= calc_time_i;
|
|
|
-- what happens when a multiplication has finished
|
-- what happens when a multiplication has finished
|
load_result <= multiplier_ready;
|
-- delay result writeback
|
|
RES_DEL_PROC : process(clk)
|
|
begin
|
|
if rising_edge(clk) then
|
|
multiplier_ready_d <= multiplier_ready;
|
|
load_result <= multiplier_ready_d;
|
|
end if;
|
|
end process;
|
-- ignore multiplier_ready when in automode, the logic will assert auto_done when finished
|
-- ignore multiplier_ready when in automode, the logic will assert auto_done when finished
|
done <= ((not run_auto) and multiplier_ready) or auto_done;
|
done <= ((not run_auto) and multiplier_ready) or auto_done;
|
|
|
-----------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------
|
-- Processes related to op_buffer cntrl and auto_run mode
|
-- Processes related to op_buffer cntrl and auto_run mode
|