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

Subversion Repositories xulalx25soc

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

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

powered by: WebSVN 2.1.0

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