OpenCores
URL https://opencores.org/ocsvn/mod_sim_exp/mod_sim_exp/trunk

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [trunk/] [rtl/] [vhdl/] [core/] [mont_ctrl.vhd] - Diff between revs 3 and 24

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 3 Rev 24
Line 50... Line 50...
 
 
library mod_sim_exp;
library mod_sim_exp;
use mod_sim_exp.mod_sim_exp_pkg.all;
use mod_sim_exp.mod_sim_exp_pkg.all;
 
 
 
 
 
-- This module controls the montgommery mutliplier and controls traffic between
 
-- RAM and multiplier. Also contains the autorun logic for exponentiations.
entity mont_ctrl is
entity mont_ctrl is
  port (
  port (
    clk   : in std_logic;
    clk   : in std_logic;
    reset : in std_logic;
    reset : in std_logic;
      -- bus side
      -- bus side
Line 76... Line 78...
  );
  );
end mont_ctrl;
end mont_ctrl;
 
 
 
 
architecture Behavioral of mont_ctrl is
architecture Behavioral of mont_ctrl is
  signal start_delayed_i      : std_logic; -- delayed version of start input
  signal start_d      : std_logic; -- delayed version of start input
  signal start_pulse_i        : std_logic;
  signal start_pulse        : std_logic;
  signal auto_start_pulse_i   : std_logic;
  signal auto_start_pulse   : std_logic;
  signal start_multiplier_i   : std_logic;
  signal start_multiplier_i   : std_logic;
  signal start_up_counter_i   : std_logic_vector(2 downto 0) := "100"; -- used in op_sel at multiplier start
  signal start_up_counter   : std_logic_vector(2 downto 0) := "100"; -- used in op_sel at multiplier start
  signal auto_start_i         : std_logic := '0';
 
  signal store_autorun_i      : std_logic;
 
  signal run_auto_i           : std_logic;
 
  signal run_auto_stored_i    : std_logic := '0';
 
  signal single_start_pulse_i : std_logic;
 
 
 
  signal calc_time_i : std_logic; -- high ('1') during multiplication
  signal calc_time_i : std_logic; -- high ('1') during multiplication
 
 
  signal x_sel_i        : 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_i        : 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_i : 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_i             : std_logic;
  signal auto_done             : std_logic;
  signal start_auto_i            : std_logic;
  signal start_auto            : std_logic;
  signal new_buf_part_i          : std_logic;
 
  signal new_buf_word_i          : std_logic;
 
  signal buf_part_i              : std_logic_vector(3 downto 0);
 
  signal pop_i                   : std_logic;
 
  signal start_autorun_cycle_i   : std_logic;
 
  signal start_autorun_cycle_1_i : std_logic;
 
  signal autorun_counter_i       : std_logic_vector(1 downto 0);
 
  signal part_counter_i          : std_logic_vector(2 downto 0);
 
  signal auto_multiplier_done_i : std_logic;
  signal auto_multiplier_done_i : std_logic;
 
 
begin
begin
 
 
        -----------------------------------------------------------------------------------
        -----------------------------------------------------------------------------------
