1 |
25 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: migsdram.v
|
4 |
|
|
//
|
5 |
|
|
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
6 |
|
|
//
|
7 |
|
|
// Purpose: To interface the Arty to a MIG Generated SDRAM
|
8 |
|
|
//
|
9 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
10 |
|
|
// Gisselquist Technology, LLC
|
11 |
|
|
//
|
12 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
13 |
|
|
//
|
14 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
15 |
|
|
//
|
16 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
17 |
|
|
// modify it under the terms of the GNU General Public License as published
|
18 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
19 |
|
|
// your option) any later version.
|
20 |
|
|
//
|
21 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
24 |
|
|
// for more details.
|
25 |
|
|
//
|
26 |
|
|
// You should have received a copy of the GNU General Public License along
|
27 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
28 |
|
|
// target there if the PDF file isn't present.) If not, see
|
29 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
30 |
|
|
//
|
31 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
32 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
33 |
|
|
//
|
34 |
|
|
//
|
35 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
//
|
37 |
|
|
//
|
38 |
|
|
module migsdram(i_clk, i_clk_200mhz, o_sys_clk, i_rst, o_sys_reset,
|
39 |
|
|
// Wishbone components
|
40 |
|
|
i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel,
|
41 |
|
|
o_wb_ack, o_wb_stall, o_wb_data, o_wb_err,
|
42 |
|
|
// SDRAM connections
|
43 |
|
|
o_ddr_ck_p, o_ddr_ck_n,
|
44 |
|
|
o_ddr_reset_n, o_ddr_cke,
|
45 |
|
|
o_ddr_cs_n, o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n,
|
46 |
|
|
o_ddr_ba, o_ddr_addr,
|
47 |
|
|
o_ddr_odt, o_ddr_dm,
|
48 |
|
|
io_ddr_dqs_p, io_ddr_dqs_n,
|
49 |
|
|
io_ddr_data,
|
50 |
|
|
// Debug connection
|
51 |
|
|
o_ram_dbg
|
52 |
|
|
);
|
53 |
|
|
parameter DDRWIDTH = 16, WBDATAWIDTH=32;
|
54 |
|
|
parameter AXIDWIDTH = 6;
|
55 |
|
|
// The SDRAM address bits (RAMABITS) are a touch more difficult to work
|
56 |
|
|
// out. Here we leave them as a fixed parameter, but there are
|
57 |
|
|
// consequences to this. Specifically, the wishbone data width, the
|
58 |
|
|
// wishbone address width, and this number have interactions not
|
59 |
|
|
// well captured here.
|
60 |
|
|
parameter RAMABITS = 28;
|
61 |
|
|
// All DDR3 memories have 8 timeslots. This, if the DDR3 memory
|
62 |
|
|
// has 16 bits to it (as above), the entire transaction must take
|
63 |
|
|
// AXIWIDTH bits ...
|
64 |
|
|
localparam AXIWIDTH= DDRWIDTH *8;
|
65 |
|
|
localparam DW=WBDATAWIDTH;
|
66 |
|
|
localparam AW=(WBDATAWIDTH==32)? RAMABITS-2
|
67 |
|
|
:((WBDATAWIDTH==64) ? RAMABITS-3
|
68 |
|
|
:((WBDATAWIDTH==128) ? RAMABITS-4
|
69 |
|
|
: RAMABITS-5)); // (WBDATAWIDTH==256)
|
70 |
|
|
localparam SELW= (WBDATAWIDTH/8);
|
71 |
|
|
//
|
72 |
|
|
input i_clk, i_clk_200mhz, i_rst;
|
73 |
|
|
output o_sys_clk;
|
74 |
|
|
output reg o_sys_reset;
|
75 |
|
|
//
|
76 |
|
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
77 |
|
|
input [(AW-1):0] i_wb_addr;
|
78 |
|
|
input [(DW-1):0] i_wb_data;
|
79 |
|
|
input [(SELW-1):0] i_wb_sel;
|
80 |
|
|
output wire o_wb_ack, o_wb_stall;
|
81 |
|
|
output wire [(DW-1):0] o_wb_data;
|
82 |
|
|
output wire o_wb_err;
|
83 |
|
|
//
|
84 |
|
|
output wire [0:0] o_ddr_ck_p, o_ddr_ck_n;
|
85 |
|
|
output wire [0:0] o_ddr_cke;
|
86 |
|
|
output wire o_ddr_reset_n,
|
87 |
|
|
o_ddr_ras_n, o_ddr_cas_n, o_ddr_we_n;
|
88 |
|
|
output wire [0:0] o_ddr_cs_n;
|
89 |
|
|
output wire [2:0] o_ddr_ba;
|
90 |
|
|
output wire [13:0] o_ddr_addr;
|
91 |
|
|
output wire [0:0] o_ddr_odt;
|
92 |
|
|
output wire [(DDRWIDTH/8-1):0] o_ddr_dm;
|
93 |
|
|
inout wire [1:0] io_ddr_dqs_p, io_ddr_dqs_n;
|
94 |
|
|
inout wire [(DDRWIDTH-1):0] io_ddr_data;
|
95 |
|
|
|
96 |
|
|
output wire [31:0] o_ram_dbg;
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
`define SDRAM_ACCESS
|
100 |
|
|
`ifdef SDRAM_ACCESS
|
101 |
|
|
|
102 |
|
|
wire aresetn;
|
103 |
|
|
assign aresetn = 1'b1; // Never reset
|
104 |
|
|
|
105 |
|
|
// Write address channel
|
106 |
|
|
wire [(AXIDWIDTH-1):0] s_axi_awid;
|
107 |
|
|
wire [(RAMABITS-1):0] s_axi_awaddr;
|
108 |
|
|
wire [7:0] s_axi_awlen;
|
109 |
|
|
wire [2:0] s_axi_awsize;
|
110 |
|
|
wire [1:0] s_axi_awburst;
|
111 |
|
|
wire [0:0] s_axi_awlock;
|
112 |
|
|
wire [3:0] s_axi_awcache;
|
113 |
|
|
wire [2:0] s_axi_awprot;
|
114 |
|
|
wire [3:0] s_axi_awqos;
|
115 |
|
|
wire s_axi_awvalid;
|
116 |
|
|
wire s_axi_awready;
|
117 |
|
|
// Writei data channel
|
118 |
|
|
wire [(AXIWIDTH-1):0] s_axi_wdata;
|
119 |
|
|
wire [(AXIWIDTH/8-1):0] s_axi_wstrb;
|
120 |
|
|
wire s_axi_wlast, s_axi_wvalid, s_axi_wready;
|
121 |
|
|
// Write response channel
|
122 |
|
|
wire s_axi_bready;
|
123 |
|
|
wire [(AXIDWIDTH-1):0] s_axi_bid;
|
124 |
|
|
wire [1:0] s_axi_bresp;
|
125 |
|
|
wire s_axi_bvalid;
|
126 |
|
|
|
127 |
|
|
// Read address channel
|
128 |
|
|
wire [(AXIDWIDTH-1):0] s_axi_arid;
|
129 |
|
|
wire [(RAMABITS-1):0] s_axi_araddr;
|
130 |
|
|
wire [7:0] s_axi_arlen;
|
131 |
|
|
wire [2:0] s_axi_arsize;
|
132 |
|
|
wire [1:0] s_axi_arburst;
|
133 |
|
|
wire [0:0] s_axi_arlock;
|
134 |
|
|
wire [3:0] s_axi_arcache;
|
135 |
|
|
wire [2:0] s_axi_arprot;
|
136 |
|
|
wire [3:0] s_axi_arqos;
|
137 |
|
|
wire s_axi_arvalid;
|
138 |
|
|
// Read response/data channel
|
139 |
|
|
wire [(AXIDWIDTH-1):0] s_axi_rid;
|
140 |
|
|
wire [(AXIWIDTH-1):0] s_axi_rdata;
|
141 |
|
|
wire [1:0] s_axi_rresp;
|
142 |
|
|
wire s_axi_rlast;
|
143 |
|
|
wire s_axi_rvalid;
|
144 |
|
|
|
145 |
|
|
// Other wires ...
|
146 |
|
|
wire init_calib_complete, mmcm_locked;
|
147 |
|
|
wire app_sr_active, app_ref_ack, app_zq_ack;
|
148 |
|
|
wire app_sr_req, app_ref_req, app_zq_req;
|
149 |
|
|
wire w_sys_reset;
|
150 |
|
|
wire [11:0] w_device_temp;
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
mig_axis mig_sdram(
|
154 |
|
|
.ddr3_ck_p(o_ddr_ck_p), .ddr3_ck_n(o_ddr_ck_n),
|
155 |
|
|
.ddr3_reset_n(o_ddr_reset_n), .ddr3_cke(o_ddr_cke),
|
156 |
|
|
.ddr3_cs_n(o_ddr_cs_n), .ddr3_ras_n(o_ddr_ras_n),
|
157 |
|
|
.ddr3_we_n(o_ddr_we_n), .ddr3_cas_n(o_ddr_cas_n),
|
158 |
|
|
.ddr3_ba(o_ddr_ba), .ddr3_addr(o_ddr_addr),
|
159 |
|
|
.ddr3_odt(o_ddr_odt),
|
160 |
|
|
.ddr3_dqs_p(io_ddr_dqs_p), .ddr3_dqs_n(io_ddr_dqs_n),
|
161 |
|
|
.ddr3_dq(io_ddr_data), .ddr3_dm(o_ddr_dm),
|
162 |
|
|
//
|
163 |
|
|
.sys_clk_i(i_clk),
|
164 |
|
|
.clk_ref_i(i_clk_200mhz),
|
165 |
|
|
.ui_clk(o_sys_clk),
|
166 |
|
|
.ui_clk_sync_rst(w_sys_reset),
|
167 |
|
|
.mmcm_locked(mmcm_locked),
|
168 |
|
|
.aresetn(aresetn),
|
169 |
|
|
.app_sr_req(1'b0),
|
170 |
|
|
.app_ref_req(1'b0),
|
171 |
|
|
.app_zq_req(1'b0),
|
172 |
|
|
.app_sr_active(app_sr_active),
|
173 |
|
|
.app_ref_ack(app_ref_ack),
|
174 |
|
|
.app_zq_ack(app_zq_ack),
|
175 |
|
|
//
|
176 |
|
|
.s_axi_awid(s_axi_awid), .s_axi_awaddr(s_axi_awaddr),
|
177 |
|
|
.s_axi_awlen(s_axi_awlen), .s_axi_awsize(s_axi_awsize),
|
178 |
|
|
.s_axi_awburst(s_axi_awburst), .s_axi_awlock(s_axi_awlock),
|
179 |
|
|
.s_axi_awcache(s_axi_awcache), .s_axi_awprot(s_axi_awprot),
|
180 |
|
|
.s_axi_awqos(s_axi_awqos), .s_axi_awvalid(s_axi_awvalid),
|
181 |
|
|
.s_axi_awready(s_axi_awready),
|
182 |
|
|
//
|
183 |
|
|
.s_axi_wready( s_axi_wready),
|
184 |
|
|
.s_axi_wdata( s_axi_wdata),
|
185 |
|
|
.s_axi_wstrb( s_axi_wstrb),
|
186 |
|
|
.s_axi_wlast( s_axi_wlast),
|
187 |
|
|
.s_axi_wvalid( s_axi_wvalid),
|
188 |
|
|
//
|
189 |
|
|
.s_axi_bready(s_axi_bready), .s_axi_bid(s_axi_bid),
|
190 |
|
|
.s_axi_bresp(s_axi_bresp), .s_axi_bvalid(s_axi_bvalid),
|
191 |
|
|
//
|
192 |
|
|
.s_axi_arid(s_axi_arid), .s_axi_araddr(s_axi_araddr),
|
193 |
|
|
.s_axi_arlen(s_axi_arlen), .s_axi_arsize(s_axi_arsize),
|
194 |
|
|
.s_axi_arburst(s_axi_arburst), .s_axi_arlock(s_axi_arlock),
|
195 |
|
|
.s_axi_arcache(s_axi_arcache), .s_axi_arprot(s_axi_arprot),
|
196 |
|
|
.s_axi_arqos(s_axi_arqos), .s_axi_arvalid(s_axi_arvalid),
|
197 |
|
|
.s_axi_arready(s_axi_arready),
|
198 |
|
|
//
|
199 |
|
|
.s_axi_rready(s_axi_rready), .s_axi_rid(s_axi_rid),
|
200 |
|
|
.s_axi_rdata(s_axi_rdata), .s_axi_rresp(s_axi_rresp),
|
201 |
|
|
.s_axi_rlast(s_axi_rlast), .s_axi_rvalid(s_axi_rvalid),
|
202 |
|
|
.init_calib_complete(init_calib_complete),
|
203 |
|
|
.sys_rst(i_rst),
|
204 |
|
|
.device_temp(w_device_temp)
|
205 |
|
|
);
|
206 |
|
|
|
207 |
|
|
wbm2axisp #(
|
208 |
|
|
.C_AXI_ID_WIDTH(AXIDWIDTH),
|
209 |
|
|
.C_AXI_DATA_WIDTH(AXIWIDTH),
|
210 |
|
|
.C_AXI_ADDR_WIDTH(RAMABITS),
|
211 |
|
|
.AW(AW), .DW(DW)
|
212 |
|
|
)
|
213 |
|
|
bus_translator (
|
214 |
|
|
.i_clk(o_sys_clk),
|
215 |
|
|
// .i_reset(i_rst), // internally unused
|
216 |
|
|
// Write address channel signals
|
217 |
|
|
.o_axi_awid( s_axi_awid),
|
218 |
|
|
.o_axi_awaddr( s_axi_awaddr),
|
219 |
|
|
.o_axi_awlen( s_axi_awlen),
|
220 |
|
|
.o_axi_awsize( s_axi_awsize),
|
221 |
|
|
.o_axi_awburst( s_axi_awburst),
|
222 |
|
|
.o_axi_awlock( s_axi_awlock),
|
223 |
|
|
.o_axi_awcache( s_axi_awcache),
|
224 |
|
|
.o_axi_awprot( s_axi_awprot), // s_axi_awqos
|
225 |
|
|
.o_axi_awqos( s_axi_awqos), // s_axi_awqos
|
226 |
|
|
.o_axi_awvalid( s_axi_awvalid),
|
227 |
|
|
.i_axi_awready( s_axi_awready),
|
228 |
|
|
//
|
229 |
|
|
.i_axi_wready( s_axi_wready),
|
230 |
|
|
.o_axi_wdata( s_axi_wdata),
|
231 |
|
|
.o_axi_wstrb( s_axi_wstrb),
|
232 |
|
|
.o_axi_wlast( s_axi_wlast),
|
233 |
|
|
.o_axi_wvalid( s_axi_wvalid),
|
234 |
|
|
//
|
235 |
|
|
.o_axi_bready( s_axi_bready),
|
236 |
|
|
.i_axi_bid( s_axi_bid),
|
237 |
|
|
.i_axi_bresp( s_axi_bresp),
|
238 |
|
|
.i_axi_bvalid( s_axi_bvalid),
|
239 |
|
|
//
|
240 |
|
|
.i_axi_arready( s_axi_arready),
|
241 |
|
|
.o_axi_arid( s_axi_arid),
|
242 |
|
|
.o_axi_araddr( s_axi_araddr),
|
243 |
|
|
.o_axi_arlen( s_axi_arlen),
|
244 |
|
|
.o_axi_arsize( s_axi_arsize),
|
245 |
|
|
.o_axi_arburst( s_axi_arburst),
|
246 |
|
|
.o_axi_arlock( s_axi_arlock),
|
247 |
|
|
.o_axi_arcache( s_axi_arcache),
|
248 |
|
|
.o_axi_arprot( s_axi_arprot),
|
249 |
|
|
.o_axi_arqos( s_axi_arqos),
|
250 |
|
|
.o_axi_arvalid( s_axi_arvalid),
|
251 |
|
|
//
|
252 |
|
|
.o_axi_rready( s_axi_rready),
|
253 |
|
|
.i_axi_rid( s_axi_rid),
|
254 |
|
|
.i_axi_rdata( s_axi_rdata),
|
255 |
|
|
.i_axi_rresp( s_axi_rresp),
|
256 |
|
|
.i_axi_rlast( s_axi_rlast),
|
257 |
|
|
.i_axi_rvalid( s_axi_rvalid),
|
258 |
|
|
//
|
259 |
|
|
.i_wb_cyc( i_wb_cyc),
|
260 |
|
|
.i_wb_stb( i_wb_stb),
|
261 |
|
|
.i_wb_we( i_wb_we),
|
262 |
|
|
.i_wb_addr( i_wb_addr),
|
263 |
|
|
.i_wb_data( i_wb_data),
|
264 |
|
|
.i_wb_sel( i_wb_sel),
|
265 |
|
|
//
|
266 |
|
|
.o_wb_ack( o_wb_ack),
|
267 |
|
|
.o_wb_stall( o_wb_stall),
|
268 |
|
|
.o_wb_data( o_wb_data),
|
269 |
|
|
.o_wb_err( o_wb_err),
|
270 |
|
|
//
|
271 |
|
|
.o_dbg( o_ram_dbg)
|
272 |
|
|
);
|
273 |
|
|
|
274 |
|
|
// Convert from active low to active high, *and* hold the system in
|
275 |
|
|
// reset until the memory comes up.
|
276 |
|
|
initial o_sys_reset = 1'b1;
|
277 |
|
|
always @(posedge o_sys_clk)
|
278 |
|
|
o_sys_reset <= (w_sys_reset)
|
279 |
|
|
||(!init_calib_complete)
|
280 |
|
|
||(!mmcm_locked);
|
281 |
|
|
`else
|
282 |
|
|
BUFG sysclk(i_clk, o_sys_clk);
|
283 |
|
|
initial o_sys_reset <= 1'b1;
|
284 |
|
|
always @(posedge i_clk)
|
285 |
|
|
o_sys_reset <= 1'b1;
|
286 |
|
|
|
287 |
|
|
OBUFDS ckobuf(.I(i_clk), .O(o_ddr_ck_p), .OB(o_ddr_ck_n));
|
288 |
|
|
|
289 |
|
|
assign o_ddr_reset_n = 1'b0;
|
290 |
|
|
assign o_ddr_cke[0] = 1'b0;
|
291 |
|
|
assign o_ddr_cs_n[0] = 1'b1;
|
292 |
|
|
assign o_ddr_cas_n = 1'b1;
|
293 |
|
|
assign o_ddr_ras_n = 1'b1;
|
294 |
|
|
assign o_ddr_we_n = 1'b1;
|
295 |
|
|
assign o_ddr_ba = 3'h0;
|
296 |
|
|
assign o_ddr_addr = 14'h00;
|
297 |
|
|
assign o_ddr_dm = 2'b00;
|
298 |
|
|
assign io_ddr_data = 16'h0;
|
299 |
|
|
|
300 |
|
|
OBUFDS dqsbufa(.I(i_clk), .O(io_ddr_dqs_p[1]), .OB(io_ddr_dqs_n[1]));
|
301 |
|
|
OBUFDS dqsbufb(.I(i_clk), .O(io_ddr_dqs_p[0]), .OB(io_ddr_dqs_n[0]));
|
302 |
|
|
|
303 |
|
|
`endif
|
304 |
|
|
|
305 |
|
|
endmodule
|
306 |
|
|
|
307 |
|
|
|