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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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