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

Subversion Repositories btc_dsha256

[/] [btc_dsha256/] [trunk/] [rtl/] [vhdl/] [sha256core/] [btc_dsha.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 nuxi1209
------------------------------------------------------------------- 
2
--                                                               --
3
--  Copyright (C) 2013 Author and VariStream Studio              --
4
--  Author : Yu Peng                                             --
5
--                                                               -- 
6
--  This source file may be used and distributed without         -- 
7
--  restriction provided that this copyright statement is not    -- 
8
--  removed from the file and that any derivative work contains  -- 
9
--  the original copyright notice and the associated disclaimer. -- 
10
--                                                               -- 
11
--  This source file is free software; you can redistribute it   -- 
12
--  and/or modify it under the terms of the GNU Lesser General   -- 
13
--  Public License as published by the Free Software Foundation; -- 
14
--  either version 2.1 of the License, or (at your option) any   -- 
15
--  later version.                                               -- 
16
--                                                               -- 
17
--  This source is distributed in the hope that it will be       -- 
18
--  useful, but WITHOUT ANY WARRANTY; without even the implied   -- 
19
--  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      -- 
20
--  PURPOSE.  See the GNU Lesser General Public License for more -- 
21
--  details.                                                     -- 
22
--                                                               -- 
23
--  You should have received a copy of the GNU Lesser General    -- 
24
--  Public License along with this source; if not, download it   -- 
25
--  from http://www.opencores.org/lgpl.shtml                     -- 
26
--                                                               -- 
27
-------------------------------------------------------------------
28 2 nuxi1209
 
29
library IEEE;
30
use IEEE.STD_LOGIC_1164.ALL;
31
use IEEE.std_logic_unsigned.all;
32
use IEEE.std_logic_arith.all;
33
use IEEE.NUMERIC_STD.ALL;
34
use work.sha_256_pkg.ALL;
35
 
36
entity btc_dsha is
37
        generic(
38
                gBASE_DELAY : integer := 1
39
        );
40
        port(
41 3 nuxi1209
                iRst_async : in std_logic := '0';
42
 
43 2 nuxi1209
                iClkReg : in std_logic := '0';
44
                iClkProcess : in std_logic := '0';
45
 
46
                iValid_p : in std_logic := '0';
47
                ivAddr : in std_logic_vector(3 downto 0) := (others=>'0');
48
                ivData : in std_logic_vector(31 downto 0) := (others=>'0');
49
 
50 5 nuxi1209
                oReachEnd_p : out std_logic := '0';
51
                oFoundNonce_p : out std_logic := '0';
52 2 nuxi1209
                ovNonce : out std_logic_vector(31 downto 0) := (others=>'0');
53
                ovDigest : out tDwordArray(0 to 7) := (others=>(others=>'0'))
54
        );
55
end btc_dsha;
56
 
57
architecture behavioral of btc_dsha is
58
        component pipelines_without_reset IS
59
                GENERIC (gBUS_WIDTH : integer := 1; gNB_PIPELINES: integer range 1 to 255 := 2);
60
                PORT(
61
                        iClk                            : IN            STD_LOGIC;
62
                        iInput                          : IN            STD_LOGIC;
63
                        ivInput                         : IN            STD_LOGIC_VECTOR(gBUS_WIDTH-1 downto 0);
64
                        oDelayed_output         : OUT           STD_LOGIC;
65
                        ovDelayed_output        : OUT           STD_LOGIC_VECTOR(gBUS_WIDTH-1 downto 0)
66
                );
67
        END component;
68
 
69
        component edgedtc is port
70
                (
71
                        iD                              : in            std_logic;
72
                        iClk                    : in            std_logic;
73
                        iResetSync_Clk  : in            std_logic;
74
                        iEdge                   : in            std_logic;
75
                        oQ                              : out           std_logic := '0'
76
                );
77
        end component;
78
 
79
        component sha_256_chunk is
80
                generic(
81
                        gMSG_IS_CONSTANT : std_logic_vector(0 to 15) := (others=>'1');
82
                        gH_IS_CONST : std_logic_vector(0 to 7) := (others=>'1');
83
                        gBASE_DELAY : integer := 3;
84
                        gOUT_VALID_GEN : boolean := false;
85
                        gUSE_BRAM_AS_LARGE_SHIFTREG : boolean := false
86
                );
87
                port(
88
                        iClk : in std_logic := '0';
89
                        iRst_async : in std_logic := '0';
90
 
91
                        iValid : in std_logic := '0';
92
 
93
                        ivMsgDword : in tDwordArray(0 to 15) := (others=>(others=>'0'));
94
 
95
                        ivH0 : in std_logic_vector(31 downto 0) := (others=>'0');
96
                        ivH1 : in std_logic_vector(31 downto 0) := (others=>'0');
97
                        ivH2 : in std_logic_vector(31 downto 0) := (others=>'0');
98
                        ivH3 : in std_logic_vector(31 downto 0) := (others=>'0');
99
                        ivH4 : in std_logic_vector(31 downto 0) := (others=>'0');
100
                        ivH5 : in std_logic_vector(31 downto 0) := (others=>'0');
101
                        ivH6 : in std_logic_vector(31 downto 0) := (others=>'0');
102
                        ivH7 : in std_logic_vector(31 downto 0) := (others=>'0');
103
 
104
                        ovH0 : out std_logic_vector(31 downto 0) := (others=>'0');
105
                        ovH1 : out std_logic_vector(31 downto 0) := (others=>'0');
106
                        ovH2 : out std_logic_vector(31 downto 0) := (others=>'0');
107
                        ovH3 : out std_logic_vector(31 downto 0) := (others=>'0');
108
                        ovH4 : out std_logic_vector(31 downto 0) := (others=>'0');
109
                        ovH5 : out std_logic_vector(31 downto 0) := (others=>'0');
110
                        ovH6 : out std_logic_vector(31 downto 0) := (others=>'0');
111
                        ovH7 : out std_logic_vector(31 downto 0) := (others=>'0');
112
 
113
                        oValid : out std_logic := '0'
114
                );
115
        end component;
116
 
117
        component HandShake is port
118
                (
119
                        iResetSync_Clk                  : in            std_logic;                                              -- Active Hi Reset
120
                        iClk                                    : in            std_logic;                                              -- Clock         
121
 
122
                        iExternalDemand                 : in            std_logic;                                              -- Async External Demand : one positive pulse
123
                        oInternalDemand                 : out           std_logic;                                              -- Sync with iClk Internal demand 
124
                        iInternalClrDemand              : in            std_logic                                               -- Clr Internal Demand
125
                        );
126
        end component;
127
 
128
        component SyncReset is
129
                port(
130
                        iClk                            : in std_logic;                                         -- Clock domain that the reset should be resynchronyze to
131
                        iAsyncReset             : in std_logic;                                         -- Asynchronous reset that should be resynchronyse
132
                        oSyncReset              : out std_logic                                         -- Synchronous reset output
133
                );
134
        end component;
135
 
136
        constant cCMD_ADDR : std_logic_vector(3 downto 0) := X"D";
137 5 nuxi1209
        constant cCMD_NOP : std_logic_vector(15 downto 0) := X"0000";
138 2 nuxi1209
        constant cCMD_START : std_logic_vector(15 downto 0) := X"0001";
139
 
140
        constant cPROCESS_DEALY : std_logic_vector(15 downto 0) := conv_std_logic_vector(64 * gBASE_DELAY * 2 + 1, 16);
141
        constant cCMP_DELAY : std_logic_vector(15 downto 0) := conv_std_logic_vector(64 * gBASE_DELAY * 2 + 1 + 2, 16);
142
 
143
        type tProcessStateMachine is (stIdle, stSearch); --, stFound, stNone);
