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