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

Subversion Repositories openarty

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

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

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    fastmaster.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     On other projects, this file would be called the "bus
8
//              interconnect".  This module connects all the devices on the
9
//      Wishbone bus within this project together.  It is created by hand, not
10
//      automatically.
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
`define NO_ZIP_WBU_DELAY
42
// `define      ZIPCPU
43
`ifdef  ZIPCPU
44 12 dgisselq
`define ZIP_SYSTEM
45 3 dgisselq
`ifndef ZIP_SYSTEM
46
`define ZIP_BONES
47
`endif  // ZIP_SYSTEM
48
`endif  // ZipCPU
49
//
50
//
51
`define SDCARD_ACCESS
52
`define ETHERNET_ACCESS
53
`ifndef VERILATOR
54
`define ICAPE_ACCESS
55
`endif
56
`define FLASH_ACCESS
57 12 dgisselq
// `define      SDRAM_ACCESS
58 3 dgisselq
`define GPS_CLOCK
59
//      UART_ACCESS and GPS_UART have both been placed within fastio
60
//              `define UART_ACCESS
61
//              `define GPS_UART
62
`define RTC_ACCESS
63
`define OLEDRGB_ACCESS
64
//
65 13 dgisselq
`ifdef  FLASH_ACCESS
66
`define FLASH_SCOPE     // Position zero
67
`else
68
`ifdef ZIPCPU
69 12 dgisselq
// `define      CPU_SCOPE       // Position zero
70 13 dgisselq
`endif
71
`endif
72 12 dgisselq
// `define      GPS_SCOPE       // Position one
73 13 dgisselq
`ifdef ICAPE_ACCESS
74
`define CFG_SCOPE       // Position one
75
`endif
76
`ifdef  SDRAM_ACCESS
77 12 dgisselq
// `define      SDRAM_SCOPE             // Position two
78 13 dgisselq
`endif
79 3 dgisselq
// `define      ENET_SCOPE
80
//
81
//
82
module  fastmaster(i_clk, i_rst,
83
                // CNC
84
                i_rx_stb, i_rx_data, o_tx_stb, o_tx_data, i_tx_busy,
85
                // Boad I/O
86
                i_sw, i_btn, o_led,
87
                o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
88
                // PMod I/O
89
                i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
90
                // The Quad SPI Flash
91
                o_qspi_cs_n, o_qspi_sck, o_qspi_dat, i_qspi_dat, o_qspi_mod,
92
                // The DDR3 SDRAM
93 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
        zipsystem #(    .RESET_ADDRESS(24'h08000),
223
                        .ADDRESS_WIDTH(ZA),
224
                        .LGICACHE(10),
225
                        .START_HALTED(1),
226
                        .EXTERNAL_INTERRUPTS(ZIPINTS),
227
                        .HIGHSPEED_CPU(1))
