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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [busmaster.v] - Blame information for rev 74

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

Line No. Rev Author Line
1 46 dgisselq
`define XULA25
2 2 dgisselq
///////////////////////////////////////////////////////////////////////////
3
//
4
// Filename:    busmaster.v
5
//
6
// Project:     XuLA2 board
7
//
8
// Purpose:     This is the highest level, Verilator simulatable, portion of
9
//              the XuLA2 core.  You should be able to successfully Verilate 
10
//      this file, and then build a test bench that tests and proves the
11
//      capability of anything within here.
12
//
13
//      In general, this means the file is little more than a wishbone
14
//      interconnect that connects multiple devices together.  User-JTAG
15
//      commands come in via i_rx_stb and i_rx_data.  These are converted into
16
//      wishbone bus interactions, the results of which come back out via
17
//      o_tx_data and o_tx_stb.
18
//
19
//
20
// Creator:     Dan Gisselquist, Ph.D.
21
//              Gisselquist Technology, LLC
22
//
23
///////////////////////////////////////////////////////////////////////////
24
//
25
// Copyright (C) 2015, Gisselquist Technology, LLC
26
//
27
// This program is free software (firmware): you can redistribute it and/or
28
// modify it under the terms of  the GNU General Public License as published
29
// by the Free Software Foundation, either version 3 of the License, or (at
30
// your option) any later version.
31
//
32
// This program is distributed in the hope that it will be useful, but WITHOUT
33
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
34
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35
// for more details.
36
//
37
// License:     GPL, v3, as defined and found on www.gnu.org,
38
//              http://www.gnu.org/licenses/gpl.html
39
//
40
//
41
///////////////////////////////////////////////////////////////////////////
42
//
43 31 dgisselq
 
44 46 dgisselq
//
45
// Configuration question #1
46
//
47
//      What innate capabilities are built into the board?
48
//
49 2 dgisselq
`define INCLUDE_ZIPCPU
50
// `define      NO_ZIP_WBU_DELAY
51
`define IMPLEMENT_ONCHIP_RAM
52 31 dgisselq
`ifndef VERILATOR
53
`ifndef XULA25
54 74 dgisselq
// `define      FANCY_ICAP_ACCESS
55 31 dgisselq
`endif
56
`endif
57 2 dgisselq
`define FLASH_ACCESS
58 74 dgisselq
`ifdef  XULA25
59
`define SDCARD_ACCESS
60
`endif
61 18 dgisselq
//
62 46 dgisselq
 
63
 
64 18 dgisselq
//
65 46 dgisselq
// Configuration question #2
66
//
67
//      Are any scopes built in to the board?
68
//
69
 
