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

Subversion Repositories s6soc

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 dgisselq
`timescale 10ns / 100ps
2
////////////////////////////////////////////////////////////////////////////////
3
//
4
// Filename:    alttop.v
5
//
6
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
7
//
8
// Purpose:     This is an alternate toplevel configuration for the CMod S6
9
//              project.  Basically, the CMod S6 has so little logic within
10
//      it, that there's no logic available for in situ reprogramming.  This
11
//      toplevel file serves that purpose: It provides full configuration
12
//      access, via the UART port, for the flash (read and write), and full
13
//      test level access for all of the devices on the board.  What it
14
//      doesn't have, however, is the ZipCPU.  (I had to give up something to
15
//      get the logic back for this purpose!)
16
//
17
// Creator:     Dan Gisselquist, Ph.D.
18
//              Gisselquist Technology, LLC
19
//
20
////////////////////////////////////////////////////////////////////////////////
21
//
22
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
23
//
24
// This program is free software (firmware): you can redistribute it and/or
25
// modify it under the terms of  the GNU General Public License as published
26
// by the Free Software Foundation, either version 3 of the License, or (at
27
// your option) any later version.
28
//
29
// This program is distributed in the hope that it will be useful, but WITHOUT
30
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
31
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
32
// for more details.
33
//
34
// You should have received a copy of the GNU General Public License along
35
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
36
// target there if the PDF file isn't present.)  If not, see
37
// <http://www.gnu.org/licenses/> for a copy.
38
//
39
// License:     GPL, v3, as defined and found on www.gnu.org,
40
//              http://www.gnu.org/licenses/gpl.html
41
//
42
//
43
////////////////////////////////////////////////////////////////////////////////
44
//
45
//
46
module alttop(i_clk_8mhz,
47
                o_qspi_cs_n, o_qspi_sck, io_qspi_dat,
48
                i_btn, o_led, o_pwm, o_pwm_shutdown_n, o_pwm_gain,
49 46 dgisselq
                        i_uart, o_uart, o_uart_rts_n, i_uart_cts_n,
50 5 dgisselq
                i_kp_row, o_kp_col,
51
                i_gpio, o_gpio,
52 8 dgisselq
                io_scl, io_sda,
53
                i_depp_astb_n, i_depp_dstb_n, i_depp_write_n, io_depp_data,
54
                        o_depp_wait
55
                );
56 5 dgisselq
        input           i_clk_8mhz;
57
        //
58
        // Quad SPI Flash
59
        output  wire            o_qspi_cs_n;
60
        output  wire            o_qspi_sck;
61
        inout   wire    [3:0]    io_qspi_dat;
62
        //
63
        // General purpose I/O
64
        input           [1:0]    i_btn;
65
        output  wire    [3:0]    o_led;
66
        output  wire            o_pwm, o_pwm_shutdown_n, o_pwm_gain;
67
        //
68
        // and our serial port
69
        input           i_uart;
70
        output  wire    o_uart;
71
        //      and it's associated control wires
72 46 dgisselq
        output  wire    o_uart_rts_n;
73
        input           i_uart_cts_n;
74 5 dgisselq
        // Our keypad
75
        input           [3:0]    i_kp_row;
76
        output  wire    [3:0]    o_kp_col;
77
        // and our GPIO
78
        input           [15:2]  i_gpio;
79
        output  wire    [15:2]  o_gpio;
80
        // and our I2C port
81
        inout                   io_scl, io_sda;
82 8 dgisselq
        // Finally, the DEPP interface ... if so enabled
83
        input                   i_depp_astb_n, i_depp_dstb_n, i_depp_write_n;
84
        inout           [7:0]    io_depp_data;
85
        output  wire    o_depp_wait;
86 5 dgisselq
 
87
        //
88
        // Clock management
89
        //
90
        //      Generate a usable clock for the rest of the board to run at.
91
        //
92
        wire    ck_zero_0, clk_s;
93
 
94
        // Clock frequency = (20 / 2) * 8Mhz = 80 MHz
95
        // Clock period = 12.5 ns
96
        DCM_SP #(
97
                .CLKDV_DIVIDE(2.0),
98
                .CLKFX_DIVIDE(2),               // Here's the divide by two
99
                .CLKFX_MULTIPLY(20),            // and here's the multiply by 20
100
                .CLKIN_DIVIDE_BY_2("FALSE"),
101
                .CLKIN_PERIOD(125.0),
102
                .CLKOUT_PHASE_SHIFT("NONE"),
103
                .CLK_FEEDBACK("1X"),
104
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
105
                .DLL_FREQUENCY_MODE("LOW"),
106
                .DUTY_CYCLE_CORRECTION("TRUE"),
107
                .PHASE_SHIFT(0),
108
                .STARTUP_WAIT("TRUE")
109
        ) u0(   .CLKIN(i_clk_8mhz),
110
                .CLK0(ck_zero_0),
111
                .CLKFB(ck_zero_0),
112
                .CLKFX(clk_s),
113
                .PSEN(1'b0),
114
                .RST(1'b0));
115
 
116
        //
117
        // The UART serial interface
118
        //
119
        //      Perhaps this should be part of our simulation model as well.
120
        //      For historical reasons, internal to Gisselquist Technology,
121
        //      this has remained separate from the simulation, allowing the
122
        //      simulation to bypass whether or not these two functions work.
123
        //
124
        wire            rx_stb, tx_stb;
125
        wire    [7:0]    rx_data, tx_data;
126
        wire            tx_busy;
127
        wire    [29:0]   uart_setup;
128
 
129 46 dgisselq
        // Baud rate is set by clock rate / baud rate desired.  Thus, 
130
        // 80 MHz / 9600 Baud = 8333, or about 0x208d.  We choose a slow
131
        // speed such as 9600 Baud to help the CPU keep up with the serial
132
        // port rate.
133
        localparam [30:0]        UART_SETUP = 31'h4000208d;
134
        assign  uart_setup = UART_SETUP;
135
 
136
        wire            reset_s;
137
        assign  reset_s = 1'b0;
138
 
139 5 dgisselq
        wire    rx_break, rx_parity_err, rx_frame_err, rx_ck_uart, tx_break;
140
        assign  tx_break = 1'b0;
141 46 dgisselq
        rxuart  #(UART_SETUP)
142
                rcvuart(clk_s, 1'b0, uart_setup,
143 5 dgisselq
                        i_uart, rx_stb, rx_data,
144
                        rx_break, rx_parity_err, rx_frame_err, rx_ck_uart);
145 46 dgisselq
        txuart  #(UART_SETUP)
146
                tcvuart(clk_s, reset_s, uart_setup, tx_break, tx_stb, tx_data,
147
                        i_uart_cts_n, o_uart, tx_busy);
148 5 dgisselq
 
149
 
150
        //
151
        // ALT-BUSMASTER
152
        //
153
        //      Busmaster is so named because it contains the wishbone
154
        //      interconnect that all of the internal devices are hung off of.
155
        //      To reconfigure this device for another purpose, usually
156
        //      the busmaster module (i.e. the interconnect) is all that needs
157
        //      to be changed: either to add more devices, or to remove them.
158
        //
159
        //      This is an alternate version of the busmaster interface,
160
        //      offering no ZipCPU and access to reprogramming via the flash.
161
        //
162
        wire    [3:0]    qspi_dat;
163
        wire    [1:0]    qspi_bmod;
164
        wire    [15:0]   w_gpio;
165 8 dgisselq
        wire    [7:0]    w_depp_data;
166 5 dgisselq
 
167 46 dgisselq
        wire    w_uart_rts_n;
168 8 dgisselq
`ifndef BYPASS_LOGIC
169 13 dgisselq
        altbusmaster    slavedbus(clk_s, 1'b0,
170 5 dgisselq
                // External ... bus control (if enabled)
171 8 dgisselq
                // DEPP I/O Control
172
                i_depp_astb_n, i_depp_dstb_n, i_depp_write_n,
173
                        io_depp_data, w_depp_data, o_depp_wait,
174
                // External UART interface
175 46 dgisselq
                rx_stb, rx_data, tx_stb, tx_data, tx_busy, w_uart_rts_n,
176 5 dgisselq
                // SPI/SD-card flash
177
                o_qspi_cs_n, o_qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod,
178
                // Board lights and switches
179
                i_btn, o_led, o_pwm, { o_pwm_shutdown_n, o_pwm_gain },
180
                // Keypad connections
181
                i_kp_row, o_kp_col,
182
                // UART control
183
                uart_setup,
184
                // GPIO lines
185
                { i_gpio, io_scl, io_sda }, w_gpio
186
                );
