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