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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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