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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [fastmaster.v] - Blame information for rev 13

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

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

powered by: WebSVN 2.1.0

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