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

Subversion Repositories btcminer

[/] [btcminer/] [trunk/] [fpga/] [ztex_ufm1_15d4.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) 2011-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_15d4 (fxclk_in, reset, clk_reset, pll_stop,  dcm_progclk, dcm_progdata, dcm_progen,  rd_clk, wr_clk, wr_start, read, write);
20
 
21
        input fxclk_in, 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;
27
        reg dcm_progclk_buf, dcm_progdata_buf, dcm_progen_buf;
28
        reg [4:0] wr_delay;
29
        reg [351:0] inbuf, inbuf_tmp;
30
        reg [127:0] outbuf;
31
        reg [7:0] read_buf, write_buf;
32
        reg [31:0] golden_nonce1, golden_nonce2;
33
 
34
        wire fxclk, clk, dcm_clk, pll_fb, pll_clk0, dcm_locked, pll_reset;
35
        wire [2:1] dcm_status;
36
        wire [31:0] golden_nonce, nonce2, hash2;
37
 
38
        miner253 m (
39
            .clk(clk),
40
            .reset(reset_buf),
41
            .midstate(inbuf[351:96]),
42
            .data(inbuf[95:0]),
43
            .golden_nonce(golden_nonce),
44
            .nonce2(nonce2),
45
            .hash2(hash2)
46
        );
47
 
48
        BUFG bufg_fxclk (
49
          .I(fxclk_in),
50
          .O(fxclk)
51
        );
52
 
53
        BUFG bufg_clk (
54
          .I(pll_clk0),
55
          .O(clk)
56
        );
57
 
58
        DCM_CLKGEN #(
59
          .CLKFX_DIVIDE(4.0),
60
          .CLKFX_MULTIPLY(32),
61
          .CLKFXDV_DIVIDE(2),
62
          .CLKIN_PERIOD(20.8333)
63
        )
64
        dcm0 (
65
          .CLKIN(fxclk),
66
          .CLKFXDV(dcm_clk),
67
          .FREEZEDCM(1'b0),
68
          .PROGCLK(dcm_progclk_buf),
69
          .PROGDATA(dcm_progdata_buf),
70
          .PROGEN(dcm_progen_buf),
71
          .LOCKED(dcm_locked),
72
          .STATUS(dcm_status),
73
          .RST(clk_reset)
74
        );
75
 
76
        PLL_BASE #(
77
            .BANDWIDTH("LOW"),
78
            .CLKFBOUT_MULT(4),
79
            .CLKOUT0_DIVIDE(4),
80
            .CLKOUT0_DUTY_CYCLE(0.5),
81
            .CLK_FEEDBACK("CLKFBOUT"),
82
            .COMPENSATION("INTERNAL"),
83
            .DIVCLK_DIVIDE(1),
84
            .REF_JITTER(0.10),
85
            .RESET_ON_LOSS_OF_LOCK("FALSE")
86
       )
87
       pll0 (
88
            .CLKFBOUT(pll_fb),
89
            .CLKOUT0(pll_clk0),
90
            .CLKFBIN(pll_fb),
91
            .CLKIN(dcm_clk),
92
            .RST(pll_reset)
93
        );
94
 
95
        assign write = write_buf;
96
        assign pll_reset = pll_stop | ~dcm_locked | clk_reset | dcm_status[2];
97
 
98
        always @ (posedge clk)
99
        begin
100
                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]) )
101
                begin
102
                    inbuf_tmp[351:344] <= read_buf;
103
                    inbuf_tmp[343:0] <= inbuf_tmp[351:8];
104
                end;
105
                inbuf <= inbuf_tmp;
106
 
107
                if ( wr_start_b1 && wr_start_b2 )
108
                begin
109
                    wr_delay <= 5'd0;
110
                end else
111
                begin
112
                    wr_delay[0] <= 1'b1;
113
                    wr_delay[4:1] <= wr_delay[3:0];
114
                end
115
 
116
                if ( ! wr_delay[4] )
117
                begin
118
                    outbuf <= { golden_nonce2, hash2, nonce2, golden_nonce1 };
119
                end else
120
                begin
121
                    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]) )
122
                        outbuf[119:0] <= outbuf[127:8];
123
                end
124
 
125
                if ( reset_buf )
126
                begin
127
                    golden_nonce2 <= 32'd0;
128
                    golden_nonce1 <= 32'd0;
129
                end else if ( golden_nonce != golden_nonce1 )
130
                begin
131
                    golden_nonce2 <= golden_nonce1;
132
                    golden_nonce1 <= golden_nonce;
133
                end
134
 
135
                read_buf <= read;
136
                write_buf <= outbuf[7:0];
137
 
138
                rd_clk_b[0] <= rd_clk;
139
                rd_clk_b[3:1] <= rd_clk_b[2:0];
140
 
141
                wr_clk_b[0] <= wr_clk;
142
                wr_clk_b[3:1] <= wr_clk_b[2:0];
143
 
144
                wr_start_b1 <= wr_start;
145
                wr_start_b2 <= wr_start_b1;
146
 
147
                reset_buf <= reset;
148
        end
149
 
150
        always @ (posedge fxclk)
151
        begin
152
                dcm_progclk_buf <= dcm_progclk;
153
                dcm_progdata_buf <= dcm_progdata;
154
                dcm_progen_buf <= dcm_progen;
155
        end
156
 
157
 
158
endmodule
159
 

powered by: WebSVN 2.1.0

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