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

Subversion Repositories btcminer

[/] [btcminer/] [trunk/] [fpga/] [ztex_ufm1_15y1.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   btcminer -- BTCMiner for ZTEX USB-FPGA Modules: HDL code for ZTEX USB-FPGA Module 1.15b (one double hash pipe)
3
   Copyright (C) 2012 ZTEX GmbH
4
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
module ztex_ufm1_15y1 (fxclk_in, reset, select, clk_reset, pll_stop,  dcm_progclk, dcm_progdata, dcm_progen,  rd_clk, wr_clk, wr_start, read, write);
20
 
21
        input fxclk_in, select, reset, clk_reset, pll_stop, dcm_progclk, dcm_progdata, dcm_progen, rd_clk, wr_clk, wr_start;
22
        input [7:0] read;
23
        output [7:0] write;
24
 
25
        reg [3:0] rd_clk_b, wr_clk_b;
26
        reg wr_start_b1, wr_start_b2, reset_buf, clk_reset_buf = 1, pll_stop_buf = 1, select_buf;
27
 
28
        reg dcm_progclk_buf, dcm_progdata_buf, dcm_progen_buf;
29
        reg [4:0] wr_delay;
30
        reg [351:0] inbuf, inbuf_tmp;
31
        reg [127:0] outbuf;
32
        reg [7:0] read_buf, write_buf;
33
        reg [31:0] golden_nonce1, golden_nonce2;
34
 
35
        wire fxclk, clk, dcm_clk, pll_fb, pll_clk0, dcm_locked, pll_reset;
36
        wire [2:1] dcm_status;
37
        wire [31:0] golden_nonce, nonce2, hash2;
38
 
39
        miner253 m (
40
            .clk(clk),
41
            .reset(reset_buf),
42
            .midstate(inbuf[351:96]),
43
            .data(inbuf[95:0]),
44
            .golden_nonce(golden_nonce),
45
            .nonce2(nonce2),
46
            .hash2(hash2)
47
        );
48
 
49
        BUFG bufg_fxclk (
50
          .I(fxclk_in),
51
          .O(fxclk)
52
        );
53
 
54
        BUFG bufg_clk (
55
          .I(pll_clk0),
56
          .O(clk)
57
        );
58
 
59
        DCM_CLKGEN #(
60
          .CLKFX_DIVIDE(4.0),
61
          .CLKFX_MULTIPLY(32),
62
          .CLKFXDV_DIVIDE(2),
63
          .CLKIN_PERIOD(20.8333)
64
        )
65
        dcm0 (
66
          .CLKIN(fxclk),
67
          .CLKFXDV(dcm_clk),
68
          .FREEZEDCM(1'b0),
69
          .PROGCLK(dcm_progclk_buf),
70
          .PROGDATA(dcm_progdata_buf),
71
          .PROGEN(dcm_progen_buf),
72
          .LOCKED(dcm_locked),
73
          .STATUS(dcm_status),
74
          .RST(clk_reset_buf)
75
        );
76
 
77
        PLL_BASE #(
78
            .BANDWIDTH("LOW"),
79
            .CLKFBOUT_MULT(4),
80
            .CLKOUT0_DIVIDE(4),
81
            .CLKOUT0_DUTY_CYCLE(0.5),
82
            .CLK_FEEDBACK("CLKFBOUT"),
83
            .COMPENSATION("INTERNAL"),
84
            .DIVCLK_DIVIDE(1),
85
            .REF_JITTER(0.10),
86
            .RESET_ON_LOSS_OF_LOCK("FALSE")
87
       )
88
       pll0 (
89
            .CLKFBOUT(pll_fb),
90
            .CLKOUT0(pll_clk0),
91
            .CLKFBIN(pll_fb),
92
            .CLKIN(dcm_clk),
93
            .RST(pll_reset)
94
        );
95
 
96
        assign write = select ? write_buf : 8'bz;;
97
        assign pll_reset = pll_stop_buf | ~dcm_locked | clk_reset_buf | dcm_status[2];
98
 
99
        always @ (posedge clk)
100
        begin
101
                if ( (rd_clk_b[3] == rd_clk_b[2]) && (rd_clk_b[2] == rd_clk_b[1]) && (rd_clk_b[1] != rd_clk_b[0]) && select_buf )
102
                begin
103
                    inbuf_tmp[351:344] <= read_buf;
104
                    inbuf_tmp[343:0] <= inbuf_tmp[351:8];
105
                end;
106
                inbuf <= inbuf_tmp;  // due to TIG's
107
 
108
                if ( wr_start_b1 && wr_start_b2 )
109
                begin
110
                    wr_delay <= 5'd0;
111
                end else
112
                begin
113
                    wr_delay[0] <= 1'b1;
114
                    wr_delay[4:1] <= wr_delay[3:0];
115
                end
116
 
117
                if ( ! wr_delay[4] )
118
                begin
119
                    outbuf <= { golden_nonce2, hash2, nonce2, golden_nonce1 };
120
                end else
121
                begin
122
                    if ( (wr_clk_b[3] == wr_clk_b[2]) && (wr_clk_b[2] == wr_clk_b[1]) && (wr_clk_b[1] != wr_clk_b[0]) )
123
                        outbuf[119:0] <= outbuf[127:8];
124
                end
125
 
126
                if ( reset_buf )
127
                begin
128
                    golden_nonce2 <= 32'd0;
129
                    golden_nonce1 <= 32'd0;
130
                end else if ( golden_nonce != golden_nonce1 )
131
                begin
132
                    golden_nonce2 <= golden_nonce1;
133
                    golden_nonce1 <= golden_nonce;
134
                end
135
 
136
                read_buf <= read;
137
                write_buf <= outbuf[7:0];
138
 
139
                rd_clk_b[0] <= rd_clk;
140
                rd_clk_b[3:1] <= rd_clk_b[2:0];
141
 
142
                wr_clk_b[0] <= wr_clk;
143
                wr_clk_b[3:1] <= wr_clk_b[2:0];
144
 
145
                wr_start_b1 <= wr_start;
146
                wr_start_b2 <= wr_start_b1;
147
 
148
                select_buf <= select;
149
                if ( select )
150
                begin
151
                    reset_buf <= reset;
152
                end
153
        end
154
 
155
        always @ (posedge fxclk)
156
        begin
157
                dcm_progclk_buf <= dcm_progclk;
158
                dcm_progdata_buf <= dcm_progdata;
159
                dcm_progen_buf <= dcm_progen & select;
160
                if ( select )
161
                begin
162
                    clk_reset_buf <= clk_reset;
163
                    pll_stop_buf <= pll_stop;
164
                end
165
        end
166
 
167
 
168
endmodule
169
 

powered by: WebSVN 2.1.0

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