144
 
145
        signal sReset_syncProcess : std_logic := '0';
146
 
147
        signal svMidState : tDwordArray(0 to 7) := (others=>(others=>'0'));
148
        signal svMerkleRootDword7 : std_logic_vector(31 downto 0) := (others=>'0');
149
        signal svTimeStamp : std_logic_vector(31 downto 0) := (others=>'0');
150
        signal svTargetBits : std_logic_vector(31 downto 0) := (others=>'0');
151
        signal svTargetIndex : std_logic_vector(7 downto 0) := (others=>'0');
152
        signal svTargetFraction : std_logic_vector(23 downto 0) := (others=>'0');
153
 
154
        signal svH : tDwordArray(0 to 7) := (others=>(others=>'0'));
155
 
156
        signal svStage1MsgDword : tDwordArray(0 to 15) := (others=>(others=>'0'));
157
        signal svStage1Digest : tDwordArray(0 to 7) := (others=>(others=>'0'));
158
 
159
        signal svStage2MsgDword : tDwordArray(0 to 15) := (others=>(others=>'0'));
160
 
161
        signal svStartNonce : std_logic_vector(31 downto 0) := (others=>'0');
162
        signal svEndNonce : std_logic_vector(31 downto 0) := (others=>'0');
163
        signal svNonce : std_logic_vector(31 downto 0) := (others=>'0');
164
        signal svCmd : std_logic_vector(15 downto 0) := (others=>'0');
165
        signal sCmdValid_syncReg_p : std_logic := '0';
166
        signal sCmdStart_syncReg_p : std_logic := '0';
167
        signal sCmdStart_syncProcess_p : std_logic := '0';
168
        signal sCmdStart_syncProcess_p_1d : std_logic := '0';
169
 
170
        signal sProcess : tProcessStateMachine := stIdle;
171
        signal svProcessDelayCnt : std_logic_vector(15 downto 0) := (others=>'0');
172
        signal sProcessOutValid : std_logic := '0';
173
        signal sProcessOutValid_1d : std_logic := '0';
174
        signal sProcessOutValid_2d : std_logic := '0';
175
        signal svCmpNounce : std_logic_vector(31 downto 0) := (others=>'0');
176
        signal svProcessNounce_1d : std_logic_vector(31 downto 0) := (others=>'0');
177
        signal svProcessNounce_2d : std_logic_vector(31 downto 0) := (others=>'0');
178
 
179
 
180
        signal svStage2DigestBig : std_logic_vector(255 downto 0) := (others=>'0');
181
        signal svStage2DigestLittle : std_logic_vector(255 downto 0) := (others=>'0');
