1 |
2 |
dgisselq |
`timescale 10ns / 100ps
|
2 |
|
|
///////////////////////////////////////////////////////////////////////////
|
3 |
|
|
//
|
4 |
|
|
// Filename: toplevel.v
|
5 |
|
|
//
|
6 |
|
|
// Project: XuLA2 board
|
7 |
|
|
//
|
8 |
|
|
// Purpose: This is the _top_level_ verilog file for the XuLA2-LX25
|
9 |
|
|
// SoC project. Everything else fits underneath here (logically).
|
10 |
|
|
// This is also the only file that will not go through Verilator. Specific
|
11 |
|
|
// to this file are the Xilinx primitives necessary to build for the
|
12 |
|
|
// XuLA2 board--with the only exception being the ICAPE_SPARTAN6 interface.
|
13 |
|
|
//
|
14 |
|
|
//
|
15 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
16 |
|
|
// Gisselquist Technology, LLC
|
17 |
|
|
//
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////
|
19 |
|
|
//
|
20 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
21 |
|
|
//
|
22 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
23 |
|
|
// modify it under the terms of the GNU General Public License as published
|
24 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
25 |
|
|
// your option) any later version.
|
26 |
|
|
//
|
27 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
28 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
29 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
30 |
|
|
// for more details.
|
31 |
|
|
//
|
32 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
33 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
34 |
|
|
//
|
35 |
|
|
//
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////
|
37 |
|
|
//
|
38 |
|
|
//
|
39 |
|
|
// `define HELLO_WORLD
|
40 |
|
|
// `define ECHO_TEST
|
41 |
|
|
//
|
42 |
|
|
module toplevel(i_clk_12mhz,
|
43 |
|
|
i_ram_feedback_clk,
|
44 |
|
|
o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
|
45 |
|
|
o_ram_clk, o_ram_cke, o_ram_cs_n, o_ram_ras_n, o_ram_cas_n,
|
46 |
|
|
o_ram_we_n, o_ram_bs, o_ram_addr, o_ram_udqm, o_ram_ldqm,
|
47 |
|
|
io_ram_data,
|
48 |
|
|
i_gpio, o_gpio, o_pwm, i_rx_uart, o_tx_uart);
|
49 |
|
|
input i_clk_12mhz;
|
50 |
|
|
input i_ram_feedback_clk;
|
51 |
|
|
//
|
52 |
|
|
// SPI connection(s): Flash and SD Card
|
53 |
|
|
output wire o_sf_cs_n;
|
54 |
|
|
output wire o_sd_cs_n;
|
55 |
|
|
output wire o_spi_sck;
|
56 |
|
|
output wire o_spi_mosi;
|
57 |
|
|
input i_spi_miso;
|
58 |
|
|
//
|
59 |
|
|
// SD RAM
|
60 |
|
|
output wire o_ram_clk, o_ram_cke;
|
61 |
|
|
output wire o_ram_cs_n, o_ram_ras_n, o_ram_cas_n, o_ram_we_n;
|
62 |
|
|
output wire [1:0] o_ram_bs;
|
63 |
|
|
output wire [12:0] o_ram_addr;
|
64 |
|
|
output wire o_ram_udqm, o_ram_ldqm;
|
65 |
|
|
inout wire [15:0] io_ram_data;
|
66 |
|
|
//
|
67 |
|
|
// General purpose I/O
|
68 |
|
|
// output [31:0] io_chan;
|
69 |
|
|
input [13:0] i_gpio;
|
70 |
|
|
output wire [14:0] o_gpio;
|
71 |
|
|
output wire o_pwm;
|
72 |
|
|
input i_rx_uart;
|
73 |
|
|
output wire o_tx_uart;
|
74 |
|
|
|
75 |
|
|
/////
|
76 |
|
|
wire [7:0] rx_data, tx_data;
|
77 |
|
|
wire rx_stb, tx_stb, tx_busy;
|
78 |
|
|
wire clk_s, reset_s, intermediate_clk, intermediate_clk_n,
|
79 |
|
|
ck_zero_0;
|
80 |
|
|
wire ck_zero_1;
|
81 |
|
|
|
82 |
|
|
DCM_SP #(
|
83 |
|
|
.CLKDV_DIVIDE(2.0),
|
84 |
|
|
.CLKFX_DIVIDE(3),
|
85 |
9 |
dgisselq |
.CLKFX_MULTIPLY(19),
|
86 |
2 |
dgisselq |
.CLKIN_DIVIDE_BY_2("FALSE"),
|
87 |
|
|
.CLKIN_PERIOD(83.333333),
|
88 |
|
|
.CLKOUT_PHASE_SHIFT("NONE"),
|
89 |
|
|
.CLK_FEEDBACK("1X"),
|
90 |
|
|
.DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
|
91 |
|
|
.DLL_FREQUENCY_MODE("LOW"),
|
92 |
|
|
.DUTY_CYCLE_CORRECTION("TRUE"),
|
93 |
|
|
.PHASE_SHIFT(0),
|
94 |
|
|
.STARTUP_WAIT("TRUE")
|
95 |
|
|
) u0( .CLKIN(i_clk_12mhz),
|
96 |
|
|
.CLK0(ck_zero_0),
|
97 |
|
|
.CLKFB(ck_zero_0),
|
98 |
|
|
.CLKFX(clk_s),
|
99 |
|
|
// .CLKFX180(intermediate_clk_n),
|
100 |
|
|
.PSEN(1'b0),
|
101 |
|
|
.RST(1'b0));
|
102 |
|
|
|
103 |
|
|
DCM_SP #(
|
104 |
|
|
.CLKDV_DIVIDE(2),
|
105 |
|
|
.CLKFX_MULTIPLY(2),
|
106 |
|
|
.CLKFX_DIVIDE(2),
|
107 |
|
|
.CLKOUT_PHASE_SHIFT("FIXED"),
|
108 |
|
|
.CLK_FEEDBACK("1X"),
|
109 |
|
|
.DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
|
110 |
|
|
.DLL_FREQUENCY_MODE("LOW"),
|
111 |
|
|
.DUTY_CYCLE_CORRECTION("TRUE"),
|
112 |
|
|
// At a clock of 92MHz ...
|
113 |
|
|
// Didn't work at -64, -70, -76 is worse than the other two
|
114 |
|
|
// -56: Write works, 0x96 reads work
|
115 |
|
|
// -48: Write fails, 0x0183 or 0x351 is first write that fails
|
116 |
|
|
// -40: Write fails, 0x071a,176a,0x576
|
117 |
|
|
// -56 was my working choice at 92 MHz
|
118 |
|
|
// That would be about a 2.4ns delay from clock to
|
119 |
|
|
// data.
|
120 |
|
|
// Suddenly needed to shift to 80 MHz.
|
121 |
|
|
// -56 no longer sort of works
|
122 |
|
|
// -49 writes seem to work, reads ... not so much
|
123 |
|
|
// -45 writes no longer working ??
|
124 |
|
|
// Read fails @ 0x891, 0x58e, @0x3d65, @0x0aec,
|
125 |
|
|
// @0x11b8, @0beb, @0x01014
|
126 |
|
|
// Trying a different approach: register in i_ram_feedback_clk,
|
127 |
|
|
// followed by o_ram_clk, instead of registering on
|
128 |
|
|
// clk_s second. Starting build at 1857
|
129 |
|
|
// Okay, so that was an error, now they are referenced to
|
130 |
|
|
// intermediate_clk, and I still need to try
|
131 |
|
|
// intermediate_clk_n if that doesn't work.
|
132 |
|
|
// THIS NEEDS A DELAY ADJUSTMENT: WBSDRAMNG adjusted from
|
133 |
|
|
// 6 to 5, and rebuild started at 1914. (finished by 1930)
|
134 |
|
|
// This one has read bugs at 0x027, 0x030, 0x039, 0x021
|
135 |
|
|
// etc. So we are worse.
|
136 |
|
|
// (We also failed timing--I did nothing to fix that)
|
137 |
|
|
//
|
138 |
|
|
// tho ... even if this works, it is wrong. The data lines
|
139 |
|
|
// going into wbsdramng need to be clocked on the system clock
|
140 |
|
|
// on entrance. Thus, the last always@ block must clock these
|
141 |
|
|
// lines on clk_s. This is fixed, and cannot change.
|
142 |
|
|
// This leaves us with a couple options for clocking the first
|
143 |
|
|
// always block:
|
144 |
|
|
//
|
145 |
|
|
// i_ram_feedback_clk, posedge (the right answer ... but
|
146 |
|
|
// giving me problems)
|
147 |
|
|
// clk_s pos/neg edge
|
148 |
|
|
// intermediate_clk posedge (Build started at 1932)
|
149 |
|
|
// Result: much worse!!
|
150 |
|
|
// intermediate_clk_n posedge (delay of 6 needed, not
|
151 |
|
|
// tested as a result.
|
152 |
|
|
//
|
153 |
|
|
//
|
154 |
|
|
.PHASE_SHIFT(-45),
|
155 |
|
|
.STARTUP_WAIT("TRUE")
|
156 |
|
|
) u1( .CLKIN(clk_s),
|
157 |
|
|
.CLK0(ck_zero_1),
|
158 |
|
|
.CLKFB(ck_zero_1),
|
159 |
|
|
.CLK180(intermediate_clk_n),
|
160 |
|
|
.PSEN(1'b0),
|
161 |
|
|
.RST(1'b0));
|
162 |
|
|
assign intermediate_clk = ck_zero_1;
|
163 |
|
|
|
164 |
|
|
ODDR2 u2( .Q(o_ram_clk),
|
165 |
|
|
.C0(intermediate_clk),
|
166 |
|
|
.C1(intermediate_clk_n),
|
167 |
|
|
.CE(1'b1), .D0(1'b1), .D1(1'b0), .R(1'b0), .S(1'b0));
|
168 |
|
|
|
169 |
|
|
// Generate active-high reset.
|
170 |
|
|
/*
|
171 |
|
|
reg r_reset;
|
172 |
|
|
initial r_reset = 1'b1;
|
173 |
|
|
always @(posedge i_clk_12mhz)
|
174 |
|
|
r_reset <= 1'b0;
|
175 |
|
|
*/
|
176 |
|
|
assign reset_s = 1'b0;
|
177 |
|
|
|
178 |
|
|
jtagser jtagtxrx(clk_s, rx_stb, rx_data, tx_stb, tx_data, tx_busy);
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
wire [15:0] ram_data;
|
182 |
|
|
wire ram_drive_data;
|
183 |
|
|
reg [15:0] r_ram_data;
|
184 |
|
|
|
185 |
|
|
busmaster #(24,15,14)
|
186 |
|
|
wbbus(clk_s, reset_s,
|
187 |
|
|
// External JTAG bus control
|
188 |
|
|
rx_stb, rx_data, tx_stb, tx_data, tx_busy,
|
189 |
|
|
// Board lights and switches ... none
|
190 |
|
|
// SPI/SD-card flash
|
191 |
|
|
o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
|
192 |
|
|
// SDRAM interface
|
193 |
|
|
// o_ram_clk, // SDRAM clock = clk_100mhz_s = clk_s
|
194 |
|
|
o_ram_cs_n, // Chip select
|
195 |
|
|
o_ram_cke, // Clock enable
|
196 |
|
|
o_ram_ras_n, // Row address strobe
|
197 |
|
|
o_ram_cas_n, // Column address strobe
|
198 |
|
|
o_ram_we_n, // Write enable
|
199 |
|
|
o_ram_bs, // Bank select
|
200 |
|
|
o_ram_addr, // Address lines
|
201 |
|
|
ram_drive_data,
|
202 |
|
|
r_ram_data, // Data lines (input)
|
203 |
|
|
ram_data, // Data lines (output)
|
204 |
|
|
{ o_ram_udqm, o_ram_ldqm },
|
205 |
|
|
// GPIO
|
206 |
|
|
i_gpio, o_gpio, o_pwm, i_rx_uart, o_tx_uart
|
207 |
|
|
);
|
208 |
|
|
|
209 |
|
|
assign io_ram_data = (ram_drive_data) ? ram_data : 16'bzzzz_zzzz_zzzz_zzzz;
|
210 |
|
|
|
211 |
|
|
reg [15:0] r_ram_data_ext_clk;
|
212 |
|
|
// always @(posedge intermediate_clk_n)
|
213 |
|
|
always @(posedge clk_s)
|
214 |
|
|
r_ram_data_ext_clk <= io_ram_data;
|
215 |
|
|
always @(posedge clk_s)
|
216 |
|
|
r_ram_data <= r_ram_data_ext_clk;
|
217 |
|
|
|
218 |
|
|
endmodule
|