1 /*********************************************************************
3 SDRAM Controller top File
5 This file is part of the sdram controller project
6 http://www.opencores.org/cores/sdr_ctrl/
8 Description: SDRAM Controller Top Module.
9 Support 81/6/32 Bit SDRAM.
10 Column Address is Programmable
14 This block integrate following sub modules
19 This module transalate the bus protocl from wishbone to custome
25 Author(s): Dinesh Annayya, dinesha@opencores.org
26 Version : 0.0 - 8th Jan 2012
27 Initial version with 16/32 Bit SDRAM Support
29 8 Bit SDRAM Support is added
31 sdram_dq and sdram_pad_clk are internally generated
33 Sdram Address witdh is increased from 12 to 13bits
36 Copyright (C) 2000 Authors and OPENCORES.ORG
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.
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
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
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
59 *******************************************************************/
68 // Input to sdram ctrl
85 /* Interface to SDRAMs */
96 pad_sdr_din , // SDRA Data Input
97 sdr_dout , // SDRAM Data Output
98 sdr_den_n , // SDRAM Data Output enable
102 cfg_req_depth , //how many req. buffer should hold
115 `define SDR_REQ_ID_W 4
117 `define SDR_RFSH_TIMER_W 12
118 `define SDR_RFSH_ROW_CNT_W 3
127 // SDRAM Commands (CS_N, RAS_N, CAS_N, WE_N)
129 `define SDR_DESEL 4'b1111
130 `define SDR_NOOP 4'b0111
131 `define SDR_ACTIVATE 4'b0011
132 `define SDR_READ 4'b0101
133 `define SDR_WRITE 4'b0100
134 `define SDR_BT 4'b0110
135 `define SDR_PRECHARGE 4'b0010
136 `define SDR_REFRESH 4'b0001
137 `define SDR_MODE 4'b0000
141 `define TARGET_DESIGN `ASIC
142 // 12 bit subtractor is not feasibile for FPGA, so changed to 6 bits
143 `define REQ_BW (`TARGET_DESIGN == `FPGA) ? 6 : 12 // Request Width
145 parameter APP_AW = 26; // Application Address Width
146 parameter APP_DW = 64; // Application Data Width
147 parameter APP_BW = 8; // Application Byte Width
148 parameter APP_RW = 9; // Application Request Width
150 parameter SDR_DW = 64; // SDR Data Width
151 parameter SDR_BW = 8; // SDR Byte Width
153 parameter dw = 64; // data width
154 parameter tw = 8; // tag id width
155 parameter bl = 9; // burst_lenght_width
157 //-----------------------------------------------
159 // ----------------------------------------------
160 input sdram_clk ; // SDRAM Clock
161 input sdram_resetn ; // Reset Signal
162 input [1:0] cfg_sdr_width ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
163 input [1:0] cfg_colbits ; // 2'b00 - 8 Bit column address,
164 // 2'b01 - 9 Bit, 10 - 10 bit, 11 - 11Bits
166 //--------------------------------------
167 // Wish Bone Interface
168 // -------------------------------------
174 //input [APP_AW-1:0] wb_addr_i ;
175 //input wb_we_i ; // 1 - Write, 0 - Read
176 //input [dw-1:0] wb_dat_i ;
177 //input [dw/8-1:0] wb_sel_i ; // Byte enable
178 //output [dw-1:0] wb_dat_o ;
180 //input [2:0] wb_cti_i ;
182 //------------------------------------------------
183 // Interface to SDRAMs
184 //------------------------------------------------
185 output sdr_cke ; // SDRAM CKE
186 output sdr_cs_n ; // SDRAM Chip Select
187 output sdr_ras_n ; // SDRAM ras
188 output sdr_cas_n ; // SDRAM cas
189 output sdr_we_n ; // SDRAM write enable
190 output [SDR_BW-1:0] sdr_dqm ; // SDRAM Data Mask
191 output [1:0] sdr_ba ; // SDRAM Bank Enable
192 output [12:0] sdr_addr ; // SDRAM Address
193 input [SDR_DW-1:0] pad_sdr_din ; // SDRA Data Input
194 output [SDR_DW-1:0] sdr_dout ; // SDRAM Data Output
195 output [SDR_BW-1:0] sdr_den_n ; // SDRAM Data Output enable
196 //------------------------------------------------
197 // Configuration Parameter // vis: changed input and output pins to wire
198 //------------------------------------------------
200 output sdr_init_done ; // Indicate SDRAM Initialisation Done
201 input [3:0] cfg_sdr_tras_d ; // Active to precharge delay
202 input [3:0] cfg_sdr_trp_d ; // Precharge to active delay
203 input [3:0] cfg_sdr_trcd_d ; // Active to R/W delay
204 input cfg_sdr_en ; // Enable SDRAM controller
205 input [1:0] cfg_req_depth ; // Maximum Request accepted by SDRAM controller
206 input [12:0] cfg_sdr_mode_reg ;
207 input [2:0] cfg_sdr_cas ; // SDRAM CAS Latency
208 input [3:0] cfg_sdr_trcar_d ; // Auto-refresh period
209 input [3:0] cfg_sdr_twr_d ; // Write recovery delay
210 input [`SDR_RFSH_TIMER_W-1 : 0] cfg_sdr_rfsh;
211 input [`SDR_RFSH_ROW_CNT_W -1 : 0] cfg_sdr_rfmax;
215 assign cfg_req_depth = 2'h3; //how many req. buffer should hold
216 assign cfg_sdr_en = 1'b1;
217 assign cfg_sdr_mode_reg = 13'h033;
218 assign cfg_sdr_tras_d = 4'h4;
219 assign cfg_sdr_trp_d = 4'h2;
220 assign cfg_sdr_trcd_d = 4'h2;
221 assign cfg_sdr_cas = 3'h3;
222 assign cfg_sdr_trcar_d = 4'h7;
223 assign cfg_sdr_twr_d = 4'h1;
224 assign cfg_sdr_rfsh = 12'h100; // reduced from 12'hC35
225 assign cfg_sdr_rfmax = 3'h6;*/
226 //assign cfg_colbits = 2'b00;
227 //assign cfg_sdr_width = 2'b00;
229 //--------------------------------------------
230 // SDRAM controller Interface
231 //--------------------------------------------
232 input app_req ; // SDRAM request
233 input app_req_wrap ; // SDRAM wrap
234 input [APP_AW-1:0] app_req_addr ; // SDRAM Request Address
235 input [bl-1:0] app_req_len ;
236 input app_req_wr_n ; // 0 - Write, 1 -> Read
237 output app_req_ack ; // SDRAM request Accepted
238 wire app_busy_n ; // 0 -> sdr busy
239 input [dw/8-1:0] app_wr_en_n ; // Active low sdr byte-wise write data valid
240 output app_wr_next_req ; // Ready to accept the next write
241 output app_rd_valid ; // sdr read valid
242 output app_last_rd ; // Indicate last Read of Burst Transfer
243 output app_last_wr ; // Indicate last Write of Burst Transfer
244 input [dw-1:0] app_wr_data ; // sdr write data
245 output [dw-1:0] app_rd_data ; // sdr read data
247 input [3:0] delay_config_reg2;
249 /****************************************
250 * These logic has to be implemented using Pads
251 * **************************************/
252 /*wire [SDR_DW-1:0] pad_sdr_din ; // SDRA Data Input
253 wire [SDR_DW-1:0] sdr_dout ; // SDRAM Data Output
254 wire [SDR_BW-1:0] sdr_den_n ; // SDRAM Data Output enable
255 wire [SDR_DW-1:0] sdr_dq ; // SDRA Data Input/output*/
257 /*assign sdr_dq0 = sdr_dq[31:0];
258 assign sdr_dq1 = sdr_dq[63:32];
261 assign sdr_dq = (&sdr_den_n == 1'b0) ? sdr_dout : {SDR_DW{1'bz}};
262 assign pad_sdr_din = {sdr_dq1, sdr_dq0};*/
266 // sdram pad clock is routed back through pad
267 // SDRAM Clock from Pad, used for registering Read Data
269 parallel_prog_delay_cell delay_inst_for_sdram_clk_pad(.in_clk(sdram_clk), .delay_config_reg(delay_config_reg2), .delayed_clk(sdram_pad_clk));
273 sdrc_core #(.SDR_DW(SDR_DW) , .SDR_BW(SDR_BW)) u_sdrc_core (
275 .pad_clk (sdram_pad_clk ) ,
276 .reset_n (sdram_resetn ) ,
277 .sdr_width (cfg_sdr_width ) ,
278 .cfg_colbits (cfg_colbits ) ,
280 /* Request from app */
281 .app_req (app_req ) ,// Transfer Request
282 .app_req_addr (app_req_addr ) ,// SDRAM Address
283 .app_req_len (app_req_len ) ,// Burst Length (in 16 bit words)
284 .app_req_wrap (app_req_wrap ) ,// Wrap mode request
285 .app_req_wr_n (app_req_wr_n ) ,// 0 => Write request, 1 => read req
286 .app_req_ack (app_req_ack ) ,// Request has been accepted
287 .cfg_req_depth (cfg_req_depth ) ,//how many req. buffer should hold
289 .app_wr_data (app_wr_data ) ,
290 .app_wr_en_n (app_wr_en_n ) ,
291 .app_rd_data (app_rd_data ) ,
292 .app_rd_valid (app_rd_valid ) ,
293 .app_last_rd (app_last_rd ) ,
294 .app_last_wr (app_last_wr ) ,
295 .app_wr_next_req (app_wr_next_req ) ,
296 .sdr_init_done (sdr_init_done ) ,
297 .app_req_dma_last (app_req ) ,
299 /* Interface to SDRAMs */
300 .sdr_cs_n (sdr_cs_n ) ,
301 .sdr_cke (sdr_cke ) ,
302 .sdr_ras_n (sdr_ras_n ) ,
303 .sdr_cas_n (sdr_cas_n ) ,
304 .sdr_we_n (sdr_we_n ) ,
305 .sdr_dqm (sdr_dqm ) ,
307 .sdr_addr (sdr_addr ) ,
308 .pad_sdr_din (pad_sdr_din ) ,
309 .sdr_dout (sdr_dout ) ,
310 .sdr_den_n (sdr_den_n ) ,
313 .cfg_sdr_en (cfg_sdr_en ) ,
314 .cfg_sdr_mode_reg (cfg_sdr_mode_reg ) ,
315 .cfg_sdr_tras_d (cfg_sdr_tras_d ) ,
316 .cfg_sdr_trp_d (cfg_sdr_trp_d ) ,
317 .cfg_sdr_trcd_d (cfg_sdr_trcd_d ) ,
318 .cfg_sdr_cas (cfg_sdr_cas ) ,
319 .cfg_sdr_trcar_d (cfg_sdr_trcar_d ) ,
320 .cfg_sdr_twr_d (cfg_sdr_twr_d ) ,
321 .cfg_sdr_rfsh (cfg_sdr_rfsh ) ,
322 .cfg_sdr_rfmax (cfg_sdr_rfmax )
325 endmodule // sdrc_core