70
//
71
// Position #1: The flash scope, or perhaps the wishbone bus/uart/jtag scope
72
//
73 2 dgisselq
// `define      FLASH_SCOPE
74 46 dgisselq
`ifndef FLASH_SCOPE
75
// `define      WBUS_SCOPE // Occupies the FLASH_SCOPE location, so both cannot be active
76
`endif
77
//
78 74 dgisselq
// Position #2: The ICAP configuration scope, could also be the SDCard scope
79
// depending on how we configure ourselves here
80 46 dgisselq
//
81 74 dgisselq
`ifdef  XULA25
82 18 dgisselq
`ifdef  FANCY_ICAP_ACCESS
83 46 dgisselq
`define CFG_SCOPE // Only defined if we have the access ...
84 74 dgisselq
`else
85
`ifdef  SDCARD_ACCESS
86
`define SDCARD_SCOPE
87 18 dgisselq
`endif
88 74 dgisselq
`endif
89
`endif
90 46 dgisselq
//
91 74 dgisselq
// Position #3: The SDRAM scope / UART scope (never both)
92 46 dgisselq
//
93 74 dgisselq
// `define      SDRAM_SCOPE
94
// `define      UART_SCOPE
95 46 dgisselq
//
96
// Position #4: The Zip CPU scope
97
//
98 31 dgisselq
`ifdef  XULA25
99 46 dgisselq
// `define      ZIP_SCOPE
100 31 dgisselq
`endif
101
 
102 2 dgisselq
module  busmaster(i_clk, i_rst,
103
                i_rx_stb, i_rx_data, o_tx_stb, o_tx_data, i_tx_busy,
104
                // The SPI Flash lines
105
                o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
106
                // The SDRAM lines
107
                o_ram_cs_n, o_ram_cke, o_ram_ras_n, o_ram_cas_n,
108
                        o_ram_we_n, o_ram_bs, o_ram_addr,
109
                        o_ram_drive_data, i_ram_data, o_ram_data,
110
                        o_ram_dqm,
111
                // Generic GPIO
112
                i_gpio, o_gpio, o_pwm,
113
                i_rx_uart, o_tx_uart);
114
        parameter       ZIP_ADDRESS_WIDTH=24, NGPO=15, NGPI=15,
115
                        ZA=ZIP_ADDRESS_WIDTH;
116
        input                   i_clk, i_rst;
117
        // The bus commander, via an external JTAG port
118
        input                   i_rx_stb;
119
        input           [7:0]    i_rx_data;
120
        output  wire            o_tx_stb;
121
        output  wire    [7:0]    o_tx_data;
122
        input                   i_tx_busy;
123
        // SPI flash control
124
        output  wire            o_sf_cs_n, o_sd_cs_n;
125
        output  wire            o_spi_sck, o_spi_mosi;
126
        input                   i_spi_miso;
127
        // SDRAM control
128
        output  wire            o_ram_cs_n, o_ram_cke;
129
        output  wire            o_ram_ras_n, o_ram_cas_n, o_ram_we_n;
130
        output  wire    [12:0]   o_ram_addr;
131
        output  wire    [1:0]    o_ram_bs;
132
        output  wire            o_ram_drive_data;
133
        input           [15:0]   i_ram_data;
134
        output  wire    [15:0]   o_ram_data;
135
        output  wire    [1:0]    o_ram_dqm;
136
        input   [(NGPI-1):0]     i_gpio;
137
        output wire [(NGPO-1):0] o_gpio;
138
        output  wire            o_pwm;
139
        input                   i_rx_uart;
140
        output  wire            o_tx_uart;
141
 
142
 
143
        //
144
        //
145
        // Master wishbone wires
146
        //
147
        //
148
        wire            wb_cyc, wb_stb, wb_we, wb_stall, wb_ack, wb_err;
149
        wire    [31:0]   wb_data, wb_idata, wb_addr;
150
 
151
        //
152
        //
153
        // First BUS master source: The JTAG
154
        //
155
        //
156
        wire    [31:0]   dwb_idata;
157
 
158
        // Wires going to devices
159
        wire            wbu_cyc, wbu_stb, wbu_we;
160
        wire    [31:0]   wbu_addr, wbu_data;
161
        // and then coming from devices
162
        wire            wbu_ack, wbu_stall, wbu_err;
163
        wire    [31:0]   wbu_idata;
164
        // And then headed back home
165
        wire    w_interrupt;
166
        // Oh, and the debug control for the ZIP CPU
167
        wire            wbu_zip_sel, zip_dbg_ack, zip_dbg_stall;
168 9 dgisselq
        assign  wbu_zip_sel =((wbu_cyc)&&(wbu_addr[24]));
169 2 dgisselq
        wire    [31:0]   zip_dbg_data;
170
        wbubus  genbus(i_clk, i_rx_stb, i_rx_data,
171
                        wbu_cyc, wbu_stb, wbu_we, wbu_addr, wbu_data,
172
`ifdef  INCLUDE_ZIPCPU
173
                        ((~wbu_zip_sel)&&(wbu_ack))
174
                                ||((wbu_zip_sel)&&(zip_dbg_ack)),
175
                        ((~wbu_zip_sel)&&(wbu_stall))
176
                                ||((wbu_zip_sel)&&(zip_dbg_stall)),
177
                                wbu_err, (wbu_zip_sel)?zip_dbg_data:dwb_idata,
178
`else
179
                        wbu_ack, wbu_stall,
180
                                wbu_err, dwb_idata,
181
`endif
182
                        w_interrupt,
183
                        o_tx_stb, o_tx_data, i_tx_busy);
184
 
185
 
186
        //
187
        //
188
        // Second BUS master source: The ZipCPU
189
        //
190
        //
191
        wire            zip_cyc, zip_stb, zip_we, zip_cpu_int;
192
        wire    [(ZA-1):0]       w_zip_addr;
193
        wire    [31:0]   zip_addr, zip_data;
194
        // and then coming from devices
195
        wire            zip_ack, zip_stall, zip_err;
196
        wire    dwb_we, dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err;
197
        wire    [31:0]   dwb_addr, dwb_odata;
198 74 dgisselq
        wire    [8:0]    w_ints_to_zip_cpu;
199 2 dgisselq
`ifdef  INCLUDE_ZIPCPU
200 31 dgisselq
`ifdef  XULA25
201 2 dgisselq
        wire    [31:0]   zip_debug;
202 74 dgisselq
        zipsystem #(24'h2000,ZA,8,1,9)