187 46 dgisselq
        assign  o_uart_rts_n = (w_uart_rts_n);
188 5 dgisselq
 
189
        //
190
        // Quad SPI support
191
        //
192
        //      Supporting a Quad SPI port requires knowing which direction the
193
        //      wires are going at each instant, whether the device is in full
194
        //      Quad mode in, full quad mode out, or simply the normal SPI
195
        //      port with one wire in and one wire out.  This utilizes our
196
        //      control wires (qspi_bmod) to set the output lines appropriately.
197
        //
198
        assign io_qspi_dat = (~qspi_bmod[1])?({2'b11,1'bz,qspi_dat[0]})
199
                                :((qspi_bmod[0])?(4'bzzzz):(qspi_dat[3:0]));
200
 
201 8 dgisselq
`else
202
        reg     [26:0]   r_counter;
203
        always @(posedge clk_s)
204
                r_counter <= r_counter+1;
205
        assign  o_led[0] = r_counter[26];
206
        assign  o_led[1] = r_counter[25];
207
        assign  o_led[2] = r_counter[24];
208
        assign  o_led[3] = r_counter[23];
209
        // assign       o_led[0] = 1'b1;
210
        // assign       o_led[1] = 1'b0;
211
        // assign       o_led[2] = 1'b1;
212
        // assign       o_led[3] = 1'b0;
213
 
214
        assign  w_gpio = 16'h3;
215
        assign  o_pwm = 1'b0;
216
        assign  o_pwm_shutdown_n = 1'b0;
217
        assign  o_pwm_gain = 1'b0;
218
 
219
        assign  o_depp_wait = (~i_depp_astb_n);
220
        assign  w_depp_data = 8'h00;
221
        assign  io_qspi_dat = 4'bzzzz;
222
        assign  o_qspi_cs_n = 1'b1;
223
        assign  o_qspi_sck = 1'b1;
224
 
225
        assign  uart_setup = 30'h080002b6;
226
 
227 46 dgisselq
        assign  o_uart_rts_n = 1'b0;
228 8 dgisselq
`endif
229 5 dgisselq
        //
230
        // I2C support
231
        //
232
        //      Supporting I2C requires a couple quick adjustments to our
233
        //      GPIO lines.  Specifically, we'll allow that when the output
234
        //      (i.e. w_gpio) pins are high, then the I2C lines float.  They
235
        //      will be (need to be) pulled up by a resistor in order to 
236
        //      match the I2C protocol, but this change makes them look/act
237
        //      more like GPIO pins.
238
        //
239
        assign  io_sda = (w_gpio[0]) ? 1'bz : 1'b0;
240
        assign  io_scl = (w_gpio[1]) ? 1'bz : 1'b0;
241
        assign  o_gpio[15:2] = w_gpio[15:2];
242
 
243 8 dgisselq
        //
244
        // DEPP return data support
245
        //
246
        assign io_depp_data = (~i_depp_write_n)? 8'bzzzz_zzzz : w_depp_data;
247
 
248 5 dgisselq
endmodule

powered by: WebSVN 2.1.0

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