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

Subversion Repositories s6soc

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

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 46 dgisselq
                        i_uart, o_uart, o_uart_rts_n, i_uart_cts_n,
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 46 dgisselq
        output  wire    o_uart_rts_n;
77
        input           i_uart_cts_n;
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 46 dgisselq
        // Baud rate is set by clock rate / baud rate desired.  Thus,
118
        // 80 MHz / 9600 Baud = 8333, or about 0x208d.  We choose a slow
119
        // speed such as 9600 Baud to help the CPU keep up with the serial
120
        // port rate.
121
        localparam [30:0]        UART_SETUP = 31'h4000208d;
122 2 dgisselq
 
123 4 dgisselq
        //
124
        // BUSMASTER
125
        //
126
        //      Busmaster is so named because it contains the wishbone
127
        //      interconnect that all of the internal devices are hung off of.
128
        //      To reconfigure this device for another purpose, usually
129
        //      the busmaster module (i.e. the interconnect) is all that needs
130
        //      to be changed: either to add more devices, or to remove them.
131
        //
132 2 dgisselq
        wire    [3:0]    qspi_dat;
133
        wire    [1:0]    qspi_bmod;
134
        wire    [15:0]   w_gpio;
135
 
136 46 dgisselq
        wire    w_uart_rts_n;
137
        busmaster       #(.UART_SETUP(UART_SETUP))
138
                masterbus(clk_s, 1'b0,
139
                // Serial port wires
140
                i_uart, o_uart_rts_n, o_uart, i_uart_cts_n,
141 2 dgisselq
                // SPI/SD-card flash
142
                o_qspi_cs_n, o_qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod,
143
                // Board lights and switches
144
                i_btn, o_led, o_pwm, { o_pwm_shutdown_n, o_pwm_gain },
145
                // Keypad connections
146
                i_kp_row, o_kp_col,
147
                // GPIO lines
148
                { i_gpio, io_scl, io_sda }, w_gpio
149
                );
150
 
151 4 dgisselq
        //
152
        // Quad SPI support
153
        //
154
        //      Supporting a Quad SPI port requires knowing which direction the
155
        //      wires are going at each instant, whether the device is in full
156
        //      Quad mode in, full quad mode out, or simply the normal SPI
157
        //      port with one wire in and one wire out.  This utilizes our
158
        //      control wires (qspi_bmod) to set the output lines appropriately.
159
        //
160 2 dgisselq
        assign io_qspi_dat = (~qspi_bmod[1])?({2'b11,1'bz,qspi_dat[0]})
161
                                :((qspi_bmod[0])?(4'bzzzz):(qspi_dat[3:0]));
162
 
163 4 dgisselq
        //
164
        // I2C support
165
        //
166
        //      Supporting I2C requires a couple quick adjustments to our
167
        //      GPIO lines.  Specifically, we'll allow that when the output
168
        //      (i.e. w_gpio) pins are high, then the I2C lines float.  They
169 46 dgisselq
        //      will be (need to be) pulled up by a resistor in order to
170 4 dgisselq
        //      match the I2C protocol, but this change makes them look/act
171
        //      more like GPIO pins.
172
        //
173 2 dgisselq
        assign  io_sda = (w_gpio[0]) ? 1'bz : 1'b0;
174
        assign  io_scl = (w_gpio[1]) ? 1'bz : 1'b0;
175
        assign  o_gpio[15:2] = w_gpio[15:2];
176
 
177
endmodule

powered by: WebSVN 2.1.0

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