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

Subversion Repositories wbicapetwo

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

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

Line No. Rev Author Line
1 2 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 Tecnology, 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
                        o_wb_ack, o_wb_stall, o_wb_data);
99
        input                   i_clk;
100
        // Wishbone inputs
101
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
102
        input           [4:0]    i_wb_addr;
103
        input           [31:0]   i_wb_data;
104
        // Wishbone outputs
105
        output  reg             o_wb_ack, o_wb_stall;
106
        output  reg     [31:0]   o_wb_data;
107
        // ICAPE2 interface signals
108
        //      These are kept internal to this block ...
109
 
110
        reg             wb_req, r_we;
111
        reg     [31:0]   r_data;
112
        reg     [4:0]    r_addr;
113
 
114
        reg     [31:0]   cfg_in;
115
        reg             cfg_cs_n, cfg_rdwrn;
116
        wire    [31:0]   cfg_out;
117
        reg     [4:0]    state;
118
        initial state = `MBOOT_IDLE;
119
        initial cfg_cs_n = 1'b1;
120
        always @(posedge i_clk)
121
        begin
122
                o_wb_ack <= 1'b0;
123
                o_wb_stall <= 1'b1;
124
                state <= state + 5'h01;
125
                wb_req <= wb_req & i_wb_cyc;
126
                case(state)
127
                `MBOOT_IDLE: begin
128
                        cfg_cs_n <= 1'b1;
129
                        cfg_rdwrn <= 1'b1;
130
                        cfg_in <= 32'hffffffff; // Dummy word
131
 
132
                        state <= `MBOOT_IDLE;
133
 
134
                        o_wb_ack <= 1'b0;
135
                        o_wb_stall <= 1'b0;
136
 
137
                        r_addr <= i_wb_addr;
138
                        r_data <= i_wb_data;
139
                        r_we   <= i_wb_we;
140
                        if((i_wb_cyc)&&(i_wb_stb))
141
                        begin
142
                                state <= `MBOOT_START;
143
                                wb_req <= 1'b1;
144
                                //
145
                                o_wb_ack <= 1'b0;
146
                                o_wb_stall <= 1'b1;
147
                        end end