228
                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
        assign  scop_sel  = (~|skipaddr)&&(wb_addr[7:3]==5'b00100);
353
        assign  rtc_sel   = (~|skipaddr)&&(wb_addr[7:2]==6'b001010);
354
        assign  sdcard_sel= (~|skipaddr)&&(wb_addr[7:2]==6'b001011);
355
        assign  netp_sel  = (~|skipaddr)&&(wb_addr[7:2]==6'b001101);
356
        assign  oled_sel  = (~|skipaddr)&&(wb_addr[7:2]==6'b001110);
357
        assign  gps_sel   = (~|skipaddr)&&(     (wb_addr[7:2]==6'b001100)
358
                                            ||  (wb_addr[7:3]==5'b01000));
359
        assign  mio_sel   = (~|skipaddr)&&(wb_addr[7:5]==3'b101);
360
        assign  flctl_sel = (~|skipaddr)&&(wb_addr[7:5]==3'b110);
361
        assign  cfg_sel   = (~|skipaddr)&&(wb_addr[7:5]==3'b111);
362
 
363
        wire    skiperr;
364
        assign  skiperr = (|wb_addr[31:27])
365
                                ||(~skipaddr[4])&&(|wb_addr[25:23])
366
                                ||(skipaddr[4:3]==2'b00)&&(|wb_addr[21:16])
367
                                ||(skipaddr[4:2]==3'b000)&&(|wb_addr[14:12])
368
                                ||(skipaddr[4:1]==4'b0000)&&(|wb_addr[10:9]);
369
 
370
 
371
        //
372
        // Peripheral acknowledgement lines
373
        //
374
        // These are only a touch more confusing, since the flash device will
375
        // ACK for both flctl_sel (the control line select), as well as the
376
        // flash_sel (the memory line select).  Hence we have one fewer ack
377
        // line.
378
        wire    io_ack, oled_ack,
379
                        rtc_ack, sdcard_ack,
380
                        netp_ack, gps_ack, mio_ack, cfg_ack, netb_ack,
381
                        mem_ack, flash_ack, ram_ack;
382
        reg     many_ack, slow_many_ack;
383
        reg     slow_ack, scop_ack;
384 13 dgisselq
        wire    [5:0]    ack_list;
385
        assign  ack_list = { ram_ack, flash_ack, mem_ack, netb_ack, netp_ack, slow_ack };
386 3 dgisselq
        initial many_ack = 1'b0;
387
        always @(posedge i_clk)
388 13 dgisselq
                many_ack <= ((ack_list != 6'h20)
389
                        &&(ack_list != 6'h10)
390
                        &&(ack_list != 6'h8)
391
                        &&(ack_list != 6'h4)
392
                        &&(ack_list != 6'h2)
393
                        &&(ack_list != 6'h1)
394
                        &&(ack_list != 6'h0));
395 3 dgisselq
        /*
396
        assign  many_ack = (    { 2'h0, ram_ack}
397
                                +{2'h0, flash_ack }
398
                                +{2'h0, mem_ack }
399
                                +{2'h0, netb_ack }
400
                                +{2'h0, slow_ack } > 3'h1 );
401
        */
402
 
403
        wire    [7:0] slow_ack_list;
404 13 dgisselq
        assign slow_ack_list = { cfg_ack, mio_ack, gps_ack,
405 3 dgisselq
                        sdcard_ack, rtc_ack, scop_ack, oled_ack, io_ack };
406
        initial slow_many_ack = 1'b0;
407
        always @(posedge i_clk)
408
                slow_many_ack <= ((slow_ack_list != 8'h80)
409
                        &&(slow_ack_list != 8'h40)
410
                        &&(slow_ack_list != 8'h20)
411
                        &&(slow_ack_list != 8'h10)
412
                        &&(slow_ack_list != 8'h08)
413
                        &&(slow_ack_list != 8'h04)
414
                        &&(slow_ack_list != 8'h02)
415
                        &&(slow_ack_list != 8'h01)
416
                        &&(slow_ack_list != 8'h00));
417
 
418
        always @(posedge i_clk)
419 13 dgisselq
                wb_ack <= (wb_cyc)&&(|ack_list);
420 3 dgisselq
        always @(posedge i_clk)
421 13 dgisselq
                slow_ack <= (wb_cyc)&&(|slow_ack_list);
422 3 dgisselq
 
423
        //
424
        // Peripheral data lines
425
        //
426
        wire    [31:0]   io_data, oled_data,
427
                        rtc_data, sdcard_data,
428
                        netp_data, gps_data, mio_data, cfg_data, netb_data,
429
                        mem_data, flash_data, ram_data;
430
        reg     [31:0]   slow_data, scop_data;
431
 
432
        // 4 control lines, 5x32 data lines ... 
433
        always @(posedge i_clk)
434
                if ((ram_ack)||(flash_ack))
435
                        wb_idata <= (ram_ack)?ram_data:flash_data;
436
                else if ((mem_ack)||(netb_ack))
437
                        wb_idata <= (mem_ack)?mem_data:netb_data;
438
                else
439 13 dgisselq
                        wb_idata <= (netp_ack)?netp_data: slow_data;
440 3 dgisselq
 
441
        // 7 control lines, 8x32 data lines
442
        always @(posedge i_clk)
443
                if ((cfg_ack)||(mio_ack))
444
                        slow_data <= (cfg_ack) ? cfg_data : mio_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 13 dgisselq
                        slow_data <= (gps_ack) ? gps_data : io_data;
451 3 dgisselq
 
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 13 dgisselq
                        ||((oled_sel)&&(oled_stall))    // Never stalls
471 3 dgisselq
                        ||((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 17 dgisselq
                .AUXUART_SETUP(30'd1736),        // 115200 Baud, 8N1
585
                .GPSUART_SETUP(30'd20833)        //   9600 Baud, 8N1
586 3 dgisselq
                ) 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 13 dgisselq
        wire    [31:0]   cfg_debug;
851 3 dgisselq
        wbicapetwo      fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
852
                                wb_addr[4:0], wb_data,
853 13 dgisselq
                                cfg_ack, cfg_stall, cfg_data, cfg_debug);
854 3 dgisselq
`else
855
        reg     r_cfg_ack;
856
        always @(posedge i_clk)
857
                r_cfg_ack <= (cfg_sel)&&(wb_stb);
858
        assign  cfg_ack   = r_cfg_ack;
859
        assign  cfg_stall = 1'b0;
860
        assign  cfg_data  = 32'h00;
861
`endif
862
 
863
        //
864
        //      RAM MEMORY ACCESS
865
        //
866
        // There is no option to turn this off--this RAM must always be
867
        // present in the design.
868
        memdev  #(15) // 32kW, or 128kB, 15 address lines
869
                blkram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we, wb_addr[14:0],
870
                                wb_data, mem_ack, mem_stall, mem_data);
871
 
872
        //
873
        //      FLASH MEMORY ACCESS
874
        //
875
`ifdef  FLASH_ACCESS
876
`ifdef  FLASH_SCOPE
877
        wire    [31:0]   flash_debug;
878
`endif
879
        wire    w_ignore_cmd_accepted;
880
        eqspiflash      flashmem(i_clk, i_rst,
881
                wb_cyc,(wb_stb)&&(flash_sel),(wb_stb)&&(flctl_sel),wb_we,
882
                        wb_addr[21:0], wb_data,
883
                flash_ack, flash_stall, flash_data,
884
                o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
885
                flash_int, w_ignore_cmd_accepted
886
`ifdef  FLASH_SCOPE
887
                , flash_debug
888
`endif
889
                );
890
`else
891
        assign  o_qspi_sck = 1'b1;
892
        assign  o_qspi_cs_n= 1'b1;
893
        assign  o_qspi_mod = 2'b01;
894
        assign  o_qspi_dat = 4'h0;
895
        assign  flash_data = 32'h00;
896
        assign  flash_stall  = 1'b0;
897
        assign  flash_int = 1'b0;
898
 
899
        reg     r_flash_ack;
900
        always @(posedge i_clk)
901
                r_flash_ack <= (wb_stb)&&(flash_sel);
902
        assign  flash_ack = r_flash_ack;
903
`endif
904
 
905
 
906
        //
907
        //
908
        //      DDR3-SDRAM
909
        //
910
        //
911
`ifdef  SDRAM_ACCESS
912 24 dgisselq
        wire    [63:0]   w_ram_wide_data;
913 12 dgisselq
        wbddrsdram      #(13,13'd1520) rami(i_clk, i_rst,
914 24 dgisselq
                wb_cyc, (wb_stb)&&(ram_sel), wb_we, wb_addr[24:0],
915
                        { wb_data, wb_data }, (wb_addr[25])? 8'hf0:8'h0f,
916
                        ram_ack, ram_stall, w_ram_wide_data,
917
                o_ddr_reset_n, o_ddr_cke, o_ddr_bus_oe,
918
                o_ddr_cmd_a, o_ddr_cmd_b, o_ddr_data, i_ddr_data);
919
 
920
        // assign       ram_data = (wb_addr[25])?w_ram_wide_data[63:32]:w_ram_wide_data[
921
        assign  ram_data = w_ram_wide_data[31:0];
922 3 dgisselq
`else
923
        assign  ram_data  = 32'h00;
924
        assign  ram_stall = 1'b0;
925
        reg     r_ram_ack;
926
        always @(posedge i_clk)
927
                r_ram_ack <= (wb_stb)&&(ram_sel);
928
        assign  ram_ack = r_ram_ack;
929
 
930
        // And idle the DDR3 SDRAM
931
        assign  o_ddr_reset_n = 1'b0;   // Leave the SDRAM in reset
932
        assign  o_ddr_cke     = 1'b0;   // Disable the SDRAM clock
933
        // DQS
934 12 dgisselq
        assign  o_ddr_dqs = 1'b0; // Leave DQS pins in high impedence
935 3 dgisselq
        // DDR3 control wires (not enabled if CKE=0)
936 12 dgisselq
        assign  o_ddr_cs_n      = 1'b1;  // Deselect command
937 3 dgisselq
        assign  o_ddr_ras_n     = 1'b1;
938
        assign  o_ddr_cas_n     = 1'b1;
939
        assign  o_ddr_we_n      = 1'b1;
940
        // (Unused) data wires
941
        assign  o_ddr_addr = 14'h00;
942
        assign  o_ddr_ba   = 3'h0;
943
        assign  o_ddr_data = 32'h00;
944
`endif
945
 
946
 
947
        //
948
        //
949
        //      WISHBONE SCOPES
950
        //
951
        //
952
        //
953
        //
954
        wire    [31:0]   scop_a_data;
955
        wire    scop_a_ack, scop_a_stall, scop_a_interrupt;
956
`ifdef  CPU_SCOPE
957
        wire    [31:0]   scop_cpu_data;
958
        wire    scop_cpu_ack, scop_cpu_stall, scop_cpu_interrupt;
959
        wire    scop_cpu_trigger;
960
        // assign       scop_cpu_trigger = zip_scope_data[30];
961
        assign  scop_cpu_trigger = (wb_stb)&&(mem_sel)&&(~wb_we)
962
                        &&(wb_err)||(zip_scope_data[31]);
963
        wbscope #(5'd13) cpuscope(i_clk, 1'b1,(scop_cpu_trigger), zip_scope_data,
964
                // Wishbone interface
965
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
966
                        wb_data,
967
                        scop_cpu_ack, scop_cpu_stall, scop_cpu_data,
968
                scop_cpu_interrupt);
969
 
970
        assign  scop_a_data = scop_cpu_data;
971
        assign  scop_a_ack = scop_cpu_ack;
972
        assign  scop_a_stall = scop_cpu_stall;
973
        assign  scop_a_interrupt = scop_cpu_interrupt;
974
`else
975
`ifdef  FLASH_SCOPE
976
        wire    [31:0]   scop_flash_data;
977
        wire    scop_flash_ack, scop_flash_stall, scop_flash_interrupt;
978
        wire    scop_flash_trigger;
979
        // assign       scop_cpu_trigger = zip_scope_data[30];
980
        assign  scop_flash_trigger = (wb_stb)&&((flash_sel)||(flctl_sel));
981
        wbscope #(5'd13) flashscope(i_clk, 1'b1,
982
                        (scop_flash_trigger), flash_debug,
983
                // Wishbone interface
984
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b00)), wb_we, wb_addr[0],
985
                        wb_data,
986
                        scop_flash_ack, scop_flash_stall, scop_flash_data,
987
                scop_flash_interrupt);
988
 
989
        assign  scop_a_data = scop_flash_data;
990
        assign  scop_a_ack = scop_flash_ack;
991
        assign  scop_a_stall = scop_flash_stall;
992
        assign  scop_a_interrupt = scop_flash_interrupt;
993
`else
994
        reg     r_scop_a_ack;
995
        always @(posedge i_clk)
996
                r_scop_a_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b00);
997
        assign  scop_a_data = 32'h00;
998
        assign  scop_a_ack = r_scop_a_ack;
999
        assign  scop_a_stall = 1'b0;
1000
        assign  scop_a_interrupt = 1'b0;
1001
`endif
1002
`endif
1003
 
1004
        wire    [31:0]   scop_b_data;
1005
        wire    scop_b_ack, scop_b_stall, scop_b_interrupt;
1006
`ifdef  GPS_SCOPE
1007
        reg     [18:0]   r_gps_debug;
1008
        wire    [31:0]   scop_gps_data;
1009
        wire            scop_gps_ack, scop_gps_stall, scop_gps_interrupt;
1010
        always @(posedge i_clk)
1011
                r_gps_debug <= {
1012
                        gps_dbg_tick, gps_tracking, gps_locked,
1013
                                gpu_data[7:0],
1014
                        // (wb_cyc)&&(wb_stb)&&(io_sel),
1015
                        (wb_stb)&&(io_sel)&&(wb_addr[4:3]==2'b11)&&(wb_we),
1016
                        (wb_stb)&&(gps_sel)&&(wb_addr[3:2]==2'b01),
1017
                                gpu_int,
1018
                                i_gps_rx, rtc_pps, ck_pps, i_gps_pps };
1019
        wbscopc #(5'd13,19,32,1) gpsscope(i_clk, 1'b1, ck_pps, r_gps_debug,
1020
                // Wishbone interface
1021
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
1022
                        wb_we, wb_addr[0], wb_data,
1023
                        scop_gps_ack, scop_gps_stall, scop_gps_data,
1024
                scop_gps_interrupt);
1025 13 dgisselq
 
1026
        assign  scop_b_ack   = scop_gps_ack;
1027
        assign  scop_b_stall = scop_gps_stall;
1028
        assign  scop_b_data  = scop_gps_data;
1029
        assign  scop_b_interrupt = scop_gps_interrupt;
1030 3 dgisselq
`else
1031 13 dgisselq
`ifdef  CFG_SCOPE
1032
        wire    [31:0]   scop_cfg_data;
1033
        wire            scop_cfg_ack, scop_cfg_stall, scop_cfg_interrupt;
1034
        wire    [31:0]   cfg_debug_2;
1035
        assign  cfg_debug_2 = {
1036
                        wb_ack, cfg_debug[30:17], slow_ack,
1037
                                slow_data[7:0], wb_data[7:0]
1038
                        };
1039
        wbscope #(5'd8,32,1) cfgscope(i_clk, 1'b1, (cfg_sel)&&(wb_stb),
1040
                        cfg_debug_2,
1041
                // Wishbone interface
1042
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b01)),
1043
                        wb_we, wb_addr[0], wb_data,
1044
                        scop_cfg_ack, scop_cfg_stall, scop_cfg_data,
1045
                scop_cfg_interrupt);
1046
 
1047
        assign  scop_b_data = scop_cfg_data;
1048
        assign  scop_b_stall = scop_cfg_stall;
1049
        assign  scop_b_ack = scop_cfg_ack;
1050
        assign  scop_b_interrupt = scop_cfg_interrupt;
1051
`else
1052 3 dgisselq
        assign  scop_b_data = 32'h00;
1053
        assign  scop_b_stall = 1'b0;
1054
        assign  scop_b_interrupt = 1'b0;
1055
 
1056
        reg     r_scop_b_ack;
1057
        always @(posedge i_clk)
1058
                r_scop_b_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b01);
1059
        assign  scop_b_ack  = r_scop_b_ack;
1060
`endif
1061 13 dgisselq
`endif
1062 3 dgisselq
 
1063
        //
1064
        // SCOPE C
1065
        //
1066
        wire    [31:0]   scop_c_data;
1067
        wire    scop_c_ack, scop_c_stall, scop_c_interrupt;
1068
        //
1069 12 dgisselq
`ifdef  SDRAM_SCOPE
1070
        wire    [31:0]   scop_sdram_data;
1071
        wire            scop_sdram_ack, scop_sdram_stall, scop_sdram_interrupt;
1072
        wire            sdram_trigger;
1073
        wire    [31:0]   sdram_debug;
1074
        assign  sdram_trigger = (ram_sel)&&(wb_stb);
1075
        assign  sdram_debug= {
1076
                        o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
1077
                        (wb_stb)&&(ram_sel), wb_we, ram_stall, ram_ack,
1078
                        o_ddr_dqs, o_ddr_dm, o_ddr_bus_oe,
1079
                                o_ddr_addr[10], o_ddr_addr[3],
1080
                        o_ddr_data[5:0], i_ddr_data[5:0], 8'h00
1081
                };
1082
 
1083
        wbscope #(5'd12,32,1) ramscope(i_clk, 1'b1, sdram_trigger, sdram_debug,
1084
                // Wishbone interface
1085
                i_clk, wb_cyc, ((wb_stb)&&(scop_sel)&&(wb_addr[2:1]==2'b10)),
1086
                        wb_we, wb_addr[0], wb_data,
1087
                        scop_sdram_ack, scop_sdram_stall, scop_sdram_data,
1088
                scop_sdram_interrupt);
1089
 
1090
        assign  scop_c_ack       = scop_sdram_ack;
1091
        assign  scop_c_stall     = scop_sdram_stall;
1092
        assign  scop_c_data      = scop_sdram_data;
1093
        assign  scop_c_interrupt = scop_sdram_interrupt;
1094
`else
1095 3 dgisselq
        assign  scop_c_data = 32'h00;
1096
        assign  scop_c_stall = 1'b0;
1097
        assign  scop_c_interrupt = 1'b0;
1098
 
1099
        reg     r_scop_c_ack;
1100
        always @(posedge i_clk)
1101
                r_scop_c_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b10);
1102
        assign  scop_c_ack = r_scop_c_ack;
1103 12 dgisselq
`endif
1104 3 dgisselq
 
1105
        //
1106
        // SCOPE D
1107
        //
1108
        wire    [31:0]   scop_d_data;
1109
        wire    scop_d_ack, scop_d_stall, scop_d_interrupt;
1110
        //
1111
//`else
1112
        assign  scop_d_data = 32'h00;
1113
        assign  scop_d_stall = 1'b0;
1114
        assign  scop_d_interrupt = 1'b0;
1115
 
1116
        reg     r_scop_d_ack;
1117
        always @(posedge i_clk)
1118
                r_scop_d_ack <= (wb_stb)&&(scop_sel)&&(wb_addr[2:1] == 2'b11);
1119
        assign  scop_d_ack = r_scop_d_ack;
1120
//`endif
1121
 
1122 13 dgisselq
        reg     all_scope_interrupts;
1123
        always @(posedge i_clk)
1124
                all_scope_interrupts <= (scop_a_interrupt)
1125
                                || (scop_b_interrupt)
1126
                                || (scop_c_interrupt)
1127
                                || (scop_d_interrupt);
1128
        assign  scop_int = all_scope_interrupts;
1129
 
1130
        // Scopes don't stall, so this line is more formality than anything
1131
        // else.
1132 3 dgisselq
        assign  scop_stall = ((wb_addr[2:1]==2'b0)?scop_a_stall
1133
                                : ((wb_addr[2:1]==2'b01)?scop_b_stall
1134
                                : ((wb_addr[2:1]==2'b11)?scop_c_stall
1135
                                : scop_d_stall))); // Will always be 1'b0;
1136
        initial scop_ack = 1'b0;
1137
        always @(posedge i_clk)
1138
                scop_ack  <= scop_a_ack | scop_b_ack | scop_c_ack | scop_d_ack;
1139
        always @(posedge i_clk)
1140
                if (scop_a_ack)
1141
                        scop_data <= scop_a_data;
1142
                else if (scop_b_ack)
1143
                        scop_data <= scop_b_data;
1144
                else if (scop_c_ack)
1145
                        scop_data <= scop_c_data;
1146
                else // if (scop_d_ack)
1147
                        scop_data <= scop_d_data;
1148
 
1149
endmodule

powered by: WebSVN 2.1.0

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