203 2 dgisselq
                zippy(i_clk, 1'b0,
204
                        // Zippys wishbone interface
205
                        zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
206
                                zip_ack, zip_stall, dwb_idata, zip_err,
207
                        w_ints_to_zip_cpu, zip_cpu_int,
208
                        // Debug wishbone interface
209
                        ((wbu_cyc)&&(wbu_zip_sel)),
210
                                ((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
211
                                wbu_data,
212
                                zip_dbg_ack, zip_dbg_stall, zip_dbg_data,
213
                        zip_debug);
214 31 dgisselq
`else
215
        zipbones #(24'h2000,ZA,8,1)
216
                zippy(i_clk, 1'b0,
217
                        // Zippys wishbone interface
218
                        zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
219
                                zip_ack, zip_stall, dwb_idata, zip_err,
220
                        w_interrupt, zip_cpu_int,
221
                        // Debug wishbone interface
222
                        ((wbu_cyc)&&(wbu_zip_sel)),
223
                                ((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
224
                                wbu_data,
225
                                zip_dbg_ack, zip_dbg_stall, zip_dbg_data);
226
`endif
227 2 dgisselq
        generate
228
        if (ZA < 32)
229
                assign  zip_addr = { {(32-ZA){1'b0}}, w_zip_addr };
230
        else
231
                assign  zip_addr = w_zip_addr;
232
        endgenerate
233
 
234
 
235
        //
236
        //
237
        // And an arbiter to decide who gets to access the bus
238
        //
239
        //
240
        /*
241
        wbarbiter #(32,32) wbu_zip_arbiter(i_clk, i_rst,
242
                // The UART interface Master
243
                wbu_addr, wbu_data, wbu_we, (wbu_stb)&&(~wbu_zip_sel),
244
                        (wbu_cyc)&&(~wbu_zip_sel), wbu_ack, wbu_stall, wbu_err,
245
                // The ZIP CPU Master
246
                zip_addr, zip_data, zip_we, zip_stb,
247
                        zip_cyc, zip_ack, zip_stall, zip_err,
248
                // Common bus returns
249
                dwb_addr,dwb_odata,dwb_we,dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err);
250
        */
251
        wbpriarbiter #(32,32) wbu_zip_arbiter(i_clk,
252
                // The ZIP CPU Master -- gets priority in the arbiter
253
                zip_cyc, zip_stb, zip_we, zip_addr, zip_data,
254
                        zip_ack, zip_stall, zip_err,
255
                // The JTAG interface Master, secondary priority,
256
                // will suffer a 1clk delay in arbitration
257
                (wbu_cyc)&&(~wbu_zip_sel), (wbu_stb)&&(~wbu_zip_sel), wbu_we,
258
                        wbu_addr, wbu_data,
259
                        wbu_ack, wbu_stall, wbu_err,
260
                // Common bus returns
261
                dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
262
                        dwb_ack, dwb_stall, dwb_err);
263
 
264
`else
265
        assign  zip_cyc = 1'b0;
266
        assign  zip_stb = 1'b0;
267
        assign  zip_we  = 1'b0;
268
        assign  zip_cpu_int = 1'b0;
269
        assign  zip_addr = 32'h000;
270
        assign  zip_data = 32'h000;
271
 
272
        reg     r_zip_dbg_ack;
273
        initial r_zip_dbg_ack = 1'b0;
274
        always @(posedge i_clk)
275
                r_zip_dbg_ack <= ((wbu_cyc)&&(wbu_zip_sel)&(wbu_stb));
276
        assign  zip_dbg_ack = r_zip_dbg_ack;
277
        assign  zip_dbg_stall = 1'b0;
278
        assign  zip_dbg_data = 32'h000;
279
 
280
        assign  dwb_addr = wbu_addr;
281
        assign  dwb_odata = wbu_data;
282
        assign  dwb_we = wbu_we;
283
        assign  dwb_stb = (wbu_stb);
284
        assign  dwb_cyc = (wbu_cyc);
285
        assign  wbu_ack = dwb_ack;
286
        assign  wbu_stall = dwb_stall;
287
        assign  dwb_idata = wb_idata;
288
        assign  wbu_err = dwb_err;
289
`endif
290
 
291
 
292
        // 
293
        // 
294
        // And because the ZIP CPU and the Arbiter create an unacceptable
295
        // delay, we fail timing.  So we add in a delay cycle ...
296
        // 
297
        // 
298
`ifdef  NO_ZIP_WBU_DELAY
299
        assign  wb_cyc    = dwb_cyc;
300
        assign  wb_stb    = dwb_stb;
301
        assign  wb_we     = dwb_we;
302
        assign  wb_addr   = dwb_addr;
303
        assign  wb_data   = dwb_odata;
304
        assign  dwb_idata = wb_idata;
305
        assign  dwb_ack   = wb_ack;
306
        assign  dwb_stall = wb_stall;
307
        assign  dwb_err   = wb_err;
308
`else
309
        busdelay        wbu_zip_delay(i_clk,
310
                        dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
311
                                dwb_ack, dwb_stall, dwb_idata, dwb_err,
312
                        wb_cyc, wb_stb, wb_we, wb_addr, wb_data,
313
                                wb_ack, wb_stall, wb_idata, wb_err);
314
`endif
315
 
316
 
317
 
318
        wire    io_sel, pwm_sel, uart_sel, flash_sel, flctl_sel, scop_sel,
319
                        cfg_sel, mem_sel, sdram_sel, sdcard_sel,
320
                        none_sel, many_sel, io_bank;
321
        wire    io_ack, flash_ack, scop_ack, cfg_ack, mem_ack,
322
                        sdram_ack, sdcard_ack, uart_ack, pwm_ack;
323
        wire    io_stall, flash_stall, scop_stall, cfg_stall, mem_stall,
324
                        sdram_stall, sdcard_stall, uart_stall, pwm_stall;
325
 
326
        wire    [31:0]   io_data, flash_data, scop_data, cfg_data, mem_data,
327
                        sdram_data, sdcard_data, uart_data, pwm_data;
328
        reg     [31:0]   bus_err_addr;
329
 
330
        assign  wb_ack = (wb_cyc)&&((io_ack)||(uart_ack)||(pwm_ack)
331
                                ||(scop_ack)||(cfg_ack)
332
                                ||(mem_ack)||(flash_ack)||(sdram_ack)
333
                                ||(sdcard_ack)
334
                                ||((none_sel)&&(1'b1)));
335
        assign  wb_stall = ((io_sel)&&(io_stall))
336
                        ||((uart_sel)&&(uart_stall))
337
                        ||((pwm_sel)&&(pwm_stall))
338
                        ||((scop_sel)&&(scop_stall))
339
                        ||((cfg_sel)&&(cfg_stall))
340
                        ||((mem_sel)&&(mem_stall))
341
                        ||((sdram_sel)&&(sdram_stall))
342
                        ||((sdcard_sel)&&(sdcard_stall))
343
                        ||((flash_sel||flctl_sel)&&(flash_stall));
344
                        // (none_sel)&&(1'b0)
345
 
346
        /*
347
        assign  wb_idata = (io_ack)?io_data
348
                        : ((scop_ack)?scop_data
349
                        : ((cfg_ack)?cfg_data
350
                        : ((mem_ack)?mem_data
351
                        : ((flash_ack)?flash_data
352
                        : 32'h00))));
353
        */
354
        assign  wb_idata =  (io_ack|scop_ack)?((io_ack )? io_data  : scop_data)
355
                        : ((uart_ack|pwm_ack)?((uart_ack)?uart_data: pwm_data)
356
                        : ((cfg_ack) ? cfg_data
357
                        : ((sdram_ack|sdcard_ack)
358
                                        ?((sdram_ack)? sdram_data : sdcard_data)
359
                        : ((mem_ack)?mem_data:flash_data)))); // if (flash_ack)
360
        assign  wb_err = ((wb_cyc)&&(wb_stb)&&(none_sel || many_sel)) || many_ack;
361
 
362
        // Addresses ...
363
        //      0000 xxxx       configuration/control registers
364
        //      001x xxxx       Down-sampler taps       (64 taps, 2 at a time)
365
        //      1xxx xxxx       Up-sampler taps
366
        //      1 xxxx xxxx xxxx xxxx xxxx      Up-sampler taps
367 31 dgisselq
 
368
        wire    pre_io, pre_pwm, pre_uart, pre_flctl, pre_scop;
369 2 dgisselq
        assign  io_bank  = (wb_cyc)&&(wb_addr[31:5] == 27'h8);
370 31 dgisselq
        assign  pre_io   = (~pre_flctl)&&(~pre_pwm)&&(~pre_uart)&&(~pre_scop);
371
        assign  io_sel   = (io_bank)&&(pre_io);
372
        assign  pre_pwm  = (wb_addr[4: 1]== 4'h4);
373
        assign  pwm_sel  = (io_bank)&&(pre_pwm);
374
        assign  pre_uart = (wb_addr[4: 1]== 4'h5)||(wb_addr[4:0]==5'h7);
375
        assign  uart_sel = (io_bank)&&(pre_uart);
376
        assign  pre_flctl= (wb_addr[4: 2]== 3'h3);
377
        assign  flctl_sel= (io_bank)&&(pre_flctl);
378
        assign  pre_scop = (wb_addr[4: 3]== 2'h3);
379
        assign  scop_sel = (io_bank)&&(pre_scop);
380 2 dgisselq
        assign  cfg_sel  =((wb_cyc)&&(wb_addr[31: 6]== 26'h05));
381
        // zip_sel is not on the bus at this point
382
        assign  mem_sel  =((wb_cyc)&&(wb_addr[31:13]== 19'h01));
383
        assign  flash_sel=((wb_cyc)&&(wb_addr[31:18]== 14'h01));
384 74 dgisselq
`ifdef  SDCARD_ACCESS
385
        assign  sdcard_sel=((wb_cyc)&&(wb_addr[31:2]== 30'h48));
386
`else
387 2 dgisselq
        assign  sdcard_sel=1'b0;
388 74 dgisselq
`endif
389 2 dgisselq
        assign  sdram_sel=((wb_cyc)&&(wb_addr[31:23]== 9'h01));
390 31 dgisselq
 
391
        assign  none_sel =((wb_cyc)&&(wb_stb)&&(~
392
                        (io_sel
393
                        ||uart_sel
394
                        ||pwm_sel
395
                        ||flctl_sel
396
                        ||scop_sel
397
                        ||cfg_sel
398
                        ||mem_sel
399
                        ||sdram_sel
400
                        ||sdcard_sel
401
                        ||flash_sel)));
402 2 dgisselq
        assign  many_sel =((wb_cyc)&&(wb_stb)&&(
403
                         {3'h0, io_sel}
404
                        +{3'h0, uart_sel}
405
                        +{3'h0, pwm_sel}
406
                        +{3'h0, flctl_sel}
407
                        +{3'h0, scop_sel}
408
                        +{3'h0, cfg_sel}
409
                        +{3'h0, mem_sel}
410
                        +{3'h0, sdram_sel}
411
                        +{3'h0, sdcard_sel}
412
                        +{3'h0, flash_sel} > 1));
413
 
414
        wire    many_ack;
415
        assign  many_ack =((wb_cyc)&&(
416
                         {3'h0, io_ack}
417
                        +{3'h0, uart_ack}
418
                        +{3'h0, pwm_ack}
419 31 dgisselq
                        // FLCTL acks through the flash, so one less check here
420 2 dgisselq
                        +{3'h0, scop_ack}
421
                        +{3'h0, cfg_ack}
422
                        +{3'h0, mem_ack}
423
                        +{3'h0, sdram_ack}
424
                        +{3'h0, sdcard_ack}
425
                        +{3'h0, flash_ack} > 1));
426
 
427
        always @(posedge i_clk)
428
                if (wb_err)
429
                        bus_err_addr <= wb_addr;
430
 
431 74 dgisselq
        wire            flash_interrupt, sdcard_interrupt, scop_interrupt,
432 2 dgisselq
                        uart_rx_int, uart_tx_int, pwm_int;
433
        // The I/O processor, herein called an ioslave
434
        ioslave #(NGPO, NGPI) runio(i_clk,
435
                        wb_cyc, (io_sel)&&(wb_stb), wb_we, wb_addr[4:0],
436
                                wb_data, io_ack, io_stall, io_data,
437
                        i_gpio, o_gpio,
438
                        bus_err_addr,
439 74 dgisselq
                        {
440
                        sdcard_interrupt,
441
                        uart_tx_int, uart_rx_int, pwm_int, scop_interrupt,
442 31 dgisselq
                                flash_interrupt,
443
`ifdef  XULA25
444
                                zip_cpu_int
445
`else
446
                                1'b0
447
`endif
448
                                },
449 2 dgisselq
                        w_ints_to_zip_cpu,
450
                        w_interrupt);
451
                // 8684
452
                // 1'bx, 4'h0, scop_sel, scop_ack, ~scop_stall, 
453
                //      wb_err, ~vga_interrupt, 2'b00, flash_interrupt
454
        //
455
 
456
        //
457
        //      UART device
458
        //
459 74 dgisselq
        wire    [31:0]   uart_debug;
460 2 dgisselq
        uartdev serialport(i_clk, i_rx_uart, o_tx_uart,
461
                        wb_cyc, (wb_stb)&&(uart_sel), wb_we,
462 9 dgisselq
                                        { ~wb_addr[2], wb_addr[0]}, wb_data,
463
                        uart_ack, uart_stall, uart_data,
464 74 dgisselq
                        uart_rx_int, uart_tx_int,
465
                        uart_debug);
466 2 dgisselq
 
467
        //
468
        //      PWM (audio) device
469
        //
470 46 dgisselq
        // The audio rate is given by the number of clock ticks between
471
        // samples.  If we are running at 80 MHz, then divide that by the
472
        // sample rate to get the first parameter for the PWM device.  The
473
        // second parameter is zero or one, indicating whether or not the
474
        // audio rate can be adjusted (1), or whether it is fixed within the
475
        // build (0).
476 74 dgisselq
        wbpwmaudio      #(16'h270f,0,16) //  8   kHz, fixed audio rate
477 46 dgisselq
                pwmdev(i_clk,
478 2 dgisselq
                        wb_cyc, (wb_stb)&&(pwm_sel), wb_we, wb_addr[0],
479
                        wb_data, pwm_ack, pwm_stall, pwm_data, o_pwm, pwm_int);
480 46 dgisselq
 
481 2 dgisselq
 
482
 
483
        //
484
        //      FLASH MEMORY CONFIGURATION ACCESS
485
        //
486
        wire    flash_cs_n, flash_sck, flash_mosi;
487 74 dgisselq
        wire    spi_user, sdcard_grant, flash_grant;
488 2 dgisselq
`ifdef  FLASH_ACCESS
489
        wbspiflash      flashmem(i_clk,
490
                wb_cyc,(wb_stb&&flash_sel),(wb_stb)&&(flctl_sel),wb_we,
491
                        wb_addr[17:0], wb_data,
492
                flash_ack, flash_stall, flash_data,
493
                flash_sck, flash_cs_n, o_sf_cs_n, flash_mosi, i_spi_miso,
494 74 dgisselq
                flash_interrupt, flash_grant);
495 2 dgisselq
`else
496
        reg     r_flash_ack;
497
        initial r_flash_ack = 1'b0;
498
        always @(posedge i_clk)
499
                r_flash_ack <= (wb_cyc)&&(wb_stb)&&((flash_sel)||(flctl_sel));
500
 
501
        assign  flash_ack = r_flash_ack;
502
        assign  flash_stall = 1'b0;
503
        assign  flash_data = 32'h0000;
504
        assign  flash_interrupt = 1'b0;
505
 
506
        assign  flash_cs_n = 1'b1;
507
        assign  flash_sck  = 1'b1;
508
        assign  flash_mosi = 1'b1;
509
`endif
510
 
511 74 dgisselq
        //
512
        //      SDCARD ACCESS
513
        //
514
        wire    sdcard_cs_n, sdcard_sck, sdcard_mosi;
515
        wire    [31:0]   sdspi_scope;
516
`ifdef  SDCARD_ACCESS
517
        sdspi   sdcard_controller(i_clk,
518
                // Wishbone interface
519
                wb_cyc, (wb_stb)&&(sdcard_sel), wb_we, wb_addr[1:0], wb_data,
520
                //      return
521
                        sdcard_ack, sdcard_stall, sdcard_data,
522
                // SPI interface
523
                sdcard_cs_n, sdcard_sck, sdcard_mosi, i_spi_miso,
524
                sdcard_interrupt, sdcard_grant, sdspi_scope);
525
`else
526
        reg     r_sdcard_ack;
527
        initial r_sdcard_ack = 1'b0;
528
        always @(posedge i_clk)
529
                r_sdcard_ack <= (wb_cyc)&&(wb_stb)&&(sdcard_sel);
530
        assign  sdcard_stall = 1'b0;
531
        assign  sdcard_ack = r_sdcard_ack;
532
        assign  sdcard_data = 32'h0000;
533
        assign  sdcard_interrupt= 1'b0;
534
`endif  // SDCARD_ACCESS
535
 
536
 
537 2 dgisselq
`ifdef  FLASH_ACCESS
538
`ifdef  SDCARD_ACCESS
539
        spiarbiter      spichk(i_clk,
540 74 dgisselq
                // Channel zero
541 2 dgisselq
                flash_cs_n, flash_sck, flash_mosi,
542 74 dgisselq
                // Channel one
543 2 dgisselq
                sdcard_cs_n, sdcard_sck, sdcard_mosi,
544 74 dgisselq
                o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi,
545
                spi_user);
546
        assign  sdcard_grant =  spi_user;
547
        assign  flash_grant  = ~spi_user;
548 2 dgisselq
`else
549
        // Flash access, but no SD card access
550
        assign  o_sf_cs_n  = flash_cs_n;
551
        assign  o_sd_cs_n  = 1'b1;
552
        assign  o_spi_sck  = flash_sck;
553
        assign  o_spi_mosi = flash_mosi;
554 74 dgisselq
        assign  spi_user = 1'b0;
555 2 dgisselq
`endif // SDCARD_ACCESS && FLASH_ACCESS
556
`else // FLASH_ACCESS
557
`ifdef  SDCARD_ACCESS
558
        // SDCard access, but no flash access
559
        assign  o_sf_cs_n  = 1'b1;
560
        assign  o_sd_cs_n  = sdcard_cs_n;
561
        assign  o_spi_sck  = sdcard_sck;
562
        assign  o_spi_mosi = sdcard_mosi;
563 74 dgisselq
        assign  spi_user = 1'b1;
564 2 dgisselq
`else
565
        // No SPI access ...
566
        assign  o_sf_cs_n  = 1'b1;
567
        assign  o_sd_cs_n  = 1'b1;
568
        assign  o_spi_sck  = 1'b1;
569
        assign  o_spi_mosi = 1'b1;
570 74 dgisselq
        assign  spi_user = 1'b0;
571 2 dgisselq
`endif // SDCARD_ACCESS, w/o FLASH_ACCESS
572
`endif // !FLASH_ACCESS
573
 
574
 
575
        //
576
        //      MULTIBOOT/ICAPE2 CONFIGURATION ACCESS
577
        //
578
        wire    [31:0]   cfg_scope;
579
`ifdef  FANCY_ICAP_ACCESS
580
        wbicape6        fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
581
                                wb_addr[5:0], wb_data,
582
                                cfg_ack, cfg_stall, cfg_data,
583
                                cfg_scope);
584
`else
585
        assign  cfg_scope = 32'h0000;
586
        reg     r_cfg_ack;
587
        initial r_cfg_ack = 1'b0;
588
        always @(posedge i_clk)
589
                r_cfg_ack <= ((wb_cyc)&&(cfg_sel)&&(wb_stb)&&(~cfg_stall));
590
        assign  cfg_ack = r_cfg_ack;
591
        assign  cfg_stall = 1'b0;
592
        assign  cfg_data = 32'h0000;
593
`endif
594
 
595
 
596
        //
597
        //      RAM MEMORY ACCESS
598
        //
599
`ifdef  IMPLEMENT_ONCHIP_RAM
600
        memdev  #(13) ram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we,
601
                        wb_addr[12:0], wb_data, mem_ack, mem_stall, mem_data);
602
`else
603
        reg     r_mem_ack;
604
        always @(posedge i_clk)
605
                r_mem_ack = (wb_cyc)&&(wb_stb)&&(mem_sel);
606
        assign  mem_data = 32'h000;
607
        assign  mem_stall = 1'b0;
608
        assign  mem_ack = r_mem_ack;
609
`endif
610
 
611
 
612
        //
613
        //      SDRAM Memory Access
614
        //
615
        wire    [31:0]   sdram_debug;
616
`ifndef BYPASS_SDRAM_ACCESS
617
        wbsdram sdram(i_clk,
618
                wb_cyc, (wb_stb)&&(sdram_sel),
619
                        wb_we, wb_addr[22:0], wb_data,
620
                        sdram_ack, sdram_stall, sdram_data,
621
                o_ram_cs_n, o_ram_cke, o_ram_ras_n, o_ram_cas_n, o_ram_we_n,
622
                        o_ram_bs, o_ram_addr,
623
                        o_ram_drive_data, i_ram_data, o_ram_data, o_ram_dqm,
624
                sdram_debug);
625
`else
626
        reg     r_sdram_ack;
627
        initial r_sdram_ack = 1'b0;
628
        always @(posedge i_clk)
629
                r_sdram_ack <= (wb_cyc)&&(wb_stb)&&(sdram_sel);
630
        assign  sdram_ack = r_sdram_ack;
631
        assign  sdram_stall = 1'b0;
632
        assign  sdram_data = 32'h0000;
633
 
634
        assign  o_ram_ce_n  = 1'b1;
635
        assign  o_ram_ras_n = 1'b1;
636
        assign  o_ram_cas_n = 1'b1;
637
        assign  o_ram_we_n  = 1'b1;
638
 
639
        assign  sdram_debug = 32'h0000;
640
`endif
641
 
642
        //
643
        //
644
        //      WISHBONE SCOPES
645
        //
646
        //
647
        //
648
        //
649 46 dgisselq
        wire    [31:0]   scop_flash_data;
650
        wire    scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
651
 
652
`ifndef FLASH_ACCESS
653 2 dgisselq
`ifdef  FLASH_SCOPE
654 46 dgisselq
`undef  FLASH_SCOPE // FLASH_SCOPE only makes sense if you have flash access
655
`endif
656
`endif
657
 
658
`ifdef  FLASH_SCOPE
659 2 dgisselq
        reg     [31:0]   r_flash_debug, last_flash_debug;
660
        always @(posedge i_clk)
661
                r_flash_debug <= flash_debug;
662
        always @(posedge i_clk)
663
                last_flash_debug <= r_flash_debug;
664
        wbscope spiscope(i_clk, 1'b1, (~o_spi_cs_n), r_flash_debug,
665
                // Wishbone interface
666
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
667
                        wb_data,
668
                        scop_flash_ack, scop_flash_stall, scop_flash_data,
669
                scop_flash_interrupt);
670
`else
671 46 dgisselq
`ifdef  WBUS_SCOPE
672
        wbscopc #(5'ha) wbuscope(i_clk, 1'b1, wbus_debug[31], wbus_debug[30:0],
673
                // Wishbone interface
674
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
675
                        wb_data,
676
                        scop_flash_ack, scop_flash_stall, scop_flash_data,
677
                scop_flash_interrupt);
678
`else
679 2 dgisselq
        assign  scop_flash_data = 32'h00;
680
        assign  scop_flash_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00);
681
        assign scop_flash_stall = 1'b0;
682
        assign scop_flash_interrupt = 1'b0;
683
`endif
684 46 dgisselq
`endif
685 2 dgisselq
 
686
 
687
        wire    [31:0]   scop_cfg_data;
688
        wire            scop_cfg_ack, scop_cfg_stall, scop_cfg_interrupt;
689
`ifdef  CFG_SCOPE
690
        wire            scop_cfg_trigger;
691
        assign  scop_cfg_trigger = (wb_cyc)&&(wb_stb)&&(cfg_sel);
692 18 dgisselq
        wbscope #(5'h7) wbcfgscope(i_clk, 1'b1, scop_cfg_trigger, cfg_scope,
693 2 dgisselq
                // Wishbone interface
694
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
695
                                wb_we, wb_addr[0], wb_data,
696
                        scop_cfg_ack, scop_cfg_stall, scop_cfg_data,
697
                scop_cfg_interrupt);
698
`else
699 74 dgisselq
`ifdef  SDCARD_SCOPE
700
        wire            scop_sd_trigger, scop_sd_ce;
701
        assign  scop_sd_trigger = (wb_cyc)&&(wb_stb)&&(sdcard_sel)&&(wb_we);
702
        assign  scop_sd_ce = 1'b1; // sdspi_scope[31];
703
        wbscope #(5'h9) sdspiscope(i_clk, scop_sd_ce,
704
                        scop_sd_trigger, sdspi_scope,
705
                // Wishbone interface
706
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
707
                        wb_we, wb_addr[0], wb_data,
708
                scop_cfg_ack, scop_cfg_stall, scop_cfg_data,scop_cfg_interrupt);
709
`else
710 2 dgisselq
        assign  scop_cfg_data = 32'h00;
711
        assign  scop_cfg_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01);
712
        assign  scop_cfg_stall = 1'b0;
713
        assign  scop_cfg_interrupt = 1'b0;
714
`endif
715 74 dgisselq
`endif
716 2 dgisselq
 
717 74 dgisselq
        wire    [31:0]   scop_two_data;
718
        wire            scop_two_ack, scop_two_stall, scop_two_interrupt;
719 2 dgisselq
`ifdef  SDRAM_SCOPE
720
        wire            sdram_trigger;
721 46 dgisselq
        assign  sdram_trigger = sdram_debug[18]; // sdram_sel;
722 2 dgisselq
 
723 46 dgisselq
        wbscope #(5'hb) sdramscope(i_clk, 1'b1, sdram_trigger,
724 2 dgisselq
                        sdram_debug,
725 46 dgisselq
                        //{ sdram_trigger, wb_data[30:0] },
726 2 dgisselq
                // Wishbone interface
727
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)), wb_we, wb_addr[0],
728
                        wb_data,
729 74 dgisselq
                        scop_two_ack, scop_two_stall, scop_two_data,
730
                scop_two_interrupt);
731 2 dgisselq
`else
732 74 dgisselq
`ifdef  UART_SCOPE
733
        wire            uart_trigger;
734
        assign  uart_trigger = uart_debug[31];
735
 
736
        // wbscopc #(5'ha) uartscope(i_clk,1'b1, uart_trigger, uart_debug[30:0],
737
        wbscope #(5'ha) uartscope(i_clk, 1'b1, uart_trigger, uart_debug[31:0],
738
                // Wishbone interface
739
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)), wb_we, wb_addr[0],
740
                        wb_data,
741
                        scop_two_ack, scop_two_stall, scop_two_data,
742
                scop_two_interrupt);
743
`else
744
        assign  scop_two_data = 32'h00;
745
        assign  scop_two_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10);
746
        assign  scop_two_stall = 1'b0;
747
        assign  scop_two_interrupt = 1'b0;
748 2 dgisselq
`endif
749 74 dgisselq
`endif
750 2 dgisselq
 
751
        wire    [31:0]   scop_zip_data;
752
        wire            scop_zip_ack, scop_zip_stall, scop_zip_interrupt;
753
`ifdef  ZIP_SCOPE
754
        wire            zip_trigger;
755
        assign  zip_trigger=(wbu_zip_sel)&&(wbu_we)&&(wbu_stb)&&(~wbu_addr[0]);
756 74 dgisselq
        wbscope #(5'h9) zipscope(i_clk, 1'b1, zip_trigger,
757 2 dgisselq
                        zip_debug,
758
                // Wishbone interface
759
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b11)), wb_we, wb_addr[0],
760
                        wb_data,
761
                        scop_zip_ack, scop_zip_stall, scop_zip_data,
762
                scop_zip_interrupt);
763
`else
764
        assign  scop_zip_data = 32'h00;
765
        assign  scop_zip_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b11);
766
        assign  scop_zip_stall = 1'b0;
767
        assign  scop_zip_interrupt = 1'b0;
768
`endif
769
 
770
 
771
        assign  scop_interrupt = scop_flash_interrupt || scop_cfg_interrupt
772 74 dgisselq
                                || scop_two_interrupt || scop_zip_interrupt;
773
        assign  scop_ack   = scop_cfg_ack | scop_flash_ack | scop_two_ack | scop_zip_ack;
774 2 dgisselq
        assign  scop_stall = ((~wb_addr[2])?
775
                                ((wb_addr[1])?scop_flash_stall:scop_cfg_stall)
776 74 dgisselq
                                : ((wb_addr[1])?scop_two_stall:scop_zip_stall));
777 2 dgisselq
        assign  scop_data  = ((scop_cfg_ack)?scop_cfg_data
778
                                : ((scop_flash_ack) ? scop_flash_data
779 74 dgisselq
                                : ((scop_two_ack) ? scop_two_data
780 2 dgisselq
                                : scop_zip_data)));
781
 
782
 
783
endmodule
784
 
785
// 0x8684 interrupts ...???

powered by: WebSVN 2.1.0

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