182
        signal svDigestIsZero : std_logic_vector(31 downto 0) := (others=>'0');
183
        signal svDigestSignificant : std_logic_vector(23 downto 0) := (others=>'0');
184
        signal sDigestHighBitsZero : std_logic := '0';
185
        signal sDigestSignificantFit : std_logic := '0';
186
        signal svCmpDelayCnt : std_logic_vector(15 downto 0) := (others=>'0');
187
        signal sCmpResultValid : std_logic := '0';
188
        signal sFoundNonceToIdle : std_logic := '0';
189
        signal sReachEndToIdle : std_logic := '0';
190
 
191
begin
192 3 nuxi1209
 
193 2 nuxi1209
        SyncReset_inst_Process : SyncReset
194
                port map(
195
                        iClk => iClkProcess,
196
                        iAsyncReset => iRst_async,
197
                        oSyncReset => sReset_syncProcess
198
                );
199
 
200
        process(iClkReg)
201
        begin
202
                if rising_edge(iClkReg) then
203
                        if iValid_p = '1' then
204
                                case ivAddr is
205
                                        when X"0" =>
206
                                        svMidState(0) <= ivData;
207
 
208
                                        when X"1" =>
209
                                        svMidState(1) <= ivData;
210
 
211
                                        when X"2" =>
212
                                        svMidState(2) <= ivData;
213
 
214
                                        when X"3" =>
215
                                        svMidState(3) <= ivData;
216
 
217
                                        when X"4" =>
218
                                        svMidState(4) <= ivData;
219
 
220
                                        when X"5" =>
221
                                        svMidState(5) <= ivData;
222
 
223
                                        when X"6" =>
224
                                        svMidState(6) <= ivData;
225
 
226
                                        when X"7" =>
227
                                        svMidState(7) <= ivData;
228
 
229
                                        when X"8" =>
230
                                        svMerkleRootDword7 <= ivData;
231
 
232
                                        when X"9" =>
233
                                        svTimeStamp <= ivData;
234
 
235
                                        when X"A" =>
236
                                        svTargetBits <= ivData;
237
 
238
                                        when X"B" =>
239
                                        svStartNonce(31 downto 0) <= ivData;
240
 
241
                                        when X"C" =>
242
                                        svEndNonce(31 downto 0) <= ivData;
243
 
244
                                        when cCMD_ADDR =>
245
                                        svCmd <= ivData(15 downto 0);
246
 
247
                                        when others =>
248
                                        svCmd <= ivData(15 downto 0);
249
                                end case;
250
                        end if;
251
                end if;
252
        end process;
253 3 nuxi1209
 
254 2 nuxi1209
        process(iClkReg, iRst_async)
255
        begin
256
                if iRst_async = '1' then
257
                        sCmdValid_syncReg_p <= '0';
258 3 nuxi1209
                        sCmdStart_syncReg_p <= '0';
259
                elsif rising_edge(iClkReg) then
260 2 nuxi1209
                        if iValid_p = '1' and ivAddr = cCMD_ADDR then
261
                                sCmdValid_syncReg_p <= '1';
262
                        else
263
                                sCmdValid_syncReg_p <= '0';
264
                        end if;
265
 
266
                        if iValid_p = '1' and ivAddr = cCMD_ADDR and ivData(15 downto 0) = cCMD_START then
267
                                sCmdStart_syncReg_p <= '1';
268
                        else
269
                                sCmdStart_syncReg_p <= '0';
270
                        end if;
271
                end if;
272
        end process;
273
 
274
        HandShake_inst : HandShake
275
                port map (
276
                        iResetSync_Clk => sReset_syncProcess,
277
                        iClk => iClkProcess,
278
 
279
                        iExternalDemand => sCmdStart_syncReg_p,
280
                        oInternalDemand => sCmdStart_syncProcess_p,
281
                        iInternalClrDemand => sCmdStart_syncProcess_p
282
                        );
283
 
284
        process(iClkProcess, iRst_async)
285
        begin
286
                if iRst_async = '1' then
287
                        sCmdStart_syncProcess_p_1d <= '0';
288
                elsif rising_edge(iClkProcess) then
289
                        sCmdStart_syncProcess_p_1d <= sCmdStart_syncProcess_p;
290
                end if;
291
        end process;
292
 
293
        process(iClkProcess)
294
        begin
295
                if rising_edge(iClkProcess) then
296
                        if sCmdStart_syncProcess_p = '1' then
297
                                for i in 0 to 7 loop
298
                                        svH(i) <= svMidState(i);
299
                                end loop;
300
 
301
                                svStage1MsgDword(0)      <= svMerkleRootDword7;
302
                                svStage1MsgDword(1)     <= svTimeStamp;
303
                                svStage1MsgDword(2)     <= svTargetBits;
304
                        end if;
305
                end if;
306
        end process;
307
 
308
        process(iClkProcess)
309
        begin
310
                if rising_edge(iClkProcess) then
311
                        if sCmdStart_syncProcess_p = '1' then
312
                                svNonce <= svStartNonce;
313
                        elsif sCmdStart_syncProcess_p_1d = '1' or sProcess = stSearch then
314
                                svNonce <= svNonce + '1';
315
                        end if;
316
 
