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

Subversion Repositories xulalx25soc

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

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

powered by: WebSVN 2.1.0

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