1 |
2 |
zeuscz |
library ieee;
|
2 |
|
|
use ieee.std_logic_1164.all;
|
3 |
|
|
use ieee.numeric_std.all;
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
entity control is
|
7 |
|
|
port(
|
8 |
|
|
data : in std_logic_vector(7 downto 0); -- input for data version(4B), hashprevblock(32B), merklehash(32B), time(4B), target(4B), difficulty(32B)
|
9 |
|
|
loaddata : in std_logic; -- loaddata = 1 for load input data
|
10 |
|
|
dataout : out bit_vector ( 7 downto 0); -- output for results
|
11 |
|
|
loaddataout : out bit; -- loaddataout = 1 when results are ready
|
12 |
|
|
clk : in std_logic; -- master clock signal
|
13 |
|
|
controlrst : in std_logic -- master reset signal
|
14 |
|
|
);
|
15 |
|
|
end control;
|
16 |
|
|
|
17 |
|
|
architecture phy2 of control is
|
18 |
|
|
|
19 |
|
|
signal md : bit_vector (31 downto 0) := (others => '0');
|
20 |
|
|
signal v : bit := '0';
|
21 |
|
|
signal m : bit_vector ( 31 downto 0) := (others => '0');
|
22 |
|
|
signal ld : bit := '0';
|
23 |
|
|
signal init : bit := '0';
|
24 |
|
|
signal rst : std_logic := '0';
|
25 |
|
|
signal hash : bit_vector (255 downto 0) := (others => '0');
|
26 |
|
|
signal cmphash : bit_vector (255 downto 0) := (others => '0');
|
27 |
|
|
signal reset : bit := '0';
|
28 |
|
|
signal resethash : bit := '0';
|
29 |
|
|
signal pom : bit := '0';
|
30 |
|
|
signal start : bit := '0';
|
31 |
|
|
signal start2 : bit := '0';
|
32 |
|
|
signal difficulty : bit_vector (255 downto 0) := (others => '0');
|
33 |
|
|
signal cmpstart : bit := '0';
|
34 |
|
|
signal loaded : bit := '0';
|
35 |
|
|
signal output : std_logic := '0';
|
36 |
|
|
signal output_slow : std_logic := '0';
|
37 |
|
|
signal clkreset : std_logic := '0';
|
38 |
|
|
signal stop : std_logic := '0';
|
39 |
|
|
signal ntime : bit_vector (31 downto 0) := (others => '0');
|
40 |
|
|
signal ntime_max : bit_vector (31 downto 0) := (others => '0');
|
41 |
|
|
signal sendend : std_logic := '0';
|
42 |
|
|
signal nonce_out : bit_vector (31 downto 0) := (others => '0');
|
43 |
|
|
signal ntime_out : bit_vector (31 downto 0) := (others => '0');
|
44 |
|
|
|
45 |
|
|
signal data1 : bit_vector (31 downto 0) := (others => '0');
|
46 |
|
|
signal data2 : bit_vector (31 downto 0) := (others => '0');
|
47 |
|
|
signal data3 : bit_vector (31 downto 0) := (others => '0');
|
48 |
|
|
signal data4 : bit_vector (31 downto 0) := (others => '0');
|
49 |
|
|
signal data5 : bit_vector (31 downto 0) := (others => '0');
|
50 |
|
|
signal data6 : bit_vector (31 downto 0) := (others => '0');
|
51 |
|
|
signal data7 : bit_vector (31 downto 0) := (others => '0');
|
52 |
|
|
signal data8 : bit_vector (31 downto 0) := (others => '0');
|
53 |
|
|
signal data9 : bit_vector (31 downto 0) := (others => '0');
|
54 |
|
|
signal data10 : bit_vector (31 downto 0) := (others => '0');
|
55 |
|
|
signal data11 : bit_vector (31 downto 0) := (others => '0');
|
56 |
|
|
signal data12 : bit_vector (31 downto 0) := (others => '0');
|
57 |
|
|
signal data13 : bit_vector (31 downto 0) := (others => '0');
|
58 |
|
|
signal data14 : bit_vector (31 downto 0) := (others => '0');
|
59 |
|
|
signal data15 : bit_vector (31 downto 0) := (others => '0');
|
60 |
|
|
signal data16 : bit_vector (31 downto 0) := (others => '0');
|
61 |
|
|
signal data17 : bit_vector (31 downto 0) := (others => '0');
|
62 |
|
|
signal data18 : bit_vector (31 downto 0) := (others => '0');
|
63 |
|
|
signal data19 : bit_vector (31 downto 0) := (others => '0');
|
64 |
|
|
signal data20 : bit_vector (31 downto 0) := X"00000000";--(others => '0'); -- nonce (32bitu)
|
65 |
|
|
signal data21 : bit_vector (31 downto 0) := X"00000080"; -- padding
|
66 |
|
|
signal data22 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
67 |
|
|
signal data23 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
68 |
|
|
signal data24 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
69 |
|
|
signal data25 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
70 |
|
|
signal data26 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
71 |
|
|
signal data27 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
72 |
|
|
signal data28 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
73 |
|
|
signal data29 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
74 |
|
|
signal data30 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
75 |
|
|
signal data31 : bit_vector (31 downto 0) := X"00000000"; -- padding
|
76 |
|
|
signal data32 : bit_vector (31 downto 0) := X"80020000"; -- padding
|
77 |
|
|
|
78 |
|
|
begin
|
79 |
|
|
|
80 |
|
|
-- sha256 unit
|
81 |
|
|
hashsha256: entity work.sha256
|
82 |
|
|
port map(
|
83 |
|
|
m => m, -- input data for hash (16*32 bits = 512bits)
|
84 |
|
|
init => init, -- init signal
|
85 |
|
|
ld => ld, -- load signal (ld = 1 for loading 256 bits, after ld = 0)
|
86 |
|
|
md => md, -- result hash 8*32 bits (256bits)
|
87 |
|
|
v => v, -- output signal = hash is ready
|
88 |
|
|
clk => CLK,
|
89 |
|
|
rst => rst
|
90 |
|
|
);
|
91 |
|
|
|
92 |
|
|
rst <= to_stdulogic(resethash);
|
93 |
|
|
|
94 |
|
|
-- load hash from sha256 unit
|
95 |
|
|
loadhash: process(clk,reset,controlrst,sendend,stop,loaded)
|
96 |
|
|
variable cnt_in : integer := 0;
|
97 |
|
|
variable cnt_in2 : integer := 0;
|
98 |
|
|
variable final : integer := 0;
|
99 |
|
|
variable complete : integer := 0;
|
100 |
|
|
|
101 |
|
|
begin
|
102 |
|
|
if ((clk = '1') and clk'event) then
|
103 |
|
|
|
104 |
|
|
pom <= '0';
|
105 |
|
|
cmpstart <= '0';
|
106 |
|
|
|
107 |
|
|
if ((controlrst = '1') or (reset = '1') or ((stop = '1') and (loaded = '0'))) then
|
108 |
|
|
cnt_in := 0;
|
109 |
|
|
cnt_in2 := 0;
|
110 |
|
|
final := 0;
|
111 |
|
|
end if;
|
112 |
|
|
|
113 |
|
|
if((v = '1') and (complete = 1)) then
|
114 |
|
|
cnt_in2 := cnt_in2+1;
|
115 |
|
|
complete :=0;
|
116 |
|
|
cmpstart <= '1';
|
117 |
|
|
elsif ((v = '1') and (final = 0)) then
|
118 |
|
|
final := 1;
|
119 |
|
|
elsif ((v = '1') and (final = 1)) then
|
120 |
|
|
cnt_in := cnt_in+1;
|
121 |
|
|
final := 0;
|
122 |
|
|
complete :=1;
|
123 |
|
|
end if;
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
if (cnt_in > 0) then
|
127 |
|
|
|
128 |
|
|
CASE cnt_in IS
|
129 |
|
|
WHEN 2 => hash(255 downto 224) <= md;
|
130 |
|
|
WHEN 3 => hash(223 downto 192) <= md;
|
131 |
|
|
WHEN 4 => hash(191 downto 160) <= md;
|
132 |
|
|
WHEN 5 => hash(159 downto 128) <= md;
|
133 |
|
|
WHEN 6 => hash(127 downto 96) <= md;
|
134 |
|
|
WHEN 7 => hash(95 downto 64) <= md;
|
135 |
|
|
WHEN 8 => hash(63 downto 32) <= md;
|
136 |
|
|
WHEN 9 => hash(31 downto 0) <= md;
|
137 |
|
|
when others =>
|
138 |
|
|
END CASE;
|
139 |
|
|
|
140 |
|
|
if((cnt_in = 9) and (complete = 1)) then
|
141 |
|
|
pom <= '1';
|
142 |
|
|
end if;
|
143 |
|
|
|
144 |
|
|
cnt_in:=cnt_in+1;
|
145 |
|
|
end if;
|
146 |
|
|
|
147 |
|
|
if (cnt_in2 > 0) then
|
148 |
|
|
|
149 |
|
|
CASE cnt_in2 IS
|
150 |
|
|
WHEN 2 => cmphash(255 downto 224) <= md;
|
151 |
|
|
WHEN 3 => cmphash(223 downto 192) <= md;
|
152 |
|
|
WHEN 4 => cmphash(191 downto 160) <= md;
|
153 |
|
|
WHEN 5 => cmphash(159 downto 128) <= md;
|
154 |
|
|
WHEN 6 => cmphash(127 downto 96) <= md;
|
155 |
|
|
WHEN 7 => cmphash(95 downto 64) <= md;
|
156 |
|
|
WHEN 8 => cmphash(63 downto 32) <= md;
|
157 |
|
|
WHEN 9 => cmphash(31 downto 0) <= md;
|
158 |
|
|
when others =>
|
159 |
|
|
END CASE;
|
160 |
|
|
|
161 |
|
|
cnt_in2:=cnt_in2+1;
|
162 |
|
|
end if;
|
163 |
|
|
end if;
|
164 |
|
|
end process;
|
165 |
|
|
|
166 |
|
|
-- process sets control signals
|
167 |
|
|
setsignals: process(clk,reset,loaded,start2,controlrst,stop)
|
168 |
|
|
variable cnt : integer := 0;
|
169 |
|
|
variable rstcnt : integer := 0;
|
170 |
|
|
variable complete : integer := 0;
|
171 |
|
|
variable final : integer := 0;
|
172 |
|
|
variable resetoff : integer := 0;
|
173 |
|
|
|
174 |
|
|
begin
|
175 |
|
|
if ((clk = '1') and clk'event) then
|
176 |
|
|
|
177 |
|
|
ld <= '0';
|
178 |
|
|
init <= '0';
|
179 |
|
|
resethash <= '0';
|
180 |
|
|
|
181 |
|
|
if ((controlrst = '1') or ((stop = '1') and (loaded = '0'))) then
|
182 |
|
|
cnt := 0;
|
183 |
|
|
final := 0;
|
184 |
|
|
resethash <= '1';
|
185 |
|
|
else
|
186 |
|
|
|
187 |
|
|
if(cnt > 0) then
|
188 |
|
|
cnt := cnt+1;
|
189 |
|
|
end if;
|
190 |
|
|
|
191 |
|
|
if((loaded = '1') and (cnt = 0)) then
|
192 |
|
|
cnt := 1;
|
193 |
|
|
resetoff := 1;
|
194 |
|
|
end if;
|
195 |
|
|
|
196 |
|
|
if(resetoff = 1) then
|
197 |
|
|
resethash <= '0';
|
198 |
|
|
else
|
199 |
|
|
resethash <= '1';
|
200 |
|
|
end if;
|
201 |
|
|
|
202 |
|
|
if (reset = '1') then
|
203 |
|
|
cnt := 1;
|
204 |
|
|
final := 0;
|
205 |
|
|
end if;
|
206 |
|
|
|
207 |
|
|
if((cnt > 0) and (cnt < 17)) then
|
208 |
|
|
ld <= '1';
|
209 |
|
|
end if;
|
210 |
|
|
|
211 |
|
|
if((v = '1') and (complete = 1)) then
|
212 |
|
|
complete :=0;
|
213 |
|
|
rstcnt := rstcnt+1;
|
214 |
|
|
elsif ((v = '1') and (final = 0)) then
|
215 |
|
|
final := 1;
|
216 |
|
|
elsif ((v = '1') and (final = 1)) then
|
217 |
|
|
rstcnt := rstcnt+1;
|
218 |
|
|
final := 0;
|
219 |
|
|
complete :=1;
|
220 |
|
|
end if;
|
221 |
|
|
|
222 |
|
|
if(rstcnt > 0 and (rstcnt < 10)) then
|
223 |
|
|
rstcnt := rstcnt+1;
|
224 |
|
|
end if;
|
225 |
|
|
|
226 |
|
|
if((rstcnt = 10) and (start2 = '1') and (complete = 0)) then
|
227 |
|
|
reset <= '1';
|
228 |
|
|
resethash <= '1';
|
229 |
|
|
rstcnt := 11;
|
230 |
|
|
elsif((rstcnt = 10) and (start2 = '0') and (complete = 0)) then
|
231 |
|
|
resethash <= '1';
|
232 |
|
|
reset <= '1';
|
233 |
|
|
elsif((rstcnt = 11) and (complete = 0)) then
|
234 |
|
|
reset <= '0';
|
235 |
|
|
rstcnt := 0;
|
236 |
|
|
end if;
|
237 |
|
|
|
238 |
|
|
if((rstcnt = 10) and (complete = 1)) then
|
239 |
|
|
reset <= '1';
|
240 |
|
|
resethash <= '1';
|
241 |
|
|
rstcnt := 11;
|
242 |
|
|
elsif((rstcnt = 11) and (complete = 1)) then
|
243 |
|
|
reset <= '0';
|
244 |
|
|
rstcnt := 0;
|
245 |
|
|
end if;
|
246 |
|
|
|
247 |
|
|
if(cnt = 1) then
|
248 |
|
|
init <= '1';
|
249 |
|
|
end if;
|
250 |
|
|
|
251 |
|
|
if ((cnt > 75) and (cnt < 92)) then
|
252 |
|
|
ld <= '1';
|
253 |
|
|
end if;
|
254 |
|
|
end if;
|
255 |
|
|
end if;
|
256 |
|
|
end process;
|
257 |
|
|
|
258 |
|
|
-- load data to sha256 unit
|
259 |
|
|
loadhashdata: process(CLK,pom,loaded,reset,start,controlrst,stop)
|
260 |
|
|
variable cnt1 : integer := 0;
|
261 |
|
|
variable cnt2 : integer := 0;
|
262 |
|
|
variable settime : integer := 0;
|
263 |
|
|
begin
|
264 |
|
|
if((clk = '1') and clk'event) then
|
265 |
|
|
|
266 |
|
|
if((controlrst = '1') or (reset = '1') or ((stop = '1') and (loaded = '0'))) then
|
267 |
|
|
cnt1:=0;
|
268 |
|
|
cnt2:=0;
|
269 |
|
|
settime := 0;
|
270 |
|
|
end if;
|
271 |
|
|
|
272 |
|
|
if((loaded = '1') and (cnt1 = 0)) then
|
273 |
|
|
cnt1:= 1;
|
274 |
|
|
end if;
|
275 |
|
|
|
276 |
|
|
if(start = '1') then
|
277 |
|
|
cnt1:= 1;
|
278 |
|
|
end if;
|
279 |
|
|
|
280 |
|
|
if (pom = '1') then
|
281 |
|
|
cnt2 := 1;
|
282 |
|
|
end if;
|
283 |
|
|
|
284 |
|
|
if ((cnt1 > 0) and (cnt1 < 92)) then
|
285 |
|
|
|
286 |
|
|
C2: case cnt1 is
|
287 |
|
|
when 1 => m <= data1;
|
288 |
|
|
when 2 => m <= data2;
|
289 |
|
|
when 3 => m <= data3;
|
290 |
|
|
when 4 => m <= data4;
|
291 |
|
|
when 5 => m <= data5;
|
292 |
|
|
when 6 => m <= data6;
|
293 |
|
|
when 7 => m <= data7;
|
294 |
|
|
when 8 => m <= data8;
|
295 |
|
|
when 9 => m <= data9;
|
296 |
|
|
when 10 => m <= data10;
|
297 |
|
|
when 11 => m <= data11;
|
298 |
|
|
when 12 => m <= data12;
|
299 |
|
|
when 13 => m <= data13;
|
300 |
|
|
when 14 => m <= data14;
|
301 |
|
|
when 15 => m <= data15;
|
302 |
|
|
when 16 => m <= data16;
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
when 76 => m <= data17;
|
306 |
|
|
when 78 => m <= data19;
|
307 |
|
|
when 79 => m <= data20;
|
308 |
|
|
when 80 => m <= data21;
|
309 |
|
|
when 81 => m <= data22;
|
310 |
|
|
when 82 => m <= data23;
|
311 |
|
|
when 83 => m <= data24;
|
312 |
|
|
when 84 => m <= data25;
|
313 |
|
|
when 85 => m <= data26;
|
314 |
|
|
when 86 => m <= data27;
|
315 |
|
|
when 87 => m <= data28;
|
316 |
|
|
when 88 => m <= data29;
|
317 |
|
|
when 89 => m <= data30;
|
318 |
|
|
when 90 => m <= data31;
|
319 |
|
|
when 91 => m <= data32;
|
320 |
|
|
when others =>
|
321 |
|
|
end case C2;
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
if((cnt1 = 77) and (settime = 0)) then
|
325 |
|
|
m <= data18;
|
326 |
|
|
settime := 1;
|
327 |
|
|
elsif((cnt1 = 77) and (settime = 1)) then
|
328 |
|
|
m <= ntime;
|
329 |
|
|
end if;
|
330 |
|
|
|
331 |
|
|
cnt1 := cnt1+1;
|
332 |
|
|
end if;
|
333 |
|
|
|
334 |
|
|
if ((cnt2 > 0) and (cnt2 < 18)) then
|
335 |
|
|
|
336 |
|
|
CASE cnt2 IS
|
337 |
|
|
WHEN 1 => m <= hash(255 downto 224);
|
338 |
|
|
WHEN 2 => m <= hash(223 downto 192);
|
339 |
|
|
WHEN 3 => m <= hash(191 downto 160);
|
340 |
|
|
WHEN 4 => m <= hash(159 downto 128);
|
341 |
|
|
WHEN 5 => m <= hash(127 downto 96);
|
342 |
|
|
WHEN 6 => m <= hash(95 downto 64);
|
343 |
|
|
WHEN 7 => m <= hash(63 downto 32);
|
344 |
|
|
WHEN 8 => m <= hash(31 downto 0);
|
345 |
|
|
WHEN 9 => m <= X"80000000";
|
346 |
|
|
WHEN 10 => m <= X"00000000";
|
347 |
|
|
WHEN 11 => m <= X"00000000";
|
348 |
|
|
WHEN 12 => m <= X"00000000";
|
349 |
|
|
WHEN 13 => m <= X"00000000";
|
350 |
|
|
WHEN 14 => m <= X"00000000";
|
351 |
|
|
WHEN 15 => m <= X"00000000";
|
352 |
|
|
WHEN 16 => m <= X"00000100";
|
353 |
|
|
when others =>
|
354 |
|
|
END CASE;
|
355 |
|
|
|
356 |
|
|
cnt2 := cnt2+1;
|
357 |
|
|
end if;
|
358 |
|
|
end if;
|
359 |
|
|
end process;
|
360 |
|
|
|
361 |
|
|
-- compare computed hash with difficulty
|
362 |
|
|
compare: process(CLK,cmpstart,controlrst,stop,loaded)
|
363 |
|
|
variable cmpcnt : integer := 0;
|
364 |
|
|
variable startcnt : integer := 0;
|
365 |
|
|
variable finish : integer := 0;
|
366 |
|
|
variable pomhash : unsigned(255 downto 0);
|
367 |
|
|
variable diff : unsigned(255 downto 0);
|
368 |
|
|
variable nonce : bit_vector(31 downto 0) := X"00000000";
|
369 |
|
|
variable one : bit_vector(31 downto 0) := X"00000001";
|
370 |
|
|
variable pom_ntime : bit_vector(31 downto 0);
|
371 |
|
|
variable settime : integer := 0;
|
372 |
|
|
begin
|
373 |
|
|
|
374 |
|
|
if ((clk = '1') and clk'event) then
|
375 |
|
|
|
376 |
|
|
output <= '0';
|
377 |
|
|
start <= '0';
|
378 |
|
|
start2 <= '0';
|
379 |
|
|
sendend <= '0';
|
380 |
|
|
|
381 |
|
|
if((controlrst = '1') or ((stop = '1') and (loaded = '0'))) then
|
382 |
|
|
cmpcnt := 0;
|
383 |
|
|
startcnt := 0;
|
384 |
|
|
nonce_out <= X"00000000";
|
385 |
|
|
nonce := X"00000000";
|
386 |
|
|
data20 <= X"00000000";
|
387 |
|
|
ntime_out <= X"00000000";
|
388 |
|
|
settime := 0;
|
389 |
|
|
end if;
|
390 |
|
|
|
391 |
|
|
if(cmpstart = '1') then
|
392 |
|
|
cmpcnt := cmpcnt+1;
|
393 |
|
|
end if;
|
394 |
|
|
|
395 |
|
|
if(cmpcnt > 0) then
|
396 |
|
|
cmpcnt := cmpcnt+1;
|
397 |
|
|
end if;
|
398 |
|
|
|
399 |
|
|
if(startcnt > 0) then
|
400 |
|
|
startcnt := startcnt+1;
|
401 |
|
|
end if;
|
402 |
|
|
|
403 |
|
|
if(startcnt = 80580) then
|
404 |
|
|
start2 <= '1';
|
405 |
|
|
end if;
|
406 |
|
|
|
407 |
|
|
if(startcnt = 80581) then
|
408 |
|
|
start <= '1';
|
409 |
|
|
startcnt := 0;
|
410 |
|
|
end if;
|
411 |
|
|
|
412 |
|
|
if(cmpcnt = 10) then
|
413 |
|
|
if(settime = 0) then
|
414 |
|
|
ntime <= data18;
|
415 |
|
|
settime := 1;
|
416 |
|
|
end if;
|
417 |
|
|
|
418 |
|
|
if(cmphash <= difficulty) then
|
419 |
|
|
|
420 |
|
|
nonce_out <= data20;
|
421 |
|
|
ntime_out <= pom_ntime;
|
422 |
|
|
|
423 |
|
|
if((nonce = X"ffffffff") and (ntime = ntime_max)) then
|
424 |
|
|
if(finish = 0) then
|
425 |
|
|
sendend <= '1';
|
426 |
|
|
output <= '1';
|
427 |
|
|
finish := 1;
|
428 |
|
|
end if;
|
429 |
|
|
elsif(nonce = X"ffffffff") then
|
430 |
|
|
nonce := X"00000000";
|
431 |
|
|
if(ntime < ntime_max) then
|
432 |
|
|
pom_ntime := to_bitvector(std_logic_vector(unsigned(to_stdlogicvector(ntime)) + X"00000001"));
|
433 |
|
|
ntime <= pom_ntime;
|
434 |
|
|
end if;
|
435 |
|
|
end if;
|
436 |
|
|
|
437 |
|
|
cmpcnt := 0;
|
438 |
|
|
nonce := to_bitvector(std_logic_vector(unsigned(to_stdlogicvector(data20(31 downto 0))) + unsigned(to_stdlogicvector(one))));
|
439 |
|
|
data20(31 downto 0) <= nonce;
|
440 |
|
|
output <= '1';
|
441 |
|
|
startcnt := 1;
|
442 |
|
|
|
443 |
|
|
else
|
444 |
|
|
|
445 |
|
|
if((nonce = X"ffffffff") and (ntime = ntime_max)) then
|
446 |
|
|
output <= '0';
|
447 |
|
|
elsif(nonce = X"ffffffff") then
|
448 |
|
|
nonce := X"00000000";
|
449 |
|
|
if(ntime < ntime_max) then
|
450 |
|
|
pom_ntime := to_bitvector(std_logic_vector(unsigned(to_stdlogicvector(ntime)) + X"00000001"));
|
451 |
|
|
ntime <= pom_ntime;
|
452 |
|
|
end if;
|
453 |
|
|
end if;
|
454 |
|
|
|
455 |
|
|
cmpcnt := 0;
|
456 |
|
|
nonce := to_bitvector(std_logic_vector(unsigned(to_stdlogicvector(data20(31 downto 0))) + unsigned(to_stdlogicvector(one))));
|
457 |
|
|
data20(31 downto 0) <= nonce;
|
458 |
|
|
output <= '0';
|
459 |
|
|
startcnt := 1;
|
460 |
|
|
end if;
|
461 |
|
|
end if;
|
462 |
|
|
end if;
|
463 |
|
|
end process;
|
464 |
|
|
|
465 |
|
|
-- load input data version(4B), hashprevblock(32B), merklehash(32B), time(4B), target(4B), difficulty(32B)
|
466 |
|
|
loadingdata: process(clk,loaddata,controlrst)
|
467 |
|
|
variable cnt : integer := 0;
|
468 |
|
|
begin
|
469 |
|
|
|
470 |
|
|
if ((clk = '1') and clk'event) then
|
471 |
|
|
|
472 |
|
|
if((controlrst = '1')) then
|
473 |
|
|
cnt := 0;
|
474 |
|
|
end if;
|
475 |
|
|
|
476 |
|
|
if((loaddata = '1')) then
|
477 |
|
|
cnt := cnt+1;
|
478 |
|
|
|
479 |
|
|
CASE cnt IS
|
480 |
|
|
-- version
|
481 |
|
|
WHEN 1 => data1(31 downto 24) <= to_bitvector(data);
|
482 |
|
|
WHEN 2 => data1(23 downto 16) <= to_bitvector(data);
|
483 |
|
|
WHEN 3 => data1(15 downto 8) <= to_bitvector(data);
|
484 |
|
|
WHEN 4 => data1(7 downto 0) <= to_bitvector(data);
|
485 |
|
|
-- hashprevblock
|
486 |
|
|
WHEN 5 => data2(31 downto 24) <= to_bitvector(data);
|
487 |
|
|
WHEN 6 => data2(23 downto 16) <= to_bitvector(data);
|
488 |
|
|
WHEN 7 => data2(15 downto 8) <= to_bitvector(data);
|
489 |
|
|
WHEN 8 => data2(7 downto 0) <= to_bitvector(data);
|
490 |
|
|
-- hashprevblock
|
491 |
|
|
WHEN 9 => data3(31 downto 24) <= to_bitvector(data);
|
492 |
|
|
WHEN 10 => data3(23 downto 16) <= to_bitvector(data);
|
493 |
|
|
WHEN 11 => data3(15 downto 8) <= to_bitvector(data);
|
494 |
|
|
WHEN 12 => data3(7 downto 0) <= to_bitvector(data);
|
495 |
|
|
-- hashprevblock
|
496 |
|
|
WHEN 13 => data4(31 downto 24) <= to_bitvector(data);
|
497 |
|
|
WHEN 14 => data4(23 downto 16) <= to_bitvector(data);
|
498 |
|
|
WHEN 15 => data4(15 downto 8) <= to_bitvector(data);
|
499 |
|
|
WHEN 16 => data4(7 downto 0) <= to_bitvector(data);
|
500 |
|
|
-- hashprevblock
|
501 |
|
|
WHEN 17 => data5(31 downto 24) <= to_bitvector(data);
|
502 |
|
|
WHEN 18 => data5(23 downto 16) <= to_bitvector(data);
|
503 |
|
|
WHEN 19 => data5(15 downto 8) <= to_bitvector(data);
|
504 |
|
|
WHEN 20 => data5(7 downto 0) <= to_bitvector(data);
|
505 |
|
|
-- hashprevblock
|
506 |
|
|
WHEN 21 => data6(31 downto 24) <= to_bitvector(data);
|
507 |
|
|
WHEN 22 => data6(23 downto 16) <= to_bitvector(data);
|
508 |
|
|
WHEN 23 => data6(15 downto 8) <= to_bitvector(data);
|
509 |
|
|
WHEN 24 => data6(7 downto 0) <= to_bitvector(data);
|
510 |
|
|
-- hashprevblock
|
511 |
|
|
WHEN 25 => data7(31 downto 24) <= to_bitvector(data);
|
512 |
|
|
WHEN 26 => data7(23 downto 16) <= to_bitvector(data);
|
513 |
|
|
WHEN 27 => data7(15 downto 8) <= to_bitvector(data);
|
514 |
|
|
WHEN 28 => data7(7 downto 0) <= to_bitvector(data);
|
515 |
|
|
-- hashprevblock
|
516 |
|
|
WHEN 29 => data8(31 downto 24) <= to_bitvector(data);
|
517 |
|
|
WHEN 30 => data8(23 downto 16) <= to_bitvector(data);
|
518 |
|
|
WHEN 31 => data8(15 downto 8) <= to_bitvector(data);
|
519 |
|
|
WHEN 32 => data8(7 downto 0) <= to_bitvector(data);
|
520 |
|
|
-- hashprevblock
|
521 |
|
|
WHEN 33 => data9(31 downto 24) <= to_bitvector(data);
|
522 |
|
|
WHEN 34 => data9(23 downto 16) <= to_bitvector(data);
|
523 |
|
|
WHEN 35 => data9(15 downto 8) <= to_bitvector(data);
|
524 |
|
|
WHEN 36 => data9(7 downto 0) <= to_bitvector(data);
|
525 |
|
|
-- merklehash
|
526 |
|
|
WHEN 37 => data10(31 downto 24) <= to_bitvector(data);
|
527 |
|
|
WHEN 38 => data10(23 downto 16) <= to_bitvector(data);
|
528 |
|
|
WHEN 39 => data10(15 downto 8) <= to_bitvector(data);
|
529 |
|
|
WHEN 40 => data10(7 downto 0) <= to_bitvector(data);
|
530 |
|
|
-- merklehash
|
531 |
|
|
WHEN 41 => data11(31 downto 24) <= to_bitvector(data);
|
532 |
|
|
WHEN 42 => data11(23 downto 16) <= to_bitvector(data);
|
533 |
|
|
WHEN 43 => data11(15 downto 8) <= to_bitvector(data);
|
534 |
|
|
WHEN 44 => data11(7 downto 0) <= to_bitvector(data);
|
535 |
|
|
-- merklehash
|
536 |
|
|
WHEN 45 => data12(31 downto 24) <= to_bitvector(data);
|
537 |
|
|
WHEN 46 => data12(23 downto 16) <= to_bitvector(data);
|
538 |
|
|
WHEN 47 => data12(15 downto 8) <= to_bitvector(data);
|
539 |
|
|
WHEN 48 => data12(7 downto 0) <= to_bitvector(data);
|
540 |
|
|
-- merklehash
|
541 |
|
|
WHEN 49 => data13(31 downto 24) <= to_bitvector(data);
|
542 |
|
|
WHEN 50 => data13(23 downto 16) <= to_bitvector(data);
|
543 |
|
|
WHEN 51 => data13(15 downto 8) <= to_bitvector(data);
|
544 |
|
|
WHEN 52 => data13(7 downto 0) <= to_bitvector(data);
|
545 |
|
|
-- merklehash
|
546 |
|
|
WHEN 53 => data14(31 downto 24) <= to_bitvector(data);
|
547 |
|
|
WHEN 54 => data14(23 downto 16) <= to_bitvector(data);
|
548 |
|
|
WHEN 55 => data14(15 downto 8) <= to_bitvector(data);
|
549 |
|
|
WHEN 56 => data14(7 downto 0) <= to_bitvector(data);
|
550 |
|
|
-- merklehash
|
551 |
|
|
WHEN 57 => data15(31 downto 24) <= to_bitvector(data);
|
552 |
|
|
WHEN 58 => data15(23 downto 16) <= to_bitvector(data);
|
553 |
|
|
WHEN 59 => data15(15 downto 8) <= to_bitvector(data);
|
554 |
|
|
WHEN 60 => data15(7 downto 0) <= to_bitvector(data);
|
555 |
|
|
-- merklehash
|
556 |
|
|
WHEN 61 => data16(31 downto 24) <= to_bitvector(data);
|
557 |
|
|
WHEN 62 => data16(23 downto 16) <= to_bitvector(data);
|
558 |
|
|
WHEN 63 => data16(15 downto 8) <= to_bitvector(data);
|
559 |
|
|
WHEN 64 => data16(7 downto 0) <= to_bitvector(data);
|
560 |
|
|
-- merklehash
|
561 |
|
|
WHEN 65 => data17(31 downto 24) <= to_bitvector(data);
|
562 |
|
|
WHEN 66 => data17(23 downto 16) <= to_bitvector(data);
|
563 |
|
|
WHEN 67 => data17(15 downto 8) <= to_bitvector(data);
|
564 |
|
|
WHEN 68 => data17(7 downto 0) <= to_bitvector(data);
|
565 |
|
|
-- time
|
566 |
|
|
WHEN 69 => data18(31 downto 24) <= to_bitvector(data);
|
567 |
|
|
WHEN 70 => data18(23 downto 16) <= to_bitvector(data);
|
568 |
|
|
WHEN 71 => data18(15 downto 8) <= to_bitvector(data);
|
569 |
|
|
WHEN 72 => data18(7 downto 0) <= to_bitvector(data);
|
570 |
|
|
-- target
|
571 |
|
|
WHEN 73 => data19(31 downto 24) <= to_bitvector(data);
|
572 |
|
|
WHEN 74 => data19(23 downto 16) <= to_bitvector(data);
|
573 |
|
|
WHEN 75 => data19(15 downto 8) <= to_bitvector(data);
|
574 |
|
|
WHEN 76 => data19(7 downto 0) <= to_bitvector(data);
|
575 |
|
|
|
576 |
|
|
-- difficulty (256bits)
|
577 |
|
|
WHEN 77 => difficulty(255 downto 248) <= to_bitvector(data);
|
578 |
|
|
WHEN 78 => difficulty(247 downto 240) <= to_bitvector(data);
|
579 |
|
|
WHEN 79 => difficulty(239 downto 232) <= to_bitvector(data);
|
580 |
|
|
WHEN 80 => difficulty(231 downto 224) <= to_bitvector(data);
|
581 |
|
|
WHEN 81 => difficulty(223 downto 216) <= to_bitvector(data);
|
582 |
|
|
WHEN 82 => difficulty(215 downto 208) <= to_bitvector(data);
|
583 |
|
|
WHEN 83 => difficulty(207 downto 200) <= to_bitvector(data);
|
584 |
|
|
WHEN 84 => difficulty(199 downto 192) <= to_bitvector(data);
|
585 |
|
|
WHEN 85 => difficulty(191 downto 184) <= to_bitvector(data);
|
586 |
|
|
WHEN 86 => difficulty(183 downto 176) <= to_bitvector(data);
|
587 |
|
|
WHEN 87 => difficulty(175 downto 168) <= to_bitvector(data);
|
588 |
|
|
WHEN 88 => difficulty(167 downto 160) <= to_bitvector(data);
|
589 |
|
|
WHEN 89 => difficulty(159 downto 152) <= to_bitvector(data);
|
590 |
|
|
WHEN 90 => difficulty(151 downto 144) <= to_bitvector(data);
|
591 |
|
|
WHEN 91 => difficulty(143 downto 136) <= to_bitvector(data);
|
592 |
|
|
WHEN 92 => difficulty(135 downto 128) <= to_bitvector(data);
|
593 |
|
|
WHEN 93 => difficulty(127 downto 120) <= to_bitvector(data);
|
594 |
|
|
WHEN 94 => difficulty(119 downto 112) <= to_bitvector(data);
|
595 |
|
|
WHEN 95 => difficulty(111 downto 104) <= to_bitvector(data);
|
596 |
|
|
WHEN 96 => difficulty(103 downto 96) <= to_bitvector(data);
|
597 |
|
|
WHEN 97 => difficulty(95 downto 88) <= to_bitvector(data);
|
598 |
|
|
WHEN 98 => difficulty(87 downto 80) <= to_bitvector(data);
|
599 |
|
|
WHEN 99 => difficulty(79 downto 72) <= to_bitvector(data);
|
600 |
|
|
WHEN 100 => difficulty(71 downto 64) <= to_bitvector(data);
|
601 |
|
|
WHEN 101 => difficulty(63 downto 56) <= to_bitvector(data);
|
602 |
|
|
WHEN 102 => difficulty(55 downto 48) <= to_bitvector(data);
|
603 |
|
|
WHEN 103 => difficulty(47 downto 40) <= to_bitvector(data);
|
604 |
|
|
WHEN 104 => difficulty(39 downto 32) <= to_bitvector(data);
|
605 |
|
|
WHEN 105 => difficulty(31 downto 24) <= to_bitvector(data);
|
606 |
|
|
WHEN 106 => difficulty(23 downto 16) <= to_bitvector(data);
|
607 |
|
|
WHEN 107 => difficulty(15 downto 8) <= to_bitvector(data);
|
608 |
|
|
WHEN 108 => difficulty(7 downto 0) <= to_bitvector(data);
|
609 |
|
|
when others =>
|
610 |
|
|
END CASE;
|
611 |
|
|
end if;
|
612 |
|
|
|
613 |
|
|
if((cnt = 4) and (data1 = X"73746f70")) then
|
614 |
|
|
stop <= '1';
|
615 |
|
|
loaded <= '0';
|
616 |
|
|
cnt := 0;
|
617 |
|
|
elsif(cnt = 108) then
|
618 |
|
|
loaded <= '1';
|
619 |
|
|
cnt := 0;
|
620 |
|
|
stop <= '0';
|
621 |
|
|
else
|
622 |
|
|
loaded <= '0';
|
623 |
|
|
end if;
|
624 |
|
|
|
625 |
|
|
if(cnt = 73) then
|
626 |
|
|
ntime_max <= to_bitvector(std_logic_vector(unsigned(to_stdlogicvector(data18)) + X"00001c20"));
|
627 |
|
|
end if;
|
628 |
|
|
|
629 |
|
|
|
630 |
|
|
|
631 |
|
|
end if;
|
632 |
|
|
end process;
|
633 |
|
|
|
634 |
|
|
-- write results to output
|
635 |
|
|
sendingdata: process(clk,output,controlrst,stop,loaddata)
|
636 |
|
|
variable cnt : integer := 0;
|
637 |
|
|
begin
|
638 |
|
|
|
639 |
|
|
if ((clk = '1') and clk'event) then
|
640 |
|
|
|
641 |
|
|
if((controlrst = '1') and (stop = '1')) then
|
642 |
|
|
cnt := 0;
|
643 |
|
|
end if;
|
644 |
|
|
|
645 |
|
|
if((cnt > 0) and (busy = '0') and (loaddata = '0') and (stop = '0')) then
|
646 |
|
|
cnt := cnt+1;
|
647 |
|
|
loaddataout <= '1';
|
648 |
|
|
elsif((output = '1') and (cnt = 0) and (busy = '0') and (loaddata = '0') and (stop = '0')) then
|
649 |
|
|
cnt := cnt+1;
|
650 |
|
|
loaddataout <= '1';
|
651 |
|
|
else
|
652 |
|
|
loaddataout <= '0';
|
653 |
|
|
end if;
|
654 |
|
|
|
655 |
|
|
CASE cnt IS
|
656 |
|
|
WHEN 1 => dataout <= nonce_out(31 downto 24);
|
657 |
|
|
WHEN 2 => loaddataout <= '0';
|
658 |
|
|
WHEN 3 => dataout <= nonce_out(23 downto 16);
|
659 |
|
|
WHEN 4 => loaddataout <= '0';
|
660 |
|
|
WHEN 5 => dataout <= nonce_out(15 downto 8);
|
661 |
|
|
WHEN 6 => loaddataout <= '0';
|
662 |
|
|
WHEN 7 => dataout <= nonce_out(7 downto 0);
|
663 |
|
|
WHEN 8 => loaddataout <= '0';
|
664 |
|
|
WHEN 9 => dataout <= ntime_out(31 downto 24);
|
665 |
|
|
WHEN 10 => loaddataout <= '0';
|
666 |
|
|
WHEN 11 => dataout <= ntime_out(23 downto 16);
|
667 |
|
|
WHEN 12 => loaddataout <= '0';
|
668 |
|
|
WHEN 13 => dataout <= ntime_out(15 downto 8);
|
669 |
|
|
WHEN 14 => loaddataout <= '0';
|
670 |
|
|
WHEN 15 => dataout <= ntime_out(7 downto 0);
|
671 |
|
|
when others =>
|
672 |
|
|
END CASE;
|
673 |
|
|
|
674 |
|
|
if(cnt = 15) then
|
675 |
|
|
cnt := 0;
|
676 |
|
|
end if;
|
677 |
|
|
|
678 |
|
|
end if;
|
679 |
|
|
end process;
|
680 |
|
|
|
681 |
|
|
end phy2;
|