317
                        svStage1MsgDword(3) <= svNonce;
318
                end if;
319
        end process;
320
 
321
        process(iClkProcess)
322
        begin
323
                if rising_edge(iClkProcess) then
324
                        if sCmdStart_syncProcess_p = '1' then
325
                                svProcessDelayCnt <= (others=>'0');
326
                                sProcessOutValid <= '0';
327
                                sProcessOutValid_1d <= '0';
328
                                sProcessOutValid_2d <= '0';
329
                        else
330
                                if sProcess = stSearch and svProcessDelayCnt < cPROCESS_DEALY then
331
                                        svProcessDelayCnt <= svProcessDelayCnt + '1';
332
                                end if;
333
 
334
                                if sProcess = stSearch and svProcessDelayCnt = cPROCESS_DEALY then
335
                                        sProcessOutValid <= '1';
336
                                elsif sReachEndToIdle = '1' or sFoundNonceToIdle = '1' then
337
                                        sProcessOutValid <= '0';
338
                                end if;
339
 
340
                                sProcessOutValid_1d <= sProcessOutValid;
341
                                sProcessOutValid_2d <= sProcessOutValid_1d;
342
                        end if;
343
                end if;
344
        end process;
345
 
346
        process(iClkProcess)
347
        begin
348
                if rising_edge(iClkProcess) then
349
                        if sCmdStart_syncProcess_p = '1' then
350
                                sProcess <= stIdle;
351
                        else
352
                                case sProcess is
353
                                        when stIdle =>
354
                                        if sCmdStart_syncProcess_p_1d = '1' then
355
                                                sProcess <= stSearch;
356
                                        end if;
357
 
358
                                        when stSearch =>
359
                                        if sFoundNonceToIdle = '1' then
360
                                                sProcess <= stIdle;
361
                                        elsif sReachEndToIdle = '1' then
362
                                                sProcess <= stIdle;
363
                                        end if;
364
 
365
                                        when others =>
366
                                        sProcess <= stIdle;
367
                                end case;
368
                        end if;
369
                end if;
370
        end process;
371
 
372
        svStage1MsgDword(4) <= X"80000000";
373
        svStage1MsgDword(5) <= X"00000000";
374
        svStage1MsgDword(6) <= X"00000000";
375
        svStage1MsgDword(7) <= X"00000000";
376
        svStage1MsgDword(8) <= X"00000000";
377
        svStage1MsgDword(9) <= X"00000000";
378
        svStage1MsgDword(10) <= X"00000000";
379
        svStage1MsgDword(11) <= X"00000000";
380
        svStage1MsgDword(12) <= X"00000000";
381
        svStage1MsgDword(13) <= X"00000000";
382
        svStage1MsgDword(14) <= X"00000000";
383
        svStage1MsgDword(15) <= X"00000280";
384
 
385
        sha_256_chunk_inst_stage1: sha_256_chunk
386
                generic map(
387
                        gMSG_IS_CONSTANT => (3 => '0', others => '1'),
388
                        gH_IS_CONST => (others => '1'),
389
                        gBASE_DELAY => gBASE_DELAY
390
                )
391
                port map(
392
                        iClk => iClkProcess,
393
                        iRst_async => iRst_async,
394
 
395
                        iValid => '0',
396
 
397
                        ivMsgDword => svStage1MsgDword,
398
 
399
                        ivH0 => svH(0),
400
                        ivH1 => svH(1),
401
                        ivH2 => svH(2),
402
                        ivH3 => svH(3),
403
                        ivH4 => svH(4),
404
                        ivH5 => svH(5),
405
                        ivH6 => svH(6),
406
                        ivH7 => svH(7),
407
 
408
                        ovH0 => svStage1Digest(0),
409
                        ovH1 => svStage1Digest(1),
410
                        ovH2 => svStage1Digest(2),
411
                        ovH3 => svStage1Digest(3),
412
                        ovH4 => svStage1Digest(4),
413
                        ovH5 => svStage1Digest(5),
414
                        ovH6 => svStage1Digest(6),
415
                        ovH7 => svStage1Digest(7),
416
 
417
                        oValid => open
418
                );
419
 
420
        svStage2MsgDword(0) <= svStage1Digest(0);
421
        svStage2MsgDword(1) <= svStage1Digest(1);
422
        svStage2MsgDword(2) <= svStage1Digest(2);
423
        svStage2MsgDword(3) <= svStage1Digest(3);
424
        svStage2MsgDword(4) <= svStage1Digest(4);
425
        svStage2MsgDword(5) <= svStage1Digest(5);
426
        svStage2MsgDword(6) <= svStage1Digest(6);
427
        svStage2MsgDword(7) <= svStage1Digest(7);
428
        svStage2MsgDword(8) <= X"80000000";
429
        svStage2MsgDword(9) <= X"00000000";
430
        svStage2MsgDword(10) <= X"00000000";
431
        svStage2MsgDword(11) <= X"00000000";
432
        svStage2MsgDword(12) <= X"00000000";
433
        svStage2MsgDword(13) <= X"00000000";
434
        svStage2MsgDword(14) <= X"00000000";
435
        svStage2MsgDword(15) <= X"00000100";
436
 
