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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [wbicapetwo.v] - Blame information for rev 25

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbicapetwo.v
4
//
5
// Project:     Wishbone to ICAPE2 interface conversion
6
//
7
// Purpose:     This routine maps the configuration registers of a 7-series
8
//              Xilinx part onto register addresses on a wishbone bus interface
9
//              via the ICAPE2 access port to those parts.  The big thing this
10
//              captures is the timing and handshaking required to read and
11
//              write registers from the configuration interface.
12
//
13
//              As an example of what can be done, writing a 32'h00f to
14
//              local address 5'h4 sends the IPROG command to the FPGA, causing
15
//              it to immediately reconfigure itself.
16
//
17
//              As another example, the warm boot start address is located
18
//              in register 5'h10.  Writing to this address, followed by
19
//              issuing the IPROG command just mentioned will cause the
20
//              FPGA to configure from that warm boot start address.
21
// 
22
//              For more details on the configuration interface, the registers
23
//              in question, their meanings and what they do, please see
24
//              User's Guide 470, the "7 Series FPGAs Configuration" User
25
//              Guide.
26
//
27
// Notes:       This module supports both reads and writes from the ICAPE2
28
//              interface.  These follow the following pattern.
29
//
30
//      For writes:
31
//              (Idle)  0xffffffff      (Dummy)
32
//              (CS/W)  0x20000000      NOOP
33
//              (CS/W)  0xaa995566      SYNC WORD
34
//              (CS/W)  0x20000000      NOOP
35
//              (CS/W)  0x20000000      NOOP
36
//              (CS/W)  ...             Write command
37
//              (CS/W)  ...             Write value, from Wishbone bus
38
//              (CS/W)  0x20000000      NOOP
39
//              (CS/W)  0x20000000      NOOP
40
//              (CS/W)  0x30008001      Write to CMD register (address 4)
41
//              (CS/W)  0x0000000d      DESYNC command
42
//              (CS/W)  0x20000000      NOOP
43
//              (CS/W)  0x20000000      NOOP
44
//              (Idle)
45
//
46
//      and for reads:
47
//              (Idle)  0xffffffff      (Dummy)
48
//              (CS/W)  0x20000000      NOOP
49
//              (CS/W)  0xaa995566      SYNC WORD
50
//              (CS/W)  0x20000000      NOOP
51
//              (CS/W)  0x20000000      NOOP
52
//              (CS/W)  ...             Read command
53
//              (CS/W)  0x20000000      NOOP
54
//              (CS/W)  0x20000000      NOOP
55
//              (Idle)  0x20000000      (Idle the interface again, so we can rd)
56
//              (CS/R)  0x20000000      (Wait)
57
//              (CS/R)  0x20000000      (Wait)
58
//              (CS/R)  0x20000000      (Wait)
59
//              (CS/R)  0x20000000      (Wait)
60
//              (Idle)  0x20000000      (Idle the interface before writing)
61
//              (CS/W)  0x20000000      NOOP
62
//              (CS/W)  0x20000000      NOOP
63
//              (CS/W)  0x30008001      Write to CMD register (address 4)
64
//              (CS/W)  0x0000000d      DESYNC command
65
//              (CS/W)  0x20000000      NOOP
66
//              (CS/W)  0x20000000      NOOP
67
//              (Idle)
68
// Creator:     Dan Gisselquist, Ph.D.
69
//              Gisselquist Technology, LLC
70
//
71
///////////////////////////////////////////////////////////////////////////
72
//
73
// Copyright (C) 2015, Gisselquist Technology, LLC
74
//
75
// This program is free software (firmware): you can redistribute it and/or
76
// modify it under the terms of  the GNU General Public License as published
77
// by the Free Software Foundation, either version 3 of the License, or (at
78
// your option) any later version.
79
//
80
// This program is distributed in the hope that it will be useful, but WITHOUT
81
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
82
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83
// for more details.
84
//
85
// License:     GPL, v3, as defined and found on www.gnu.org,
86
//              http://www.gnu.org/licenses/gpl.html
87
//
88
//
89
///////////////////////////////////////////////////////////////////////////
90
//
91
`define MBOOT_IDLE      5'h00
92
`define MBOOT_START     5'h01
93
`define MBOOT_READ      5'h06
94
`define MBOOT_WRITE     5'h0f
95
`define MBOOT_DESYNC    5'h11
96
module  wbicapetwo(i_clk,
97
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
98 13 dgisselq
                        o_wb_ack, o_wb_stall, o_wb_data, o_dbg);
99 25 dgisselq
        parameter       LGDIV = 3; /// Log of the clock divide
100 3 dgisselq
        input                   i_clk;
101
        // Wishbone inputs
102
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
103
        input           [4:0]    i_wb_addr;
104
        input           [31:0]   i_wb_data;
105
        // Wishbone outputs
106
        output  reg             o_wb_ack, o_wb_stall;
107
        output  reg     [31:0]   o_wb_data;
108 13 dgisselq
        // Debugging output
109
        output  wire    [31:0]   o_dbg;
110 3 dgisselq
        // ICAPE2 interface signals
111
        //      These are kept internal to this block ...
112
 
113
        reg             wb_req, r_we;
114
        reg     [31:0]   r_data;
115
        reg     [4:0]    r_addr;
116
 
117 25 dgisselq
 
118 13 dgisselq
        reg             clk_stb, clk_stall;
119
        wire            slow_clk;
120
 
121 25 dgisselq
        generate
122
        if (LGDIV <= 1)
123 13 dgisselq
        begin
124 25 dgisselq
                reg             r_slow_clk;
125
                always @(posedge i_clk)
126
                begin
127
                        r_slow_clk  <= (slow_clk + 1'b1);
128
                        // We'll move on the positive edge of the clock,
129
                        // so therefore clk_stb must be true one clock before
130
                        // that, so we test for it one clock before that.
131
                        clk_stb   <= (slow_clk == 1'b1);
132
                        // CLK_STALL is set to true two clocks before any
133
                        // cycle that will, by necessity, stall.
134
                        clk_stall <= (slow_clk != 1'b0); //True all but 1ckcycle
135
                end
136 13 dgisselq
 
137 25 dgisselq
                assign  slow_clk = r_slow_clk;
138
        end else begin
139
                reg     [(LGDIV-1):0]    slow_clk_counter;
140
 
141
                always @(posedge i_clk)
142
                begin
143
                        slow_clk_counter  <= slow_clk_counter + 1'b1;
144
                        // We'll move on the positive edge of the clock, so therefore
145
                        // clk_stb must be true one clock before that, so we test for
146
                        // it one clock before that.
147
                        clk_stb   <= (slow_clk_counter=={{(LGDIV){1'b1}},1'b0});
148
                        // CLK_STALL is set to true two clocks before any cycle that
149
                        // will, by necessity, stall.
150
                        clk_stall <= (slow_clk_counter!={{(LGDIV){1'b0}},1'b1});
151
                end
152
 
153
                assign  slow_clk = slow_clk_counter[(LGDIV-1)];
154
        end endgenerate
155
 
156 3 dgisselq
        reg     [31:0]   cfg_in;
157
        reg             cfg_cs_n, cfg_rdwrn;
158
        wire    [31:0]   cfg_out;
159
        reg     [4:0]    state;
160
        initial state = `MBOOT_IDLE;
