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] - Blame information for rev 95

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 JonasDC
----------------------------------------------------------------------  
2
----  mont_ctrl                                                   ---- 
3
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9
----    control unit for a pipelined montgomery multiplier, with  ----
10
----    split pipeline operation and "auto-run" support           ----
11
----                                                              ----
12
----  Dependencies:                                               ----
13
----    - autorun_cntrl                                           ----
14
----                                                              ----
15
----  Authors:                                                    ----
16
----      - Geoffrey Ottoy, DraMCo research group                 ----
17
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
18
----                                                              ---- 
19
---------------------------------------------------------------------- 
20
----                                                              ---- 
21
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
22
----                                                              ---- 
23
---- This source file may be used and distributed without         ---- 
24
---- restriction provided that this copyright statement is not    ---- 
25
---- removed from the file and that any derivative work contains  ---- 
26
---- the original copyright notice and the associated disclaimer. ---- 
27
----                                                              ---- 
28
---- This source file is free software; you can redistribute it   ---- 
29
---- and/or modify it under the terms of the GNU Lesser General   ---- 
30
---- Public License as published by the Free Software Foundation; ---- 
31
---- either version 2.1 of the License, or (at your option) any   ---- 
32
---- later version.                                               ---- 
33
----                                                              ---- 
34
---- This source is distributed in the hope that it will be       ---- 
35
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
36
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
37
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
38
---- details.                                                     ---- 
39
----                                                              ---- 
40
---- You should have received a copy of the GNU Lesser General    ---- 
41
---- Public License along with this source; if not, download it   ---- 
42
---- from http://www.opencores.org/lgpl.shtml                     ---- 
43
----                                                              ---- 
44
----------------------------------------------------------------------
45 2 JonasDC
 
46 3 JonasDC
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.std_logic_arith.all;
49
use ieee.std_logic_unsigned.all;
50 2 JonasDC
 
51 3 JonasDC
library mod_sim_exp;
52
use mod_sim_exp.mod_sim_exp_pkg.all;
53
 
54
 
55 24 JonasDC
-- This module controls the montgommery mutliplier and controls traffic between
56
-- RAM and multiplier. Also contains the autorun logic for exponentiations.
57 2 JonasDC
entity mont_ctrl is
58 3 JonasDC
  port (
59
    clk   : in std_logic;
60
    reset : in std_logic;
61
      -- bus side
62
    start           : in std_logic;
63
    x_sel_single    : in std_logic_vector(1 downto 0);
64
    y_sel_single    : in std_logic_vector(1 downto 0);
65
    run_auto        : in std_logic;
66
    op_buffer_empty : in std_logic;
67
    op_sel_buffer   : in std_logic_vector(31 downto 0);
68
    read_buffer     : out std_logic;
69
    done            : out std_logic;
70
    calc_time       : out std_logic;
71
      -- multiplier side
72
    op_sel           : out std_logic_vector(1 downto 0);
73
    load_x           : out std_logic;
74
    load_result      : out std_logic;
75
    start_multiplier : out std_logic;
76
    multiplier_ready : in std_logic
77 2 JonasDC
  );
78
end mont_ctrl;
79
 
80 3 JonasDC
 
81 2 JonasDC
architecture Behavioral of mont_ctrl is
82 95 JonasDC
  signal start_d            : std_logic; -- delayed version of start input
83 24 JonasDC
  signal start_pulse        : std_logic;
84
  signal auto_start_pulse   : std_logic;
85 95 JonasDC
  signal start_multiplier_i : std_logic;
86
  signal start_up_counter   : std_logic_vector(3 downto 0) := "1000"; -- used in op_sel at multiplier start
87 2 JonasDC
 
88 3 JonasDC
  signal calc_time_i : std_logic; -- high ('1') during multiplication
89
 
90 24 JonasDC
  signal x_sel        : std_logic_vector(1 downto 0); -- the operand used as x input
91
  signal y_sel        : std_logic_vector(1 downto 0); -- the operand used as y input
92
  signal x_sel_buffer : std_logic_vector(1 downto 0); -- x operand as specified by fifo buffer (autorun)
93 3 JonasDC
 
94 95 JonasDC
  signal auto_done              : std_logic;
95
  signal start_auto             : std_logic;
96 3 JonasDC
  signal auto_multiplier_done_i : std_logic;
97 95 JonasDC
  signal multiplier_ready_d     : std_logic;
98 2 JonasDC
begin
99
 
100 95 JonasDC
  -----------------------------------------------------------------------------------