437
        sha_256_chunk_inst_stage2: sha_256_chunk
438
                generic map(
439
                        gMSG_IS_CONSTANT => (0 => '0',
440
                                                                1 => '0',
441
                                                                2 => '0',
442
                                                                3 => '0',
443
                                                                4 => '0',
444
                                                                5 => '0',
445
                                                                6 => '0',
446
                                                                7 => '0',
447
                                                                others => '1'),
448
                        gH_IS_CONST => (others => '1'),
449
                        gBASE_DELAY => gBASE_DELAY
450
                )
451
                port map(
452
                        iClk => iClkProcess,
453
                        iRst_async => iRst_async,
454
 
455
                        iValid => '0',
456
 
457
                        ivMsgDword => svStage2MsgDword,
458
 
459
                        ivH0 => X"6a09e667",
460
                        ivH1 => X"bb67ae85",
461
                        ivH2 => X"3c6ef372",
462
                        ivH3 => X"a54ff53a",
463
                        ivH4 => X"510e527f",
464
                        ivH5 => X"9b05688c",
465
                        ivH6 => X"1f83d9ab",
466
                        ivH7 => X"5be0cd19",
467
 
468
                        ovH0 => svStage2DigestBig(((7 + 1) * 32 - 1) downto (7 * 32)),
469
                        ovH1 => svStage2DigestBig(((6 + 1) * 32 - 1) downto (6 * 32)),
470
                        ovH2 => svStage2DigestBig(((5 + 1) * 32 - 1) downto (5 * 32)),
471
                        ovH3 => svStage2DigestBig(((4 + 1) * 32 - 1) downto (4 * 32)),
472
                        ovH4 => svStage2DigestBig(((3 + 1) * 32 - 1) downto (3 * 32)),
473
                        ovH5 => svStage2DigestBig(((2 + 1) * 32 - 1) downto (2 * 32)),
474
                        ovH6 => svStage2DigestBig(((1 + 1) * 32 - 1) downto (1 * 32)),
475
                        ovH7 => svStage2DigestBig(((0 + 1) * 32 - 1) downto (0 * 32)),
476
 
477
                        oValid => open
478
                );
479
 
480
        Stage2DigestLittle_gen : for i in 0 to 31 generate
481
                svStage2DigestLittle(((i + 1) * 8 - 1) downto (i * 8)) <= svStage2DigestBig(((31 - i + 1) * 8 - 1) downto ((31 - i) * 8));
482
        end generate;
483
 
484
        Digest_gen : for i in 0 to 7 generate
485
                ovDigest(i) <= svStage2DigestBig(((i + 1) * 32 - 1) downto (i * 32));
486
        end generate;
487
 
488
        process(iClkProcess)
489
        begin
490
                if rising_edge(iClkProcess) then
491
                        for i in 0 to 31 loop
492
                                if svStage2DigestLittle(((i + 1) * 8 - 1) downto (i * 8)) = X"00" then
493
                                        svDigestIsZero(i) <= '1';
494
                                else
495
                                        svDigestIsZero(i) <= '0';
496
                                end if;
497
                        end loop;
498
 
499
                        case svTargetIndex(4 downto 0) is
500
                                when "00011" =>
501
                                svDigestSignificant <= svStage2DigestLittle(8 * 3 - 1 downto 8 * (3 - 3));
502
 
503
                                when "00100" =>
504
                                svDigestSignificant <= svStage2DigestLittle(8 * 4 - 1 downto 8 * (4 - 3));
505
 
506
                                when "00101" =>
507
                                svDigestSignificant <= svStage2DigestLittle(8 * 5 - 1 downto 8 * (5 - 3));
508
 
509
                                when "00110" =>
510
                                svDigestSignificant <= svStage2DigestLittle(8 * 6 - 1 downto 8 * (6 - 3));
511
 
512
                                when "00111" =>
513
                                svDigestSignificant <= svStage2DigestLittle(8 * 7 - 1 downto 8 * (7 - 3));
514
 
515
                                when "01000" =>
516
                                svDigestSignificant <= svStage2DigestLittle(8 * 8 - 1 downto 8 * (8 - 3));
517
 
518
                                when "01001" =>
519
                                svDigestSignificant <= svStage2DigestLittle(8 * 9 - 1 downto 8 * (9 - 3));
520
 
521
                                when "01010" =>
522
                                svDigestSignificant <= svStage2DigestLittle(8 * 10 - 1 downto 8 * (10 - 3));
523
 
524
                                when "01011" =>
525
                                svDigestSignificant <= svStage2DigestLittle(8 * 11 - 1 downto 8 * (11 - 3));
526
 
527
                                when "01100" =>
528
                                svDigestSignificant <= svStage2DigestLittle(8 * 12 - 1 downto 8 * (12 - 3));
529
 
530
                                when "01101" =>
531
                                svDigestSignificant <= svStage2DigestLittle(8 * 13 - 1 downto 8 * (13 - 3));
532
 
533
                                when "01110" =>
534
                                svDigestSignificant <= svStage2DigestLittle(8 * 14 - 1 downto 8 * (14 - 3));
535
 
536
                                when "01111" =>
537
                                svDigestSignificant <= svStage2DigestLittle(8 * 15 - 1 downto 8 * (15 - 3));
