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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [busmaster.v] - Blame information for rev 27

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

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    busmaster.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     This is the "bus interconnect", herein called the "busmaster".
8
//              This module connects all the devices on the Wishbone bus
9
//              within this project together.  It is created by hand, not
10
//      automatically.
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
`define NO_ZIP_WBU_DELAY
42
`define ZIPCPU
43
//
44
//
45
`define SDCARD_ACCESS
46
`define ETHERNET_ACCESS
47
`ifndef VERILATOR
48
`define ICAPE_ACCESS
49
`endif
50
`define FLASH_ACCESS
51 25 dgisselq
`define SDRAM_ACCESS
52 3 dgisselq
`define GPS_CLOCK
53
//      UART_ACCESS and GPS_UART have both been placed within fastio
54
//              `define UART_ACCESS
55
//              `define GPS_UART
56
`define RTC_ACCESS
57
`define OLEDRGB_ACCESS
58
//
59 25 dgisselq
//
60
//
61
//
62
//
63
// Now, conditional compilation based upon what capabilities we have turned
64
// on
65
//
66
`ifdef  ZIPCPU
67
`define ZIP_SYSTEM
68
`ifndef ZIP_SYSTEM
69
`define ZIP_BONES
70
`endif  // ZIP_SYSTEM
71
`endif  // ZipCPU
72
//
73
//
74
// SCOPE POSITION ZERO
75
//
76
`ifdef  FLASH_ACCESS
77
`define FLASH_SCOPE     // Position zero
78
`else
79
`ifdef ZIPCPU
80
// `define      CPU_SCOPE       // Position zero
81
`endif
82
`endif
83
//
84
// SCOPE POSITION ONE
85
//
86
// `define      GPS_SCOPE       // Position one
87
`ifdef ICAPE_ACCESS
88
`define CFG_SCOPE       // Position one
89
`endif
90
//
91
// SCOPE POSITION TWO
92
//
93
`ifdef  SDRAM_ACCESS
94
`define SDRAM_SCOPE             // Position two
95
`endif
96 3 dgisselq
// `define      ENET_SCOPE
97
//
98
//
99
module  busmaster(i_clk, i_rst,
100
                // CNC
101
                i_rx_stb, i_rx_data, o_tx_stb, o_tx_data, i_tx_busy,
102
                // Boad I/O
103
                i_sw, i_btn, o_led,
104
                o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
105
                // PMod I/O
106
                i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
107
                // The Quad SPI Flash
108
                o_qspi_cs_n, o_qspi_sck, o_qspi_dat, i_qspi_dat, o_qspi_mod,
109
                // The DDR3 SDRAM
110 25 dgisselq
                // The actual wires need to be controlled from the device
111
                // dependent file.  In order to keep this device independent,
112
                // we export only the wishbone interface to the RAM.
113
                // o_ddr_ck_p, o_ddr_ck_n, o_ddr_reset_n, o_ddr_cke,
114
                // o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
115
                // o_ddr_ba, o_ddr_addr, o_ddr_odt, o_ddr_dm,
116
                // io_ddr_dqs_p, io_ddr_dqs_n, io_ddr_data,
117
                o_ram_cyc, o_ram_stb, o_ram_we, o_ram_addr, o_ram_wdata,
118
                        i_ram_ack, i_ram_stall, i_ram_rdata, i_ram_err,
119
                        i_ram_dbg,
120 3 dgisselq
                // The SD Card
121
                o_sd_sck, o_sd_cmd, o_sd_data, i_sd_cmd, i_sd_data, i_sd_detect,
122
                // Ethernet control (MDIO) lines
123
                o_mdclk, o_mdio, o_mdwe, i_mdio,
124
                // OLED Control interface (roughly SPI)
125
                o_oled_sck, o_oled_cs_n, o_oled_mosi, o_oled_dcn,
126
                o_oled_reset_n, o_oled_vccen, o_oled_pmoden,
127
                // The GPS PMod
128
                i_gps_pps, i_gps_3df
129
                );
130 25 dgisselq
        parameter       ZA=24, ZIPINTS=14;
131
        input                   i_clk, i_rst;
132 3 dgisselq
        // The bus commander, via an external uart 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
        // I/O to/from board level devices
139
        input           [3:0]    i_sw;   // 16 switch bus
140
        input           [3:0]    i_btn;  // 5 Buttons
141
        output  wire    [3:0]    o_led;  // 16 wide LED's
142
        output  wire    [2:0]    o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3;
143
        // PMod UARTs
144
        input                   i_aux_rx;
145
        output  wire            o_aux_tx, o_aux_cts;
146
        input                   i_gps_rx;
147
        output  wire            o_gps_tx;
148
        // Quad-SPI flash control
149
        output  wire            o_qspi_cs_n, o_qspi_sck;
150
        output  wire    [3:0]    o_qspi_dat;
151
        input           [3:0]    i_qspi_dat;
152
        output  wire    [1:0]    o_qspi_mod;
153 25 dgisselq
        //
154 3 dgisselq
        // DDR3 RAM controller
155 25 dgisselq
        //
156
        // These would be our RAM control lines.  However, these are device,
157
        // implementation, and architecture dependent, rather than just simply
158
        // logic dependent.  Therefore, this interface as it exists cannot
159
        // exist here.  Instead, we export a device independent wishbone to
160
        // the RAM rather than the RAM wires themselves.
161
        //
162
        // output       wire    o_ddr_ck_p, o_ddr_ck_n,o_ddr_reset_n, o_ddr_cke,
163
        //                      o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n,o_ddr_we_n;
164
        // output       wire    [2:0]   o_ddr_ba;
165
        // output       wire    [13:0]  o_ddr_addr;
166
        // output       wire            o_ddr_odt;
167
        // output       wire    [1:0]   o_ddr_dm;
168
        // inout        wire    [1:0]   io_ddr_dqs_p, io_ddr_dqs_n;
169
        // inout        wire    [15:0]  io_ddr_data;
170
        //
171
        output  wire            o_ram_cyc, o_ram_stb, o_ram_we;
172
        output  wire    [25:0]   o_ram_addr;
173
        output  wire    [31:0]   o_ram_wdata;
174
        input                   i_ram_ack, i_ram_stall;
175
        input           [31:0]   i_ram_rdata;
176
        input                   i_ram_err;
177
        input           [31:0]   i_ram_dbg;
178 3 dgisselq
        // The SD Card
179
        output  wire            o_sd_sck;
180
        output  wire            o_sd_cmd;
181
        output  wire    [3:0]    o_sd_data;
182
        input                   i_sd_cmd;
183
        input           [3:0]    i_sd_data;
184
        input                   i_sd_detect;
185
        // Ethernet control (MDIO)
186
        output  wire            o_mdclk, o_mdio, o_mdwe;
187
        input                   i_mdio;
188
        // OLEDRGB interface
189
        output  wire            o_oled_sck, o_oled_cs_n, o_oled_mosi,
190
                                o_oled_dcn, o_oled_reset_n, o_oled_vccen,
191
                                o_oled_pmoden;
192
        // GPS PMod (GPS UART above)
193
        input                   i_gps_pps;
194
        input                   i_gps_3df;
195
 
196
        //
197
        //
198
        // Master wishbone wires
199
        //
200
        //