101
  -- Processes related to starting and stopping the multiplier
102
  -----------------------------------------------------------------------------------
103
  -- generate a start pulse (duration 1 clock cycle) based on ext. start sig
104
  START_PULSE_PROC : process(clk)
105
  begin
106
    if rising_edge(clk) then
107
      start_d <= start;
108
    end if;
109
  end process START_PULSE_PROC;
110
 
111
  start_pulse <= start and (not start_d);
112
  start_auto <= start_pulse and run_auto;
113
 
114
  -- to start the multiplier we first need to select the x_operand and
115
  -- clock it in the x shift register
116
  -- the we select the y_operand and start the multiplier
117
 
118
  -- start_up_counter
119
  --   default state : "1000"
120
  --   at start pulse counter resets to 0 and counts up to "1000"
121
  START_MULT_PROC : process(clk, reset)
122
  begin
123
    if reset = '1' then
124
      start_up_counter <= "1000";
125
    elsif rising_edge(clk) then
126
      if start_pulse = '1' or auto_start_pulse = '1' then
127
        start_up_counter <= "0000";
128
      elsif start_up_counter(3) /= '1' then
129
        start_up_counter <= start_up_counter + '1';
130
      else
131
        start_up_counter <= "1000";
132
      end if;
133
    end if;
134
  end process;
135 2 JonasDC
 
136 95 JonasDC
  -- select operands (autorun/single run)
137
  x_sel <= x_sel_buffer when (run_auto = '1') else x_sel_single;
138
  y_sel <= "11" when (run_auto = '1') else y_sel_single; -- y is operand3 in auto mode
139
 
140
  -- clock operands to operand_mem output (first x, then y)
141
  with start_up_counter(3 downto 2) select
142
    op_sel <= x_sel when "00",  -- start_up_counter="00xx" (first 4 cycles)
143
                  y_sel when others;  -- 
144
  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"
145
 
146
  -- start multiplier when start_up_counter="x111"
147
  start_multiplier_i <= start_up_counter(2) and start_up_counter(1) and start_up_counter(0);
148
  start_multiplier <= start_multiplier_i;
149
 
150
  -- signal calc time is high during multiplication
151
  CALC_TIME_PROC : process(clk, reset)
152
  begin
153
    if reset = '1' then
154
      calc_time_i <= '0';
155
    elsif rising_edge(clk) then
156
      if start_multiplier_i = '1' then
157
        calc_time_i <= '1';
158
      elsif multiplier_ready = '1' then
159
        calc_time_i <= '0';
160
      else
161
        calc_time_i <= calc_time_i;
162
      end if;
163
    end if;
164
  end process CALC_TIME_PROC;
165
  calc_time <= calc_time_i;
166
 
167
  -- what happens when a multiplication has finished
168
  -- delay result writeback
169
  RES_DEL_PROC : process(clk)
170
  begin
171
    if rising_edge(clk) then
172
      multiplier_ready_d <= multiplier_ready;
173
      load_result <= multiplier_ready_d;
174
    end if;
175
  end process;
176
  -- ignore multiplier_ready when in automode, the logic will assert auto_done when finished
177
  done <= ((not run_auto) and multiplier_ready) or auto_done;
178
 
179
  -----------------------------------------------------------------------------------
180
  -- Processes related to op_buffer cntrl and auto_run mode
181
  -- start_auto     -> start autorun mode operation
182
  -- auto_start_pulse <- autorun logic starts the multiplier
183
  -- auto_done        <- autorun logic signals when autorun operation has finished
184
  -- x_sel_buffer   <- autorun logic determines which operand is used as x
185
 
186
  -- check buffer empty signal
187
  -----------------------------------------------------------------------------------
188
 
189
  -- multiplier_ready is only passed to autorun control when in autorun mode
190
  auto_multiplier_done_i <= (multiplier_ready and run_auto);
191 24 JonasDC
 
192 3 JonasDC
  autorun_control_logic : autorun_cntrl port map(
193
    clk              => clk,
194
    reset            => reset,
195 24 JonasDC
    start            => start_auto,
196
    done             => auto_done,
197
    op_sel           => x_sel_buffer,
198
    start_multiplier => auto_start_pulse,
199 3 JonasDC
    multiplier_done  => auto_multiplier_done_i,
200
    read_buffer      => read_buffer,
201
    buffer_din       => op_sel_buffer,
202
    buffer_empty     => op_buffer_empty
203
  );
204
 
205 2 JonasDC
end Behavioral;

powered by: WebSVN 2.1.0

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