538
 
539
                                when "10000" =>
540
                                svDigestSignificant <= svStage2DigestLittle(8 * 16 - 1 downto 8 * (16 - 3));
541
 
542
                                when "10001" =>
543
                                svDigestSignificant <= svStage2DigestLittle(8 * 17 - 1 downto 8 * (17 - 3));
544
 
545
                                when "10010" =>
546
                                svDigestSignificant <= svStage2DigestLittle(8 * 18 - 1 downto 8 * (18 - 3));
547
 
548
                                when "10011" =>
549
                                svDigestSignificant <= svStage2DigestLittle(8 * 19 - 1 downto 8 * (19 - 3));
550
 
551
                                when "10100" =>
552
                                svDigestSignificant <= svStage2DigestLittle(8 * 20 - 1 downto 8 * (20 - 3));
553
 
554
                                when "10101" =>
555
                                svDigestSignificant <= svStage2DigestLittle(8 * 21 - 1 downto 8 * (21 - 3));
556
 
557
                                when "10110" =>
558
                                svDigestSignificant <= svStage2DigestLittle(8 * 22 - 1 downto 8 * (22 - 3));
559
 
560
                                when "10111" =>
561
                                svDigestSignificant <= svStage2DigestLittle(8 * 23 - 1 downto 8 * (23 - 3));
562
 
563
                                when "11000" =>
564
                                svDigestSignificant <= svStage2DigestLittle(8 * 24 - 1 downto 8 * (24 - 3));
565
 
566
                                when "11001" =>
567
                                svDigestSignificant <= svStage2DigestLittle(8 * 25 - 1 downto 8 * (25 - 3));
568
 
569
                                when "11010" =>
570
                                svDigestSignificant <= svStage2DigestLittle(8 * 26 - 1 downto 8 * (26 - 3));
571
 
572
                                when "11011" =>
573
                                svDigestSignificant <= svStage2DigestLittle(8 * 27 - 1 downto 8 * (27 - 3));
574
 
575
                                when "11100" =>
576
                                svDigestSignificant <= svStage2DigestLittle(8 * 28 - 1 downto 8 * (28 - 3));
577
 
578
                                when others => --"11101", Maximum difficulty
579
                                svDigestSignificant <= svStage2DigestLittle(8 * 29 - 1 downto 8 * (29 - 3));
580
                        end case;
581
                end if;
582
        end process;
583
 
584
        svTargetIndex <= svTargetBits(7 downto 0);
585
        svTargetFraction(7 downto 0) <= svTargetBits(31 downto 24);
586
        svTargetFraction(15 downto 8) <= svTargetBits(23 downto 16);
587
        svTargetFraction(23 downto 16) <= svTargetBits(15 downto 8);
588
 
589
        process(iClkProcess)
590
        begin
591
                if rising_edge(iClkProcess) then
592
                        case svTargetIndex(4 downto 0) is
593
                                when "00011" =>
594
                                if svDigestIsZero(31 downto 3) = conv_std_logic_vector(-1, 31 - 3 + 1) then
595
                                        sDigestHighBitsZero <= '1';
596
                                else
597
                                        sDigestHighBitsZero <= '0';
598
                                end if;
599
 
600
                                when "00100" =>
601
                                if svDigestIsZero(31 downto 4) = conv_std_logic_vector(-1, 31 - 4 + 1) then
602
                                        sDigestHighBitsZero <= '1';
603
                                else
604
                                        sDigestHighBitsZero <= '0';
605
                                end if;
606
 
607
                                when "00101" =>
608
                                if svDigestIsZero(31 downto 5) = conv_std_logic_vector(-1, 31 - 5 + 1) then
609
                                        sDigestHighBitsZero <= '1';
610
                                else
611
                                        sDigestHighBitsZero <= '0';
612
                                end if;
613
 
614
                                when "00110" =>
615
                                if svDigestIsZero(31 downto 6) = conv_std_logic_vector(-1, 31 - 6 + 1) then
616
                                        sDigestHighBitsZero <= '1';
617
                                else
618
                                        sDigestHighBitsZero <= '0';
619
                                end if;
620
 
621
                                when "00111" =>
622
                                if svDigestIsZero(31 downto 7) = conv_std_logic_vector(-1, 31 - 7 + 1) then
623
                                        sDigestHighBitsZero <= '1';
624
                                else
625
                                        sDigestHighBitsZero <= '0';
626
                                end if;
627
 
628
                                when "01000" =>
629
                                if svDigestIsZero(31 downto 8) = conv_std_logic_vector(-1, 31 - 8 + 1) then
630
                                        sDigestHighBitsZero <= '1';
631
                                else
632
                                        sDigestHighBitsZero <= '0';
633
                                end if;
634
 
635
                                when "01001" =>
636
                                if svDigestIsZero(31 downto 9) = conv_std_logic_vector(-1, 31 - 9 + 1) then
637
                                        sDigestHighBitsZero <= '1';
638
                                else
639
                                        sDigestHighBitsZero <= '0';
640
                                end if;
641
 
642
                                when "01010" =>
643
                                if svDigestIsZero(31 downto 10) = conv_std_logic_vector(-1, 31 - 10 + 1) then