201 25 dgisselq
        wire            wb_cyc, wb_stb, wb_we, wb_stall, wb_err, ram_err;
202 3 dgisselq
        wire    [31:0]   wb_data, wb_addr;
203
        reg             wb_ack;
204
        reg     [31:0]   wb_idata;
205
 
206
        // Interrupts
207
        wire            gpio_int, oled_int, flash_int, scop_int;
208
        wire            enet_tx_int, enet_rx_int, sdcard_int, rtc_int, rtc_pps,
209
                        auxrx_int, auxtx_int, gpsrx_int, sw_int, btn_int;
210
 
211
        //
212
        //
213
        // First BUS master source: The UART
214
        //
215
        //
216
        wire    [31:0]   dwb_idata;
217
 
218
        // Wires going to devices
219
        wire            wbu_cyc, wbu_stb, wbu_we;
220
        wire    [31:0]   wbu_addr, wbu_data;
221
        // and then coming from devices
222
        wire            wbu_ack, wbu_stall, wbu_err;
223
        wire    [31:0]   wbu_idata;
224
        // And then headed back home
225
        wire    w_interrupt;
226
        // Oh, and the debug control for the ZIP CPU
227
        wire            wbu_zip_sel, zip_dbg_ack, zip_dbg_stall;
228
        wire    [31:0]   zip_dbg_data;
229
        wbubus  genbus(i_clk, i_rx_stb, i_rx_data,
230
                        wbu_cyc, wbu_stb, wbu_we, wbu_addr, wbu_data,
231
                        (wbu_zip_sel)?zip_dbg_ack:wbu_ack,
232
                        (wbu_zip_sel)?zip_dbg_stall:wbu_stall,
233
                                wbu_err,
234
                                (wbu_zip_sel)?zip_dbg_data:wbu_idata,
235
                        w_interrupt,
236
                        o_tx_stb, o_tx_data, i_tx_busy);
237
 
238
        // assign       o_dbg = (wbu_ack)&&(wbu_cyc);
239
 
240
        wire    zip_cpu_int; // True if the CPU suddenly halts
241
`ifdef  ZIPCPU
242
        // Are we trying to access the ZipCPU?  Such accesses must be special,
243
        // because they must succeed regardless of whether or not the ZipCPU
244
        // is on the bus.  Hence, we trap them here.
245
        assign  wbu_zip_sel = (wbu_addr[27]);
246
 
247
        //
248
        //
249
        // Second BUS master source: The ZipCPU
250
        //
251
        //
252
        wire            zip_cyc, zip_stb, zip_we;
253
        wire    [(ZA-1):0]       w_zip_addr;
254
        wire    [31:0]   zip_data, zip_scope_data;
255
        // and then coming from devices
256
        wire            zip_ack, zip_stall, zip_err;
257
 
258
`ifdef  ZIP_SYSTEM
259
        wire    [(ZIPINTS-1):0]  zip_interrupt_vec = {
260
                // Lazy(ier) interrupts
261
                oled_int, gpio_int, rtc_int, scop_int, flash_int, sw_int, btn_int,
262
                // Fast interrupts
263
                sdcard_int, auxtx_int, auxrx_int, enet_tx_int, enet_rx_int,
264
                        gpsrx_int, rtc_pps
265
                };
266
 
267 27 dgisselq
        zipsystem #(    .RESET_ADDRESS(24'h0480000),
268 3 dgisselq
                        .ADDRESS_WIDTH(ZA),
269
                        .LGICACHE(10),
270
                        .START_HALTED(1),
271
                        .EXTERNAL_INTERRUPTS(ZIPINTS),
272
                        .HIGHSPEED_CPU(0))
