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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [rtl/] [toplevel.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
`timescale 10ns / 100ps
2 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
3
//
4
// Filename:    toplevel.v
5
//
6
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
7
//
8
// Purpose:     This is (supposed to be) the one Xilinx specific file in the
9
//              project.  The idea is that all of the board specific logic,
10
//      the logic used in simulation, is kept in the busmaster.v  file.  It's
11
//      not quite true, since rxuart and txuart modules are instantiated here,
12
//      but it's mostly true.
13
//
14
//      One thing that makes this module unique is that all of its inputs and
15
//      outputs must match those on the chip, as specified within the cmod.ucf
16
//      file (up one directory).
17
//
18
//      Within this file you will find specific I/O for output pins, such as
19
//      the necessary adjustments to make an I2C port from GPIO pins, as well
20
//      as the clock management approach.
21
//
22
//
23
//
24
// Creator:     Dan Gisselquist, Ph.D.
25
//              Gisselquist Technology, LLC
26
//
27
////////////////////////////////////////////////////////////////////////////////
28
//
29
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
30
//
31
// This program is free software (firmware): you can redistribute it and/or
32
// modify it under the terms of  the GNU General Public License as published
33
// by the Free Software Foundation, either version 3 of the License, or (at
34
// your option) any later version.
35
//
36
// This program is distributed in the hope that it will be useful, but WITHOUT
37
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
38
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
39
// for more details.
40
//
41
// You should have received a copy of the GNU General Public License along
42
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
43
// target there if the PDF file isn't present.)  If not, see
44
// <http://www.gnu.org/licenses/> for a copy.
45
//
46
// License:     GPL, v3, as defined and found on www.gnu.org,
47
//              http://www.gnu.org/licenses/gpl.html
48
//
49
//
50
////////////////////////////////////////////////////////////////////////////////
51
//
52
//
53 51 dgisselq
`define LOWLOGIC_FLASH
54 2 dgisselq
module toplevel(i_clk_8mhz,
55
                o_qspi_cs_n, o_qspi_sck, io_qspi_dat,
56
                i_btn, o_led, o_pwm, o_pwm_shutdown_n, o_pwm_gain,
57 46 dgisselq
                        i_uart, o_uart, o_uart_rts_n, i_uart_cts_n,
58 2 dgisselq
                i_kp_row, o_kp_col,
59
                i_gpio, o_gpio,
60
                io_scl, io_sda);
61
        input           i_clk_8mhz;
62
        //
63
        // Quad SPI Flash
64
        output  wire            o_qspi_cs_n;
65
        output  wire            o_qspi_sck;
66
        inout   wire    [3:0]    io_qspi_dat;
67
        //
68
        // General purpose I/O
69
        input           [1:0]    i_btn;
70
        output  wire    [3:0]    o_led;
71
        output  wire            o_pwm, o_pwm_shutdown_n, o_pwm_gain;
72
        //
73
        // and our serial port
74
        input           i_uart;
75
        output  wire    o_uart;
76 4 dgisselq
        //      and it's associated control wires
77 46 dgisselq
        output  wire    o_uart_rts_n;
78
        input           i_uart_cts_n;
79 2 dgisselq
        // Our keypad
80
        input           [3:0]    i_kp_row;
81
        output  wire    [3:0]    o_kp_col;
82
        // and our GPIO
83
        input           [15:2]  i_gpio;
84
        output  wire    [15:2]  o_gpio;
85
        // and our I2C port
86
        inout                   io_scl, io_sda;
87
 
88
 
89 4 dgisselq
        //
90
        // Clock management
91
        //
92
        //      Generate a usable clock for the rest of the board to run at.
93
        //
94 51 dgisselq
        wire    ck_zero_0, clk_s, clk_sn;
95 4 dgisselq
 
96
        // Clock frequency = (20 / 2) * 8Mhz = 80 MHz
97
        // Clock period = 12.5 ns
98 2 dgisselq
        DCM_SP #(
99
                .CLKDV_DIVIDE(2.0),
100 4 dgisselq
                .CLKFX_DIVIDE(2),               // Here's the divide by two
101
                .CLKFX_MULTIPLY(20),            // and here's the multiply by 20
102 2 dgisselq
                .CLKIN_DIVIDE_BY_2("FALSE"),
103
                .CLKIN_PERIOD(125.0),
104
                .CLKOUT_PHASE_SHIFT("NONE"),
105
                .CLK_FEEDBACK("1X"),
106
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
107
                .DLL_FREQUENCY_MODE("LOW"),
108
                .DUTY_CYCLE_CORRECTION("TRUE"),
109
                .PHASE_SHIFT(0),
110
                .STARTUP_WAIT("TRUE")
111
        ) u0(   .CLKIN(i_clk_8mhz),
112
                .CLK0(ck_zero_0),
113
                .CLKFB(ck_zero_0),
114
                .CLKFX(clk_s),
115 51 dgisselq
                .CLKFX180(clk_sn),
116 2 dgisselq
                .PSEN(1'b0),
117
                .RST(1'b0));
118
 
119 46 dgisselq
        // Baud rate is set by clock rate / baud rate desired.  Thus,
120
        // 80 MHz / 9600 Baud = 8333, or about 0x208d.  We choose a slow
121
        // speed such as 9600 Baud to help the CPU keep up with the serial
122
        // port rate.
123
        localparam [30:0]        UART_SETUP = 31'h4000208d;
124 2 dgisselq
 
125 4 dgisselq
        //
126
        // BUSMASTER
127
        //
128
        //      Busmaster is so named because it contains the wishbone
129
        //      interconnect that all of the internal devices are hung off of.
130
        //      To reconfigure this device for another purpose, usually
131
        //      the busmaster module (i.e. the interconnect) is all that needs
132
        //      to be changed: either to add more devices, or to remove them.
133
        //
134 51 dgisselq
`ifdef  LOWLOGIC_FLASH
135
        wire    [1:0]    qspi_sck;
136
`else
137
        wire            qspi_sck;
138
`endif
139
        wire            qspi_cs_n;
140 2 dgisselq
        wire    [3:0]    qspi_dat;
141
        wire    [1:0]    qspi_bmod;
142
        wire    [15:0]   w_gpio;
143
 
144 46 dgisselq
        wire    w_uart_rts_n;
145
        busmaster       #(.UART_SETUP(UART_SETUP))
146
                masterbus(clk_s, 1'b0,
147
                // Serial port wires
148
                i_uart, o_uart_rts_n, o_uart, i_uart_cts_n,
149 2 dgisselq
                // SPI/SD-card flash
150 51 dgisselq
                qspi_cs_n, qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod,
151 2 dgisselq
                // Board lights and switches
152
                i_btn, o_led, o_pwm, { o_pwm_shutdown_n, o_pwm_gain },
153
                // Keypad connections
154
                i_kp_row, o_kp_col,
155
                // GPIO lines
156
                { i_gpio, io_scl, io_sda }, w_gpio
157
                );
158
 
159 4 dgisselq
        //
160
        // Quad SPI support
161
        //
162
        //      Supporting a Quad SPI port requires knowing which direction the
163
        //      wires are going at each instant, whether the device is in full
164
        //      Quad mode in, full quad mode out, or simply the normal SPI
165
        //      port with one wire in and one wire out.  This utilizes our
166
        //      control wires (qspi_bmod) to set the output lines appropriately.
167
        //
168 51 dgisselq
        //
169
        //      2'b0?   -- Normal SPI
170
        //      2'b10   -- Quad Output
171
        //      2'b11   -- Quad Input
172
`ifdef  LOWLOGIC_FLASH
173
        reg             r_qspi_cs_n;
174
        reg     [1:0]    r_qspi_bmod;
175
        reg     [3:0]    r_qspi_dat, r_qspi_z;
176
        reg     [1:0]    r_qspi_sck;
177
        always @(posedge clk_s)
178
                r_qspi_sck <= qspi_sck;
179
        xoddr   xqspi_sck({clk_s, clk_sn}, r_qspi_sck, o_qspi_sck);
180
        initial r_qspi_cs_n = 1'b1;
181
        initial r_qspi_z = 4'b1101;
182
        always @(posedge clk_s)
183
        begin
184
                r_qspi_dat  <= (qspi_bmod[1]) ? qspi_dat:{ 3'b111, qspi_dat[0]};
185
                r_qspi_z    <= (!qspi_bmod[1])? 4'b1101
186
                                : ((qspi_bmod[0]) ? 4'h0 : 4'hf);
187
                r_qspi_cs_n <= qspi_cs_n;
188
        end
189
 
190
        assign  o_qspi_cs_n    = r_qspi_cs_n;
191
        assign  io_qspi_dat[0] = (r_qspi_z[0]) ? r_qspi_dat[0] : 1'bz;
192
        assign  io_qspi_dat[1] = (r_qspi_z[1]) ? r_qspi_dat[1] : 1'bz;
193
        assign  io_qspi_dat[2] = (r_qspi_z[2]) ? r_qspi_dat[2] : 1'bz;
194
        assign  io_qspi_dat[3] = (r_qspi_z[3]) ? r_qspi_dat[3] : 1'bz;
195
`else
196
        assign io_qspi_dat = (!qspi_bmod[1])?({2'b11,1'bz,qspi_dat[0]})
197 2 dgisselq
                                :((qspi_bmod[0])?(4'bzzzz):(qspi_dat[3:0]));
198
 
199 51 dgisselq
        assign  o_qspi_cs_n = qspi_cs_n;
200
        assign  o_qspi_sck  = qspi_sck;
201
`endif  // LOWLOGIC_FLASH
202
 
203 4 dgisselq
        //
204
        // I2C support
205
        //
206
        //      Supporting I2C requires a couple quick adjustments to our
207
        //      GPIO lines.  Specifically, we'll allow that when the output
208
        //      (i.e. w_gpio) pins are high, then the I2C lines float.  They
209 46 dgisselq
        //      will be (need to be) pulled up by a resistor in order to
210 4 dgisselq
        //      match the I2C protocol, but this change makes them look/act
211
        //      more like GPIO pins.
212
        //
213 2 dgisselq
        assign  io_sda = (w_gpio[0]) ? 1'bz : 1'b0;
214
        assign  io_scl = (w_gpio[1]) ? 1'bz : 1'b0;
215
        assign  o_gpio[15:2] = w_gpio[15:2];
216
 
217
endmodule

powered by: WebSVN 2.1.0

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