644
                                        sDigestHighBitsZero <= '1';
645
                                else
646
                                        sDigestHighBitsZero <= '0';
647
                                end if;
648
 
649
                                when "01011" =>
650
                                if svDigestIsZero(31 downto  11) = conv_std_logic_vector(-1, 31 - 11 + 1) then
651
                                        sDigestHighBitsZero <= '1';
652
                                else
653
                                        sDigestHighBitsZero <= '0';
654
                                end if;
655
 
656
                                when "01100" =>
657
                                if svDigestIsZero(31 downto  12) = conv_std_logic_vector(-1, 31 - 12 + 1) then
658
                                        sDigestHighBitsZero <= '1';
659
                                else
660
                                        sDigestHighBitsZero <= '0';
661
                                end if;
662
 
663
                                when "01101" =>
664
                                if svDigestIsZero(31 downto  13) = conv_std_logic_vector(-1, 31 -13 + 1) then
665
                                        sDigestHighBitsZero <= '1';
666
                                else
667
                                        sDigestHighBitsZero <= '0';
668
                                end if;
669
 
670
                                when "01110" =>
671
                                if svDigestIsZero(31 downto  14) = conv_std_logic_vector(-1, 31 - 14 + 1) then
672
                                        sDigestHighBitsZero <= '1';
673
                                else
674
                                        sDigestHighBitsZero <= '0';
675
                                end if;
676
 
677
                                when "01111" =>
678
                                if svDigestIsZero(31 downto  15) = conv_std_logic_vector(-1, 31 - 15 + 1) then
679
                                        sDigestHighBitsZero <= '1';
680
                                else
681
                                        sDigestHighBitsZero <= '0';
682
                                end if;
683
 
684
                                when "10000" =>
685
                                if svDigestIsZero(31 downto  16) = conv_std_logic_vector(-1, 31 - 16 + 1) then
686
                                        sDigestHighBitsZero <= '1';
687
                                else
688
                                        sDigestHighBitsZero <= '0';
689
                                end if;
690
 
691
                                when "10001" =>
692
                                if svDigestIsZero(31 downto  17) = conv_std_logic_vector(-1, 31 - 17 + 1) then
693
                                        sDigestHighBitsZero <= '1';
694
                                else
695
                                        sDigestHighBitsZero <= '0';
696
                                end if;
697
 
698
                                when "10010" =>
699
                                if svDigestIsZero(31 downto  18) = conv_std_logic_vector(-1, 31 - 18 + 1) then
700
                                        sDigestHighBitsZero <= '1';
701
                                else
702
                                        sDigestHighBitsZero <= '0';
703
                                end if;
704
 
705
                                when "10011" =>
706
                                if svDigestIsZero(31 downto  19) = conv_std_logic_vector(-1, 31 - 19 + 1) then
707
                                        sDigestHighBitsZero <= '1';
708
                                else
709
                                        sDigestHighBitsZero <= '0';
710
                                end if;
711
 
712
                                when "10100" =>
713
                                if svDigestIsZero(31 downto  20) = conv_std_logic_vector(-1, 31 - 20 + 1) then
714
                                        sDigestHighBitsZero <= '1';
715
                                else
716
                                        sDigestHighBitsZero <= '0';
717
                                end if;
718
 
719
                                when "10101" =>
720
                                if svDigestIsZero(31 downto  21) = conv_std_logic_vector(-1, 31 - 21 + 1) then
721
                                        sDigestHighBitsZero <= '1';
722
                                else
723
                                        sDigestHighBitsZero <= '0';
724
                                end if;
725
 
726
                                when "10110" =>
727
                                if svDigestIsZero(31 downto  22) = conv_std_logic_vector(-1, 31 - 22 + 1) then
728
                                        sDigestHighBitsZero <= '1';
729
                                else
730
                                        sDigestHighBitsZero <= '0';
731
                                end if;
732
 
733
                                when "10111" =>
734
                                if svDigestIsZero(31 downto  23) = conv_std_logic_vector(-1, 31 - 23 + 1) then
735
                                        sDigestHighBitsZero <= '1';
736
                                else
737
                                        sDigestHighBitsZero <= '0';
738
                                end if;
739
 
740
                                when "11000" =>
741
                                if svDigestIsZero(31 downto  24) = conv_std_logic_vector(-1, 31 - 24 + 1) then
742
                                        sDigestHighBitsZero <= '1';
743
                                else
744
                                        sDigestHighBitsZero <= '0';
745
                                end if;
746
 
747
                                when "11001" =>
748
                                if svDigestIsZero(31 downto  25) = conv_std_logic_vector(-1, 31 - 25 + 1) then
749
                                        sDigestHighBitsZero <= '1';
750
                                else
751
                                        sDigestHighBitsZero <= '0';
752
                                end if;
753
 
754
                                when "11010" =>
755
                                if svDigestIsZero(31 downto  26) = conv_std_logic_vector(-1, 31 - 26 + 1) then
756
                                        sDigestHighBitsZero <= '1';
757
                                else
758
                                        sDigestHighBitsZero <= '0';
759
                                end if;
760
 
761
                                when "11011" =>
762
                                if svDigestIsZero(31 downto  27) = conv_std_logic_vector(-1, 31 - 27 + 1) then
