1 |
19 |
dinesha |
/*********************************************************************
|
2 |
|
|
|
3 |
|
|
SDRAM Controller top File
|
4 |
|
|
|
5 |
|
|
This file is part of the sdram controller project
|
6 |
|
|
http://www.opencores.org/cores/sdr_ctrl/
|
7 |
|
|
|
8 |
|
|
Description: SDRAM Controller Top Module.
|
9 |
|
|
Support 81/6/32 Bit SDRAM.
|
10 |
|
|
Column Address is Programmable
|
11 |
|
|
Bank Bit are 2 Bit
|
12 |
|
|
Row Bits are 12 Bits
|
13 |
|
|
|
14 |
|
|
This block integrate following sub modules
|
15 |
|
|
|
16 |
|
|
sdrc_core
|
17 |
|
|
SDRAM Controller file
|
18 |
|
|
wb2sdrc
|
19 |
|
|
This module transalate the bus protocl from wishbone to custome
|
20 |
|
|
sdram controller
|
21 |
|
|
|
22 |
|
|
To Do:
|
23 |
|
|
nothing
|
24 |
|
|
|
25 |
|
|
Author(s): Dinesh Annayya, dinesha@opencores.org
|
26 |
|
|
Version : 0.0 - 8th Jan 2012
|
27 |
|
|
Initial version with 16/32 Bit SDRAM Support
|
28 |
|
|
: 0.1 - 24th Jan 2012
|
29 |
|
|
8 Bit SDRAM Support is added
|
30 |
|
|
0.2 - 31st Jan 2012
|
31 |
|
|
sdram_dq and sdram_pad_clk are internally generated
|
32 |
|
|
0.3 - 26th April 2013
|
33 |
|
|
Sdram Address witdh is increased from 12 to 13bits
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
Copyright (C) 2000 Authors and OPENCORES.ORG
|
37 |
|
|
|
38 |
|
|
This source file may be used and distributed without
|
39 |
|
|
restriction provided that this copyright statement is not
|
40 |
|
|
removed from the file and that any derivative work contains
|
41 |
|
|
the original copyright notice and the associated disclaimer.
|
42 |
|
|
|
43 |
|
|
This source file is free software; you can redistribute it
|
44 |
|
|
and/or modify it under the terms of the GNU Lesser General
|
45 |
|
|
Public License as published by the Free Software Foundation;
|
46 |
|
|
either version 2.1 of the License, or (at your option) any
|
47 |
|
|
later version.
|
48 |
|
|
|
49 |
|
|
This source is distributed in the hope that it will be
|
50 |
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied
|
51 |
|
|
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
52 |
|
|
PURPOSE. See the GNU Lesser General Public License for more
|
53 |
|
|
details.
|
54 |
|
|
|
55 |
|
|
You should have received a copy of the GNU Lesser General
|
56 |
|
|
Public License along with this source; if not, download it
|
57 |
|
|
from http://www.opencores.org/lgpl.shtml
|
58 |
|
|
|
59 |
|
|
*******************************************************************/
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
`include "sdrc_define.v"
|
63 |
|
|
module sdrc_top
|
64 |
|
|
(
|
65 |
|
|
cfg_sdr_width ,
|
66 |
|
|
cfg_colbits ,
|
67 |
|
|
|
68 |
|
|
// WB bus
|
69 |
|
|
wb_rst_i ,
|
70 |
|
|
wb_clk_i ,
|
71 |
|
|
|
72 |
|
|
wb_stb_i ,
|
73 |
|
|
wb_ack_o ,
|
74 |
|
|
wb_addr_i ,
|
75 |
|
|
wb_we_i ,
|
76 |
|
|
wb_dat_i ,
|
77 |
|
|
wb_sel_i ,
|
78 |
|
|
wb_dat_o ,
|
79 |
|
|
wb_cyc_i ,
|
80 |
|
|
wb_cti_i ,
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
/* Interface to SDRAMs */
|
84 |
|
|
sdram_clk ,
|
85 |
|
|
sdram_resetn ,
|
86 |
|
|
sdr_cs_n ,
|
87 |
|
|
sdr_cke ,
|
88 |
|
|
sdr_ras_n ,
|
89 |
|
|
sdr_cas_n ,
|
90 |
|
|
sdr_we_n ,
|
91 |
|
|
sdr_dqm ,
|
92 |
|
|
sdr_ba ,
|
93 |
|
|
sdr_addr ,
|
94 |
20 |
dinesha |
pad_sdr_din ,
|
95 |
|
|
sdr_dout ,
|
96 |
|
|
sdr_den_n ,
|
97 |
|
|
sdram_pad_clk ,
|
98 |
19 |
dinesha |
|
99 |
|
|
/* Parameters */
|
100 |
|
|
sdr_init_done ,
|
101 |
|
|
cfg_req_depth , //how many req. buffer should hold
|
102 |
|
|
cfg_sdr_en ,
|
103 |
|
|
cfg_sdr_mode_reg ,
|
104 |
|
|
cfg_sdr_tras_d ,
|
105 |
|
|
cfg_sdr_trp_d ,
|
106 |
|
|
cfg_sdr_trcd_d ,
|
107 |
|
|
cfg_sdr_cas ,
|
108 |
|
|
cfg_sdr_trcar_d ,
|
109 |
|
|
cfg_sdr_twr_d ,
|
110 |
|
|
cfg_sdr_rfsh ,
|
111 |
|
|
cfg_sdr_rfmax
|
112 |
|
|
);
|
113 |
|
|
|
114 |
20 |
dinesha |
parameter APP_AW = 32; // Application Address Width
|
115 |
19 |
dinesha |
parameter APP_DW = 32; // Application Data Width
|
116 |
|
|
parameter APP_BW = 4; // Application Byte Width
|
117 |
|
|
parameter APP_RW = 9; // Application Request Width
|
118 |
|
|
|
119 |
20 |
dinesha |
parameter SDR_DW = 8; // SDR Data Width
|
120 |
|
|
parameter SDR_BW = 1; // SDR Byte Width
|
121 |
19 |
dinesha |
|
122 |
|
|
parameter tw = 8; // tag id width
|
123 |
|
|
parameter bl = 9; // burst_lenght_width
|
124 |
|
|
|
125 |
|
|
//-----------------------------------------------
|
126 |
|
|
// Global Variable
|
127 |
|
|
// ----------------------------------------------
|
128 |
|
|
input sdram_clk ; // SDRAM Clock
|
129 |
|
|
input sdram_resetn ; // Reset Signal
|
130 |
|
|
input [1:0] cfg_sdr_width ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
|
131 |
|
|
input [1:0] cfg_colbits ; // 2'b00 - 8 Bit column address,
|
132 |
|
|
// 2'b01 - 9 Bit, 10 - 10 bit, 11 - 11Bits
|
133 |
|
|
|
134 |
|
|
//--------------------------------------
|
135 |
|
|
// Wish Bone Interface
|
136 |
|
|
// -------------------------------------
|
137 |
|
|
input wb_rst_i ;
|
138 |
|
|
input wb_clk_i ;
|
139 |
|
|
|
140 |
|
|
input wb_stb_i ;
|
141 |
|
|
output wb_ack_o ;
|
142 |
20 |
dinesha |
input [APP_AW-1:0] wb_addr_i ;
|
143 |
19 |
dinesha |
input wb_we_i ; // 1 - Write, 0 - Read
|
144 |
20 |
dinesha |
input [APP_DW-1:0] wb_dat_i ;
|
145 |
|
|
input [APP_DW/8-1:0] wb_sel_i ; // Byte enable
|
146 |
|
|
output [APP_DW-1:0] wb_dat_o ;
|
147 |
19 |
dinesha |
input wb_cyc_i ;
|
148 |
|
|
input [2:0] wb_cti_i ;
|
149 |
|
|
|
150 |
|
|
//------------------------------------------------
|
151 |
|
|
// Interface to SDRAMs
|
152 |
|
|
//------------------------------------------------
|
153 |
|
|
output sdr_cke ; // SDRAM CKE
|
154 |
|
|
output sdr_cs_n ; // SDRAM Chip Select
|
155 |
|
|
output sdr_ras_n ; // SDRAM ras
|
156 |
|
|
output sdr_cas_n ; // SDRAM cas
|
157 |
|
|
output sdr_we_n ; // SDRAM write enable
|
158 |
|
|
output [SDR_BW-1:0] sdr_dqm ; // SDRAM Data Mask
|
159 |
|
|
output [1:0] sdr_ba ; // SDRAM Bank Enable
|
160 |
|
|
output [12:0] sdr_addr ; // SDRAM Address
|
161 |
20 |
dinesha |
input sdram_pad_clk ; // Sdram clock loop back from pad
|
162 |
|
|
input [SDR_DW-1:0] pad_sdr_din ; // SDRA Data Input
|
163 |
|
|
output [SDR_DW-1:0] sdr_dout ; // SDRAM Data Output
|
164 |
|
|
output [SDR_BW-1:0] sdr_den_n ; // SDRAM Data Output enable
|
165 |
19 |
dinesha |
|
166 |
|
|
//------------------------------------------------
|
167 |
|
|
// Configuration Parameter
|
168 |
|
|
//------------------------------------------------
|
169 |
|
|
output sdr_init_done ; // Indicate SDRAM Initialisation Done
|
170 |
|
|
input [3:0] cfg_sdr_tras_d ; // Active to precharge delay
|
171 |
|
|
input [3:0] cfg_sdr_trp_d ; // Precharge to active delay
|
172 |
|
|
input [3:0] cfg_sdr_trcd_d ; // Active to R/W delay
|
173 |
|
|
input cfg_sdr_en ; // Enable SDRAM controller
|
174 |
|
|
input [1:0] cfg_req_depth ; // Maximum Request accepted by SDRAM controller
|
175 |
|
|
input [12:0] cfg_sdr_mode_reg ;
|
176 |
|
|
input [2:0] cfg_sdr_cas ; // SDRAM CAS Latency
|
177 |
|
|
input [3:0] cfg_sdr_trcar_d ; // Auto-refresh period
|
178 |
|
|
input [3:0] cfg_sdr_twr_d ; // Write recovery delay
|
179 |
|
|
input [`SDR_RFSH_TIMER_W-1 : 0] cfg_sdr_rfsh;
|
180 |
|
|
input [`SDR_RFSH_ROW_CNT_W -1 : 0] cfg_sdr_rfmax;
|
181 |
|
|
|
182 |
|
|
//--------------------------------------------
|
183 |
|
|
// SDRAM controller Interface
|
184 |
|
|
//--------------------------------------------
|
185 |
|
|
wire app_req ; // SDRAM request
|
186 |
|
|
wire [APP_AW-1:0] app_req_addr ; // SDRAM Request Address
|
187 |
|
|
wire [bl-1:0] app_req_len ;
|
188 |
|
|
wire app_req_wr_n ; // 0 - Write, 1 -> Read
|
189 |
|
|
wire app_req_ack ; // SDRAM request Accepted
|
190 |
|
|
wire app_busy_n ; // 0 -> sdr busy
|
191 |
20 |
dinesha |
wire [APP_DW/8-1:0] app_wr_en_n ; // Active low sdr byte-wise write data valid
|
192 |
19 |
dinesha |
wire app_wr_next_req ; // Ready to accept the next write
|
193 |
|
|
wire app_rd_valid ; // sdr read valid
|
194 |
|
|
wire app_last_rd ; // Indicate last Read of Burst Transfer
|
195 |
|
|
wire app_last_wr ; // Indicate last Write of Burst Transfer
|
196 |
20 |
dinesha |
wire [APP_DW-1:0] app_wr_data ; // sdr write data
|
197 |
|
|
wire [APP_DW-1:0] app_rd_data ; // sdr read data
|
198 |
19 |
dinesha |
|
199 |
|
|
/****************************************
|
200 |
|
|
* These logic has to be implemented using Pads
|
201 |
|
|
* **************************************/
|
202 |
|
|
wire [SDR_DW-1:0] pad_sdr_din ; // SDRA Data Input
|
203 |
|
|
wire [SDR_DW-1:0] sdr_dout ; // SDRAM Data Output
|
204 |
|
|
wire [SDR_BW-1:0] sdr_den_n ; // SDRAM Data Output enable
|
205 |
|
|
|
206 |
|
|
|
207 |
20 |
dinesha |
//assign sdr_dq = (&sdr_den_n == 1'b0) ? sdr_dout : {SDR_DW{1'bz}};
|
208 |
|
|
//assign pad_sdr_din = sdr_dq;
|
209 |
19 |
dinesha |
|
210 |
|
|
// sdram pad clock is routed back through pad
|
211 |
|
|
// SDRAM Clock from Pad, used for registering Read Data
|
212 |
20 |
dinesha |
//wire #(1.0) sdram_pad_clk = sdram_clk;
|
213 |
19 |
dinesha |
|
214 |
|
|
/************** Ends Here **************************/
|
215 |
20 |
dinesha |
wb2sdrc #(.dw(APP_DW),.tw(tw),.bl(bl),.APP_AW(APP_AW)) u_wb2sdrc (
|
216 |
19 |
dinesha |
// WB bus
|
217 |
|
|
.wb_rst_i (wb_rst_i ) ,
|
218 |
|
|
.wb_clk_i (wb_clk_i ) ,
|
219 |
|
|
|
220 |
|
|
.wb_stb_i (wb_stb_i ) ,
|
221 |
|
|
.wb_ack_o (wb_ack_o ) ,
|
222 |
|
|
.wb_addr_i (wb_addr_i ) ,
|
223 |
|
|
.wb_we_i (wb_we_i ) ,
|
224 |
|
|
.wb_dat_i (wb_dat_i ) ,
|
225 |
|
|
.wb_sel_i (wb_sel_i ) ,
|
226 |
|
|
.wb_dat_o (wb_dat_o ) ,
|
227 |
|
|
.wb_cyc_i (wb_cyc_i ) ,
|
228 |
|
|
.wb_cti_i (wb_cti_i ) ,
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
//SDRAM Controller Hand-Shake Signal
|
232 |
|
|
.sdram_clk (sdram_clk ) ,
|
233 |
|
|
.sdram_resetn (sdram_resetn ) ,
|
234 |
|
|
.sdr_req (app_req ) ,
|
235 |
|
|
.sdr_req_addr (app_req_addr ) ,
|
236 |
|
|
.sdr_req_len (app_req_len ) ,
|
237 |
|
|
.sdr_req_wr_n (app_req_wr_n ) ,
|
238 |
|
|
.sdr_req_ack (app_req_ack ) ,
|
239 |
|
|
.sdr_busy_n (app_busy_n ) ,
|
240 |
|
|
.sdr_wr_en_n (app_wr_en_n ) ,
|
241 |
|
|
.sdr_wr_next (app_wr_next_req ) ,
|
242 |
|
|
.sdr_rd_valid (app_rd_valid ) ,
|
243 |
|
|
.sdr_last_rd (app_last_rd ) ,
|
244 |
|
|
.sdr_wr_data (app_wr_data ) ,
|
245 |
|
|
.sdr_rd_data (app_rd_data )
|
246 |
|
|
|
247 |
|
|
);
|
248 |
|
|
|
249 |
|
|
|
250 |
20 |
dinesha |
sdrc_core #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW),.APP_AW(APP_AW)) u_sdrc_core (
|
251 |
19 |
dinesha |
.clk (sdram_clk ) ,
|
252 |
|
|
.pad_clk (sdram_pad_clk ) ,
|
253 |
|
|
.reset_n (sdram_resetn ) ,
|
254 |
|
|
.sdr_width (cfg_sdr_width ) ,
|
255 |
|
|
.cfg_colbits (cfg_colbits ) ,
|
256 |
|
|
|
257 |
|
|
/* Request from app */
|
258 |
|
|
.app_req (app_req ) ,// Transfer Request
|
259 |
|
|
.app_req_addr (app_req_addr ) ,// SDRAM Address
|
260 |
|
|
.app_req_len (app_req_len ) ,// Burst Length (in 16 bit words)
|
261 |
|
|
.app_req_wrap (1'b0 ) ,// Wrap mode request
|
262 |
|
|
.app_req_wr_n (app_req_wr_n ) ,// 0 => Write request, 1 => read req
|
263 |
|
|
.app_req_ack (app_req_ack ) ,// Request has been accepted
|
264 |
|
|
.cfg_req_depth (cfg_req_depth ) ,//how many req. buffer should hold
|
265 |
|
|
|
266 |
|
|
.app_wr_data (app_wr_data ) ,
|
267 |
|
|
.app_wr_en_n (app_wr_en_n ) ,
|
268 |
|
|
.app_rd_data (app_rd_data ) ,
|
269 |
|
|
.app_rd_valid (app_rd_valid ) ,
|
270 |
|
|
.app_last_rd (app_last_rd ) ,
|
271 |
|
|
.app_last_wr (app_last_wr ) ,
|
272 |
|
|
.app_wr_next_req (app_wr_next_req ) ,
|
273 |
|
|
.sdr_init_done (sdr_init_done ) ,
|
274 |
|
|
.app_req_dma_last (app_req ) ,
|
275 |
|
|
|
276 |
|
|
/* Interface to SDRAMs */
|
277 |
|
|
.sdr_cs_n (sdr_cs_n ) ,
|
278 |
|
|
.sdr_cke (sdr_cke ) ,
|
279 |
|
|
.sdr_ras_n (sdr_ras_n ) ,
|
280 |
|
|
.sdr_cas_n (sdr_cas_n ) ,
|
281 |
|
|
.sdr_we_n (sdr_we_n ) ,
|
282 |
|
|
.sdr_dqm (sdr_dqm ) ,
|
283 |
|
|
.sdr_ba (sdr_ba ) ,
|
284 |
|
|
.sdr_addr (sdr_addr ) ,
|
285 |
|
|
.pad_sdr_din (pad_sdr_din ) ,
|
286 |
|
|
.sdr_dout (sdr_dout ) ,
|
287 |
|
|
.sdr_den_n (sdr_den_n ) ,
|
288 |
|
|
|
289 |
|
|
/* Parameters */
|
290 |
|
|
.cfg_sdr_en (cfg_sdr_en ) ,
|
291 |
|
|
.cfg_sdr_mode_reg (cfg_sdr_mode_reg ) ,
|
292 |
|
|
.cfg_sdr_tras_d (cfg_sdr_tras_d ) ,
|
293 |
|
|
.cfg_sdr_trp_d (cfg_sdr_trp_d ) ,
|
294 |
|
|
.cfg_sdr_trcd_d (cfg_sdr_trcd_d ) ,
|
295 |
|
|
.cfg_sdr_cas (cfg_sdr_cas ) ,
|
296 |
|
|
.cfg_sdr_trcar_d (cfg_sdr_trcar_d ) ,
|
297 |
|
|
.cfg_sdr_twr_d (cfg_sdr_twr_d ) ,
|
298 |
|
|
.cfg_sdr_rfsh (cfg_sdr_rfsh ) ,
|
299 |
|
|
.cfg_sdr_rfmax (cfg_sdr_rfmax )
|
300 |
|
|
);
|
301 |
|
|
|
302 |
|
|
endmodule // sdrc_core
|