148
                `MBOOT_START: cfg_in <= 32'hffffffff; // NOOP
149
                5'h02: begin
150
                        cfg_cs_n <= 1'b0; // Activate interface
151
                        cfg_rdwrn <= 1'b0;
152
                        cfg_in <= 32'h20000000; // NOOP
153
                        end
154
                5'h03: cfg_in <= 32'haa995566;  // Sync word
155
                5'h04: cfg_in <= 32'h20000000; // NOOP
156
                5'h05: begin
157
                        cfg_in <= 32'h20000000; // NOOP
158
                        state <= (r_we) ? `MBOOT_WRITE : `MBOOT_READ;
159
                        end
160
                `MBOOT_READ: cfg_in <= { 8'h28, 6'h0, r_addr, 13'h001 };
161
                5'h07: cfg_in <= 32'h20000000; // NOOP
162
                5'h08: cfg_in <= 32'h20000000; // NOOP
163
                5'h09: begin // Idle the interface before the read cycle
164
                        cfg_cs_n <= 1'b1;
165
                        cfg_rdwrn <= 1'b1;
166
                        cfg_in <= 32'h20000000; // NOOP
167
                        end
168
                5'h0a: begin // Re-activate the interface and wait 3 cycles
169
                        cfg_cs_n <= 1'b0;
170
                        cfg_rdwrn <= 1'b1;
171
                        cfg_in <= 32'h20000000; // NOOP
172
                        end
173
                5'h0b: // ... still waiting, cycle two
174
                        cfg_in <= 32'h20000000; // NOOP
175
                5'h0c: // ... still waiting, cycle three
176
                        cfg_in <= 32'h20000000; // NOOP
177
                5'h0d: // ... still waiting, cycle four
178
                        cfg_in <= 32'h20000000; // NOOP
179
                5'h0e: begin // and now our answer is there
180
                        cfg_cs_n <= 1'b1;
181
                        cfg_rdwrn <= 1'b1;
182
                        cfg_in <= 32'h20000000; // NOOP
183
                        //
184
                        // Wishbone return
185
                        o_wb_ack <= wb_req;
186
                        o_wb_data <= cfg_out;
187
                        wb_req <= 1'b0;
188
                        //
189
                        state <= `MBOOT_DESYNC;
190
                        end
191
                `MBOOT_WRITE:   // Issue a write command to the given address
192
                        cfg_in <= { 8'h30, 6'h0, r_addr, 13'h001 };
193
                5'h10: cfg_in <= r_data;        // Write the value
194
                `MBOOT_DESYNC: begin
195
                        cfg_cs_n <= 1'b0;
196
                        cfg_rdwrn <= 1'b0;
197
                        cfg_in <= 32'h20000000; // 1st NOOP
198
                        end
199
                5'h12: cfg_in <= 32'h20000000;  // 2nd NOOP
200
                5'h13: cfg_in <= 32'h30008001;  // Write to CMD register
201
                5'h14: cfg_in <= 32'h0000000d;  // DESYNC command
202
                5'h15: cfg_in <= 32'h20000000;  // NOOP
203
                5'h16: cfg_in <= 32'h20000000;  // NOOP
204
                5'h17: begin
205
                        // Acknowledge the bus transaction, it is now complete
206
                        o_wb_ack <= wb_req;
207
                        o_wb_stall <= 1'b0;
208
                        wb_req <= 1'b0;
209
                        //
210
                        cfg_cs_n <= 1'b1;
211
                        cfg_rdwrn <= 1'b0;
212
                        cfg_in <= 32'hffffffff; // DUMMY
213
                        //
214
                        state <= `MBOOT_IDLE;
215
                        end
216
                default: begin
217
                        o_wb_ack <= 1'b0;
218
                        o_wb_stall <= 1'b1;
219
                        cfg_cs_n <= 1'b1;
220
                        cfg_rdwrn <= 1'b0;
221
                        state <= `MBOOT_IDLE;
222
                        cfg_in <= 32'hffffffff; // DUMMY WORD
223
                        end
224
                endcase
225
        end
226
 
227
        genvar  k;
228
        //
229
        // The data registers to the ICAPE2 interface are bit swapped within
230
        // each byte.  Thus, in order to read from or write to the interface,
231
        // we need to bit swap the bits in each byte.  These next lines
232
        // accomplish that for both the input and output ports.
233
        //
234
        wire    [31:0]   bit_swapped_cfg_in;
235
        generate
236
        for(k=0; k<8; k=k+1)
237
        begin
238
                assign bit_swapped_cfg_in[   k] = cfg_in[   7-k];
239
                assign bit_swapped_cfg_in[ 8+k] = cfg_in[ 8+7-k];
240
                assign bit_swapped_cfg_in[16+k] = cfg_in[16+7-k];
241
                assign bit_swapped_cfg_in[24+k] = cfg_in[24+7-k];
242
        end endgenerate
243
 
244
        wire    [31:0]   bit_swapped_cfg_out;
245
        generate
246
        for(k=0; k<8; k=k+1)
247
        begin
248
                assign cfg_out[   k] = bit_swapped_cfg_out[   7-k];
249
                assign cfg_out[ 8+k] = bit_swapped_cfg_out[ 8+7-k];
250
                assign cfg_out[16+k] = bit_swapped_cfg_out[16+7-k];
251
                assign cfg_out[24+k] = bit_swapped_cfg_out[24+7-k];
252
        end endgenerate
253
 
254
        ICAPE2 #(.ICAP_WIDTH("X32")) reconfig(.CLK(i_clk),
255
                        .CSIB(cfg_cs_n), .RDWRB(cfg_rdwrn),
256
                        .I(bit_swapped_cfg_in), .O(bit_swapped_cfg_out));
257
endmodule

powered by: WebSVN 2.1.0

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