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 3

Go to most recent revision | 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 2 JonasDC
entity mont_ctrl is
56 3 JonasDC
  port (
57
    clk   : in std_logic;
58
    reset : in std_logic;
59
      -- bus side
60
    start           : in std_logic;
61
    x_sel_single    : in std_logic_vector(1 downto 0);
62
    y_sel_single    : in std_logic_vector(1 downto 0);
63
    run_auto        : in std_logic;
64
    op_buffer_empty : in std_logic;
65
    op_sel_buffer   : in std_logic_vector(31 downto 0);
66
    read_buffer     : out std_logic;
67
    buffer_noread   : in std_logic;
68
    done            : out std_logic;
69
    calc_time       : out std_logic;
70
      -- multiplier side
71
    op_sel           : out std_logic_vector(1 downto 0);
72
    load_x           : out std_logic;
73
    load_result      : out std_logic;
74
    start_multiplier : out std_logic;
75
    multiplier_ready : in std_logic
76 2 JonasDC
  );
77
end mont_ctrl;
78
 
79 3 JonasDC
 
80 2 JonasDC
architecture Behavioral of mont_ctrl is
81 3 JonasDC
  signal start_delayed_i      : std_logic; -- delayed version of start input
82
  signal start_pulse_i        : std_logic;
83
  signal auto_start_pulse_i   : std_logic;
84
  signal start_multiplier_i   : std_logic;
85
  signal start_up_counter_i   : std_logic_vector(2 downto 0) := "100"; -- used in op_sel at multiplier start
86
  signal auto_start_i         : std_logic := '0';
87
  signal store_autorun_i      : std_logic;
88
  signal run_auto_i           : std_logic;
89
  signal run_auto_stored_i    : std_logic := '0';
90
  signal single_start_pulse_i : std_logic;
91 2 JonasDC
 
92 3 JonasDC
  signal calc_time_i : std_logic; -- high ('1') during multiplication
93
 
94
  signal x_sel_i        : std_logic_vector(1 downto 0); -- the operand used as x input
95
  signal y_sel_i        : std_logic_vector(1 downto 0); -- the operand used as y input
96
  signal x_sel_buffer_i : std_logic_vector(1 downto 0); -- x operand as specified by fifo buffer (autorun)
97
 
98
  signal auto_done_i             : std_logic;
99
  signal start_auto_i            : std_logic;
100
  signal new_buf_part_i          : std_logic;
101
  signal new_buf_word_i          : std_logic;
102
  signal buf_part_i              : std_logic_vector(3 downto 0);
103
  signal pop_i                   : std_logic;
104
  signal start_autorun_cycle_i   : std_logic;
105
  signal start_autorun_cycle_1_i : std_logic;
106
  signal autorun_counter_i       : std_logic_vector(1 downto 0);
107
  signal part_counter_i          : std_logic_vector(2 downto 0);
108
  signal auto_multiplier_done_i : std_logic;
109 2 JonasDC
 
110
begin
111
 
112
        -----------------------------------------------------------------------------------
113
        -- Processes related to starting and stopping the multiplier
114
        -----------------------------------------------------------------------------------
115
        -- generate a start pulse (duration 1 clock cycle) based on ext. start sig
116
        START_PULSE_PROC: process(clk)
117
        begin
118
                if rising_edge(clk) then
119
                        start_delayed_i <= start;
120
                end if;
121
        end process START_PULSE_PROC;
122
        start_pulse_i <= start and (not start_delayed_i);
123
        single_start_pulse_i <= start_pulse_i and (not run_auto_i);
124
        start_auto_i <= start_pulse_i and run_auto_i;
125
 
126
        -- to start the multiplier we first need to select the y_operand and
127
        -- clock it in the y_register
128
        -- the we select the x_operand and start the multiplier
129
        START_MULT_PROC: process(clk, reset)
130
        begin
131
                if reset = '1' then
132
                        start_up_counter_i <= "100";
133
                elsif rising_edge(clk) then