763
                                        sDigestHighBitsZero <= '1';
764
                                else
765
                                        sDigestHighBitsZero <= '0';
766
                                end if;
767
 
768
                                when "11100" =>
769
                                if svDigestIsZero(31 downto  28) = conv_std_logic_vector(-1, 31 - 28 + 1) then
770
                                        sDigestHighBitsZero <= '1';
771
                                else
772
                                        sDigestHighBitsZero <= '0';
773
                                end if;
774
 
775
                                when others => --"11101", Maximum difficulty
776
                                if svDigestIsZero(31 downto  29) = conv_std_logic_vector(-1, 31 - 29 + 1) then
777
                                        sDigestHighBitsZero <= '1';
778
                                else
779
                                        sDigestHighBitsZero <= '0';
780
                                end if;
781
                        end case;
782
 
783
                        if svDigestSignificant <= svTargetFraction(23 downto 0) then
784
                                sDigestSignificantFit <= '1';
785
                        else
786
                                sDigestSignificantFit <= '0';
787
                        end if;
788
                end if;
789
        end process;
790
 
791
        process(iClkProcess)
792
        begin
793
                if rising_edge(iClkProcess) then
794
                        if sCmdStart_syncProcess_p = '1' then
795
                                svCmpDelayCnt <= (others=>'0');
796
                                sCmpResultValid <= '0';
797
                        else
798
                                if sProcess = stSearch and svCmpDelayCnt < cCMP_DELAY then
799
                                        svCmpDelayCnt <= svCmpDelayCnt + '1';
800
                                end if;
801
 
802
                                if sProcess = stSearch and svCmpDelayCnt = cCMP_DELAY then
803
                                        sCmpResultValid <= '1';
804
                                else
805
                                        sCmpResultValid <= '0';
806
                                end if;
807
                        end if;
808
                end if;
809
        end process;
810
 
811
        process(iClkProcess)
812
        begin
813
                if rising_edge(iClkProcess) then
814
                        if sCmdStart_syncProcess_p = '1' then
815
                                svCmpNounce <= svStartNonce;
816
                        elsif sCmpResultValid = '1' then
817
                                svCmpNounce <= svCmpNounce + '1';
818
                        end if;
819
                end if;
820
        end process;
821
 
822
        process(iClkProcess)
823
        begin
824
                if rising_edge(iClkProcess) then
825
                        if sCmdStart_syncProcess_p = '1' then
826
                                sReachEndToIdle <= '0';
827
                        else
828
                                if sProcess = stSearch and sCmpResultValid = '1' and svCmpNounce = svEndNonce then
829
                                        sReachEndToIdle <= '1';
830
                                else
831
                                        sReachEndToIdle <= '0';
832
                                end if;
833
                        end if;
834
                end if;
835
        end process;
836
 
837
        process(iClkProcess)
838
        begin
839
                if rising_edge(iClkProcess) then
840
                        if sCmdStart_syncProcess_p = '1' then
841 5 nuxi1209
                                oReachEnd_p <= '0';
842 2 nuxi1209
                        else
843
                                if sProcess = stSearch and sReachEndToIdle = '1' and sFoundNonceToIdle = '0' then
844 5 nuxi1209
                                        oReachEnd_p <= '1';
845 2 nuxi1209
                                else
846 5 nuxi1209
                                        oReachEnd_p <= '0';
847 2 nuxi1209
                                end if;
848
                        end if;
849
                end if;
850
        end process;
851
 
852
        process(iClkProcess)
853
        begin
854
                if rising_edge(iClkProcess) then
855
                        if sCmdStart_syncProcess_p = '1' then
856
                                sFoundNonceToIdle <= '0';
857
                        else
858
                                if sProcess = stSearch and sCmpResultValid = '1' and sDigestHighBitsZero = '1' and sDigestSignificantFit = '1' then
859
                                        sFoundNonceToIdle <= '1';
860
                                else
861
                                        sFoundNonceToIdle <= '0';
862
                                end if;
863
                        end if;
864
                end if;
865
        end process;
866
 
867
        process(iClkProcess)
868
        begin
869
                if rising_edge(iClkProcess) then
870
                        if sCmdStart_syncProcess_p = '1' then
871 5 nuxi1209
                                oFoundNonce_p <= '0';
872 2 nuxi1209
                        else
873
                                if sProcess = stSearch and sFoundNonceToIdle = '1' then
874 5 nuxi1209
                                        oFoundNonce_p <= '1';
875 2 nuxi1209
                                else
876 5 nuxi1209
                                        oFoundNonce_p <= '0';
877 2 nuxi1209
                                end if;
878
                        end if;
879
                end if;
880
        end process;
881
 
882
        pipelines_without_reset_inst_Nonce : pipelines_without_reset
883
                GENERIC map(gBUS_WIDTH => 32, gNB_PIPELINES => 2)
884
                PORT map(
885
                        iClk => iClkProcess,
886
                        iInput => '0',
887
                        ivInput => svCmpNounce,
888
                        oDelayed_output => open,
889
                        ovDelayed_output => ovNonce
890
                );
891
 
892
end behavioral;

powered by: WebSVN 2.1.0

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