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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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