134
                        if start_pulse_i = '1' or auto_start_pulse_i = '1' then
135
                                start_up_counter_i <= "000";
136
                        elsif start_up_counter_i(2) /= '1' then
137
                                start_up_counter_i <= start_up_counter_i + '1';
138
                        else
139
                                start_up_counter_i <= "100";
140
                        end if;
141
                else
142
                        start_up_counter_i <= start_up_counter_i;
143
                end if;
144
        end process;
145
 
146
        -- select operands (autorun/single run)
147
        x_sel_i <= x_sel_buffer_i when (run_auto_i = '1') else x_sel_single;
148
        y_sel_i <= "11" when (run_auto_i = '1') else y_sel_single; -- y is operand3 in auto mode
149
 
150
        -- clock operands to operand_mem output (first y, then x)
151
        with start_up_counter_i(2 downto 1) select
152
                op_sel <= y_sel_i when "00",
153
                          x_sel_i when others;
154
        load_x <= start_up_counter_i(0) and (not start_up_counter_i(1));
155
        -- start multiplier
156
        start_multiplier_i <= start_up_counter_i(1) and start_up_counter_i(0);
157
        start_multiplier <= start_multiplier_i;
158
 
159
        -- signal calc time is high during multiplication
160
        CALC_TIME_PROC: process(clk, reset)
161
        begin
162
                if reset = '1' then
163
                        calc_time_i <= '0';
164
                elsif rising_edge(clk) then
165
                        if start_multiplier_i = '1' then
166
                                calc_time_i <= '1';
167
                        elsif multiplier_ready = '1' then
168
                                calc_time_i <= '0';
169
                        else
170
                                calc_time_i <= calc_time_i;
171
                        end if;
172
                else
173
                        calc_time_i <= calc_time_i;
174
                end if;
175
        end process CALC_TIME_PROC;
176
        calc_time <= calc_time_i;
177
 
178
        -- what happens when a multiplication has finished
179
        load_result <= multiplier_ready;
180
        -- ignore multiplier_ready when in automode, the logic will assert auto_done_i when finished
181
        done <= ((not run_auto_i) and multiplier_ready) or auto_done_i;
182
 
183
        -----------------------------------------------------------------------------------
184
        -- Processes related to op_buffer cntrl and auto_run mode
185
        -- start_auto_i     -> start autorun mode operation
186
        -- auto_start_pulse <- autorun logic starts the multiplier
187
        -- auto_done        <- autorun logic signals when autorun operation has finished
188
        -- x_sel_buffer_i   <- autorun logic determines which operand is used as x
189
 
190
        -- check buffer empty signal
191
        -----------------------------------------------------------------------------------
192
 
193
        -- at the beginning of each new multiplication we store the current autorun bit
194
--      STORE_AUTORUN_PROC: process(clk)
195
--      begin
196
--              if rising_edge(clk) then
197
--                      if store_autorun_i = '1' then
198
--                              run_auto_stored_i <= run_auto;
199
--                      else
200
--                              run_auto_stored_i <= run_auto_stored_i;
201
--                      end if;
202
--              end if;
203
--      end process STORE_AUTORUN_PROC;
204
        run_auto_i <= run_auto;
205
 
206
        -- multiplier_ready is only passed to autorun control when in autorun mode
207
        auto_multiplier_done_i <= (multiplier_ready and run_auto_i);
208 3 JonasDC
 
209
  autorun_control_logic : autorun_cntrl port map(
210
    clk              => clk,
211
    reset            => reset,
212
    start            => start_auto_i,
213
    done             => auto_done_i,
214
    op_sel           => x_sel_buffer_i,
215
    start_multiplier => auto_start_pulse_i,
216
    multiplier_done  => auto_multiplier_done_i,
217
    read_buffer      => read_buffer,
218
    buffer_din       => op_sel_buffer,
219
    buffer_empty     => op_buffer_empty
220
  );
221
 
222 2 JonasDC
end Behavioral;

powered by: WebSVN 2.1.0

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