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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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