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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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