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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [toplevel.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:    toplevel.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     This is the top level Verilog file.  It is to be contrasted
8
//              with the other top level Verilog file in this same project in
9
//      that *this* top level is designed to create a *safe*, low-speed
10 25 dgisselq
//      (80MHz), configuration that can be used to test peripherals and other
11
//      things on the way to building a full featured high speed (160MHz)
12
//      configuration.
13 3 dgisselq
//
14
//      Differences between this file and fasttop.v should be limited to speed
15
//      related differences (such as the number of counts per UART baud), and
16
//      the different daughter module: fastmaster.v (for 200MHz designs) vs
17
//      busmaster.v (for 100MHz designs).
18
//
19
// Creator:     Dan Gisselquist, Ph.D.
20
//              Gisselquist Technology, LLC
21
//
22
////////////////////////////////////////////////////////////////////////////////
23
//
24
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
25
//
26
// This program is free software (firmware): you can redistribute it and/or
27
// modify it under the terms of  the GNU General Public License as published
28
// by the Free Software Foundation, either version 3 of the License, or (at
29
// your option) any later version.
30
//
31
// This program is distributed in the hope that it will be useful, but WITHOUT
32
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
33
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34
// for more details.
35
//
36
// You should have received a copy of the GNU General Public License along
37
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
38
// target there if the PDF file isn't present.)  If not, see
39
// <http://www.gnu.org/licenses/> for a copy.
40
//
41
// License:     GPL, v3, as defined and found on www.gnu.org,
42
//              http://www.gnu.org/licenses/gpl.html
43
//
44
//
45
////////////////////////////////////////////////////////////////////////////////
46
//
47
//
48 25 dgisselq
module toplevel(sys_clk_i, i_reset_btn,
49 3 dgisselq
        i_sw,                   // Switches
50
        i_btn,                  // Buttons
51
        o_led,                  // Single color LEDs
52
        o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3, // Color LEDs
53
        // RS232 UART
54
        i_uart_rx, o_uart_tx,
55
        // Quad-SPI Flash control
56
        o_qspi_sck, o_qspi_cs_n, io_qspi_dat,
57
        // Missing: Ethernet
58
        o_eth_mdclk, io_eth_mdio,
59
        // Memory
60 25 dgisselq
        ddr3_reset_n, ddr3_cke, ddr3_ck_p, ddr3_ck_n,
61
        ddr3_cs_n, ddr3_ras_n, ddr3_cas_n, ddr3_we_n,
62
        ddr3_dqs_p, ddr3_dqs_n,
63
        ddr3_addr, ddr3_ba,
64
        ddr3_dq, ddr3_dm, ddr3_odt,
65 3 dgisselq
        // SD Card
66
        o_sd_sck, io_sd_cmd, io_sd, i_sd_cs, i_sd_wp,
67
        // GPS Pmod
68
        i_gps_pps, i_gps_3df, i_gps_rx, o_gps_tx,
69
        // OLED Pmod
70
        o_oled_sck, o_oled_cs_n, o_oled_mosi, o_oled_dcn, o_oled_reset_n,
71
                o_oled_vccen, o_oled_pmoden,
72
        // PMod I/O
73
        i_aux_rx, i_aux_rts, o_aux_tx, o_aux_cts
74
        );
75 25 dgisselq
        input           [0:0]     sys_clk_i;
76
        input                   i_reset_btn;
77 3 dgisselq
        input           [3:0]    i_sw;   // Switches
78
        input           [3:0]    i_btn;  // Buttons
79
        output  wire    [3:0]    o_led;  // LED
80
        output  wire    [2:0]    o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3;
81
        // UARTs
82
        input                   i_uart_rx;
83
        output  wire            o_uart_tx;
84
        // Quad SPI flash
85
        output  wire            o_qspi_sck, o_qspi_cs_n;
86
        inout   [3:0]            io_qspi_dat;
87
        // Ethernet // Not yet implemented
88
        // Ethernet control (MDIO)
89
        output  wire            o_eth_mdclk;
90
        inout   wire            io_eth_mdio;
91
        // DDR3 SDRAM
92 25 dgisselq
        output  wire            ddr3_reset_n;
93
        output  wire    [0:0]     ddr3_cke;
94
        output  wire    [0:0]     ddr3_ck_p, ddr3_ck_n;
95
        output  wire    [0:0]     ddr3_cs_n;
96
        output  wire            ddr3_ras_n, ddr3_cas_n, ddr3_we_n;
97
        output  wire    [2:0]    ddr3_ba;
98
        output  wire    [13:0]   ddr3_addr;
99
        output  wire    [0:0]     ddr3_odt;
100
        output  wire    [1:0]    ddr3_dm;
101
        inout           [1:0]    ddr3_dqs_p, ddr3_dqs_n;
102
        inout           [15:0]   ddr3_dq;
103 3 dgisselq
        //
104
        // SD Card
105
        output  wire            o_sd_sck;
106
        inout                   io_sd_cmd;
107
        inout           [3:0]    io_sd;
108
        input                   i_sd_cs;
109
        input                   i_sd_wp;
110
        // GPS PMod
111
        input                   i_gps_pps, i_gps_3df, i_gps_rx;
112
        output  wire            o_gps_tx;
113
        // OLEDRGB PMod
114
        output  wire            o_oled_sck, o_oled_cs_n, o_oled_mosi,
115
                                o_oled_dcn, o_oled_reset_n, o_oled_vccen,
116
                                o_oled_pmoden;
117
        // Aux UART
118
        input                   i_aux_rx, i_aux_rts;
119
        output  wire            o_aux_tx, o_aux_cts;
120
 
121
        // Build our master clock
122 25 dgisselq
        wire    s_clk, sys_clk, mem_clk_200mhz,
123
                clk1_unused, clk2_unused, enet_clk, clk4_unnused,
124
                clk5_unused, clk_feedback, clk_locked, mem_clk_200mhz_nobuf;
125 3 dgisselq
        PLLE2_BASE      #(
126
                .BANDWIDTH("OPTIMIZED"),        // OPTIMIZED, HIGH, LOW
127
                .CLKFBOUT_PHASE(0.0),   // Phase offset in degrees of CLKFB, (-360-360)
128 25 dgisselq
                .CLKIN1_PERIOD(10.0),   // Input clock period in ns resolution
129 3 dgisselq
                // CLKOUT0_DIVIDE - CLKOUT5_DIVIDE: divide amount for each CLKOUT(1-128)
130
                .CLKFBOUT_MULT(8),      // Multiply value for all CLKOUT (2-64)
131 25 dgisselq
                .CLKOUT0_DIVIDE(8),     // 100 MHz      (Clock for MIG)
132
                .CLKOUT1_DIVIDE(4),     // 200 MHz      (MIG Reference clock)
133
                .CLKOUT2_DIVIDE(32),    //  50 MHz      (Unused)
134
                .CLKOUT3_DIVIDE(64),    //  25 MHz      (Unused/Ethernet clock)
135
                .CLKOUT4_DIVIDE(32),    //  50 MHz      (Unused clock?)
136
                .CLKOUT5_DIVIDE(24),    //  66 MHz
137 3 dgisselq
                // CLKOUT0_DUTY_CYCLE -- Duty cycle for each CLKOUT
138
                .CLKOUT0_DUTY_CYCLE(0.5),
139
                .CLKOUT1_DUTY_CYCLE(0.5),
140
                .CLKOUT2_DUTY_CYCLE(0.5),
141
                .CLKOUT3_DUTY_CYCLE(0.5),
142
                .CLKOUT4_DUTY_CYCLE(0.5),
143
                .CLKOUT5_DUTY_CYCLE(0.5),
144
                // CLKOUT0_PHASE -- phase offset for each CLKOUT
145
                .CLKOUT0_PHASE(0.0),
146 25 dgisselq
                .CLKOUT1_PHASE(0.0),
147 3 dgisselq
                .CLKOUT2_PHASE(0.0),
148
                .CLKOUT3_PHASE(0.0),
149
                .CLKOUT4_PHASE(0.0),
150
                .CLKOUT5_PHASE(0.0),
151
                .DIVCLK_DIVIDE(1),      // Master division value , (1-56)
152 25 dgisselq
                .REF_JITTER1(0.0),      // Ref. input jitter in UI (0.000-0.999)
153
                .STARTUP_WAIT("TRUE")   // Delay DONE until PLL Locks, ("TRUE"/"FALSE")
154 3 dgisselq
        ) genclock(
155
                // Clock outputs: 1-bit (each) output
156 25 dgisselq
                .CLKOUT0(mem_clk_nobuf),
157
                .CLKOUT1(mem_clk_200mhz_nobuf),
158
                .CLKOUT2(clk2_unused),
159 3 dgisselq
                .CLKOUT3(enet_clk),
160
                .CLKOUT4(clk4_unused),
161
                .CLKOUT5(clk5_unused),
162
                .CLKFBOUT(clk_feedback), // 1-bit output, feedback clock
163
                .LOCKED(clk_locked),
164 25 dgisselq
                .CLKIN1(sys_clk),
165 3 dgisselq
                .PWRDWN(1'b0),
166
                .RST(1'b0),
167 25 dgisselq
                .CLKFBIN(clk_feedback_bufd)     // 1-bit input, feedback clock
168 3 dgisselq
        );
169 25 dgisselq
 
170
        BUFH    feedback_buffer(.I(clk_feedback),.O(clk_feedback_bufd));
171
        // BUFG memref_buffer(.I(mem_clk_200mhz_nobuf),.O(mem_clk_200mhz));
172
        IBUF    sysclk_buf(.I(sys_clk_i[0]), .O(sys_clk));
173
 
174
        //
175
        //
176 3 dgisselq
        // UART interface
177 25 dgisselq
        //
178
        //
179 3 dgisselq
        wire    [29:0]   bus_uart_setup;
180 25 dgisselq
        // assign       bus_uart_setup = 30'h10000014; // ~4MBaud, 7 bits
181
        assign          bus_uart_setup = 30'h10000051; // ~1MBaud, 7 bits
182 3 dgisselq
 
183
        wire    [7:0]    rx_data, tx_data;
184
        wire            rx_break, rx_parity_err, rx_frame_err, rx_stb;
185
        wire            tx_stb, tx_busy;
186
 
187 25 dgisselq
        //
188
        // RESET LOGIC
189
        //
190
        // Okay, so this looks bad at a first read--but it's not really that
191
        // bad.  If you look close, there are two parts to the reset logic.
192
        // The first is the "PRE"-reset.  This is a wire, set from the external
193
        // reset button.  In good old-fashioned asynch-logic to synchronous
194
        // logic fashion, we synchronize this wire by registering it first
195
        // to pre_reset, and then to pwr_reset (the actual reset wire).
196
        //
197
        reg     [7:0]    pre_reset;
198
        reg             pwr_reset;
199
        // Since all our stuff is synchronous to the clock that comes out of 
200
        // the memory controller, sys_reset must needs come out of the memory
201
        // controller.
202
        //
203
        // Logic description starts with the PRE-reset, so as to make certain
204
        // we include the reset button.  The memory controller wants an active
205
        // low reset here, so we provide such.
206 3 dgisselq
        initial pre_reset = 1'b0;
207 25 dgisselq
        always @(posedge sys_clk)
208
                pre_reset <= ((!i_reset_btn)||(!clk_locked))
209
                                        ? 8'h00 : {pre_reset[6:0], 1'b1};
210
        //
211
        // and then continues with the actual reset, now that we've
212
        // synchronized our reset button wire.  This is an active LOW reset.
213
        initial pwr_reset = 1'b0;
214
        always @(posedge sys_clk)
215
                pwr_reset <= pre_reset[7];
216
        //
217
        // Of course, this only goes into the memory controller.  The true
218
        // device reset comes out of that memory controller, synchronized to
219
        // our memory generator provided clock(s)
220 3 dgisselq
 
221
        wire    w_ck_uart, w_uart_tx;
222 25 dgisselq
        rxuart  rcv(s_clk, s_reset, bus_uart_setup, i_uart_rx,
223 3 dgisselq
                                rx_stb, rx_data, rx_break,
224
                                rx_parity_err, rx_frame_err, w_ck_uart);
225 25 dgisselq
        txuart  txv(s_clk, s_reset, bus_uart_setup|30'h8000000, 1'b0,
226 3 dgisselq
                                tx_stb, tx_data, o_uart_tx, tx_busy);
227
 
228
 
229 25 dgisselq
        wire    [3:0]    w_led;
230
        reg     [24:0]   dbg_counter;
231
        always @(posedge  sys_clk)
232
                dbg_counter <= dbg_counter + 25'h01;
233
        assign o_led = { w_led[3:2],
234
                        ((!pwr_reset)&(dbg_counter[24]))
235
                                ||((pwr_reset)&&(w_led[1])),
236
                        (s_reset & dbg_counter[23])
237
                                ||((!s_reset)&&(w_led[0])) };
238 3 dgisselq
 
239
 
240
 
241
        //////
242
        //
243
        //
244
        // The WB bus interconnect, herein called busmaster, which handles
245
        // just about ... everything.  It is in contrast to the other WB bus
246
        // interconnect, fastmaster, in that the busmaster build permits
247 25 dgisselq
        // peripherals that can *only* operate at 80MHz, no faster, no slower.
248 3 dgisselq
        //
249
        //
250
        //////
251 25 dgisselq
        wire            w_qspi_sck, w_qspi_cs_n;
252 3 dgisselq
        wire    [1:0]    qspi_bmod;
253
        wire    [3:0]    qspi_dat;
254
        wire    [3:0]    i_qspi_dat;
255
 
256
        //
257 25 dgisselq
        // The SDRAM interface wires
258 3 dgisselq
        //
259 25 dgisselq
        wire            ram_cyc, ram_stb, ram_we;
260
        wire    [25:0]   ram_addr;
261
        wire    [31:0]   ram_rdata, ram_wdata;
262
        wire            ram_ack, ram_stall, ram_err;
263
        wire    [31:0]   ram_dbg;
264
        //
265 3 dgisselq
        wire            w_mdio, w_mdwe;
266
        //
267
        wire            w_sd_cmd;
268
        wire    [3:0]    w_sd_data;
269 25 dgisselq
        busmaster       wbbus(s_clk, s_reset,
270 3 dgisselq
                // External USB-UART bus control
271
                rx_stb, rx_data, tx_stb, tx_data, tx_busy,
272
                // Board lights and switches
273 25 dgisselq
                i_sw, i_btn, w_led,
274 3 dgisselq
                o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
275
                // Board level PMod I/O
276
                i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
277
                // Quad SPI flash
278 25 dgisselq
                w_qspi_cs_n, w_qspi_sck, qspi_dat, i_qspi_dat, qspi_bmod,
279 3 dgisselq
                // DDR3 SDRAM
280 25 dgisselq
                // o_ddr_reset_n, o_ddr_cke, o_ddr_ck_p, o_ddr_ck_n,
281
                // o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
282
                // o_ddr_ba, o_ddr_addr, o_ddr_odt, o_ddr_dm,
283
                // io_ddr_dqs_p, io_ddr_dqs_n, io_ddr_data,
284
                ram_cyc, ram_stb, ram_we, ram_addr, ram_wdata,
285
                        ram_ack, ram_stall, ram_rdata, ram_err,
286
                        ram_dbg,
287 3 dgisselq
                // SD Card
288
                o_sd_sck, w_sd_cmd, w_sd_data, io_sd_cmd, io_sd, i_sd_cs,
289
                // Ethernet control (MDIO) lines
290
                o_eth_mdclk, w_mdio, w_mdwe, io_eth_mdio,
291
                // OLEDRGB PMod wires
292
                o_oled_sck, o_oled_cs_n, o_oled_mosi, o_oled_dcn,
293
                o_oled_reset_n, o_oled_vccen, o_oled_pmoden,
294
                // GPS PMod
295
                i_gps_pps, i_gps_3df
296
                );
297
 
298
        //////
299
        //
300
        //
301
        // The rest of this file *should* be identical to fasttop.v.  Any
302
        // differences should be worked out with meld or some such program
303
        // to keep them to a minimum.
304
        //
305
        //
306
        // Some wires need special treatment, and so are not quite completely
307
        // handled by the bus master.  These are handled below.
308
        //
309
        //
310
        //////
311
 
312
        //
313
        //
314
        // QSPI)BMOD, Quad SPI bus mode, Bus modes are:
315
        //      0?      Normal serial mode, one bit in one bit out
316
        //      10      Quad SPI mode, going out
317
        //      11      Quad SPI mode coming from the device (read mode)
318
        //
319
        //      ??      Dual mode in  (not yet)
320
        //      ??      Dual mode out (not yet)
321
        //
322
        //
323 25 dgisselq
        wire    [3:0]    i_qspi_pedge, i_qspi_nedge;
324
 
325
        xoddr   xqspi_sck( s_clk, { w_qspi_sck,  w_qspi_sck }, o_qspi_sck);
326
        xoddr   xqspi_csn( s_clk, { w_qspi_cs_n, w_qspi_cs_n },o_qspi_cs_n);
327
        //
328
        xioddr  xqspi_d0(  s_clk, (qspi_bmod != 2'b11),
329 3 dgisselq
                { qspi_dat[0], qspi_dat[0] },
330 25 dgisselq
                { i_qspi_pedge[0], i_qspi_nedge[0] }, io_qspi_dat[0]);
331
        xioddr  xqspi_d1(  s_clk, (qspi_bmod==2'b10),
332 3 dgisselq
                { qspi_dat[1], qspi_dat[1] },
333 25 dgisselq
                { i_qspi_pedge[1], i_qspi_nedge[1] }, io_qspi_dat[1]);
334
        xioddr  xqspi_d2(  s_clk, (qspi_bmod!=2'b11),
335
                (qspi_bmod[1])?{ qspi_dat[2], qspi_dat[2] }:2'b11,
336
                { i_qspi_pedge[2], i_qspi_nedge[2] }, io_qspi_dat[2]);
337
        xioddr  xqspi_d3(  s_clk, (qspi_bmod!=2'b11),
338
                (qspi_bmod[1])?{ qspi_dat[3], qspi_dat[3] }:2'b11,
339
                { i_qspi_pedge[3], i_qspi_nedge[3] }, io_qspi_dat[3]);
340 3 dgisselq
 
341 25 dgisselq
        assign  i_qspi_dat = i_qspi_pedge;
342 3 dgisselq
        //
343
        // Proposed QSPI mode select, to allow dual I/O mode
344
        //      000     Normal SPI mode
345
        //      001     Dual mode input
346
        //      010     Dual mode, output
347
        //      101     Quad I/O mode input
348
        //      110     Quad I/O mode output
349
        //
350
        //
351
 
352
 
353
        //
354
        //
355
        // Wires for setting up the SD Card Controller
356
        //
357
        //
358
        assign io_sd_cmd = w_sd_cmd ? 1'bz:1'b0;
359
        assign io_sd[0] = w_sd_data[0]? 1'bz:1'b0;
360
        assign io_sd[1] = w_sd_data[1]? 1'bz:1'b0;
361
        assign io_sd[2] = w_sd_data[2]? 1'bz:1'b0;
362
        assign io_sd[3] = w_sd_data[3]? 1'bz:1'b0;
363
 
364
 
365
        //
366
        //
367
        // Wire(s) for setting up the MDIO ethernet control structure
368
        //
369
        //
370
        assign  io_eth_mdio = (w_mdwe)?w_mdio : 1'bz;
371
 
372 25 dgisselq
 
373 3 dgisselq
        //
374
        //
375 25 dgisselq
        // Now, to set up our memory ...
376 3 dgisselq
        //
377
        //
378 25 dgisselq
        migsdram rami(
379
                .i_clk(mem_clk_nobuf), .i_clk_200mhz(mem_clk_200mhz_nobuf),
380
                .o_sys_clk(s_clk), .i_rst(pwr_reset), .o_sys_reset(s_reset),
381
                .i_wb_cyc(ram_cyc), .i_wb_stb(ram_stb), .i_wb_we(ram_we),
382
                        .i_wb_addr(ram_addr), .i_wb_data(ram_wdata),
383
                        .i_wb_sel(4'hf),
384
                .o_wb_ack(ram_ack), .o_wb_stall(ram_stall),
385
                        .o_wb_data(ram_rdata), .o_wb_err(ram_err),
386
                .o_ddr_ck_p(ddr3_ck_p),         .o_ddr_ck_n(ddr3_ck_n),
387
                .o_ddr_reset_n(ddr3_reset_n),   .o_ddr_cke(ddr3_cke),
388
                .o_ddr_cs_n(ddr3_cs_n),         .o_ddr_ras_n(ddr3_ras_n),
389
                        .o_ddr_cas_n(ddr3_cas_n), .o_ddr_we_n(ddr3_we_n),
390
                .o_ddr_ba(ddr3_ba),             .o_ddr_addr(ddr3_addr),
391
                        .o_ddr_odt(ddr3_odt),   .o_ddr_dm(ddr3_dm),
392
                .io_ddr_dqs_p(ddr3_dqs_p),      .io_ddr_dqs_n(ddr3_dqs_n),
393
                .io_ddr_data(ddr3_dq),
394
        //
395
                .o_ram_dbg(ram_dbg)
396
        );
397 3 dgisselq
 
398
endmodule
399
 

powered by: WebSVN 2.1.0

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