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

Subversion Repositories salsa20

[/] [salsa20/] [trunk/] [rtl/] [salsaa_dm.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 lukasz.dzi
--
2
-- Copyright 2012 iQUBE research
3
--
4
-- This file is part of Salsa20IpCore.
5
--
6
-- Salsa20IpCore is free software: you can redistribute it and/or modify
7
-- it under the terms of the GNU Lesser General Public License as published by
8
-- the Free Software Foundation, either version 3 of the License, or
9
-- (at your option) any later version.
10
--
11
-- Salsa20IpCore is distributed in the hope that it will be useful,
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
-- GNU Lesser General Public License for more details.
15
--
16
-- You should have received a copy of the GNU Lesser General Public License
17
-- along with Salsa20IpCore.  If not, see <http://www.gnu.org/licenses/>.
18
--
19
-- contact: Rúa Fonte das Abelleiras s/n, Campus Universitario de Vigo, 36310, Vigo (Spain)
20
-- e-mail: lukasz.dzianach@iqube.es, info@iqube.es
21
-- 
22
 
23
library IEEE;
24
use IEEE.std_logic_1164.all;
25
use IEEE.std_logic_unsigned.all;
26
use IEEE.NUMERIC_STD.all;
27
 
28
 
29
entity salsaa_dm is
30
        port (
31
                clk             : in std_logic;
32
                reset   : in std_logic;
33
 
34
                -- iface for user
35
                data                    : out std_logic_vector(31 downto 0);
36
                data_req        : in std_logic;
37
                data_valid      : out std_logic;
38
 
39
                -- iface to salsaa_mc
40
                mc_data                 : in std_logic_vector(511 downto 0);
41
                mc_restart      : out std_logic;
42
                mc_busy                 : in std_logic
43
 
44
        );
45
end entity salsaa_dm;
46
 
47
architecture rtl of salsaa_dm is
48
 
49
type reg_type is array(0 to 15) of std_logic_vector(31 downto 0);
50
 
51
signal state                    : std_logic_vector (3 downto 0);
52
signal reg                              : reg_type;
53
signal reg_idx                          : std_logic_vector (3 downto 0);
54
 
55
 
56
constant dm_rst                         : std_logic_vector := x"0";
57
constant dm_wmc_dr              : std_logic_vector := x"1";
58
constant dm_wmc_ndr             : std_logic_vector := x"2";
59
constant dm_idl                 : std_logic_vector := x"3";
60
constant dm_lmd                 : std_logic_vector := x"4";
61
constant dm_lmdps                       : std_logic_vector := x"5";
62
constant dm_ps                          : std_logic_vector := x"6";
63
 
64
constant max_reg_idx    : std_logic_vector := x"f";
65
 
66
begin
67
 
68
main:   process(clk) is
69
begin
70
        if (clk'event and clk='1') then
71
                if (reset='1') then
72
                        state <= dm_rst;
73
 
74
                        for Z in 0 to 15
75
                        loop
76
                                --reg(Z) <= mc_data(32 * Z + 31 downto 32 * Z + 0);                     
77
                                reg(Z) <= x"00000000";
78
                        end loop;
79
 
80
                        data_valid <= '0';
81
                        data <= x"00000000";
82
                        reg_idx <= x"0";
83
 
84
                else
85
 
86
                        case state is
87
 
88
                                when dm_rst =>
89
                                        reg_idx <= x"0";
90
                                        data_valid <= '0';
91
                                        mc_restart <= '0';
92
 
93
                                        if mc_busy = '0' and data_req = '1' then
94
                                                state <= dm_lmdps;
95
                                        elsif data_req = '1' then
96
                                                state <= dm_wmc_dr;
97
                                        elsif  mc_busy = '0' then
98
                                                state <= dm_lmd;
99
                                        end if;
100
 
101
                                when dm_lmdps =>
102
 
103
                                        -- state to reg
104
                                        reg(00) <= mc_data(32 * 00 + 31 downto 32 * 00 + 0);
105
                                        reg(01) <= mc_data(32 * 01 + 31 downto 32 * 01 + 0);
106
                                        reg(02) <= mc_data(32 * 02 + 31 downto 32 * 02 + 0);
107
                                        reg(03) <= mc_data(32 * 03 + 31 downto 32 * 03 + 0);
108
                                        reg(04) <= mc_data(32 * 04 + 31 downto 32 * 04 + 0);
109
                                        reg(05) <= mc_data(32 * 05 + 31 downto 32 * 05 + 0);
110
                                        reg(06) <= mc_data(32 * 06 + 31 downto 32 * 06 + 0);
111
                                        reg(07) <= mc_data(32 * 07 + 31 downto 32 * 07 + 0);
112
                                        reg(08) <= mc_data(32 * 08 + 31 downto 32 * 08 + 0);
113
                                        reg(09) <= mc_data(32 * 09 + 31 downto 32 * 09 + 0);
114
                                        reg(10) <= mc_data(32 * 10 + 31 downto 32 * 10 + 0);
115
                                        reg(11) <= mc_data(32 * 11 + 31 downto 32 * 11 + 0);
116
                                        reg(12) <= mc_data(32 * 12 + 31 downto 32 * 12 + 0);
117
                                        reg(13) <= mc_data(32 * 13 + 31 downto 32 * 13 + 0);
118
                                        reg(14) <= mc_data(32 * 14 + 31 downto 32 * 14 + 0);
119
                                        reg(15) <= mc_data(32 * 15 + 31 downto 32 * 15 + 0);
120
 
121
                                        reg_idx <= reg_idx + x"1";
122
                                        data_valid <= '1';
123
                                        mc_restart <= '1';
124
                                        data <= mc_data(32 * 00 + 31 downto 32 * 00 + 0);
125
 
126
                                        if data_req = '1' then
127
                                                state <= dm_ps;
128
                                        else
129
                                                state <= dm_idl;
130
                                        end if;
131
 
132
                                when dm_lmd =>
133
 
134
                                        -- state to reg
135
                                        reg(00) <= mc_data(32 * 00 + 31 downto 32 * 00 + 0);
136
                                        reg(01) <= mc_data(32 * 01 + 31 downto 32 * 01 + 0);
137
                                        reg(02) <= mc_data(32 * 02 + 31 downto 32 * 02 + 0);
138
                                        reg(03) <= mc_data(32 * 03 + 31 downto 32 * 03 + 0);
139
                                        reg(04) <= mc_data(32 * 04 + 31 downto 32 * 04 + 0);
140
                                        reg(05) <= mc_data(32 * 05 + 31 downto 32 * 05 + 0);
141
                                        reg(06) <= mc_data(32 * 06 + 31 downto 32 * 06 + 0);
142
                                        reg(07) <= mc_data(32 * 07 + 31 downto 32 * 07 + 0);
143
                                        reg(08) <= mc_data(32 * 08 + 31 downto 32 * 08 + 0);
144
                                        reg(09) <= mc_data(32 * 09 + 31 downto 32 * 09 + 0);
145
                                        reg(10) <= mc_data(32 * 10 + 31 downto 32 * 10 + 0);
146
                                        reg(11) <= mc_data(32 * 11 + 31 downto 32 * 11 + 0);
147
                                        reg(12) <= mc_data(32 * 12 + 31 downto 32 * 12 + 0);
148
                                        reg(13) <= mc_data(32 * 13 + 31 downto 32 * 13 + 0);
149
                                        reg(14) <= mc_data(32 * 14 + 31 downto 32 * 14 + 0);
150
                                        reg(15) <= mc_data(32 * 15 + 31 downto 32 * 15 + 0);
151
 
152
                                        reg_idx <= x"0";
153
                                        data_valid <= '0';
154
                                        mc_restart <= '1';
155
 
156
                                        if data_req = '1' then
157
                                                state <= dm_ps;
158
                                        else
159
                                                state <= dm_idl;
160
                                        end if;
161
 
162
                                when dm_ps =>
163
 
164
                                        -- loading data to output
165
                                        data <= reg(to_integer(unsigned(reg_idx)));
166
                                        data_valid <= '1';
167
 
168
                                        -- mc should not restart in this state
169
                                        mc_restart <= '0';
170
 
171
                                        -- moving reg_idx
172
                                        if reg_idx = max_reg_idx then
173
                                                reg_idx <= x"0";
174
                                        else
175
                                                reg_idx <= reg_idx + x"1";
176
                                        end if;
177
 
178
 
179
 
180
                                        -- selecting next state
181
                                        if reg_idx = max_reg_idx then
182
                                                -- considering the situation when the last reg_idx
183
                                                if data_req = '0' and mc_busy = '0' then
184
                                                        state <= dm_lmd;
185
                                                elsif data_req = '0' and mc_busy = '1' then
186
                                                        state <= dm_wmc_ndr;
187
                                                elsif data_req = '1' and mc_busy = '0' then
188
                                                        state <= dm_lmdps;
189
                                                elsif data_req = '1' and mc_busy = '1' then
190
                                                        state <= dm_wmc_dr;
191
                                                end if;
192
                                        else
193
                                                -- considering typical situation
194
                                                if data_req = '1' then
195
                                                        state <= dm_ps;
196
                                                elsif data_req = '0' then
197
                                                        state <= dm_idl;
198
                                                end if;
199
                                        end if;
200
 
201
                                when dm_idl =>
202
 
203
                                        -- no valid data
204
                                        data_valid <= '0';
205
 
206
                                        -- mc should not restart in this state
207
                                        mc_restart <= '0';
208
 
209
                                        -- selecting next state CHECK THIS CODE
210
                                        if data_req = '1' then
211
                                                state <= dm_ps;
212
                                        elsif data_req = '0' then
213
                                                state <= dm_idl;
214
                                        end if;
215
 
216
                                when dm_wmc_dr =>
217
 
218
                                        -- no valid data
219
                                        data_valid <= '0';
220
 
221
                                        -- mc should not restart in this state
222
                                        mc_restart <= '0';
223
 
224
                                        -- sett to the beginning of data register
225
                                        reg_idx <= x"0";
226
 
227
                                        -- selecting next state
228
                                        if mc_busy = '0' then
229
                                                state <= dm_lmdps;
230
                                        end if;
231
 
232
                                when dm_wmc_ndr =>
233
 
234
                                        -- no valid data
235
                                        data_valid <= '0';
236
 
237
                                        -- mc should not restart in this state
238
                                        mc_restart <= '0';
239
 
240
                                        -- set to the beginning of data register
241
                                        reg_idx <= x"0";
242
 
243
                                        -- selecting next state
244
                                        if mc_busy = '0' and data_req = '0' then
245
                                                state <= dm_lmd;
246
                                        elsif mc_busy = '0' and data_req = '1' then
247
                                                state <= dm_lmdps;
248
                                        elsif mc_busy = '1' and data_req = '0' then
249
                                                state <= dm_wmc_ndr;
250
                                        elsif mc_busy = '1' and data_req = '1' then
251
                                                state <= dm_wmc_dr;
252
                                        end if;
253
 
254
                                when others =>
255
                                        null;
256
 
257
                        end case;
258
 
259
                end if;
260
        end if;
261
end process;
262
 
263
end architecture rtl;

powered by: WebSVN 2.1.0

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