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

Subversion Repositories xulalx25soc

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

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 106 dgisselq
 
379
`ifndef SPEEDY_IO
380
 
381 31 dgisselq
        wire    pre_io, pre_pwm, pre_uart, pre_flctl, pre_scop;
382 2 dgisselq
        assign  io_bank  = (wb_cyc)&&(wb_addr[31:5] == 27'h8);
383 31 dgisselq
        assign  pre_io   = (~pre_flctl)&&(~pre_pwm)&&(~pre_uart)&&(~pre_scop);
384
        assign  io_sel   = (io_bank)&&(pre_io);
385
        assign  pre_pwm  = (wb_addr[4: 1]== 4'h4);
386
        assign  pwm_sel  = (io_bank)&&(pre_pwm);
387
        assign  pre_uart = (wb_addr[4: 1]== 4'h5)||(wb_addr[4:0]==5'h7);
388
        assign  uart_sel = (io_bank)&&(pre_uart);
389
        assign  pre_flctl= (wb_addr[4: 2]== 3'h3);
390
        assign  flctl_sel= (io_bank)&&(pre_flctl);
391
        assign  pre_scop = (wb_addr[4: 3]== 2'h3);
392
        assign  scop_sel = (io_bank)&&(pre_scop);
393 2 dgisselq
        assign  cfg_sel  =((wb_cyc)&&(wb_addr[31: 6]== 26'h05));
394
        // zip_sel is not on the bus at this point
395
        assign  mem_sel  =((wb_cyc)&&(wb_addr[31:13]== 19'h01));
396
        assign  flash_sel=((wb_cyc)&&(wb_addr[31:18]== 14'h01));
397 74 dgisselq
`ifdef  SDCARD_ACCESS
398
        assign  sdcard_sel=((wb_cyc)&&(wb_addr[31:2]== 30'h48));
399
`else
400 2 dgisselq
        assign  sdcard_sel=1'b0;
401 74 dgisselq
`endif
402 2 dgisselq
        assign  sdram_sel=((wb_cyc)&&(wb_addr[31:23]== 9'h01));
403 106 dgisselq
`else
404
        // While the following would make the bus infinitely easier to decode,
405
        // it would also scramble where everything on the bus is located at,
406
        // while also making it difficult to access these values via offsets
407
        // of a register.  Further, while simpler, everything would alias all
408
        // over the place as well--that is, devices would show up at multiple
409
        // locations on the bus.  It's all a tradeoff.
410
        assign  iovec = { wb_addr[23],wb_addr[18],wb_addr[15:13] }
411 31 dgisselq
 
412 106 dgisselq
        assign  sdram_sel =((wb_cyc)&&(io_vec[4]));
413
        assign  flash_sel =((wb_cyc)&&(io_vec[4:3]==2'b01));
414
        assign  mem_sel   =((wb_cyc)&&(io_vec[4:0]==5'h07));
415
        assign  cfg_sel   =((wb_cyc)&&(io_vec[4:0]==5'h06));
416
`ifdef  SDCARD_ACCESS
417
        assign  sdcard_sel=((wb_cyc)&&(io_vec[4:0]==5'h05));
418
`else
419
        assign  sdcard_sel=1'b0;
420
`endif
421
        assign  scop_sel  =((wb_cyc)&&(io_vec[4:0]==5'h04));
422
        assign  rtc_sel   =((wb_cyc)&&(io_vec[4:0]==5'h03));
423
        assign  rtc_sel   =((wb_cyc)&&(io_vec[4:0]==5'h03));
424
        assign  puf_sel   =((wb_cyc)&&(io_vec[4:0]==5'h02));
425
        assign  io_sel    =((wb_cyc)&&(io_vec[4:0]==5'h01));
426
        assign  wb_err    =((wb_cyc)&&(io_vec[4:0]==5'h00));
427
        assign  flctl_sel = (puf_sel)&&(wb_addr[3]);
428
        assign  pwm_sel   = (puf_sel)&&(wb_addr[3:2]==2'b00);
429
        // Note that in the following definition, the UART is given four words
430
        // despite the fact that it can probably only use 3.
431
        assign  uart_sel  = (puf_sel)&&(wb_addr[3:2]==2'b01);
432
 
433
`endif
434
 
435 31 dgisselq
        assign  none_sel =((wb_cyc)&&(wb_stb)&&(~
436
                        (io_sel
437
                        ||uart_sel
438
                        ||pwm_sel
439
                        ||flctl_sel
440
                        ||scop_sel
441
                        ||cfg_sel
442
                        ||mem_sel
443
                        ||sdram_sel
444
                        ||sdcard_sel
445
                        ||flash_sel)));
446 2 dgisselq
        assign  many_sel =((wb_cyc)&&(wb_stb)&&(
447
                         {3'h0, io_sel}
448
                        +{3'h0, uart_sel}
449
                        +{3'h0, pwm_sel}
450
                        +{3'h0, flctl_sel}
451
                        +{3'h0, scop_sel}
452
                        +{3'h0, cfg_sel}
453
                        +{3'h0, mem_sel}
454
                        +{3'h0, sdram_sel}
455
                        +{3'h0, sdcard_sel}
456
                        +{3'h0, flash_sel} > 1));
457
 
458
        wire    many_ack;
459
        assign  many_ack =((wb_cyc)&&(
460
                         {3'h0, io_ack}
461
                        +{3'h0, uart_ack}
462
                        +{3'h0, pwm_ack}
463 31 dgisselq
                        // FLCTL acks through the flash, so one less check here
464 2 dgisselq
                        +{3'h0, scop_ack}
465
                        +{3'h0, cfg_ack}
466
                        +{3'h0, mem_ack}
467
                        +{3'h0, sdram_ack}
468
                        +{3'h0, sdcard_ack}
469
                        +{3'h0, flash_ack} > 1));
470
 
471
        always @(posedge i_clk)
472
                if (wb_err)
473
                        bus_err_addr <= wb_addr;
474
 
475 74 dgisselq
        wire            flash_interrupt, sdcard_interrupt, scop_interrupt,
476 2 dgisselq
                        uart_rx_int, uart_tx_int, pwm_int;
477 106 dgisselq
        wire    [(NGPO-1):0]     w_gpio;
478 2 dgisselq
        // The I/O processor, herein called an ioslave
479
        ioslave #(NGPO, NGPI) runio(i_clk,
480
                        wb_cyc, (io_sel)&&(wb_stb), wb_we, wb_addr[4:0],
481
                                wb_data, io_ack, io_stall, io_data,
482 106 dgisselq
                        i_gpio, w_gpio,
483 2 dgisselq
                        bus_err_addr,
484 74 dgisselq
                        {
485
                        sdcard_interrupt,
486
                        uart_tx_int, uart_rx_int, pwm_int, scop_interrupt,
487 31 dgisselq
                                flash_interrupt,
488
`ifdef  XULA25
489
                                zip_cpu_int
490
`else
491
                                1'b0
492
`endif
493
                                },
494 2 dgisselq
                        w_ints_to_zip_cpu,
495
                        w_interrupt);
496
                // 8684
497
                // 1'bx, 4'h0, scop_sel, scop_ack, ~scop_stall, 
498
                //      wb_err, ~vga_interrupt, 2'b00, flash_interrupt
499
        //
500
 
501
        //
502
        //      UART device
503
        //
504 74 dgisselq
        wire    [31:0]   uart_debug;
505 2 dgisselq
        uartdev serialport(i_clk, i_rx_uart, o_tx_uart,
506
                        wb_cyc, (wb_stb)&&(uart_sel), wb_we,
507 9 dgisselq
                                        { ~wb_addr[2], wb_addr[0]}, wb_data,
508
                        uart_ack, uart_stall, uart_data,
509 74 dgisselq
                        uart_rx_int, uart_tx_int,
510
                        uart_debug);
511 2 dgisselq
 
512
        //
513
        //      PWM (audio) device
514
        //
515 46 dgisselq
        // The audio rate is given by the number of clock ticks between
516
        // samples.  If we are running at 80 MHz, then divide that by the
517
        // sample rate to get the first parameter for the PWM device.  The
518
        // second parameter is zero or one, indicating whether or not the
519
        // audio rate can be adjusted (1), or whether it is fixed within the
520
        // build (0).
521 83 dgisselq
`ifdef  XULA25
522 106 dgisselq
`define FMHACK
523
 
524
`ifdef  FMHACK
525
        wbfmtxhack      #(16'd1813)     // 44.1 kHz, user adjustable
526
`else
527 83 dgisselq
        wbpwmaudio      #(16'd1813,1)   // 44.1 kHz, user adjustable
528 106 dgisselq
`endif
529
 
530 83 dgisselq
`else
531 101 dgisselq
        wbpwmaudio      #(16'h270f,0,16) //  8   kHz, fixed audio rate
532 83 dgisselq
`endif
533 46 dgisselq
                pwmdev(i_clk,
534 2 dgisselq
                        wb_cyc, (wb_stb)&&(pwm_sel), wb_we, wb_addr[0],
535
                        wb_data, pwm_ack, pwm_stall, pwm_data, o_pwm, pwm_int);
536 46 dgisselq
 
537 106 dgisselq
`ifdef  FMHACK
538
        assign  o_gpio = {(NGPO){o_pwm}};
539
`else
540
        assign  o_gpio = w_gpio;
541
`endif
542 2 dgisselq
 
543 106 dgisselq
 
544
 
545 2 dgisselq
        //
546
        //      FLASH MEMORY CONFIGURATION ACCESS
547
        //
548
        wire    flash_cs_n, flash_sck, flash_mosi;
549 74 dgisselq
        wire    spi_user, sdcard_grant, flash_grant;
550 2 dgisselq
`ifdef  FLASH_ACCESS
551
        wbspiflash      flashmem(i_clk,
552
                wb_cyc,(wb_stb&&flash_sel),(wb_stb)&&(flctl_sel),wb_we,
553
                        wb_addr[17:0], wb_data,
554
                flash_ack, flash_stall, flash_data,
555
                flash_sck, flash_cs_n, o_sf_cs_n, flash_mosi, i_spi_miso,
556 74 dgisselq
                flash_interrupt, flash_grant);
557 2 dgisselq
`else
558
        reg     r_flash_ack;
559
        initial r_flash_ack = 1'b0;
560
        always @(posedge i_clk)
561
                r_flash_ack <= (wb_cyc)&&(wb_stb)&&((flash_sel)||(flctl_sel));
562
 
563
        assign  flash_ack = r_flash_ack;
564
        assign  flash_stall = 1'b0;
565
        assign  flash_data = 32'h0000;
566
        assign  flash_interrupt = 1'b0;
567
 
568
        assign  flash_cs_n = 1'b1;
569
        assign  flash_sck  = 1'b1;
570
        assign  flash_mosi = 1'b1;
571
`endif
572
 
573 74 dgisselq
        //
574
        //      SDCARD ACCESS
575
        //
576
        wire    sdcard_cs_n, sdcard_sck, sdcard_mosi;
577
        wire    [31:0]   sdspi_scope;
578
`ifdef  SDCARD_ACCESS
579
        sdspi   sdcard_controller(i_clk,
580
                // Wishbone interface
581
                wb_cyc, (wb_stb)&&(sdcard_sel), wb_we, wb_addr[1:0], wb_data,
582
                //      return
583
                        sdcard_ack, sdcard_stall, sdcard_data,
584
                // SPI interface
585
                sdcard_cs_n, sdcard_sck, sdcard_mosi, i_spi_miso,
586
                sdcard_interrupt, sdcard_grant, sdspi_scope);
587
`else
588
        reg     r_sdcard_ack;
589
        initial r_sdcard_ack = 1'b0;
590
        always @(posedge i_clk)
591
                r_sdcard_ack <= (wb_cyc)&&(wb_stb)&&(sdcard_sel);
592
        assign  sdcard_stall = 1'b0;
593
        assign  sdcard_ack = r_sdcard_ack;
594
        assign  sdcard_data = 32'h0000;
595
        assign  sdcard_interrupt= 1'b0;
596
`endif  // SDCARD_ACCESS
597
 
598
 
599 2 dgisselq
`ifdef  FLASH_ACCESS
600
`ifdef  SDCARD_ACCESS
601
        spiarbiter      spichk(i_clk,
602 74 dgisselq
                // Channel zero
603 2 dgisselq
                flash_cs_n, flash_sck, flash_mosi,
604 74 dgisselq
                // Channel one
605 2 dgisselq
                sdcard_cs_n, sdcard_sck, sdcard_mosi,
606 74 dgisselq
                o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi,
607
                spi_user);
608
        assign  sdcard_grant =  spi_user;
609
        assign  flash_grant  = ~spi_user;
610 2 dgisselq
`else
611
        // Flash access, but no SD card access
612
        assign  o_sf_cs_n  = flash_cs_n;
613
        assign  o_sd_cs_n  = 1'b1;
614
        assign  o_spi_sck  = flash_sck;
615
        assign  o_spi_mosi = flash_mosi;
616 74 dgisselq
        assign  spi_user = 1'b0;
617 83 dgisselq
        assign  flash_grant = 1'b1;
618
        assign  sdcard_grant= 1'b0;
619 2 dgisselq
`endif // SDCARD_ACCESS && FLASH_ACCESS
620
`else // FLASH_ACCESS
621
`ifdef  SDCARD_ACCESS
622
        // SDCard access, but no flash access
623
        assign  o_sf_cs_n  = 1'b1;
624
        assign  o_sd_cs_n  = sdcard_cs_n;
625
        assign  o_spi_sck  = sdcard_sck;
626
        assign  o_spi_mosi = sdcard_mosi;
627 74 dgisselq
        assign  spi_user = 1'b1;
628 83 dgisselq
        assign  flash_grant = 1'b0;
629
        assign  sdcard_grant= 1'b1;
630 2 dgisselq
`else
631
        // No SPI access ...
632
        assign  o_sf_cs_n  = 1'b1;
633
        assign  o_sd_cs_n  = 1'b1;
634
        assign  o_spi_sck  = 1'b1;
635
        assign  o_spi_mosi = 1'b1;
636 74 dgisselq
        assign  spi_user = 1'b0;
637 83 dgisselq
        assign  flash_grant = 1'b0;
638
        assign  sdcard_grant= 1'b0;
639 2 dgisselq
`endif // SDCARD_ACCESS, w/o FLASH_ACCESS
640
`endif // !FLASH_ACCESS
641
 
642
 
643
        //
644
        //      MULTIBOOT/ICAPE2 CONFIGURATION ACCESS
645
        //
646
        wire    [31:0]   cfg_scope;
647
`ifdef  FANCY_ICAP_ACCESS
648
        wbicape6        fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
649
                                wb_addr[5:0], wb_data,
650
                                cfg_ack, cfg_stall, cfg_data,
651
                                cfg_scope);
652
`else
653
        assign  cfg_scope = 32'h0000;
654
        reg     r_cfg_ack;
655
        initial r_cfg_ack = 1'b0;
656
        always @(posedge i_clk)
657
                r_cfg_ack <= ((wb_cyc)&&(cfg_sel)&&(wb_stb)&&(~cfg_stall));
658
        assign  cfg_ack = r_cfg_ack;
659
        assign  cfg_stall = 1'b0;
660
        assign  cfg_data = 32'h0000;
661
`endif
662
 
663
 
664
        //
665
        //      RAM MEMORY ACCESS
666
        //
667
`ifdef  IMPLEMENT_ONCHIP_RAM
668
        memdev  #(13) ram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we,
669
                        wb_addr[12:0], wb_data, mem_ack, mem_stall, mem_data);
670
`else
671
        reg     r_mem_ack;
672
        always @(posedge i_clk)
673
                r_mem_ack = (wb_cyc)&&(wb_stb)&&(mem_sel);
674
        assign  mem_data = 32'h000;
675
        assign  mem_stall = 1'b0;
676
        assign  mem_ack = r_mem_ack;
677
`endif
678
 
679
 
680
        //
681
        //      SDRAM Memory Access
682
        //
683
        wire    [31:0]   sdram_debug;
684
`ifndef BYPASS_SDRAM_ACCESS
685
        wbsdram sdram(i_clk,
686
                wb_cyc, (wb_stb)&&(sdram_sel),
687
                        wb_we, wb_addr[22:0], wb_data,
688
                        sdram_ack, sdram_stall, sdram_data,
689
                o_ram_cs_n, o_ram_cke, o_ram_ras_n, o_ram_cas_n, o_ram_we_n,
690
                        o_ram_bs, o_ram_addr,
691
                        o_ram_drive_data, i_ram_data, o_ram_data, o_ram_dqm,
692
                sdram_debug);
693
`else
694
        reg     r_sdram_ack;
695
        initial r_sdram_ack = 1'b0;
696
        always @(posedge i_clk)
697
                r_sdram_ack <= (wb_cyc)&&(wb_stb)&&(sdram_sel);
698
        assign  sdram_ack = r_sdram_ack;
699
        assign  sdram_stall = 1'b0;
700
        assign  sdram_data = 32'h0000;
701
 
702
        assign  o_ram_ce_n  = 1'b1;
703
        assign  o_ram_ras_n = 1'b1;
704
        assign  o_ram_cas_n = 1'b1;
705
        assign  o_ram_we_n  = 1'b1;
706
 
707
        assign  sdram_debug = 32'h0000;
708
`endif
709
 
710
        //
711
        //
712
        //      WISHBONE SCOPES
713
        //
714
        //
715
        //
716
        //
717 46 dgisselq
        wire    [31:0]   scop_flash_data;
718
        wire    scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
719
 
720
`ifndef FLASH_ACCESS
721 2 dgisselq
`ifdef  FLASH_SCOPE
722 46 dgisselq
`undef  FLASH_SCOPE // FLASH_SCOPE only makes sense if you have flash access
723
`endif
724
`endif
725
 
726
`ifdef  FLASH_SCOPE
727 2 dgisselq
        reg     [31:0]   r_flash_debug, last_flash_debug;
728
        always @(posedge i_clk)
729
                r_flash_debug <= flash_debug;
730
        always @(posedge i_clk)
731
                last_flash_debug <= r_flash_debug;
732
        wbscope spiscope(i_clk, 1'b1, (~o_spi_cs_n), r_flash_debug,
733
                // Wishbone interface
734
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
735
                        wb_data,
736
                        scop_flash_ack, scop_flash_stall, scop_flash_data,
737
                scop_flash_interrupt);
738
`else
739 46 dgisselq
`ifdef  WBUS_SCOPE
740
        wbscopc #(5'ha) wbuscope(i_clk, 1'b1, wbus_debug[31], wbus_debug[30:0],
741
                // Wishbone interface
742
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
743
                        wb_data,
744
                        scop_flash_ack, scop_flash_stall, scop_flash_data,
745
                scop_flash_interrupt);
746
`else
747 2 dgisselq
        assign  scop_flash_data = 32'h00;
748
        assign  scop_flash_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00);
749
        assign scop_flash_stall = 1'b0;
750
        assign scop_flash_interrupt = 1'b0;
751
`endif
752 46 dgisselq
`endif
753 2 dgisselq
 
754
 
755
        wire    [31:0]   scop_cfg_data;
756
        wire            scop_cfg_ack, scop_cfg_stall, scop_cfg_interrupt;
757
`ifdef  CFG_SCOPE
758
        wire            scop_cfg_trigger;
759
        assign  scop_cfg_trigger = (wb_cyc)&&(wb_stb)&&(cfg_sel);
760 18 dgisselq
        wbscope #(5'h7) wbcfgscope(i_clk, 1'b1, scop_cfg_trigger, cfg_scope,
761 2 dgisselq
                // Wishbone interface
762
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
763
                                wb_we, wb_addr[0], wb_data,
764
                        scop_cfg_ack, scop_cfg_stall, scop_cfg_data,
765
                scop_cfg_interrupt);
766
`else
767 74 dgisselq
`ifdef  SDCARD_SCOPE
768
        wire            scop_sd_trigger, scop_sd_ce;
769
        assign  scop_sd_trigger = (wb_cyc)&&(wb_stb)&&(sdcard_sel)&&(wb_we);
770
        assign  scop_sd_ce = 1'b1; // sdspi_scope[31];
771
        wbscope #(5'h9) sdspiscope(i_clk, scop_sd_ce,
772
                        scop_sd_trigger, sdspi_scope,
773
                // Wishbone interface
774
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
775
                        wb_we, wb_addr[0], wb_data,
776
                scop_cfg_ack, scop_cfg_stall, scop_cfg_data,scop_cfg_interrupt);
777
`else
778 2 dgisselq
        assign  scop_cfg_data = 32'h00;
779
        assign  scop_cfg_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01);
780
        assign  scop_cfg_stall = 1'b0;
781
        assign  scop_cfg_interrupt = 1'b0;
782
`endif
783 74 dgisselq
`endif
784 2 dgisselq
 
785 74 dgisselq
        wire    [31:0]   scop_two_data;
786
        wire            scop_two_ack, scop_two_stall, scop_two_interrupt;
787 2 dgisselq
`ifdef  SDRAM_SCOPE
788
        wire            sdram_trigger;
789 46 dgisselq
        assign  sdram_trigger = sdram_debug[18]; // sdram_sel;
790 2 dgisselq
 
791 46 dgisselq
        wbscope #(5'hb) sdramscope(i_clk, 1'b1, sdram_trigger,
792 2 dgisselq
                        sdram_debug,
793 46 dgisselq
                        //{ sdram_trigger, wb_data[30:0] },
794 2 dgisselq
                // Wishbone interface
795
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)), wb_we, wb_addr[0],
796
                        wb_data,
797 74 dgisselq
                        scop_two_ack, scop_two_stall, scop_two_data,
798
                scop_two_interrupt);
799 2 dgisselq
`else
800 74 dgisselq
`ifdef  UART_SCOPE
801
        wire            uart_trigger;
802
        assign  uart_trigger = uart_debug[31];
803
 
804
        // wbscopc #(5'ha) uartscope(i_clk,1'b1, uart_trigger, uart_debug[30:0],
805
        wbscope #(5'ha) uartscope(i_clk, 1'b1, uart_trigger, uart_debug[31:0],
806
                // Wishbone interface
807
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)), wb_we, wb_addr[0],
808
                        wb_data,
809
                        scop_two_ack, scop_two_stall, scop_two_data,
810
                scop_two_interrupt);
811
`else
812
        assign  scop_two_data = 32'h00;
813
        assign  scop_two_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10);
814
        assign  scop_two_stall = 1'b0;
815
        assign  scop_two_interrupt = 1'b0;
816 2 dgisselq
`endif
817 74 dgisselq
`endif
818 2 dgisselq
 
819
        wire    [31:0]   scop_zip_data;
820
        wire            scop_zip_ack, scop_zip_stall, scop_zip_interrupt;
821
`ifdef  ZIP_SCOPE
822
        wire            zip_trigger;
823
        assign  zip_trigger=(wbu_zip_sel)&&(wbu_we)&&(wbu_stb)&&(~wbu_addr[0]);
824 74 dgisselq
        wbscope #(5'h9) zipscope(i_clk, 1'b1, zip_trigger,
825 2 dgisselq
                        zip_debug,
826
                // Wishbone interface
827
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b11)), wb_we, wb_addr[0],
828
                        wb_data,
829
                        scop_zip_ack, scop_zip_stall, scop_zip_data,
830
                scop_zip_interrupt);
831
`else
832
        assign  scop_zip_data = 32'h00;
833
        assign  scop_zip_ack  = (wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b11);
834
        assign  scop_zip_stall = 1'b0;
835
        assign  scop_zip_interrupt = 1'b0;
836
`endif
837
 
838
 
839
        assign  scop_interrupt = scop_flash_interrupt || scop_cfg_interrupt
840 74 dgisselq
                                || scop_two_interrupt || scop_zip_interrupt;
841
        assign  scop_ack   = scop_cfg_ack | scop_flash_ack | scop_two_ack | scop_zip_ack;
842 2 dgisselq
        assign  scop_stall = ((~wb_addr[2])?
843
                                ((wb_addr[1])?scop_flash_stall:scop_cfg_stall)
844 74 dgisselq
                                : ((wb_addr[1])?scop_two_stall:scop_zip_stall));
845 2 dgisselq
        assign  scop_data  = ((scop_cfg_ack)?scop_cfg_data
846
                                : ((scop_flash_ack) ? scop_flash_data
847 74 dgisselq
                                : ((scop_two_ack) ? scop_two_data
848 2 dgisselq
                                : scop_zip_data)));
849
 
850
 
851
endmodule
852
 
853
// 0x8684 interrupts ...???

powered by: WebSVN 2.1.0

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