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

Subversion Repositories s6soc

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

Go to most recent revision | 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 2 dgisselq
module toplevel(i_clk_8mhz,
54
                o_qspi_cs_n, o_qspi_sck, io_qspi_dat,
55
                i_btn, o_led, o_pwm, o_pwm_shutdown_n, o_pwm_gain,
56 12 dgisselq
                        i_uart, o_uart, o_uart_cts, i_uart_rts,
57 2 dgisselq
                i_kp_row, o_kp_col,
58
                i_gpio, o_gpio,
59
                io_scl, io_sda);
60
        input           i_clk_8mhz;
61
        //
62
        // Quad SPI Flash
63
        output  wire            o_qspi_cs_n;
64
        output  wire            o_qspi_sck;
65
        inout   wire    [3:0]    io_qspi_dat;
66
        //
67
        // General purpose I/O
68
        input           [1:0]    i_btn;
69
        output  wire    [3:0]    o_led;
70
        output  wire            o_pwm, o_pwm_shutdown_n, o_pwm_gain;
71
        //
72
        // and our serial port
73
        input           i_uart;
74
        output  wire    o_uart;
75 4 dgisselq
        //      and it's associated control wires
76 12 dgisselq
        output  wire    o_uart_cts;
77
        input           i_uart_rts;
78 2 dgisselq
        // Our keypad
79
        input           [3:0]    i_kp_row;
80
        output  wire    [3:0]    o_kp_col;
81
        // and our GPIO
82
        input           [15:2]  i_gpio;
83
        output  wire    [15:2]  o_gpio;
84
        // and our I2C port
85
        inout                   io_scl, io_sda;
86
 
87
 
88 4 dgisselq
        //
89
        // Clock management
90
        //
91
        //      Generate a usable clock for the rest of the board to run at.
92
        //
93
        wire    ck_zero_0, clk_s;
94
 
95
        // Clock frequency = (20 / 2) * 8Mhz = 80 MHz
96
        // Clock period = 12.5 ns
97 2 dgisselq
        DCM_SP #(
98
                .CLKDV_DIVIDE(2.0),
99 4 dgisselq
                .CLKFX_DIVIDE(2),               // Here's the divide by two
100
                .CLKFX_MULTIPLY(20),            // and here's the multiply by 20
101 2 dgisselq
                .CLKIN_DIVIDE_BY_2("FALSE"),
102
                .CLKIN_PERIOD(125.0),
103
                .CLKOUT_PHASE_SHIFT("NONE"),
104
                .CLK_FEEDBACK("1X"),
105
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
106
                .DLL_FREQUENCY_MODE("LOW"),
107
                .DUTY_CYCLE_CORRECTION("TRUE"),
108
                .PHASE_SHIFT(0),
109
                .STARTUP_WAIT("TRUE")
110
        ) u0(   .CLKIN(i_clk_8mhz),
111
                .CLK0(ck_zero_0),
112
                .CLKFB(ck_zero_0),
113
                .CLKFX(clk_s),
114
                .PSEN(1'b0),
115
                .RST(1'b0));
116
 
117 4 dgisselq
        //
118
        // The UART serial interface
119
        //
120
        //      Perhaps this should be part of our simulation model as well.
121
        //      For historical reasons, internal to Gisselquist Technology,
122
        //      this has remained separate from the simulation, allowing the
123
        //      simulation to bypass whether or not these two functions work.
124
        //
125 2 dgisselq
        wire            rx_stb, tx_stb;
126
        wire    [7:0]    rx_data, tx_data;
127
        wire            tx_busy;
128
        wire    [29:0]   uart_setup;
129
 
130 31 dgisselq
        wire            reset_s;
131
        assign  reset_s = 1'b0;
132
 
133 2 dgisselq
        wire    rx_break, rx_parity_err, rx_frame_err, rx_ck_uart, tx_break;
134
        assign  tx_break = 1'b0;
135 13 dgisselq
        rxuart  rcvuart(clk_s, 1'b0, uart_setup,
136 4 dgisselq
                        i_uart, rx_stb, rx_data,
137 2 dgisselq
                        rx_break, rx_parity_err, rx_frame_err, rx_ck_uart);
138
        txuart  tcvuart(clk_s, reset_s, uart_setup, tx_break, tx_stb, tx_data,
139 12 dgisselq
                        o_uart, tx_busy);
140 2 dgisselq
 
141
 
142 4 dgisselq
        //
143
        // BUSMASTER
144
        //
145
        //      Busmaster is so named because it contains the wishbone
146
        //      interconnect that all of the internal devices are hung off of.
147
        //      To reconfigure this device for another purpose, usually
148
        //      the busmaster module (i.e. the interconnect) is all that needs
149
        //      to be changed: either to add more devices, or to remove them.
150
        //
151 2 dgisselq
        wire    [3:0]    qspi_dat;
152
        wire    [1:0]    qspi_bmod;
153
        wire    [15:0]   w_gpio;
154
 
155 13 dgisselq
        busmaster       masterbus(clk_s, 1'b0,
156 2 dgisselq
                // External ... bus control (if enabled)
157 12 dgisselq
                rx_stb, rx_data, tx_stb, tx_data, tx_busy, w_uart_cts,
158 2 dgisselq
                // SPI/SD-card flash
159
                o_qspi_cs_n, o_qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod,
160
                // Board lights and switches
161
                i_btn, o_led, o_pwm, { o_pwm_shutdown_n, o_pwm_gain },
162
                // Keypad connections
163
                i_kp_row, o_kp_col,
164
                // UART control
165
                uart_setup,
166
                // GPIO lines
167
                { i_gpio, io_scl, io_sda }, w_gpio
168
                );
169 12 dgisselq
        assign  o_uart_cts = (w_uart_cts)&&(i_uart_rts);
170 2 dgisselq
 
171 4 dgisselq
        //
172
        // Quad SPI support
173
        //
174
        //      Supporting a Quad SPI port requires knowing which direction the
175
        //      wires are going at each instant, whether the device is in full
176
        //      Quad mode in, full quad mode out, or simply the normal SPI
177
        //      port with one wire in and one wire out.  This utilizes our
178
        //      control wires (qspi_bmod) to set the output lines appropriately.
179
        //
180 2 dgisselq
        assign io_qspi_dat = (~qspi_bmod[1])?({2'b11,1'bz,qspi_dat[0]})
181
                                :((qspi_bmod[0])?(4'bzzzz):(qspi_dat[3:0]));
182
 
183 4 dgisselq
        //
184
        // I2C support
185
        //
186
        //      Supporting I2C requires a couple quick adjustments to our
187
        //      GPIO lines.  Specifically, we'll allow that when the output
188
        //      (i.e. w_gpio) pins are high, then the I2C lines float.  They
189
        //      will be (need to be) pulled up by a resistor in order to 
190
        //      match the I2C protocol, but this change makes them look/act
191
        //      more like GPIO pins.
192
        //
193 2 dgisselq
        assign  io_sda = (w_gpio[0]) ? 1'bz : 1'b0;
194
        assign  io_scl = (w_gpio[1]) ? 1'bz : 1'b0;
195
        assign  o_gpio[15:2] = w_gpio[15:2];
196
 
197
endmodule

powered by: WebSVN 2.1.0

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