Line 114... Line 103...
        -----------------------------------------------------------------------------------
        -----------------------------------------------------------------------------------
        -- generate a start pulse (duration 1 clock cycle) based on ext. start sig
        -- generate a start pulse (duration 1 clock cycle) based on ext. start sig
        START_PULSE_PROC: process(clk)
        START_PULSE_PROC: process(clk)
        begin
        begin
                if rising_edge(clk) then
                if rising_edge(clk) then
                        start_delayed_i <= start;
                        start_d <= start;
                end if;
                end if;
        end process START_PULSE_PROC;
        end process START_PULSE_PROC;
        start_pulse_i <= start and (not start_delayed_i);
        start_pulse <= start and (not start_d);
        single_start_pulse_i <= start_pulse_i and (not run_auto_i);
        start_auto <= start_pulse and run_auto;
        start_auto_i <= start_pulse_i and run_auto_i;
 
 
        -- to start the multiplier we first need to select the x_operand and
        -- to start the multiplier we first need to select the y_operand and
        -- clock it in the x shift register
        -- clock it in the y_register
        -- the we select the y_operand and start the multiplier
        -- the we select the x_operand and start the multiplier
 
 
        -- start_up_counter
 
        --   default state : "100"
 
        --   at start pulse counter resets to 0 and counts up to "100"
        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_i <= "100";
                        start_up_counter <= "100";
                elsif rising_edge(clk) then
                elsif rising_edge(clk) then
                        if start_pulse_i = '1' or auto_start_pulse_i = '1' then
                        if start_pulse = '1' or auto_start_pulse = '1' then
                                start_up_counter_i <= "000";
                                start_up_counter <= "000";
                        elsif start_up_counter_i(2) /= '1' then
                        elsif start_up_counter(2) /= '1' then
                                start_up_counter_i <= start_up_counter_i + '1';
                                start_up_counter <= start_up_counter + '1';
                        else
                        else
                                start_up_counter_i <= "100";
                                start_up_counter <= "100";
                        end if;
                        end if;
                else
                else
                        start_up_counter_i <= start_up_counter_i;
                        start_up_counter <= start_up_counter;
                end if;
                end if;
        end process;
        end process;
 
 
        -- select operands (autorun/single run)
        -- select operands (autorun/single run)
        x_sel_i <= x_sel_buffer_i when (run_auto_i = '1') else x_sel_single;
        x_sel <= x_sel_buffer when (run_auto = '1') else x_sel_single;
        y_sel_i <= "11" when (run_auto_i = '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 y, then x)
        -- clock operands to operand_mem output (first x, then y)
        with start_up_counter_i(2 downto 1) select
        with start_up_counter(2 downto 1) select
                op_sel <= y_sel_i when "00",
                op_sel <= x_sel when "00",  -- start_up_counter="00x" (first 2 cycles)
                          x_sel_i when others;
                          y_sel when others;  -- 
        load_x <= start_up_counter_i(0) and (not start_up_counter_i(1));
        load_x <= start_up_counter(0) and (not start_up_counter(1)); -- latch x operand if start_up_counter="x01"
        -- start multiplier
 
        start_multiplier_i <= start_up_counter_i(1) and start_up_counter_i(0);
        -- start multiplier when start_up_counter="x11"
 
        start_multiplier_i <= 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 175... Line 168...
        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;
        load_result <= multiplier_ready;
        -- ignore multiplier_ready when in automode, the logic will assert auto_done_i when finished
        -- ignore multiplier_ready when in automode, the logic will assert auto_done when finished
        done <= ((not run_auto_i) and multiplier_ready) or auto_done_i;
        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
        -- start_auto_i     -> start autorun mode operation
        -- start_auto     -> start autorun mode operation
        -- auto_start_pulse <- autorun logic starts the multiplier
        -- auto_start_pulse <- autorun logic starts the multiplier
        -- auto_done        <- autorun logic signals when autorun operation has finished
        -- auto_done        <- autorun logic signals when autorun operation has finished
        -- x_sel_buffer_i   <- autorun logic determines which operand is used as x
        -- x_sel_buffer   <- autorun logic determines which operand is used as x
 
 
        -- check buffer empty signal
        -- check buffer empty signal
        -----------------------------------------------------------------------------------
        -----------------------------------------------------------------------------------
 
 
        -- at the beginning of each new multiplication we store the current autorun bit
 
--      STORE_AUTORUN_PROC: process(clk)
 
--      begin
 
--              if rising_edge(clk) then
 
--                      if store_autorun_i = '1' then
 
--                              run_auto_stored_i <= run_auto;
 
--                      else
 
--                              run_auto_stored_i <= run_auto_stored_i;
 
--                      end if;
 
--              end if;
 
--      end process STORE_AUTORUN_PROC;
 
        run_auto_i <= run_auto;
 
 
 
        -- multiplier_ready is only passed to autorun control when in autorun mode
        -- multiplier_ready is only passed to autorun control when in autorun mode
        auto_multiplier_done_i <= (multiplier_ready and run_auto_i);
        auto_multiplier_done_i <= (multiplier_ready and run_auto);
 
 
  autorun_control_logic : autorun_cntrl port map(
  autorun_control_logic : autorun_cntrl port map(
    clk              => clk,
    clk              => clk,
    reset            => reset,
    reset            => reset,
    start            => start_auto_i,
    start            => start_auto,
    done             => auto_done_i,
    done             => auto_done,
    op_sel           => x_sel_buffer_i,
    op_sel           => x_sel_buffer,
    start_multiplier => auto_start_pulse_i,
    start_multiplier => auto_start_pulse,
    multiplier_done  => auto_multiplier_done_i,
    multiplier_done  => auto_multiplier_done_i,
    read_buffer      => read_buffer,
    read_buffer      => read_buffer,
    buffer_din       => op_sel_buffer,
    buffer_din       => op_sel_buffer,
    buffer_empty     => op_buffer_empty
    buffer_empty     => op_buffer_empty
  );
  );

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.