273
                zippy(i_clk, i_rst,
274
                        // Zippys wishbone interface
275
                        zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
276
                                zip_ack, zip_stall, dwb_idata, zip_err,
277
                        zip_interrupt_vec, zip_cpu_int,
278
                        // Debug wishbone interface
279
                        ((wbu_cyc)&&(wbu_zip_sel)),
280
                                ((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
281
                                wbu_data,
282
                                zip_dbg_ack, zip_dbg_stall, zip_dbg_data
283
`ifdef  CPU_DEBUG
284
                        , zip_scope_data
285
`endif
286
                        );
287
`else // ZIP_SYSTEM
288
        wire    w_zip_cpu_int_ignored;
289
        zipbones #(     .RESET_ADDRESS(24'h08000),
290
                        .ADDRESS_WIDTH(ZA),
291
                        .LGICACHE(10),
292
                        .START_HALTED(1),
293
                        .HIGHSPEED_CPU(0))
294
                zippy(i_clk, i_rst,
295
                        // Zippys wishbone interface
296
                        zip_cyc, zip_stb, zip_we, w_zip_addr, zip_data,
297
                                zip_ack, zip_stall, dwb_idata, zip_err,
298
                        w_interrupt, w_zip_cpu_int_ignored,
299
                        // Debug wishbone interface
300
                        ((wbu_cyc)&&(wbu_zip_sel)),
301
                                ((wbu_stb)&&(wbu_zip_sel)),wbu_we, wbu_addr[0],
302
                                wbu_data,
303
                                zip_dbg_ack, zip_dbg_stall, zip_dbg_data
304
`ifdef  CPU_DEBUG
305
                        , zip_scope_data
306
`endif
307
                        );
308
        assign  zip_cpu_int = 1'b0;
309
`endif  // ZIP_SYSTEM v ZIP_BONES
310
 
311
        wire [31:0]      zip_addr;
312
        generate
313
        if (ZA < 32)
314
                assign  zip_addr = { {(32-ZA){1'b0}}, w_zip_addr};
315
        else
316
                assign  zip_addr = w_zip_addr;
317
        endgenerate
318
 
319
        //
320
        //
321
        // And an arbiter to decide who gets to access the bus
322
        //
323
        //
324
        wire    dwb_we, dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err;
325
        wire    [31:0]   dwb_addr, dwb_odata;
326
        wbpriarbiter #(32,32) wbu_zip_arbiter(i_clk,
327
                // The ZIP CPU Master -- Gets the priority slot
328
                zip_cyc, zip_stb, zip_we, zip_addr, zip_data,
329
                        zip_ack, zip_stall, zip_err,
330
                // The UART interface Master
331
                (wbu_cyc)&&(~wbu_zip_sel), (wbu_stb)&&(~wbu_zip_sel), wbu_we,
332
                        wbu_addr, wbu_data,
333
                        wbu_ack, wbu_stall, wbu_err,
334
                // Common bus returns
335
                dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
336
                        dwb_ack, dwb_stall, dwb_err);
337
 
338
        // 
339
        // 
340
        // And because the ZIP CPU and the Arbiter create an unacceptable
341
        // delay, we fail timing.  So we add in a delay cycle ...
342
        // 
343
        // 
344
        assign  wbu_idata = dwb_idata;
345
        busdelay        wbu_zip_delay(i_clk,
346
                        dwb_cyc, dwb_stb, dwb_we, dwb_addr, dwb_odata,
347
                                dwb_ack, dwb_stall, dwb_idata, dwb_err,
348
                        wb_cyc, wb_stb, wb_we, wb_addr, wb_data,
349
                                wb_ack, wb_stall, wb_idata, wb_err);
350
 
351
`else   // ZIPCPU
352
        assign  zip_cpu_int = 1'b0; // No CPU here to halt
353
        assign  wbu_zip_sel = 1'b0;
354
 
355
        // If there's no ZipCPU, there's no need for a Zip/WB-Uart bus delay.
356
        // We can go directly from the WB-Uart master bus to the master bus
357
        // itself.
358
        assign  wb_cyc    = wbu_cyc;
359
        assign  wb_stb    = wbu_stb;
360
        assign  wb_we     = wbu_we;
361
        assign  wb_addr   = wbu_addr;
362
        assign  wb_data   = wbu_data;
363
        assign  wbu_idata = wb_idata;
364
        assign  wbu_ack   = wb_ack;
365
        assign  wbu_stall = wb_stall;
366
        assign  wbu_err   = wb_err;
367
 
368
        // The CPU never halts if it doesn't exist, so set this interrupt to
369
        // zero.
370
        assign  zip_cpu_int= 1'b0;
371
`endif  // ZIPCPU
372
 
373
 
374
        //
375
        // Peripheral select lines.
376
        //
377
        // These lines will be true during any wishbone cycle whose address
378
        // line selects the given I/O peripheral.  The none_sel and many_sel
379
        // lines are used to detect problems, such as when no device is
380
        // selected or many devices are selected.  Such problems will lead to
381
        // bus errors (below).
382
        //
383
        wire    io_sel, scop_sel, netb_sel,
384
                        flctl_sel, rtc_sel, sdcard_sel, netp_sel,
385
                        oled_sel, gps_sel, mio_sel, cfg_sel,
386
                        mem_sel, flash_sel, ram_sel,
387
                        none_sel, many_sel;
388
 
389
        wire    [4:0]    skipaddr;
390
        assign  skipaddr = { wb_addr[26], wb_addr[22], wb_addr[15], wb_addr[11],
391
                                ~wb_addr[8] };
392
        assign  ram_sel   = (skipaddr[4]);
393
        assign  flash_sel = (skipaddr[4:3]==2'b01);
394
        assign  mem_sel   = (skipaddr[4:2]==3'b001);
395
        assign  netb_sel  = (skipaddr[4:1]==4'b0001);
396
        assign  io_sel    = (~|skipaddr)&&(wb_addr[7:5]==3'b000);
397 27 dgisselq
        assign  scop_sel  = (~|skipaddr)&&(wb_addr[7:3]==5'b0010_0);
398
        assign  rtc_sel   = (~|skipaddr)&&(wb_addr[7:2]==6'b0010_10);
399
        assign  sdcard_sel= (~|skipaddr)&&(wb_addr[7:2]==6'b0010_11);
400
        //assign gps_sel  = (~|skipaddr)&&(wb_addr[7:2]==6'b0011_00);
401
        assign  oled_sel  = (~|skipaddr)&&(wb_addr[7:2]==6'b0011_01);
402
        assign  netp_sel  = (~|skipaddr)&&(wb_addr[7:3]==5'b0011_1);
403
        assign  gps_sel   = (~|skipaddr)&&(     (wb_addr[7:2]==6'b0011_00)
404
                                            ||  (wb_addr[7:3]==5'b0100_0));
405 3 dgisselq
        assign  mio_sel   = (~|skipaddr)&&(wb_addr[7:5]==3'b101);
406
        assign  flctl_sel = (~|skipaddr)&&(wb_addr[7:5]==3'b110);
407
        assign  cfg_sel   = (~|skipaddr)&&(wb_addr[7:5]==3'b111);
408
 
409
        wire    skiperr;
410
        assign  skiperr = (|wb_addr[31:27])
411
                                ||(~skipaddr[4])&&(|wb_addr[25:23])
412
                                ||(skipaddr[4:3]==2'b00)&&(|wb_addr[21:16])
413
                                ||(skipaddr[4:2]==3'b000)&&(|wb_addr[14:12])
414
                                ||(skipaddr[4:1]==4'b0000)&&(|wb_addr[10:9]);
415
 
416
 
417
        //
418
        // Peripheral acknowledgement lines
419
        //
420
        // These are only a touch more confusing, since the flash device will
421
        // ACK for both flctl_sel (the control line select), as well as the
422
        // flash_sel (the memory line select).  Hence we have one fewer ack
423
        // line.
424
        wire    io_ack, oled_ack,
425
                        rtc_ack, sdcard_ack,
426
                        netp_ack, gps_ack, mio_ack, cfg_ack, netb_ack,
427
                        mem_ack, flash_ack, ram_ack;
428
        reg     many_ack, slow_many_ack;
429
        reg     slow_ack, scop_ack;
430 25 dgisselq
        wire    [5:0]    ack_list;
431
        assign  ack_list = { ram_ack, flash_ack, mem_ack, netb_ack, netp_ack, slow_ack };
432 3 dgisselq
        initial many_ack = 1'b0;
433
        always @(posedge i_clk)
434 25 dgisselq
                many_ack <= ((ack_list != 6'h20)
435
                        &&(ack_list != 6'h10)
436
                        &&(ack_list != 6'h8)
437
                        &&(ack_list != 6'h4)
438
                        &&(ack_list != 6'h2)
439
                        &&(ack_list != 6'h1)
440
                        &&(ack_list != 6'h0));
441 3 dgisselq
        /*
442
        assign  many_ack = (    { 2'h0, ram_ack}
443
                                +{2'h0, flash_ack }
444
                                +{2'h0, mem_ack }
445
                                +{2'h0, netb_ack }
446
                                +{2'h0, slow_ack } > 3'h1 );
447
        */
448
 
449
        wire    [7:0] slow_ack_list;
450 25 dgisselq
        assign slow_ack_list = { cfg_ack, mio_ack, gps_ack,
451 3 dgisselq
                        sdcard_ack, rtc_ack, scop_ack, oled_ack, io_ack };
452
        initial slow_many_ack = 1'b0;
453
        always @(posedge i_clk)
454
                slow_many_ack <= ((slow_ack_list != 8'h80)
455
                        &&(slow_ack_list != 8'h40)
456
                        &&(slow_ack_list != 8'h20)
457
                        &&(slow_ack_list != 8'h10)
458
                        &&(slow_ack_list != 8'h08)
459
                        &&(slow_ack_list != 8'h04)
460
                        &&(slow_ack_list != 8'h02)
461
                        &&(slow_ack_list != 8'h01)
462
                        &&(slow_ack_list != 8'h00));
463
 
464
        always @(posedge i_clk)
465 25 dgisselq
                wb_ack <= (wb_cyc)&&(|ack_list);
466 3 dgisselq
        always @(posedge i_clk)
467 25 dgisselq
                slow_ack <= (wb_cyc)&&(|slow_ack_list);
468 3 dgisselq
 
469
        //
470
        // Peripheral data lines
471
        //
472
        wire    [31:0]   io_data, oled_data,
473
                        rtc_data, sdcard_data,
474
                        netp_data, gps_data, mio_data, cfg_data, netb_data,
475
                        mem_data, flash_data, ram_data;
476
        reg     [31:0]   slow_data, scop_data;
477
 
478
        // 4 control lines, 5x32 data lines ... 
479
        always @(posedge i_clk)
480
                if ((ram_ack)||(flash_ack))
481
                        wb_idata <= (ram_ack)?ram_data:flash_data;
482
                else if ((mem_ack)||(netb_ack))
483
                        wb_idata <= (mem_ack)?mem_data:netb_data;
484
                else
485 25 dgisselq
                        wb_idata <= (netp_ack)?netp_data: slow_data;
486 3 dgisselq
 
487
        // 7 control lines, 8x32 data lines
488
        always @(posedge i_clk)
489
                if ((cfg_ack)||(mio_ack))
490
                        slow_data <= (cfg_ack) ? cfg_data : mio_data;
491
                else if ((sdcard_ack)||(rtc_ack))
492
                        slow_data <= (sdcard_ack)?sdcard_data : rtc_data;
493
                else if ((scop_ack)|(oled_ack))
494
                        slow_data <= (scop_ack)?scop_data:oled_data;
495
                else
496 25 dgisselq
                        slow_data <= (gps_ack) ? gps_data : io_data;
497 3 dgisselq
 
498
        //
499
        // Peripheral stall lines
500
        //
501
        // As per the wishbone spec, these cannot be clocked or delayed.  They
502
        // *must* be done via combinatorial logic.
503
        //
504
        wire    io_stall, scop_stall, oled_stall,
505
                        rtc_stall, sdcard_stall,
506
                        netp_stall, gps_stall, mio_stall, cfg_stall, netb_stall,
507
                        mem_stall, flash_stall, ram_stall,
508
                        many_stall;
509
        assign  wb_stall = (wb_cyc)&&(
510
                        ((io_sel)&&(io_stall))          // Never stalls
511
                        ||((scop_sel)&&(scop_stall))    // Never stalls
512
                        ||((rtc_sel)&&(rtc_stall))      // Never stalls
513
                        ||((sdcard_sel)&&(sdcard_stall))// Never stalls
514
                        ||((netp_sel)&&(netp_stall))
515
                        ||((gps_sel)&&(gps_stall))      //(maybe? never stalls?)
516 25 dgisselq
                        ||((oled_sel)&&(oled_stall))    // Never stalls
517 3 dgisselq
                        ||((mio_sel)&&(mio_stall))
518
                        ||((cfg_sel)&&(cfg_stall))
519
                        ||((netb_sel)&&(netb_stall))    // Never stalls
520
                        ||((mem_sel)&&(mem_stall))      // Never stalls
521
                        ||((flash_sel|flctl_sel)&&(flash_stall))
522
                        ||((ram_sel)&&(ram_stall)));
523
 
524
 
525
        //
526
        // Bus Error calculation(s)
527
        //
528
 
529
        // Selecting nothing is only an error if the strobe line is high as well
530
        // as the cycle line.  However, this is captured within the wb_err
531
        // logic itself, so we can ignore it for a line or two.
532
        assign  none_sel = ( //(skiperr)||
533
                                (~|{ io_sel, scop_sel, flctl_sel, rtc_sel,
534
                                        sdcard_sel, netp_sel, gps_sel,
535
                                        oled_sel,
536
                                        mio_sel, cfg_sel, netb_sel, mem_sel,
537
                                        flash_sel,ram_sel }));
538
        //
539
        // Selecting multiple devices at once is a design flaw that should
540
        // never happen.  Hence, if this logic won't build, we won't include
541
        // it.  Still, having this logic in place has saved my tush more than
542
        // once.
543
        //
544
        reg     [31:0]   sel_addr;
545
        always @(posedge i_clk)
546
                sel_addr <= wb_addr;
547
 
548
        reg     many_sel_a, many_sel_b, single_sel_a, single_sel_b, last_stb;
549
        always @(posedge i_clk)
550
        begin
551
                last_stb <= wb_stb;
552
 
553
                single_sel_a <= (wb_stb)&&((ram_sel)|(flash_sel)
554
                                        |(mem_sel)|(netb_sel)|(cfg_sel));
555
                many_sel_a <= 1'b0;
556
                if ((ram_sel)&&((flash_sel)||(mem_sel)||(netb_sel)||cfg_sel))
557
                        many_sel_a <= 1'b1;
558
                else if ((flash_sel)&&((mem_sel)||(netb_sel)||cfg_sel))
559
                        many_sel_a <= 1'b1;
560
                else if ((mem_sel)&&((netb_sel)||cfg_sel))
561
                        many_sel_a <= 1'b1;
562
                else if ((netb_sel)&&(cfg_sel))
563
                        many_sel_a <= 1'b1;
564
 
565
                single_sel_b <= (wb_stb)&&((mio_sel)||(gps_sel)||(netp_sel)
566
                                        ||(sdcard_sel)||(rtc_sel)||(flctl_sel)
567
                                        ||(oled_sel)||(scop_sel)||(io_sel));
568
                many_sel_b <= 1'b0;
569
                if ((mio_sel)&&((gps_sel)||(netp_sel)||(sdcard_sel)||(rtc_sel)
570
                                ||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
571
                        many_sel_b <= 1'b1;
572
                else if ((gps_sel)&&((netp_sel)||(sdcard_sel)||(rtc_sel)
573
                                ||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
574
                        many_sel_b <= 1'b1;
575
                else if ((netp_sel)&&((sdcard_sel)||(rtc_sel)
576
                                ||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
577
                        many_sel_b <= 1'b1;
578
                else if ((sdcard_sel)&&((rtc_sel)
579
                                ||(flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
580
                        many_sel_b <= 1'b1;
581
                else if ((rtc_sel)&&((flctl_sel)||(scop_sel)||(oled_sel)||(io_sel)))
582
                        many_sel_b <= 1'b1;
583
                else if ((flctl_sel)&&((scop_sel)||(oled_sel)||(io_sel)))
584
                        many_sel_b <= 1'b1;
585
                else if ((scop_sel)&&((oled_sel)||(io_sel)))
586
                        many_sel_b <= 1'b1;
587
                else if ((oled_sel)&&(io_sel))
588
                        many_sel_b <= 1'b1;
589
        end
590
 
591
        wire    sel_err; // 5 inputs
592
        assign  sel_err = ( (last_stb)&&(~single_sel_a)&&(~single_sel_b))
593
                                ||((single_sel_a)&&(single_sel_b))
594
                                ||((single_sel_a)&&(many_sel_a))
595
                                ||((single_sel_b)&&(many_sel_b));
596 25 dgisselq
        assign  wb_err = (wb_cyc)&&(sel_err || many_ack || slow_many_ack||ram_err);
597 3 dgisselq
 
598
 
599
        // Finally, if we ever encounter a bus error, knowing the address of
600
        // the error will be important to figuring out how to fix it.  Hence,
601
        // we grab it here.  Be aware, however, that this might not truly be
602
        // the address that caused an error: in the case of none_sel it will
603
        // be, but if many_ack or slow_many_ack are true then we might just be
604
        // looking at an address on the bus that was nearby the one requested.
605
        reg     [31:0]   bus_err_addr;
606
        initial bus_err_addr = 32'h00;
607
        always @(posedge i_clk)
608
                if (wb_err)
609
                        bus_err_addr <= sel_addr;
610
 
611
        //
612
        // I/O peripheral
613
        //
614
        // The I/O processor, herein called an fastio.  This is a unique
615
        // set of peripherals--these are all of the peripherals that can answer
616
        // in a single clock--or, rather, they are the peripherals that can 
617
        // answer the bus before their clock.  Hence, the fastio simply consists
618
        // of a mux that selects between various peripheral responses.  Further,
619
        // these peripherals are not allowed to stall the bus.
620
        //
621
        // There is no option for turning these off--they will always be on.
622
        wire    [8:0]    master_ints;
623
        assign  master_ints = { zip_cpu_int, oled_int, rtc_int, sdcard_int,
624
                        enet_tx_int, enet_rx_int,
625
                        scop_int, flash_int, rtc_pps };
626
        wire    [5:0]    board_ints;
627
        wire    [3:0]    w_led;
628
        wire    rtc_ppd;
629
        fastio  #(
630 25 dgisselq
                .AUXUART_SETUP(30'hd705),        // 115200 Baud, 8N1, from 81.25M
631
                .GPSUART_SETUP(30'hd8464),       //   9600 Baud, 8N1
632
                .EXTRACLOCK(0)
633 3 dgisselq
                ) runio(i_clk, i_sw, i_btn,
634
                        w_led, o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
635
                        i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
636
                        wb_cyc, (io_sel)&&(wb_stb), wb_we, wb_addr[4:0],
637
                                wb_data, io_ack, io_stall, io_data,
638
                        rtc_ppd,
639
                        bus_err_addr, master_ints, w_interrupt,
640
                        board_ints);
641
        assign  { gpio_int, auxrx_int, auxtx_int, gpsrx_int, sw_int, btn_int } = board_ints;
642
 
643
        /*
644
        reg     [25:0]  dbg_counter_err, dbg_counter_cyc, dbg_counter_sel,
645
                        dbg_counter_many;
646
        // assign wb_err = (wb_cyc)&&(sel_err || many_ack || slow_many_ack);
647
        always @(posedge i_clk)
648
                if (wbu_cyc)
649
                        dbg_counter_cyc <= 0;
650
                else if (!dbg_counter_cyc[25])
651
                        dbg_counter_cyc <= dbg_counter_cyc+26'h1;
652
        always @(posedge i_clk)
653
                if (wbu_err)
654
                        dbg_counter_err <= 0;
655
                else if (!dbg_counter_err[25])
656
                        dbg_counter_err <= dbg_counter_err+26'h1;
657
        always @(posedge i_clk)
658
                if ((wb_cyc)&&(sel_err))
659
                        dbg_counter_sel <= 0;
660
                else if (!dbg_counter_sel[25])
661
                        dbg_counter_sel <= dbg_counter_sel+26'h1;
662
        always @(posedge i_clk)
663
                if ((wb_cyc)&&(many_ack))
664
                        dbg_counter_many <= 0;
665
                else if (!dbg_counter_many[25])
666
                        dbg_counter_many <= dbg_counter_many+26'h1;
667
        assign o_led = {
668
                (!dbg_counter_many[25])|w_led[3],
669
                (!dbg_counter_sel[25])|w_led[2],
670
                (!dbg_counter_cyc[25])|w_led[1],
671
                (!dbg_counter_err[25])|w_led[0] };
672
        */
673
        assign  o_led = w_led;
674
 
675
 
676
        //
677
        //
678
        //      Real Time Clock (RTC) device level access
679
        //
680
        //
681
        wire    gps_tracking, ck_pps;
682
        wire    [63:0]   gps_step;
683
`ifdef  RTC_ACCESS
684 25 dgisselq
        rtcgps
685
                // #(32'h15798f)        // 2^48 / 200MHz
686
                // #(32'h1a6e3a)        // 2^48 / 162.5 MHz
687
                #(32'h34dc74)           // 2^48 /  81.25MHz
688
                // #(32'h35afe6)        // 2^48 /  80.0 MHz
689 3 dgisselq
                thertc(i_clk,
690
                        wb_cyc, (wb_stb)&&(rtc_sel), wb_we,
691
                                wb_addr[1:0], wb_data,
692
                                rtc_data, rtc_int, rtc_ppd,
693
                        gps_tracking, ck_pps, gps_step[47:16], rtc_pps);
694
`else
695
        assign  rtc_data = 32'h00;
696
        assign  rtc_int   = 1'b0;
697
        assign  rtc_pps   = 1'b0;
698
        assign  rtc_ppd   = 1'b0;
699
`endif
700
        reg     r_rtc_ack;
701
        initial r_rtc_ack = 1'b0;
702
        always @(posedge i_clk)
703
                r_rtc_ack <= (wb_stb)&&(rtc_sel);
704
        assign  rtc_ack = r_rtc_ack;
705
        assign  rtc_stall = 1'b0;
706
 
707
        //
708
        //
709
        //      SDCard device level access
710
        //
711
        //
712
`ifdef  SDCARD_ACCESS
713
        wire    [31:0]   sd_dbg;
714
        // SPI mapping
715
        wire    w_sd_cs_n, w_sd_mosi, w_sd_miso;
716
 
717
        sdspi   sdctrl(i_clk,
718
                        wb_cyc, (wb_stb)&&(sdcard_sel), wb_we,
719
                                wb_addr[1:0], wb_data,
720
                                sdcard_ack, sdcard_stall, sdcard_data,
721
                        w_sd_cs_n, o_sd_sck, w_sd_mosi, w_sd_miso,
722
                        sdcard_int, 1'b1, sd_dbg);
723
        assign  w_sd_miso = i_sd_data[0];
724
        assign  o_sd_data = { w_sd_cs_n, 3'b111 };
725
        assign  o_sd_cmd  = w_sd_mosi;
726
`else
727
        reg     r_sdcard_ack;
728
        always @(posedge i_clk)
729
                r_sdcard_ack <= (wb_stb)&&(sdcard_sel);
730
        assign  sdcard_ack = r_sdcard_ack;
731
 
732
        assign  sdcard_data = 32'h00;
733
        assign  sdcard_stall= 1'b0;
734
        assign  sdcard_int  = 1'b0;
735
`endif
736
 
737
        //
738
        //
739
        //      OLEDrgb device control
740
        //
741
        //
742
`ifdef  OLEDRGB_ACCESS
743 27 dgisselq
        wboled
744
                .#( .CBITS(4))// Div ck by 2^4=16, words take 200ns@81.25MHz
745
                rgbctrl(i_clk,
746 3 dgisselq
                        wb_cyc, (wb_stb)&&(oled_sel), wb_we,
747
                                wb_addr[1:0], wb_data,
748
                                oled_ack, oled_stall, oled_data,
749
                        o_oled_sck, o_oled_cs_n, o_oled_mosi, o_oled_dcn,
750
                        { o_oled_reset_n, o_oled_vccen, o_oled_pmoden },
751
                        oled_int);
752
`else
753
        assign  o_oled_cs_n    = 1'b1;
754
        assign  o_oled_sck     = 1'b1;
755
        assign  o_oled_mosi    = 1'b1;
756
        assign  o_oled_dcn     = 1'b1;
757
        assign  o_oled_reset_n = 1'b0;
758
        assign  o_oled_vccen   = 1'b0;
759
        assign  o_oled_pmoden  = 1'b0;
760
 
761
        reg     r_oled_ack;
762
        always @(posedge i_clk)
763
                r_oled_ack <= (wb_stb)&&(oled_sel);
764
        assign  oled_ack = r_oled_ack;
765
 
766
        assign  oled_data = 32'h00;
767
        assign  oled_stall= 1'b0;
768
        assign  oled_int  = 1'b0;
769
`endif
770
 
771
        //
772
        //
773
        //      GPS CLOCK CONTROLS, BOTH THE TEST BENCH AND THE CLOCK ITSELF
774
        //
775
        //
776
        wire    [63:0]   gps_now, gps_err;
777
        wire    [31:0]   gck_data, gtb_data;
778
        wire    gck_ack, gck_stall, gtb_ack, gtb_stall;
779
`ifdef  GPS_CLOCK
780
        //
781
        //      GPS CLOCK SCHOOL TESTING
782
        //
783
        wire    gps_pps, tb_pps, gps_locked;
784
        wire    [1:0]    gps_dbg_tick;
785
 
786
        gpsclock_tb ppscktb(i_clk, ck_pps, tb_pps,
787
                        (wb_stb)&&(gps_sel)&&(wb_addr[3]),
788
                                wb_we, wb_addr[2:0],
789
                                wb_data, gtb_ack, gtb_stall, gtb_data,
790
                        gps_err, gps_now, gps_step);
791
`ifdef  GPSTB
792
        assign  gps_pps = tb_pps; // Let the truth come from our test bench
793
`else
794
        assign  gps_pps = i_gps_pps;
795
`endif
796
        wire    gps_led;
797
 
798
        //
799
        //      GPS CLOCK CONTROL
800
        //
801 25 dgisselq
        gpsclock #(
802
                .DEFAULT_STEP(32'h834d_c736)
803
                ) ppsck(i_clk, 1'b0, gps_pps, ck_pps, gps_led,
804 3 dgisselq
                        (wb_stb)&&(gps_sel)&&(~wb_addr[3]),
805
                                wb_we, wb_addr[1:0],
806
                                wb_data, gck_ack, gck_stall, gck_data,
807
                        gps_tracking, gps_now, gps_step, gps_err, gps_locked,
808
                        gps_dbg_tick);
809
`else
810
 
811
        assign  gps_err = 64'h0;
812
        assign  gps_now = 64'h0;
813
        assign  gck_data = 32'h0;
814
        assign  gtb_data = 32'h0;
815
        assign  gtb_stall = 1'b0;
816
        assign  gck_stall = 1'b0;
817
        assign  ck_pps = 1'b0;
818
 
819
        assign  gps_tracking = 1'b0;
820
        // Appropriate step for a 200MHz clock
821
        assign  gps_step = { 16'h00, 32'h015798e, 16'h00 };
822
 
823
        reg     r_gck_ack;
824
        always @(posedge i_clk)
825
                r_gck_ack <= (wb_stb)&&(gps_sel);
826
        assign  gck_ack = r_gck_ack;
827
        assign  gtb_ack = r_gck_ack;
828
 
829
`endif
830
 
831
        assign  gps_ack   = (gck_ack | gtb_ack);
832
        assign  gps_stall = (gck_stall | gtb_stall);
833
        assign  gps_data  = (gck_ack) ? gck_data : gtb_data;
834
 
835
 
836
        //
837
        //      ETHERNET DEVICE ACCESS
838
        //
839
`ifdef  ETHERNET_ACCESS
840
        reg     r_mio_ack, r_netb_ack, r_netp_ack;
841
        always @(posedge i_clk)
842
                r_mio_ack <= (wb_stb)&&(mio_sel);
843
        always @(posedge i_clk)
844
                r_netp_ack <= (wb_stb)&&(netp_sel);
845
        assign  mio_ack = r_mio_ack;
846
        assign  netp_ack = r_netp_ack;
847
 
848
        assign  mio_data  = 32'h00;
849
        assign  netp_data = 32'h00;
850
        assign  mio_stall = 1'b0;
851
        assign  netp_stall= 1'b0;
852
        assign  enet_rx_int = 1'b0;
853
        assign  enet_tx_int = 1'b0;
854
 
855 25 dgisselq
        enetctrl #(2)
856 3 dgisselq
                mdio(i_clk, i_rst, wb_cyc, (wb_stb)&&(netb_sel), wb_we,
857
                        wb_addr[4:0], wb_data[15:0],
858
                        netb_ack, netb_stall, netb_data,
859
                        o_mdclk, o_mdio, i_mdio, o_mdwe);
860
`else
861
        reg     r_mio_ack, r_netb_ack, r_netp_ack;
862
        always @(posedge i_clk)
863
                r_mio_ack <= (wb_stb)&&(mio_sel);
864
        always @(posedge i_clk)
865
                r_netp_ack <= (wb_stb)&&(netp_sel);
866
        assign  mio_ack = r_mio_ack;
867
        assign  netp_ack = r_netp_ack;
868
 
869
        assign  mio_data  = 32'h00;
870
        assign  netp_data = 32'h00;
871
        assign  mio_stall = 1'b0;
872
        assign  netp_stall= 1'b0;
873
        assign  enet_rx_int = 1'b0;
874
        assign  enet_tx_int = 1'b0;
875
 
876
        //
877
        // 2kW memory, 1kW for each of transmit and receive.  (Max pkt length
878
        // is 512W, so this allows for two 512W in memory.)  Since we don't
879
        // really have ethernet without ETHERNET_ACCESS defined, this just
880
        // consumes resources for us so we have an idea of what might be 
881
        // available when we do have ETHERNET_ACCESS defined.
882
        //
883
        memdev #(11) enet_buffers(i_clk, wb_cyc, (wb_stb)&&(netb_sel), wb_we,
884
                wb_addr[10:0], wb_data, netb_ack, netb_stall, netb_data);
885
        assign  o_mdclk = 1'b1;
886
        assign  o_mdio = 1'b1;
887
        assign  o_mdwe = 1'b1;
888
 
889
`endif
890
 
891
 
892
        //
893
        //      MULTIBOOT/ICAPE2 CONFIGURATION ACCESS
894
        //
895
`ifdef  ICAPE_ACCESS
896 25 dgisselq
        wire    [31:0]   cfg_debug;
897
        wbicapetwo      #(.LGDIV(1)) // Divide the clock by two
898
                fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
899 3 dgisselq
                                wb_addr[4:0], wb_data,
900 25 dgisselq
                                cfg_ack, cfg_stall, cfg_data, cfg_debug);
901 3 dgisselq
`else
902
        reg     r_cfg_ack;
903
        always @(posedge i_clk)
904
                r_cfg_ack <= (cfg_sel)&&(wb_stb);
905
        assign  cfg_ack   = r_cfg_ack;
906
        assign  cfg_stall = 1'b0;
907
        assign  cfg_data  = 32'h00;
908
`endif
909
 
910
        //
911
        //      RAM MEMORY ACCESS
912
        //
913
        // There is no option to turn this off--this RAM must always be
914
        // present in the design.
915 25 dgisselq
        memdev  #(.AW(15),
916
                .EXTRACLOCK(0)) // 32kW, or 128kB, 15 address lines
917 3 dgisselq
                blkram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we, wb_addr[14:0],
918
                                wb_data, mem_ack, mem_stall, mem_data);
919
 
920
        //
921
        //      FLASH MEMORY ACCESS
922
        //
923
`ifdef  FLASH_ACCESS
924
`ifdef  FLASH_SCOPE
925
        wire    [31:0]   flash_debug;
926
`endif
927
        wire    w_ignore_cmd_accepted;
928
        eqspiflash      flashmem(i_clk, i_rst,
929
                wb_cyc,(wb_stb)&&(flash_sel),(wb_stb)&&(flctl_sel),wb_we,
930
                        wb_addr[21:0], wb_data,
931
                flash_ack, flash_stall, flash_data,
932
                o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
933
                flash_int, w_ignore_cmd_accepted
934
`ifdef  FLASH_SCOPE
935
                , flash_debug
936
`endif
937
                );
938
`else
939
        assign  o_qspi_sck = 1'b1;
940
        assign  o_qspi_cs_n= 1'b1;
941
        assign  o_qspi_mod = 2'b01;
942
        assign  o_qspi_dat = 4'h0;
943
        assign  flash_data = 32'h00;
944
        assign  flash_stall  = 1'b0;
945
        assign  flash_int = 1'b0;
946
 
947
        reg     r_flash_ack;
948
        always @(posedge i_clk)
949
                r_flash_ack <= (wb_stb)&&(flash_sel);
950
        assign  flash_ack = r_flash_ack;
951
`endif
952
 
953
 
954
        //
955
        //
956
        //      DDR3-SDRAM
957
        //
958
        //
959
`ifdef  SDRAM_ACCESS
960 25 dgisselq
        //wbddrsdram    rami(i_clk,
961
        //      wb_cyc, (wb_stb)&&(ram_sel), wb_we, wb_addr[25:0], wb_data,
962
        //              ram_ack, ram_stall, ram_data,
963
        //      o_ddr_reset_n, o_ddr_cke,
964
        //      o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
965
        //      o_ddr_dqs,
966
        //      o_ddr_addr, o_ddr_ba, o_ddr_data, i_ddr_data);
967
 
968
        assign  o_ram_cyc       = wb_cyc;
969
        assign  o_ram_stb       = (wb_stb)&&(ram_sel);
970
        assign  o_ram_we        = wb_we;
971
        assign  o_ram_addr      = wb_addr[25:0];
972
        assign  o_ram_wdata     = wb_data;
973
        assign  ram_ack = i_ram_ack;
974
        assign  ram_stall       = i_ram_stall;
975
        assign  ram_data        = i_ram_rdata;
976
        assign  ram_err         = i_ram_err;
977
        /*
978
        migsdram rami(i_clk, i_memref_clk_200mhz, i_rst,
979 3 dgisselq
                wb_cyc, (wb_stb)&&(ram_sel), wb_we, wb_addr[25:0], wb_data,
980 25 dgisselq
                        4'hf,
981
                ram_ack, ram_stall, ram_data, ram_err,
982
                //
983
                o_ddr_ck_p, o_ddr_ck_n,
984 3 dgisselq
                o_ddr_reset_n, o_ddr_cke,
985
                o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
986 25 dgisselq
                o_ddr_ba, o_ddr_addr,
987
                o_ddr_odt, o_ddr_dm,
988
                io_ddr_dqs_p, io_ddr_dqs_n,
989
                io_ddr_data,
990
                ram_ready
991
        );
992
        */
993 3 dgisselq
`else
994
        assign  ram_data  = 32'h00;
995
        assign  ram_stall = 1'b0;
996
        reg     r_ram_ack;
997
        always @(posedge i_clk)
998
                r_ram_ack <= (wb_stb)&&(ram_sel);
999
        assign  ram_ack = r_ram_ack;
1000
 
1001
        // And idle the DDR3 SDRAM
1002
        assign  o_ddr_reset_n = 1'b0;   // Leave the SDRAM in reset
1003
        assign  o_ddr_cke     = 1'b0;   // Disable the SDRAM clock
1004
        // DQS
1005
        assign  o_ddr_dqs = 3'b100; // Leave DQS pins in high impedence
1006
        // DDR3 control wires (not enabled if CKE=0)
1007
        assign  o_ddr_cs_n      = 1'b0;  // NOOP command
1008
        assign  o_ddr_ras_n     = 1'b1;
1009
        assign  o_ddr_cas_n     = 1'b1;
1010
        assign  o_ddr_we_n      = 1'b1;
1011
        // (Unused) data wires
1012
        assign  o_ddr_addr = 14'h00;
1013
        assign  o_ddr_ba   = 3'h0;
1014
        assign  o_ddr_data = 32'h00;
1015
`endif
1016
 
1017
 
1018
        //
1019
        //
1020
        //      WISHBONE SCOPES
1021
        //
1022
        //
1023
        //
1024
        //
1025
        wire    [31:0]   scop_a_data;
1026
        wire    scop_a_ack, scop_a_stall, scop_a_interrupt;
1027
`ifdef  CPU_SCOPE
1028
        wire    [31:0]   scop_cpu_data;
1029
        wire    scop_cpu_ack, scop_cpu_stall, scop_cpu_interrupt;
1030
        wire    scop_cpu_trigger;
1031
        // assign       scop_cpu_trigger = zip_scope_data[30];
1032
        assign  scop_cpu_trigger = (wb_stb)&&(mem_sel)&&(~wb_we)
1033
                        &&(wb_err)||(zip_scope_data[31]);
1034
        wbscope #(5'd13) cpuscope(i_clk, 1'b1,(scop_cpu_trigger), zip_scope_data,
1035
                // Wishbone interface
1036 25 dgisselq
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)),
1037
                        wb_we, wb_addr[0], wb_data,
1038 3 dgisselq
                        scop_cpu_ack, scop_cpu_stall, scop_cpu_data,
1039
                scop_cpu_interrupt);
1040
 
1041
        assign  scop_a_data = scop_cpu_data;
1042
        assign  scop_a_ack = scop_cpu_ack;
1043
        assign  scop_a_stall = scop_cpu_stall;
1044
        assign  scop_a_interrupt = scop_cpu_interrupt;
1045
`else
1046
`ifdef  FLASH_SCOPE
1047
        wire    [31:0]   scop_flash_data;
1048
        wire    scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
1049
        wire    scop_flash_trigger;
1050
        // assign       scop_cpu_trigger = zip_scope_data[30];
1051
        assign  scop_flash_trigger = (wb_stb)&&((flash_sel)||(flctl_sel));
1052
        wbscope #(5'd13) flashscope(i_clk, 1'b1,
1053
                        (scop_flash_trigger), flash_debug,
1054
                // Wishbone interface
1055 25 dgisselq
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)),
1056
                        wb_we, wb_addr[0], wb_data,
1057 3 dgisselq
                        scop_flash_ack, scop_flash_stall, scop_flash_data,
1058
                scop_flash_interrupt);
1059
 
1060
        assign  scop_a_data = scop_flash_data;
1061
        assign  scop_a_ack = scop_flash_ack;
1062
        assign  scop_a_stall = scop_flash_stall;
1063
        assign  scop_a_interrupt = scop_flash_interrupt;
1064
`else
1065
        reg     r_scop_a_ack;
1066
        always @(posedge i_clk)
1067
                r_scop_a_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b00);
1068
        assign  scop_a_data = 32'h00;
1069
        assign  scop_a_ack = r_scop_a_ack;
1070
        assign  scop_a_stall = 1'b0;
1071
        assign  scop_a_interrupt = 1'b0;
1072
`endif
1073
`endif
1074
 
1075
        wire    [31:0]   scop_b_data;
1076
        wire    scop_b_ack, scop_b_stall, scop_b_interrupt;
1077
`ifdef  GPS_SCOPE
1078
        reg     [18:0]   r_gps_debug;
1079
        wire    [31:0]   scop_gps_data;
1080
        wire            scop_gps_ack, scop_gps_stall, scop_gps_interrupt;
1081
        always @(posedge i_clk)
1082
                r_gps_debug <= {
1083
                        gps_dbg_tick, gps_tracking, gps_locked,
1084
                                gpu_data[7:0],
1085
                        // (wb_cyc)&&(wb_stb)&&(io_sel),
1086
                        (wb_stb)&&(io_sel)&&(wb_addr[4:3]==2'b11)&&(wb_we),
1087
                        (wb_stb)&&(gps_sel)&&(wb_addr[3:2]==2'b01),
1088
                                gpu_int,
1089
                                i_gps_rx, rtc_pps, ck_pps, i_gps_pps };
1090
        wbscopc #(5'd13,19,32,1) gpsscope(i_clk, 1'b1, ck_pps, r_gps_debug,
1091
                // Wishbone interface
1092
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
1093
                        wb_we, wb_addr[0], wb_data,
1094
                        scop_gps_ack, scop_gps_stall, scop_gps_data,
1095
                scop_gps_interrupt);
1096 25 dgisselq
 
1097
        assign  scop_b_ack   = scop_gps_ack;
1098
        assign  scop_b_stall = scop_gps_stall;
1099
        assign  scop_b_data  = scop_gps_data;
1100
        assign  scop_b_interrupt = scop_gps_interrupt;
1101 3 dgisselq
`else
1102 25 dgisselq
`ifdef  CFG_SCOPE
1103
        wire    [31:0]   scop_cfg_data;
1104
        wire            scop_cfg_ack, scop_cfg_stall, scop_cfg_interrupt;
1105
        wire    [31:0]   cfg_debug_2;
1106
        assign  cfg_debug_2 = {
1107
                        wb_ack, cfg_debug[30:17], slow_ack,
1108
                                slow_data[7:0], wb_data[7:0]
1109
                        };
1110
        wbscope #(5'd8,32,1) cfgscope(i_clk, 1'b1, (cfg_sel)&&(wb_stb),
1111
                        cfg_debug_2,
1112
                // Wishbone interface
1113
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
1114
                        wb_we, wb_addr[0], wb_data,
1115
                        scop_cfg_ack, scop_cfg_stall, scop_cfg_data,
1116
                scop_cfg_interrupt);
1117
 
1118
        assign  scop_b_data = scop_cfg_data;
1119
        assign  scop_b_stall = scop_cfg_stall;
1120
        assign  scop_b_ack = scop_cfg_ack;
1121
        assign  scop_b_interrupt = scop_cfg_interrupt;
1122
`else
1123 3 dgisselq
        assign  scop_b_data = 32'h00;
1124
        assign  scop_b_stall = 1'b0;
1125
        assign  scop_b_interrupt = 1'b0;
1126
 
1127
        reg     r_scop_b_ack;
1128
        always @(posedge i_clk)
1129
                r_scop_b_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b01);
1130
        assign  scop_b_ack  = r_scop_b_ack;
1131
`endif
1132 25 dgisselq
`endif
1133 3 dgisselq
 
1134
        //
1135
        // SCOPE C
1136
        //
1137
        wire    [31:0]   scop_c_data;
1138
        wire    scop_c_ack, scop_c_stall, scop_c_interrupt;
1139
        //
1140 25 dgisselq
`ifdef  SDRAM_SCOPE
1141
        wire    [31:0]   scop_sdram_data;
1142
        wire            scop_sdram_ack, scop_sdram_stall, scop_sdram_interrupt;
1143
        wire            sdram_trigger;
1144
        wire    [31:0]   sdram_debug;
1145
        assign  sdram_trigger = (ram_sel)&&(wb_stb);
1146
        assign  sdram_debug= i_ram_dbg;
1147
 
1148
        wbscope #(5'd10,32,1) ramscope(i_clk, 1'b1, sdram_trigger, sdram_debug,
1149
                // Wishbone interface
1150
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)),
1151
                        wb_we, wb_addr[0], wb_data,
1152
                        scop_sdram_ack, scop_sdram_stall, scop_sdram_data,
1153
                scop_sdram_interrupt);
1154
 
1155
        assign  scop_c_ack       = scop_sdram_ack;
1156
        assign  scop_c_stall     = scop_sdram_stall;
1157
        assign  scop_c_data      = scop_sdram_data;
1158
        assign  scop_c_interrupt = scop_sdram_interrupt;
1159
`else
1160 3 dgisselq
        assign  scop_c_data = 32'h00;
1161
        assign  scop_c_stall = 1'b0;
1162
        assign  scop_c_interrupt = 1'b0;
1163
 
1164
        reg     r_scop_c_ack;
1165
        always @(posedge i_clk)
1166
                r_scop_c_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b10);
1167
        assign  scop_c_ack = r_scop_c_ack;
1168 25 dgisselq
`endif
1169 3 dgisselq
 
1170
        //
1171
        // SCOPE D
1172
        //
1173
        wire    [31:0]   scop_d_data;
1174
        wire    scop_d_ack, scop_d_stall, scop_d_interrupt;
1175
        //
1176
//`else
1177
        assign  scop_d_data = 32'h00;
1178
        assign  scop_d_stall = 1'b0;
1179
        assign  scop_d_interrupt = 1'b0;
1180
 
1181
        reg     r_scop_d_ack;
1182
        always @(posedge i_clk)
1183
                r_scop_d_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b11);
1184
        assign  scop_d_ack = r_scop_d_ack;
1185
//`endif
1186
 
1187 25 dgisselq
        reg     all_scope_interrupts;
1188
        always @(posedge i_clk)
1189
                all_scope_interrupts <= (scop_a_interrupt)
1190
                                || (scop_b_interrupt)
1191
                                || (scop_c_interrupt)
1192
                                || (scop_d_interrupt);
1193
        assign  scop_int = all_scope_interrupts;
1194
 
1195
        // Scopes don't stall, so this line is more formality than anything
1196
        // else.
1197 3 dgisselq
        assign  scop_stall = ((wb_addr[2:1]==2'b0)?scop_a_stall
1198
                                : ((wb_addr[2:1]==2'b01)?scop_b_stall
1199 25 dgisselq
                                : ((wb_addr[2:1]==2'b10)?scop_c_stall
1200 3 dgisselq
                                : scop_d_stall))); // Will always be 1'b0;
1201
        initial scop_ack = 1'b0;
1202
        always @(posedge i_clk)
1203
                scop_ack  <= scop_a_ack | scop_b_ack | scop_c_ack | scop_d_ack;
1204
        always @(posedge i_clk)
1205
                if (scop_a_ack)
1206
                        scop_data <= scop_a_data;
1207
                else if (scop_b_ack)
1208
                        scop_data <= scop_b_data;
1209
                else if (scop_c_ack)
1210
                        scop_data <= scop_c_data;
1211
                else // if (scop_d_ack)
1212
                        scop_data <= scop_d_data;
1213
 
1214
endmodule

powered by: WebSVN 2.1.0

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