-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlux_ctr.vhd
executable file
·298 lines (227 loc) · 7.21 KB
/
lux_ctr.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY luxcontroller IS
PORT ( clk : in std_logic ; -- System Clock
rst : in std_logic ; -- System Rese
run : in std_logic ; -- run lux algo
);
END luxcontroller;
ARCHITECTURE RTL OF controller IS
component lux is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
start : in STD_LOGIC;
start_rst : in STD_LOGIC;
done : out STD_LOGIC;
Mt : in STD_LOGIC_VECTOR (31 downto 0);
Cout : out STD_LOGIC_VECTOR (31 downto 0)
);
end component ;
component ram_dual is
generic( d_width : integer := 12;
addr_width : integer := 8;
mem_depth : integer := 32
);
port (o1 : out STD_LOGIC_VECTOR(d_width - 1 downto 0);
o2 : out STD_LOGIC_VECTOR(d_width - 1 downto 0);
we1 : in STD_LOGIC;
we2 : in STD_LOGIC;
rst : in STD_LOGIC;
clk : in STD_LOGIC;
d1 : in STD_LOGIC_VECTOR(d_width - 1 downto 0);
addr1 : in unsigned(addr_width - 1 downto 0);
d2 : in STD_LOGIC_VECTOR(d_width - 1 downto 0);
addr2 : in unsigned(addr_width - 1 downto 0)
);
end component;
-- FSM States
type state_type is (idle, first_round, wait_R_first,Mt_round, wait_R_Mt,last_Mt,
last_round32,last_round32n,wait_R_32,wait_R_32n,lenght_round0,wait_R_lenght0,
lenght_round1,wait_R_lenght1, empty_round,wait_R_empty, c3_round,wait_R_C3);
-- FSM registers
signal state_reg : state_type;
signal state_next: state_type;
signal count_round_reg, count_round_next : unsigned(32 downto 0);
signal lux_start : STD_LOGIC;
signal lux_start_rst : STD_LOGIC;
signal lux_done : STD_LOGIC;
signal lux_Mt : STD_LOGIC_VECTOR (31 downto 0);
signal lux_Cout : STD_LOGIC_VECTOR (31 downto 0);
signal ramMt_o1, ramMt_o2, ramMt_we1 , ramMt_we2 : STD_LOGIC;
signal ramC3_o1, ramC3_o2, ramC3_we1 , ramC3_we2 : STD_LOGIC;
signal ramMt_d1,ramMt_d2,ramC3_d1,ramC3_d2 :STD_LOGIC_VECTOR (31 downto 0);
signal ramC3_addr1,ramC3_addr2 : unsigned( 3 downto 0);
signal ramMt_addr1,ramMt_addr2 : unsigned( 9 downto 0);
BEGIN
U_lux: lux PORT MAP (
clk => clk,
rst => rst,
start => lux_start,
start_rst => lux_start_rst,
done => lux_done,
Mt => lux_Mt,
Cout =>lux_Cout
);
U_ram_Mt: ram_dual
generic map (d_width => 32,
addr_width => 1024,
mem_depth : integer := 10)
PORT MAP (
o1 =>ramMt_o1 ,
o2 =>ramMt_o2 ,
we1 =>ramMt_we1 ,
we2 =>ramMt_we2 ,
rst =>rst ,
clk =>clk ,
d1 =>ramMt_d1 ,
addr1=>ramMt_addr1 ,
d2 =>ramMt_d2 ,
addr2=>ramMt_addr2 );
U_ram_C3: ram_dual
generic map (d_width => 32,
addr_width => 8,
mem_depth : integer := 4)
PORT MAP (
o1 =>ramC3_o1 ,
o2 =>ramC3_o2 ,
we1 =>ramC3_we1 ,
we2 =>ramC3_we2 ,
rst =>rst ,
clk =>clk ,
d1 =>ramC3_d1 ,
addr1=>ramC3_addr1 ,
d2 =>ramC3_d2 ,
addr2=>ramC3_addr2 );
cloked_process : process( clk, rst )
begin
if( rst='1' ) then
state_reg <= idle;
message_lenght_reg <= (others=>'0') ;
count_round_reg <= (others=>'0') ;
elsif( clk'event and clk='1' ) then
state_reg <= state_next;
count_round_reg <= count_round_next;
message_lenght_reg <= message_lenght_next;
end if;
end process ;
combinatory_FSM_next : process(state_reg, run, lux_done, message_lenght_reg, count_round_reg)
begin
state_next<= state_reg;
case state_reg is
when idle =>
if run = '1' then
state_next <=first_round;
end if
when first_round =>
state_next <=wait_R_first;
when wait_R_first =>
if lux_done = '1' then
state_next <=
end if;
when Mt_round =>
state_next <=wait_R_Mt;
when wait_R_Mt =>
if lux_done = '1' and message_lenght_reg = count_round_reg then
state_next <=last_Mt;
elsif lux_done = '1' then
state_next <= Mt_round;
end if;
when last_Mt =>
if message_lenght_reg(5 downto 0) = "00000" then
state_next <=last_round32;
else
state_next <=last_round32n;
end if;
when last_round32 =>
state_next <= wait_R_32;
when last_round32n =>
state_next <= wait_R_32n;
when wait_R_32 =>
if lux_done = '1' then
state_next <= lenght_round0;
end if;
when wait_R_32n =>
if lux_done = '1' then
state_next <= lenght_round0;
end if;
when lenght_round0 =>
state_next <= wait_R_lenght0;
when wait_R_lenght0 =>
if lux_done = '1' then
state_next <=lenght_round1;
end if;
when lenght_round1 =>wait_R_lenght1;
state_next <=
when wait_R_lenght1 =>
if lux_done = '1' then
state_next <=empty_round;
end if;
when empty_round =>
state_next <=wait_R_empty;
when wait_R_empty =>
if lux_done = '1' and count_round_reg = 15 then
state_next <= c3_round;
elsif lux_done = '1' then
state_next <= empty_round;
end if;
when c3_round =>
state_next <= wait_R_C3;
when wait_R_C3 =>
if lux_done = '1' and count_round_reg = 7 then
state_next <= idle;
elsif lux_done = '1' then
state_next <= c3_round;
end if;
when others =>
end case;
end process;
combinatory_command : process( )
begin
lux_start <= '0';
lux_start_rst <= '0' ;
-- lux_Mt <= ? (RAM_mt, modif last, 08, 00, lenght0,lenght1)
-- addr_ram_mt ? (read)
-- save C3 addr++ ramC3_addr1 (write)
case state_reg is
when idle =>
when first_round =>
lux_start_rst <= '1';
--lux_Mt <= RAM_MT
--addr_ram_mt ++
when wait_R_first =>
when Mt_round =>
lux_start <= '1';
--lux_Mt <= RAM_MT
--addr_ram_mt ++
when wait_R_Mt =>
when last_Mt =>
when last_round32 =>
lux_start <= '1';
--lux_Mt <= "80"
when last_round32n =>
lux_start <= '1';
--lux_Mt <= MMM10000000 (modified last)
when wait_R_32 =>
when wait_R_32n =>
when lenght_round0 =>
lux_start <= '1';
--lux_Mt <= lenght 0 (4byte)
when wait_R_lenght0 =>
when lenght_round1 =>
lux_start <= '1';
----lux_Mt <= lenght 1 (4byte)
when wait_R_lenght1 =>
when empty_round =>
lux_start <= '1';
----lux_Mt <= 0000000000
when wait_R_empty =>
when c3_round =>
lux_start <= '1';
----lux_Mt <= 0000000000
-- save C3 addr++
when wait_R_C3 =>
when others =>
end case;
end process;