161
        initial cfg_cs_n = 1'b1;
162
        always @(posedge i_clk)
163
        begin
164 13 dgisselq
                // In general, o_wb_ack is always zero.  The exceptions to this
165
                // will be handled individually below.
166 3 dgisselq
                o_wb_ack <= 1'b0;
167 13 dgisselq
                // We can simplify our logic a touch by always setting
168
                // o_wb_data.  It will only be examined if o_wb_ack
169
                // is also true, so this is okay.
170
                o_wb_data <= cfg_out;
171
 
172 3 dgisselq
                // Turn any request "off", so that it will not be ack'd, if
173
                // the wb_cyc line is ever lowered.
174
                wb_req <= wb_req & i_wb_cyc;
175 13 dgisselq
                o_wb_stall <= (state != `MBOOT_IDLE)||(clk_stall);
176
                if (clk_stb)
177 3 dgisselq
                begin
178
                        state <= state + 5'h01;
179
                        case(state)
180
                        `MBOOT_IDLE: begin
181
                                cfg_cs_n <= 1'b1;
182
                                cfg_rdwrn <= 1'b1;
183
                                cfg_in <= 32'hffffffff; // Dummy word
184
 
185
                                state <= `MBOOT_IDLE;
186
 
187
                                o_wb_ack <= 1'b0;
188
 
189
                                r_addr <= i_wb_addr;
190
                                r_data <= i_wb_data;
191
                                r_we   <= i_wb_we;
192 13 dgisselq
                                if(i_wb_stb) // &&(!o_wb_stall)
193 3 dgisselq
                                begin
194
                                        state <= `MBOOT_START;
195
                                        wb_req <= 1'b1;
196
                                        //
197
                                        o_wb_ack <= 1'b0;
198
                                end end
199 13 dgisselq
                        `MBOOT_START: begin
200
                                cfg_in <= 32'hffffffff; // NOOP
201
                                cfg_cs_n <= 1'b1;
202
                                end
203 3 dgisselq
                        5'h02: begin
204
                                cfg_cs_n <= 1'b0; // Activate interface
205
                                cfg_rdwrn <= 1'b0;
206
                                cfg_in <= 32'h20000000; // NOOP
207
                                end
208 13 dgisselq
                        5'h03: begin
209
                                cfg_in <= 32'haa995566; // Sync word
210
                                cfg_cs_n <= 1'b0;
211
                                end
212
                        5'h04: begin
213
                                cfg_in <= 32'h20000000; // NOOP
214
                                cfg_cs_n <= 1'b0;
215
                                end
216 3 dgisselq
                        5'h05: begin
217
                                cfg_in <= 32'h20000000; // NOOP
218
                                state <= (r_we) ? `MBOOT_WRITE : `MBOOT_READ;
219 13 dgisselq
                                cfg_cs_n <= 1'b0;
220 3 dgisselq
                                end
221 13 dgisselq
                        `MBOOT_READ: begin
222
                                cfg_cs_n <= 1'b0;
223
                                cfg_in <= { 8'h28, 6'h0, r_addr, 13'h001 };
224
                                end
225
                        5'h07: begin
226
                                cfg_cs_n <= 1'b0;
227
                                cfg_in <= 32'h20000000; // NOOP
228
                                end
229
                        5'h08: begin
230
                                cfg_cs_n <= 1'b0;
231
                                cfg_in <= 32'h20000000; // NOOP
232
                                end
233 3 dgisselq
                        5'h09: begin // Idle the interface before the read cycle
234
                                cfg_cs_n <= 1'b1;
235
                                cfg_rdwrn <= 1'b1;
236
                                cfg_in <= 32'h20000000; // NOOP
237
                                end
238
                        5'h0a: begin // Re-activate the interface and wait 3 cycles
239
                                cfg_cs_n <= 1'b0;
240
                                cfg_rdwrn <= 1'b1;
241
                                cfg_in <= 32'h20000000; // NOOP
242
                                end
243 13 dgisselq
                        5'h0b: begin // ... still waiting, cycle two
244 3 dgisselq
                                cfg_in <= 32'h20000000; // NOOP
245 13 dgisselq
                                cfg_cs_n <= 1'b0;
246
                                end
247
                        5'h0c: begin // ... still waiting, cycle three
248 3 dgisselq
                                cfg_in <= 32'h20000000; // NOOP
249 13 dgisselq
                                cfg_cs_n <= 1'b0;
250
                                end
251
                        5'h0d: begin // ... still waiting, cycle four
252 3 dgisselq
                                cfg_in <= 32'h20000000; // NOOP
253 13 dgisselq
                                cfg_cs_n <= 1'b0;
254
                                end
255 3 dgisselq
                        5'h0e: begin // and now our answer is there
256
                                cfg_cs_n <= 1'b1;
257
                                cfg_rdwrn <= 1'b1;
258
                                cfg_in <= 32'h20000000; // NOOP
259
                                //
260
                                // Wishbone return
261
                                o_wb_ack <= wb_req;
262 13 dgisselq
                                // o_wb_data <= cfg_out; // Independent of state
263 3 dgisselq
                                wb_req <= 1'b0;
264
                                //
265
                                state <= `MBOOT_DESYNC;
266
                                end
267 13 dgisselq
                        `MBOOT_WRITE: begin
268
                                // Issue a write command to the given address
269 3 dgisselq
                                cfg_in <= { 8'h30, 6'h0, r_addr, 13'h001 };
270 13 dgisselq
                                cfg_cs_n <= 1'b0;
271
                                end
272
                        5'h10: begin
273
                                cfg_in <= r_data;       // Write the value
274
                                cfg_cs_n <= 1'b0;
275
                                end
276 3 dgisselq
                        `MBOOT_DESYNC: begin
277
                                cfg_cs_n <= 1'b0;
278
                                cfg_rdwrn <= 1'b0;
279
                                cfg_in <= 32'h20000000; // 1st NOOP
280
                                end
281 13 dgisselq
                        5'h12: begin
282
                                cfg_cs_n <= 1'b0;
283
                                cfg_in <= 32'h20000000; // 2nd NOOP
284
                                end
285
                        5'h13: begin
286
                                cfg_cs_n <= 1'b0;
287
                                cfg_in <= 32'h30008001; // Write to CMD register
288
                                end
289
                        5'h14: begin
290
                                cfg_cs_n <= 1'b0;
291
                                cfg_in <= 32'h0000000d; // DESYNC command
292
                                end
293
                        5'h15: begin
294
                                cfg_cs_n <= 1'b0;
295
                                cfg_in <= 32'h20000000; // NOOP
296
                                end
297
                        5'h16: begin
298
                                cfg_cs_n <= 1'b0;
299
                                cfg_in <= 32'h20000000; // NOOP
300
                                end
301 3 dgisselq
                        5'h17: begin
302
                                // Acknowledge the bus transaction, it is now complete
303
                                o_wb_ack <= wb_req;
304
                                wb_req <= 1'b0;
305
                                //
306
                                cfg_cs_n <= 1'b1;
307
                                cfg_rdwrn <= 1'b0;
308
                                cfg_in <= 32'hffffffff; // DUMMY
309
                                //
310
                                state <= `MBOOT_IDLE;
311
                                end
312
                        default: begin
313 13 dgisselq
                                wb_req <= 1'b0;
314 3 dgisselq
                                cfg_cs_n <= 1'b1;
315
                                cfg_rdwrn <= 1'b0;
316
                                state <= `MBOOT_IDLE;
317
                                cfg_in <= 32'hffffffff; // DUMMY WORD
318
                                end
319
                        endcase
320
                end
321
        end
322
 
323
        genvar  k;
324
        //
325
        // The data registers to the ICAPE2 interface are bit swapped within
326
        // each byte.  Thus, in order to read from or write to the interface,
327
        // we need to bit swap the bits in each byte.  These next lines
328
        // accomplish that for both the input and output ports.
329
        //
330
        wire    [31:0]   bit_swapped_cfg_in;
331
        generate
332
        for(k=0; k<8; k=k+1)
333
        begin
334
                assign bit_swapped_cfg_in[   k] = cfg_in[   7-k];
335
                assign bit_swapped_cfg_in[ 8+k] = cfg_in[ 8+7-k];
336
                assign bit_swapped_cfg_in[16+k] = cfg_in[16+7-k];
337
                assign bit_swapped_cfg_in[24+k] = cfg_in[24+7-k];
338
        end endgenerate
339
 
340
        wire    [31:0]   bit_swapped_cfg_out;
341
        generate
342
        for(k=0; k<8; k=k+1)
343
        begin
344
                assign cfg_out[   k] = bit_swapped_cfg_out[   7-k];
345
                assign cfg_out[ 8+k] = bit_swapped_cfg_out[ 8+7-k];
346
                assign cfg_out[16+k] = bit_swapped_cfg_out[16+7-k];
347
                assign cfg_out[24+k] = bit_swapped_cfg_out[24+7-k];
348
        end endgenerate
349
 
350
        ICAPE2 #(.ICAP_WIDTH("X32")) reconfig(.CLK(slow_clk),
351
                        .CSIB(cfg_cs_n), .RDWRB(cfg_rdwrn),
352
                        .I(bit_swapped_cfg_in), .O(bit_swapped_cfg_out));
353 13 dgisselq
 
354
        assign o_dbg = {
355
`ifdef  DIVIDE_BY_FOUR
356
                slow_clk_counter, clk_stb, clk_stall,
357
`else
358
                1'b0, slow_clk, clk_stb, clk_stall,
359
`endif
360
                i_wb_stb, o_wb_ack, cfg_cs_n, cfg_rdwrn,
361
                o_wb_stall, state, 2'h0,
362
                        cfg_in[7:0],
363
                        cfg_out[7:0] };
364
 
365 3 dgisselq
endmodule

powered by: WebSVN 2.1.0

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