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

Subversion Repositories openarty

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

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

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

powered by: WebSVN 2.1.0

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