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 |
51 |
dgisselq |
// `define LOWLOGIC_FLASH
|
47 |
5 |
dgisselq |
module alttop(i_clk_8mhz,
|
48 |
|
|
o_qspi_cs_n, o_qspi_sck, io_qspi_dat,
|
49 |
|
|
i_btn, o_led, o_pwm, o_pwm_shutdown_n, o_pwm_gain,
|
50 |
46 |
dgisselq |
i_uart, o_uart, o_uart_rts_n, i_uart_cts_n,
|
51 |
5 |
dgisselq |
i_kp_row, o_kp_col,
|
52 |
|
|
i_gpio, o_gpio,
|
53 |
8 |
dgisselq |
io_scl, io_sda,
|
54 |
|
|
i_depp_astb_n, i_depp_dstb_n, i_depp_write_n, io_depp_data,
|
55 |
|
|
o_depp_wait
|
56 |
|
|
);
|
57 |
5 |
dgisselq |
input i_clk_8mhz;
|
58 |
|
|
//
|
59 |
|
|
// Quad SPI Flash
|
60 |
|
|
output wire o_qspi_cs_n;
|
61 |
|
|
output wire o_qspi_sck;
|
62 |
|
|
inout wire [3:0] io_qspi_dat;
|
63 |
|
|
//
|
64 |
|
|
// General purpose I/O
|
65 |
|
|
input [1:0] i_btn;
|
66 |
|
|
output wire [3:0] o_led;
|
67 |
|
|
output wire o_pwm, o_pwm_shutdown_n, o_pwm_gain;
|
68 |
|
|
//
|
69 |
|
|
// and our serial port
|
70 |
|
|
input i_uart;
|
71 |
|
|
output wire o_uart;
|
72 |
|
|
// and it's associated control wires
|
73 |
46 |
dgisselq |
output wire o_uart_rts_n;
|
74 |
|
|
input i_uart_cts_n;
|
75 |
5 |
dgisselq |
// Our keypad
|
76 |
|
|
input [3:0] i_kp_row;
|
77 |
|
|
output wire [3:0] o_kp_col;
|
78 |
|
|
// and our GPIO
|
79 |
|
|
input [15:2] i_gpio;
|
80 |
|
|
output wire [15:2] o_gpio;
|
81 |
|
|
// and our I2C port
|
82 |
|
|
inout io_scl, io_sda;
|
83 |
8 |
dgisselq |
// Finally, the DEPP interface ... if so enabled
|
84 |
|
|
input i_depp_astb_n, i_depp_dstb_n, i_depp_write_n;
|
85 |
|
|
inout [7:0] io_depp_data;
|
86 |
|
|
output wire o_depp_wait;
|
87 |
5 |
dgisselq |
|
88 |
|
|
//
|
89 |
|
|
// Clock management
|
90 |
|
|
//
|
91 |
|
|
// Generate a usable clock for the rest of the board to run at.
|
92 |
|
|
//
|
93 |
51 |
dgisselq |
wire ck_zero_0, clk_s, clk_sn;
|
94 |
5 |
dgisselq |
|
95 |
|
|
// Clock frequency = (20 / 2) * 8Mhz = 80 MHz
|
96 |
|
|
// Clock period = 12.5 ns
|
97 |
|
|
DCM_SP #(
|
98 |
|
|
.CLKDV_DIVIDE(2.0),
|
99 |
|
|
.CLKFX_DIVIDE(2), // Here's the divide by two
|
100 |
|
|
.CLKFX_MULTIPLY(20), // and here's the multiply by 20
|
101 |
|
|
.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 |
51 |
dgisselq |
.CLKFX180(clk_sn),
|
115 |
5 |
dgisselq |
.PSEN(1'b0),
|
116 |
|
|
.RST(1'b0));
|
117 |
|
|
|
118 |
|
|
//
|
119 |
|
|
// The UART serial interface
|
120 |
|
|
//
|
121 |
|
|
// Perhaps this should be part of our simulation model as well.
|
122 |
|
|
// For historical reasons, internal to Gisselquist Technology,
|
123 |
|
|
// this has remained separate from the simulation, allowing the
|
124 |
|
|
// simulation to bypass whether or not these two functions work.
|
125 |
|
|
//
|
126 |
|
|
wire rx_stb, tx_stb;
|
127 |
|
|
wire [7:0] rx_data, tx_data;
|
128 |
|
|
wire tx_busy;
|
129 |
|
|
wire [29:0] uart_setup;
|
130 |
|
|
|
131 |
51 |
dgisselq |
// Baud rate is set by clock rate / baud rate desired. Thus,
|
132 |
46 |
dgisselq |
// 80 MHz / 9600 Baud = 8333, or about 0x208d. We choose a slow
|
133 |
|
|
// speed such as 9600 Baud to help the CPU keep up with the serial
|
134 |
|
|
// port rate.
|
135 |
|
|
localparam [30:0] UART_SETUP = 31'h4000208d;
|
136 |
|
|
assign uart_setup = UART_SETUP;
|
137 |
|
|
|
138 |
|
|
wire reset_s;
|
139 |
|
|
assign reset_s = 1'b0;
|
140 |
|
|
|
141 |
5 |
dgisselq |
wire rx_break, rx_parity_err, rx_frame_err, rx_ck_uart, tx_break;
|
142 |
|
|
assign tx_break = 1'b0;
|
143 |
46 |
dgisselq |
rxuart #(UART_SETUP)
|
144 |
|
|
rcvuart(clk_s, 1'b0, uart_setup,
|
145 |
5 |
dgisselq |
i_uart, rx_stb, rx_data,
|
146 |
|
|
rx_break, rx_parity_err, rx_frame_err, rx_ck_uart);
|
147 |
46 |
dgisselq |
txuart #(UART_SETUP)
|
148 |
|
|
tcvuart(clk_s, reset_s, uart_setup, tx_break, tx_stb, tx_data,
|
149 |
|
|
i_uart_cts_n, o_uart, tx_busy);
|
150 |
5 |
dgisselq |
|
151 |
|
|
|
152 |
|
|
//
|
153 |
|
|
// ALT-BUSMASTER
|
154 |
|
|
//
|
155 |
|
|
// Busmaster is so named because it contains the wishbone
|
156 |
|
|
// interconnect that all of the internal devices are hung off of.
|
157 |
|
|
// To reconfigure this device for another purpose, usually
|
158 |
|
|
// the busmaster module (i.e. the interconnect) is all that needs
|
159 |
|
|
// to be changed: either to add more devices, or to remove them.
|
160 |
|
|
//
|
161 |
|
|
// This is an alternate version of the busmaster interface,
|
162 |
|
|
// offering no ZipCPU and access to reprogramming via the flash.
|
163 |
|
|
//
|
164 |
51 |
dgisselq |
`ifdef LOWLOGIC_FLASH
|
165 |
|
|
wire [1:0] qspi_sck;
|
166 |
|
|
`else
|
167 |
|
|
wire qspi_sck;
|
168 |
|
|
`endif
|
169 |
|
|
wire qspi_cs_n;
|
170 |
5 |
dgisselq |
wire [3:0] qspi_dat;
|
171 |
|
|
wire [1:0] qspi_bmod;
|
172 |
|
|
wire [15:0] w_gpio;
|
173 |
8 |
dgisselq |
wire [7:0] w_depp_data;
|
174 |
5 |
dgisselq |
|
175 |
46 |
dgisselq |
wire w_uart_rts_n;
|
176 |
8 |
dgisselq |
`ifndef BYPASS_LOGIC
|
177 |
13 |
dgisselq |
altbusmaster slavedbus(clk_s, 1'b0,
|
178 |
5 |
dgisselq |
// External ... bus control (if enabled)
|
179 |
8 |
dgisselq |
// DEPP I/O Control
|
180 |
|
|
i_depp_astb_n, i_depp_dstb_n, i_depp_write_n,
|
181 |
|
|
io_depp_data, w_depp_data, o_depp_wait,
|
182 |
|
|
// External UART interface
|
183 |
46 |
dgisselq |
rx_stb, rx_data, tx_stb, tx_data, tx_busy, w_uart_rts_n,
|
184 |
5 |
dgisselq |
// SPI/SD-card flash
|
185 |
51 |
dgisselq |
qspi_cs_n, qspi_sck, qspi_dat, io_qspi_dat, qspi_bmod,
|
186 |
5 |
dgisselq |
// Board lights and switches
|
187 |
|
|
i_btn, o_led, o_pwm, { o_pwm_shutdown_n, o_pwm_gain },
|
188 |
|
|
// Keypad connections
|
189 |
|
|
i_kp_row, o_kp_col,
|
190 |
|
|
// UART control
|
191 |
|
|
uart_setup,
|
192 |
|
|
// GPIO lines
|
193 |
|
|
{ i_gpio, io_scl, io_sda }, w_gpio
|
194 |
|
|
);
|
195 |
46 |
dgisselq |
assign o_uart_rts_n = (w_uart_rts_n);
|
196 |
5 |
dgisselq |
|
197 |
|
|
//
|
198 |
|
|
// Quad SPI support
|
199 |
|
|
//
|
200 |
|
|
// Supporting a Quad SPI port requires knowing which direction the
|
201 |
|
|
// wires are going at each instant, whether the device is in full
|
202 |
|
|
// Quad mode in, full quad mode out, or simply the normal SPI
|
203 |
|
|
// port with one wire in and one wire out. This utilizes our
|
204 |
|
|
// control wires (qspi_bmod) to set the output lines appropriately.
|
205 |
|
|
//
|
206 |
51 |
dgisselq |
//
|
207 |
|
|
// 2'b0? -- Normal SPI
|
208 |
|
|
// 2'b10 -- Quad Output
|
209 |
|
|
// 2'b11 -- Quad Input
|
210 |
|
|
`ifdef LOWLOGIC_FLASH
|
211 |
|
|
reg r_qspi_cs_n;
|
212 |
|
|
reg [1:0] r_qspi_bmod;
|
213 |
|
|
reg [3:0] r_qspi_dat, r_qspi_z;
|
214 |
|
|
reg [1:0] r_qspi_sck;
|
215 |
|
|
always @(posedge clk_s)
|
216 |
|
|
r_qspi_sck <= qspi_sck;
|
217 |
|
|
xoddr xqspi_sck({clk_s, clk_sn}, r_qspi_sck, o_qspi_sck);
|
218 |
|
|
initial r_qspi_cs_n = 1'b1;
|
219 |
|
|
initial r_qspi_z = 4'b1101;
|
220 |
|
|
always @(posedge clk_s)
|
221 |
|
|
begin
|
222 |
|
|
r_qspi_dat <= (qspi_bmod[1]) ? qspi_dat:{ 3'b111, qspi_dat[0]};
|
223 |
|
|
r_qspi_z <= (!qspi_bmod[1])? 4'b1101
|
224 |
|
|
: ((qspi_bmod[0]) ? 4'h0 : 4'hf);
|
225 |
|
|
r_qspi_cs_n <= qspi_cs_n;
|
226 |
|
|
end
|
227 |
|
|
|
228 |
|
|
assign o_qspi_cs_n = r_qspi_cs_n;
|
229 |
|
|
assign io_qspi_dat[0] = (r_qspi_z[0]) ? r_qspi_dat[0] : 1'bz;
|
230 |
|
|
assign io_qspi_dat[1] = (r_qspi_z[1]) ? r_qspi_dat[1] : 1'bz;
|
231 |
|
|
assign io_qspi_dat[2] = (r_qspi_z[2]) ? r_qspi_dat[2] : 1'bz;
|
232 |
|
|
assign io_qspi_dat[3] = (r_qspi_z[3]) ? r_qspi_dat[3] : 1'bz;
|
233 |
|
|
`else
|
234 |
|
|
assign io_qspi_dat = (!qspi_bmod[1])?({2'b11,1'bz,qspi_dat[0]})
|
235 |
5 |
dgisselq |
:((qspi_bmod[0])?(4'bzzzz):(qspi_dat[3:0]));
|
236 |
|
|
|
237 |
51 |
dgisselq |
assign o_qspi_cs_n = qspi_cs_n;
|
238 |
|
|
assign o_qspi_sck = qspi_sck;
|
239 |
|
|
`endif // LOWLOGIC_FLASH
|
240 |
|
|
|
241 |
|
|
`else // BYPASS_LOGIC
|
242 |
8 |
dgisselq |
reg [26:0] r_counter;
|
243 |
|
|
always @(posedge clk_s)
|
244 |
|
|
r_counter <= r_counter+1;
|
245 |
|
|
assign o_led[0] = r_counter[26];
|
246 |
|
|
assign o_led[1] = r_counter[25];
|
247 |
|
|
assign o_led[2] = r_counter[24];
|
248 |
|
|
assign o_led[3] = r_counter[23];
|
249 |
|
|
// assign o_led[0] = 1'b1;
|
250 |
|
|
// assign o_led[1] = 1'b0;
|
251 |
|
|
// assign o_led[2] = 1'b1;
|
252 |
|
|
// assign o_led[3] = 1'b0;
|
253 |
|
|
|
254 |
|
|
assign w_gpio = 16'h3;
|
255 |
|
|
assign o_pwm = 1'b0;
|
256 |
|
|
assign o_pwm_shutdown_n = 1'b0;
|
257 |
|
|
assign o_pwm_gain = 1'b0;
|
258 |
|
|
|
259 |
|
|
assign o_depp_wait = (~i_depp_astb_n);
|
260 |
|
|
assign w_depp_data = 8'h00;
|
261 |
|
|
assign io_qspi_dat = 4'bzzzz;
|
262 |
|
|
assign o_qspi_cs_n = 1'b1;
|
263 |
|
|
assign o_qspi_sck = 1'b1;
|
264 |
|
|
|
265 |
|
|
assign uart_setup = 30'h080002b6;
|
266 |
|
|
|
267 |
46 |
dgisselq |
assign o_uart_rts_n = 1'b0;
|
268 |
51 |
dgisselq |
`endif // BYPASS_LOGIC
|
269 |
5 |
dgisselq |
//
|
270 |
|
|
// I2C support
|
271 |
|
|
//
|
272 |
|
|
// Supporting I2C requires a couple quick adjustments to our
|
273 |
|
|
// GPIO lines. Specifically, we'll allow that when the output
|
274 |
|
|
// (i.e. w_gpio) pins are high, then the I2C lines float. They
|
275 |
51 |
dgisselq |
// will be (need to be) pulled up by a resistor in order to
|
276 |
5 |
dgisselq |
// match the I2C protocol, but this change makes them look/act
|
277 |
|
|
// more like GPIO pins.
|
278 |
|
|
//
|
279 |
|
|
assign io_sda = (w_gpio[0]) ? 1'bz : 1'b0;
|
280 |
|
|
assign io_scl = (w_gpio[1]) ? 1'bz : 1'b0;
|
281 |
|
|
assign o_gpio[15:2] = w_gpio[15:2];
|
282 |
|
|
|
283 |
8 |
dgisselq |
//
|
284 |
|
|
// DEPP return data support
|
285 |
|
|
//
|
286 |
|
|
assign io_depp_data = (~i_depp_write_n)? 8'bzzzz_zzzz : w_depp_data;
|
287 |
|
|
|
288 |
5 |
dgisselq |
endmodule
|