1 |
568 |
julius |
//*****************************************************************************
|
2 |
|
|
// DISCLAIMER OF LIABILITY
|
3 |
|
|
//
|
4 |
|
|
// This file contains proprietary and confidential information of
|
5 |
|
|
// Xilinx, Inc. ("Xilinx"), that is distributed under a license
|
6 |
|
|
// from Xilinx, and may be used, copied and/or disclosed only
|
7 |
|
|
// pursuant to the terms of a valid license agreement with Xilinx.
|
8 |
|
|
//
|
9 |
|
|
// XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION
|
10 |
|
|
// ("MATERIALS") "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
11 |
|
|
// EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING WITHOUT
|
12 |
|
|
// LIMITATION, ANY WARRANTY WITH RESPECT TO NONINFRINGEMENT,
|
13 |
|
|
// MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. Xilinx
|
14 |
|
|
// does not warrant that functions included in the Materials will
|
15 |
|
|
// meet the requirements of Licensee, or that the operation of the
|
16 |
|
|
// Materials will be uninterrupted or error-free, or that defects
|
17 |
|
|
// in the Materials will be corrected. Furthermore, Xilinx does
|
18 |
|
|
// not warrant or make any representations regarding use, or the
|
19 |
|
|
// results of the use, of the Materials in terms of correctness,
|
20 |
|
|
// accuracy, reliability or otherwise.
|
21 |
|
|
//
|
22 |
|
|
// Xilinx products are not designed or intended to be fail-safe,
|
23 |
|
|
// or for use in any application requiring fail-safe performance,
|
24 |
|
|
// such as life-support or safety devices or systems, Class III
|
25 |
|
|
// medical devices, nuclear facilities, applications related to
|
26 |
|
|
// the deployment of airbags, or any other applications that could
|
27 |
|
|
// lead to death, personal injury or severe property or
|
28 |
|
|
// environmental damage (individually and collectively, "critical
|
29 |
|
|
// applications"). Customer assumes the sole risk and liability
|
30 |
|
|
// of any use of Xilinx products in critical applications,
|
31 |
|
|
// subject only to applicable laws and regulations governing
|
32 |
|
|
// limitations on product liability.
|
33 |
|
|
//
|
34 |
|
|
// Copyright 2005, 2006, 2007, 2008 Xilinx, Inc.
|
35 |
|
|
// All rights reserved.
|
36 |
|
|
//
|
37 |
|
|
// This disclaimer and copyright notice must be retained as part
|
38 |
|
|
// of this file at all times.
|
39 |
|
|
//*****************************************************************************
|
40 |
|
|
// ____ ____
|
41 |
|
|
// / /\/ /
|
42 |
|
|
// /___/ \ / Vendor : Xilinx
|
43 |
|
|
// \ \ \/ Version : 3.6.1
|
44 |
|
|
// \ \ Application : MIG
|
45 |
|
|
// / / Filename : s3adsp_ddr2_controller_0.v
|
46 |
|
|
// /___/ /\ Date Last Modified : $Date: 2010/11/26 18:25:41 $
|
47 |
|
|
// \ \ / \ Date Created : Mon May 2 2005
|
48 |
|
|
// \___\/\___\
|
49 |
|
|
// Device : Spartan-3/3A/3A-DSP
|
50 |
|
|
// Design Name : DDR2 SDRAM
|
51 |
|
|
// Purpose : This is main controller block. This includes the following
|
52 |
|
|
// features:
|
53 |
|
|
// - The controller state machine that controls the
|
54 |
|
|
// initialization process upon power up, as well as the
|
55 |
|
|
// read, write, and refresh commands.
|
56 |
|
|
// - Accepts and decodes the user commands.
|
57 |
|
|
// - Generates the address and Bank address and control signals
|
58 |
|
|
// to the memory
|
59 |
|
|
// - Generates control signals for other modules.
|
60 |
|
|
//*****************************************************************************
|
61 |
|
|
`timescale 1ns/100ps
|
62 |
|
|
`include "s3adsp_ddr2_parameters_0.v"
|
63 |
|
|
|
64 |
|
|
module s3adsp_ddr2_controller_0
|
65 |
|
|
(
|
66 |
|
|
input clk/* synthesis syn_keep=1 */,
|
67 |
|
|
input rst0,
|
68 |
|
|
input rst180,
|
69 |
|
|
input [((`ROW_ADDRESS
|
70 |
|
|
+ `COLUMN_ADDRESS)-1):0] address,
|
71 |
|
|
input [`BANK_ADDRESS-1:0] bank_address,
|
72 |
|
|
input [2:0] command_register,
|
73 |
|
|
input burst_done,
|
74 |
|
|
output ddr_rasb_cntrl,
|
75 |
|
|
output ddr_casb_cntrl,
|
76 |
|
|
output [`BANK_ADDRESS-1:0] ddr_ba_cntrl,
|
77 |
|
|
output [`ROW_ADDRESS-1:0] ddr_address_cntrl,
|
78 |
|
|
output ddr_csb_cntrl,
|
79 |
|
|
output dqs_enable,
|
80 |
|
|
output dqs_reset /* synthesis syn_keep=1 */,
|
81 |
|
|
output rst_dqs_div_int,
|
82 |
|
|
output cmd_ack,
|
83 |
|
|
output init,
|
84 |
|
|
output ddr_web_cntrl,
|
85 |
|
|
output ddr_cke_cntrl,
|
86 |
|
|
output reg write_enable,
|
87 |
|
|
output reg rst_calib,
|
88 |
|
|
output reg ddr_odt_cntrl,
|
89 |
|
|
output reg ar_done,
|
90 |
|
|
input wait_200us,
|
91 |
|
|
output auto_ref_req,
|
92 |
|
|
output reg read_fifo_rden // Read Enable signal for read fifo(to data_read module)
|
93 |
|
|
);
|
94 |
|
|
|
95 |
|
|
localparam IDLE = 4'b0000;
|
96 |
|
|
localparam PRECHARGE = 4'b0001;
|
97 |
|
|
localparam AUTO_REFRESH = 4'b0010;
|
98 |
|
|
localparam ACTIVE = 4'b0011;
|
99 |
|
|
localparam FIRST_WRITE = 4'b0100;
|
100 |
|
|
localparam WRITE_WAIT = 4'b0101;
|
101 |
|
|
localparam BURST_WRITE = 4'b0110;
|
102 |
|
|
localparam PRECHARGE_AFTER_WRITE = 4'b0111;
|
103 |
|
|
localparam PRECHARGE_AFTER_WRITE_2 = 4'b1000;
|
104 |
|
|
localparam READ_WAIT = 4'b1001;
|
105 |
|
|
localparam BURST_READ = 4'b1010;
|
106 |
|
|
localparam ACTIVE_WAIT = 4'b1011;
|
107 |
|
|
|
108 |
|
|
localparam INIT_IDLE = 2'b00;
|
109 |
|
|
localparam INIT_PRECHARGE = 2'b01;
|
110 |
|
|
localparam INIT_LOAD_MODE_REG = 2'b10;
|
111 |
|
|
localparam INIT_AUTO_REFRESH = 2'b11;
|
112 |
|
|
|
113 |
|
|
parameter COL_WIDTH = `COLUMN_ADDRESS;
|
114 |
|
|
parameter ROW_WIDTH = `ROW_ADDRESS;
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
reg [3:0] current_state;
|
118 |
|
|
reg [3:0] next_state;
|
119 |
|
|
reg [1:0] init_current_state;
|
120 |
|
|
reg [1:0] init_next_state;
|
121 |
|
|
reg [((`ROW_ADDRESS
|
122 |
|
|
+ `COLUMN_ADDRESS)-1):0] address_reg;
|
123 |
|
|
reg auto_ref;
|
124 |
|
|
reg auto_ref1;
|
125 |
|
|
reg autoref_value;
|
126 |
|
|
reg auto_ref_detect1;
|
127 |
|
|
reg [(`MAX_REF_WIDTH-1):0] autoref_count;
|
128 |
|
|
reg auto_ref_issued;
|
129 |
|
|
reg [`BANK_ADDRESS-1:0] ba_address_reg1;
|
130 |
|
|
reg [`BANK_ADDRESS-1:0] ba_address_reg2;
|
131 |
|
|
reg [2:0] burst_length;
|
132 |
|
|
reg [2:0] cas_count;
|
133 |
|
|
reg [4:0] ras_count;
|
134 |
|
|
|
135 |
|
|
reg [`ROW_ADDRESS-1:0] column_address_reg;
|
136 |
|
|
reg [`ROW_ADDRESS-1:0] column_address_reg1;
|
137 |
|
|
reg [2:0] wr;
|
138 |
|
|
reg ddr_rasb2;
|
139 |
|
|
reg ddr_casb2;
|
140 |
|
|
reg ddr_web2;
|
141 |
|
|
reg [`BANK_ADDRESS-1:0] ddr_ba1;
|
142 |
|
|
reg [`ROW_ADDRESS-1:0] ddr_address1;
|
143 |
|
|
reg [3:0] init_count;
|
144 |
|
|
reg init_done;
|
145 |
|
|
reg init_done_r1;
|
146 |
|
|
reg init_memory;
|
147 |
|
|
reg init_mem;
|
148 |
|
|
reg [6:0] init_pre_count;
|
149 |
|
|
reg [7:0] dll_rst_count;
|
150 |
|
|
reg [(`MAX_REF_WIDTH-1):0] ref_freq_cnt;
|
151 |
|
|
reg read_cmd1;
|
152 |
|
|
reg read_cmd2;
|
153 |
|
|
reg read_cmd3;
|
154 |
|
|
reg [2:0] rcd_count;
|
155 |
|
|
reg [7:0] rfc_counter_value;
|
156 |
|
|
reg [7:0] rfc_count;
|
157 |
|
|
reg rfc_count_reg;
|
158 |
|
|
reg ar_done_reg;
|
159 |
|
|
reg rdburst_end_1;
|
160 |
|
|
reg rdburst_end_2;
|
161 |
|
|
reg [`ROW_ADDRESS-1:0] row_address_reg;
|
162 |
|
|
reg rst_dqs_div_r;
|
163 |
|
|
reg rst_dqs_div_r1; //For Reg Dimm
|
164 |
|
|
reg [2:0] wrburst_end_cnt;
|
165 |
|
|
reg wrburst_end_1;
|
166 |
|
|
reg wrburst_end_2;
|
167 |
|
|
reg wrburst_end_3;
|
168 |
|
|
reg [2:0] wr_count;
|
169 |
|
|
reg write_cmd1;
|
170 |
|
|
reg write_cmd2;
|
171 |
|
|
reg write_cmd3;
|
172 |
|
|
reg [2:0] dqs_div_cascount;
|
173 |
|
|
reg [2:0] dqs_div_rdburstcount;
|
174 |
|
|
reg dqs_enable1;
|
175 |
|
|
reg dqs_enable2;
|
176 |
|
|
reg dqs_enable3;
|
177 |
|
|
reg dqs_reset1_clk0;
|
178 |
|
|
reg dqs_reset2_clk0;
|
179 |
|
|
reg dqs_reset3_clk0;
|
180 |
|
|
reg dqs_enable_int;
|
181 |
|
|
reg dqs_reset_int;
|
182 |
|
|
reg rst180_r;
|
183 |
|
|
reg rst0_r;
|
184 |
|
|
reg ddr_odt2;
|
185 |
|
|
reg go_to_active;
|
186 |
|
|
reg accept_cmd_in;
|
187 |
|
|
reg odt_deassert;
|
188 |
|
|
reg [2:0] rp_count;
|
189 |
|
|
reg auto_ref_wait;
|
190 |
|
|
reg auto_ref_wait1;
|
191 |
|
|
reg auto_ref_wait2;
|
192 |
|
|
reg [7:0] count6;
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
wire [`ROW_ADDRESS - 1:0] lmr;
|
196 |
|
|
wire [`ROW_ADDRESS - 1:0] emr;
|
197 |
|
|
wire [`ROW_ADDRESS - 1:0] lmr_dll_rst;
|
198 |
|
|
wire [`ROW_ADDRESS - 1:0] lmr_dll_set;
|
199 |
|
|
wire [`ROW_ADDRESS-1:0] column_address;
|
200 |
|
|
|
201 |
|
|
wire write_cmd_in;
|
202 |
|
|
wire read_cmd_in;
|
203 |
|
|
wire init_cmd_in;
|
204 |
|
|
wire wrburst_end;
|
205 |
|
|
wire [`ROW_ADDRESS-1:0] row_address;
|
206 |
|
|
wire rdburst_end;
|
207 |
|
|
wire init_done_value;
|
208 |
|
|
wire ddr_rasb1;
|
209 |
|
|
wire ddr_casb1;
|
210 |
|
|
wire ddr_web1;
|
211 |
|
|
wire ack_reg;
|
212 |
|
|
wire ack_o;
|
213 |
|
|
wire auto_ref_issued_p;
|
214 |
|
|
wire ar_done_p;
|
215 |
|
|
wire go_to_active_value;
|
216 |
|
|
wire ddr_odt1;
|
217 |
|
|
wire rst_dqs_div_int1;
|
218 |
|
|
wire [2:0] burst_cnt_max;
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
// Input : COMMAND REGISTER FORMAT
|
222 |
|
|
// 000 - NOP
|
223 |
|
|
// 010 - Initialize memory
|
224 |
|
|
// 100 - Write Request
|
225 |
|
|
// 110 - Read request
|
226 |
|
|
|
227 |
|
|
// Input : Address format
|
228 |
|
|
// row address = address((`ROW_ADDRESS+ `COLUMN_ADDRESS) -1 : `COLUMN_ADDRESS)
|
229 |
|
|
// column addres = address( `COLUMN_ADDRESS-1 : 0)
|
230 |
|
|
|
231 |
|
|
assign ddr_csb_cntrl = 1'b0;
|
232 |
|
|
assign row_address = address_reg[((`ROW_ADDRESS +
|
233 |
|
|
`COLUMN_ADDRESS)-1):
|
234 |
|
|
`COLUMN_ADDRESS];
|
235 |
|
|
assign init = init_done;
|
236 |
|
|
assign ddr_rasb_cntrl = ddr_rasb2;
|
237 |
|
|
assign ddr_casb_cntrl = ddr_casb2;
|
238 |
|
|
assign ddr_web_cntrl = ddr_web2;
|
239 |
|
|
assign ddr_address_cntrl = ddr_address1;
|
240 |
|
|
assign ddr_ba_cntrl = ddr_ba1;
|
241 |
|
|
assign rst_dqs_div_int = rst_dqs_div_int1;
|
242 |
|
|
assign emr = `EXT_LOAD_MODE_REGISTER;
|
243 |
|
|
assign lmr = `LOAD_MODE_REGISTER;
|
244 |
|
|
assign lmr_dll_rst = {lmr[`ROW_ADDRESS - 1 : 9],1'b1,lmr[7:0]};
|
245 |
|
|
assign lmr_dll_set = {lmr[`ROW_ADDRESS - 1 : 9],1'b0,lmr[7:0]};
|
246 |
|
|
assign ddr_cke_cntrl = ~wait_200us;
|
247 |
|
|
|
248 |
|
|
// turn off auto-precharge when issuing read/write commands (A10 = 0)
|
249 |
|
|
// mapping the column address for linear addressing.
|
250 |
|
|
generate
|
251 |
|
|
if (COL_WIDTH == ROW_WIDTH-1) begin: gen_ddr_addr_col_0
|
252 |
|
|
assign column_address = {address_reg[COL_WIDTH-1:10], 1'b0,
|
253 |
|
|
address_reg[9:0]};
|
254 |
|
|
end else begin
|
255 |
|
|
if (COL_WIDTH > 10) begin: gen_ddr_addr_col_1
|
256 |
|
|
assign column_address = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}},
|
257 |
|
|
address_reg[COL_WIDTH-1:10], 1'b0,
|
258 |
|
|
address_reg[9:0]};
|
259 |
|
|
end else begin: gen_ddr_addr_col_2
|
260 |
|
|
assign column_address = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, 1'b0,
|
261 |
|
|
address_reg[COL_WIDTH-1:0]};
|
262 |
|
|
end
|
263 |
|
|
end
|
264 |
|
|
endgenerate
|
265 |
|
|
|
266 |
|
|
always @ (negedge clk)
|
267 |
|
|
rst180_r <= rst180;
|
268 |
|
|
|
269 |
|
|
always @ (posedge clk)
|
270 |
|
|
rst0_r <= rst0;
|
271 |
|
|
|
272 |
|
|
//******************************************************************************
|
273 |
|
|
// Register user address
|
274 |
|
|
//******************************************************************************
|
275 |
|
|
|
276 |
|
|
always @ (negedge clk) begin
|
277 |
|
|
row_address_reg <= row_address;
|
278 |
|
|
column_address_reg <= column_address;
|
279 |
|
|
ba_address_reg1 <= bank_address;
|
280 |
|
|
ba_address_reg2 <= ba_address_reg1;
|
281 |
|
|
address_reg <= address;
|
282 |
|
|
end
|
283 |
|
|
|
284 |
|
|
always @ (negedge clk) begin
|
285 |
|
|
if (rst180_r == 1'b1) begin
|
286 |
|
|
burst_length <= 3'b000;
|
287 |
|
|
wr <= 3'd0;
|
288 |
|
|
end
|
289 |
|
|
else begin
|
290 |
|
|
burst_length <= lmr[2:0];
|
291 |
|
|
wr <= `TWR_COUNT_VALUE;
|
292 |
|
|
end
|
293 |
|
|
end
|
294 |
|
|
|
295 |
|
|
always @( negedge clk ) begin
|
296 |
|
|
if ( rst180_r )
|
297 |
|
|
accept_cmd_in <= 1'b0;
|
298 |
|
|
else if ( current_state == IDLE && ((rp_count == 3'd0 && rfc_count_reg &&
|
299 |
|
|
!auto_ref_wait && !auto_ref_issued)))
|
300 |
|
|
accept_cmd_in <= 1'b1;
|
301 |
|
|
else
|
302 |
|
|
accept_cmd_in <= 1'b0;
|
303 |
|
|
end
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
//******************************************************************************
|
307 |
|
|
// Commands from user.
|
308 |
|
|
//******************************************************************************
|
309 |
|
|
assign init_cmd_in = (command_register == 3'b010);
|
310 |
|
|
assign write_cmd_in = (command_register == 3'b100 &&
|
311 |
|
|
accept_cmd_in == 1'b1) ;
|
312 |
|
|
assign read_cmd_in = (command_register == 3'b110 &&
|
313 |
|
|
accept_cmd_in == 1'b1) ;
|
314 |
|
|
|
315 |
|
|
//******************************************************************************
|
316 |
|
|
// write_cmd1 is asserted when user issued write command and the controller s/m
|
317 |
|
|
// is in idle state and AUTO_REF is not asserted.
|
318 |
|
|
//******************************************************************************
|
319 |
|
|
|
320 |
|
|
always @ (negedge clk) begin
|
321 |
|
|
if (rst180_r == 1'b1) begin
|
322 |
|
|
write_cmd1 <= 1'b0;
|
323 |
|
|
write_cmd2 <= 1'b0;
|
324 |
|
|
write_cmd3 <= 1'b0;
|
325 |
|
|
end
|
326 |
|
|
else begin
|
327 |
|
|
if (accept_cmd_in)
|
328 |
|
|
write_cmd1 <= write_cmd_in;
|
329 |
|
|
write_cmd2 <= write_cmd1;
|
330 |
|
|
write_cmd3 <= write_cmd2;
|
331 |
|
|
end
|
332 |
|
|
end
|
333 |
|
|
|
334 |
|
|
//******************************************************************************
|
335 |
|
|
// read_cmd1 is asserted when user issued read command and the controller s/m
|
336 |
|
|
// is in idle state and AUTO_REF is not asserted.
|
337 |
|
|
//******************************************************************************
|
338 |
|
|
|
339 |
|
|
always @ (negedge clk) begin
|
340 |
|
|
if (rst180_r == 1'b1) begin
|
341 |
|
|
read_cmd1 <= 1'b0;
|
342 |
|
|
read_cmd2 <= 1'b0;
|
343 |
|
|
read_cmd3 <= 1'b0;
|
344 |
|
|
end
|
345 |
|
|
else begin
|
346 |
|
|
if (accept_cmd_in)
|
347 |
|
|
read_cmd1 <= read_cmd_in;
|
348 |
|
|
read_cmd2 <= read_cmd1;
|
349 |
|
|
read_cmd3 <= read_cmd2;
|
350 |
|
|
end
|
351 |
|
|
end
|
352 |
|
|
|
353 |
|
|
//******************************************************************************
|
354 |
|
|
// ras_count- Active to Precharge time
|
355 |
|
|
// Controller is giving tras violation when user issues a single read command for
|
356 |
|
|
// BL=4 and tRAS is more then 42ns.It uses a fixed clk count of 7 clocks which is
|
357 |
|
|
// 7*6(@166) = 42ns. Addded ras_count counter which will take care of tras timeout.
|
358 |
|
|
// RAS_COUNT_VALUE parameter is used to load the counter and it depends on the
|
359 |
|
|
// selected memory and frequency
|
360 |
|
|
//******************************************************************************
|
361 |
|
|
always @( negedge clk ) begin
|
362 |
|
|
if ( rst180_r )
|
363 |
|
|
ras_count <= 5'd0;
|
364 |
|
|
else if ( current_state == ACTIVE )
|
365 |
|
|
ras_count <= `RAS_COUNT_VALUE-1;
|
366 |
|
|
else if ( ras_count != 5'b00000 )
|
367 |
|
|
ras_count <= ras_count - 1'b1;
|
368 |
|
|
end
|
369 |
|
|
//******************************************************************************
|
370 |
|
|
// rfc_count
|
371 |
|
|
// An executable command can be issued only after Trfc period after a AUTOREFRESH
|
372 |
|
|
// command is issued. rfc_count_value is set in the parameter file depending on
|
373 |
|
|
// the memory device speed grade and the selected frequency.For example for 5B
|
374 |
|
|
// speed grade, trfc= 75 at 133Mhz, rfc_counter_value = 8'b00001010.
|
375 |
|
|
// ( Trfc/clk_period= 75/7.5= 10)
|
376 |
|
|
//******************************************************************************
|
377 |
|
|
|
378 |
|
|
always @( negedge clk ) begin
|
379 |
|
|
if (rst180_r == 1'b1)
|
380 |
|
|
rfc_count <= 8'd0;
|
381 |
|
|
else if(current_state == AUTO_REFRESH)
|
382 |
|
|
rfc_count <= rfc_counter_value;
|
383 |
|
|
else if(rfc_count != 8'd0)
|
384 |
|
|
rfc_count <= rfc_count - 1'b1;
|
385 |
|
|
end
|
386 |
|
|
|
387 |
|
|
//******************************************************************************
|
388 |
|
|
// rp_count
|
389 |
|
|
// An executable command can be issued only after Trp period after a PRECHARGE
|
390 |
|
|
// command is issued.
|
391 |
|
|
//******************************************************************************
|
392 |
|
|
|
393 |
|
|
always @( negedge clk ) begin
|
394 |
|
|
if ( rst180_r )
|
395 |
|
|
rp_count <= 3'b000;
|
396 |
|
|
else if ( current_state == PRECHARGE )
|
397 |
|
|
rp_count <= `RP_COUNT_VALUE;
|
398 |
|
|
else if ( rp_count != 3'b000 )
|
399 |
|
|
rp_count <= rp_count - 1'b1;
|
400 |
|
|
end
|
401 |
|
|
//******************************************************************************
|
402 |
|
|
// rcd_count
|
403 |
|
|
// ACTIVE to READ/WRITE delay - Minimum interval between ACTIVE and READ/WRITE command.
|
404 |
|
|
//******************************************************************************
|
405 |
|
|
|
406 |
|
|
always @( negedge clk ) begin
|
407 |
|
|
if ( rst180_r )
|
408 |
|
|
rcd_count <= 3'b000;
|
409 |
|
|
else if ( current_state == ACTIVE )
|
410 |
|
|
rcd_count <= 3'b001;
|
411 |
|
|
else if ( rcd_count != 3'b000 )
|
412 |
|
|
rcd_count <= rcd_count - 1'b1;
|
413 |
|
|
end
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
//******************************************************************************
|
417 |
|
|
// WR Counter a PRECHARGE command can be applied only after 3 cycles after a
|
418 |
|
|
// WRITE command has finished executing
|
419 |
|
|
//******************************************************************************
|
420 |
|
|
|
421 |
|
|
always @(negedge clk) begin
|
422 |
|
|
if (rst180_r)
|
423 |
|
|
wr_count <= 3'b000;
|
424 |
|
|
else
|
425 |
|
|
if (dqs_enable_int)
|
426 |
|
|
wr_count <= wr ;
|
427 |
|
|
else if (wr_count != 3'b000)
|
428 |
|
|
wr_count <= wr_count - 3'b001;
|
429 |
|
|
end
|
430 |
|
|
|
431 |
|
|
//******************************************************************************
|
432 |
|
|
// autoref_count - This counter is used to issue AUTO REFRESH command to
|
433 |
|
|
// the memory for every 7.8125us.
|
434 |
|
|
// (Auto Refresh Request is raised for every 7.7 us to allow for termination
|
435 |
|
|
// of any ongoing bus transfer).For example at 166MHz frequency
|
436 |
|
|
// autoref_count = refresh_time_period/clock_period = 7.7us/6.02ns = 1279
|
437 |
|
|
//******************************************************************************
|
438 |
|
|
|
439 |
|
|
always @ (negedge clk) begin
|
440 |
|
|
if (rst180_r == 1'b1) begin
|
441 |
|
|
rfc_counter_value <= `RFC_COUNT_VALUE;
|
442 |
|
|
ref_freq_cnt <= `MAX_REF_CNT;
|
443 |
|
|
autoref_value <= 1'b0;
|
444 |
|
|
end
|
445 |
|
|
else begin
|
446 |
|
|
rfc_counter_value <= `RFC_COUNT_VALUE;
|
447 |
|
|
ref_freq_cnt <= `MAX_REF_CNT;
|
448 |
|
|
autoref_value <= (autoref_count == ref_freq_cnt);
|
449 |
|
|
end
|
450 |
|
|
end
|
451 |
|
|
|
452 |
|
|
always @(negedge clk) begin
|
453 |
|
|
if(rst180_r)
|
454 |
|
|
autoref_count <= `MAX_REF_WIDTH'b0;
|
455 |
|
|
else if(autoref_value)
|
456 |
|
|
autoref_count <= `MAX_REF_WIDTH'b0;
|
457 |
|
|
else
|
458 |
|
|
autoref_count <= autoref_count + 1'b1;
|
459 |
|
|
end
|
460 |
|
|
|
461 |
|
|
always @ (negedge clk) begin
|
462 |
|
|
if (rst180_r == 1'b1) begin
|
463 |
|
|
auto_ref_detect1 <= 1'b0;
|
464 |
|
|
auto_ref1 <= 1'b0;
|
465 |
|
|
end
|
466 |
|
|
else begin
|
467 |
|
|
auto_ref_detect1 <= autoref_value && init_done;
|
468 |
|
|
auto_ref1 <= auto_ref_detect1;
|
469 |
|
|
end
|
470 |
|
|
end
|
471 |
|
|
|
472 |
|
|
assign ar_done_p = (ar_done_reg == 1'b1) ? 1'b1 : 1'b0;
|
473 |
|
|
|
474 |
|
|
always @ (negedge clk) begin
|
475 |
|
|
if (rst180_r == 1'b1) begin
|
476 |
|
|
auto_ref_wait <= 1'b0;
|
477 |
|
|
ar_done <= 1'b0;
|
478 |
|
|
auto_ref_issued <= 1'b0;
|
479 |
|
|
end
|
480 |
|
|
else begin
|
481 |
|
|
if (auto_ref1 && !auto_ref_wait)
|
482 |
|
|
auto_ref_wait <= 1'b1;
|
483 |
|
|
else if (auto_ref_issued_p)
|
484 |
|
|
auto_ref_wait <= 1'b0;
|
485 |
|
|
else
|
486 |
|
|
auto_ref_wait <= auto_ref_wait;
|
487 |
|
|
|
488 |
|
|
ar_done <= ar_done_p;
|
489 |
|
|
auto_ref_issued <= auto_ref_issued_p;
|
490 |
|
|
end
|
491 |
|
|
end
|
492 |
|
|
|
493 |
|
|
always @ (negedge clk) begin
|
494 |
|
|
if (rst180_r == 1'b1) begin
|
495 |
|
|
auto_ref_wait1 <= 1'b0;
|
496 |
|
|
auto_ref_wait2 <= 1'b0;
|
497 |
|
|
auto_ref <= 1'b0;
|
498 |
|
|
end
|
499 |
|
|
else begin
|
500 |
|
|
if (auto_ref_issued_p) begin
|
501 |
|
|
auto_ref_wait1 <= 1'b0;
|
502 |
|
|
auto_ref_wait2 <= 1'b0;
|
503 |
|
|
auto_ref <= 1'b0;
|
504 |
|
|
end
|
505 |
|
|
else begin
|
506 |
|
|
auto_ref_wait1 <= auto_ref_wait;
|
507 |
|
|
auto_ref_wait2 <= auto_ref_wait1;
|
508 |
|
|
auto_ref <= auto_ref_wait2;
|
509 |
|
|
end
|
510 |
|
|
end
|
511 |
|
|
end
|
512 |
|
|
|
513 |
|
|
assign auto_ref_req = auto_ref_wait;
|
514 |
|
|
assign auto_ref_issued_p = (current_state == AUTO_REFRESH);
|
515 |
|
|
|
516 |
|
|
//******************************************************************************
|
517 |
|
|
// Common counter for the Initialization sequence
|
518 |
|
|
//******************************************************************************
|
519 |
|
|
always @(negedge clk) begin
|
520 |
|
|
if(rst180_r)
|
521 |
|
|
count6 <= 8'd0;
|
522 |
|
|
else if(init_current_state == INIT_AUTO_REFRESH || init_current_state ==
|
523 |
|
|
INIT_PRECHARGE || init_current_state == INIT_LOAD_MODE_REG)
|
524 |
|
|
count6 <= `RFC_COUNT_VALUE;
|
525 |
|
|
else if(count6 != 8'd0)
|
526 |
|
|
count6 <= count6 - 1'b1;
|
527 |
|
|
else
|
528 |
|
|
count6 <= 8'd0;
|
529 |
|
|
end
|
530 |
|
|
|
531 |
|
|
//******************************************************************************
|
532 |
|
|
// While doing consecutive READs or WRITEs, the burst_cnt_max value determines
|
533 |
|
|
// when the next READ or WRITE command should be issued. burst_cnt_max shows the
|
534 |
|
|
// number of clock cycles for each burst.
|
535 |
|
|
// e.g burst_cnt_max = 2 for a burst length of 4
|
536 |
|
|
// = 4 for a burst length of 8
|
537 |
|
|
//******************************************************************************
|
538 |
|
|
assign burst_cnt_max = (burst_length == 3'b010) ? 3'b010 :
|
539 |
|
|
(burst_length == 3'b011) ? 3'b100 :
|
540 |
|
|
3'b000;
|
541 |
|
|
|
542 |
|
|
always @( negedge clk) begin
|
543 |
|
|
if(rst180_r)
|
544 |
|
|
cas_count <= 3'b000;
|
545 |
|
|
else if(current_state == BURST_READ)
|
546 |
|
|
cas_count <= burst_cnt_max - 1'b1;
|
547 |
|
|
else if(cas_count != 3'b000)
|
548 |
|
|
cas_count <= cas_count - 1'b1;
|
549 |
|
|
end
|
550 |
|
|
|
551 |
|
|
|
552 |
|
|
always @( negedge clk ) begin
|
553 |
|
|
if(rst180_r)
|
554 |
|
|
wrburst_end_cnt <= 3'b000;
|
555 |
|
|
else if((current_state == FIRST_WRITE) || (current_state == BURST_WRITE))
|
556 |
|
|
wrburst_end_cnt <= burst_cnt_max;
|
557 |
|
|
else if(wrburst_end_cnt != 3'b000)
|
558 |
|
|
wrburst_end_cnt <= wrburst_end_cnt - 1'b1;
|
559 |
|
|
end
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
always @ (negedge clk) begin
|
563 |
|
|
if (rst180_r == 1'b1)
|
564 |
|
|
rdburst_end_1 <= 1'b0;
|
565 |
|
|
else begin
|
566 |
|
|
rdburst_end_2 <= rdburst_end_1;
|
567 |
|
|
if (burst_done == 1'b1)
|
568 |
|
|
rdburst_end_1 <= 1'b1;
|
569 |
|
|
else
|
570 |
|
|
rdburst_end_1 <= 1'b0;
|
571 |
|
|
end
|
572 |
|
|
end
|
573 |
|
|
|
574 |
|
|
assign rdburst_end = rdburst_end_1 || rdburst_end_2 ;
|
575 |
|
|
|
576 |
|
|
always @ (negedge clk) begin
|
577 |
|
|
if (rst180_r == 1'b1)
|
578 |
|
|
wrburst_end_1 <= 1'b0;
|
579 |
|
|
else begin
|
580 |
|
|
wrburst_end_2 <= wrburst_end_1;
|
581 |
|
|
wrburst_end_3 <= wrburst_end_2;
|
582 |
|
|
if (burst_done == 1'b1)
|
583 |
|
|
wrburst_end_1 <= 1'b1;
|
584 |
|
|
else
|
585 |
|
|
wrburst_end_1 <= 1'b0;
|
586 |
|
|
end
|
587 |
|
|
end
|
588 |
|
|
|
589 |
|
|
assign wrburst_end = wrburst_end_1 || wrburst_end_2 || wrburst_end_3;
|
590 |
|
|
|
591 |
|
|
//******************************************************************************
|
592 |
|
|
// dqs_enable and dqs_reset signals are used to generate DQS signal during write
|
593 |
|
|
// data.
|
594 |
|
|
//******************************************************************************
|
595 |
|
|
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
assign dqs_enable = dqs_enable2;
|
599 |
|
|
assign dqs_reset = dqs_reset2_clk0;
|
600 |
|
|
|
601 |
|
|
always @ (negedge clk) begin
|
602 |
|
|
if (rst180_r == 1'b1) begin
|
603 |
|
|
dqs_enable_int <= 1'b0;
|
604 |
|
|
dqs_reset_int <= 1'b0;
|
605 |
|
|
end
|
606 |
|
|
else begin
|
607 |
|
|
dqs_enable_int <= ((current_state == FIRST_WRITE) ||
|
608 |
|
|
(current_state == BURST_WRITE) ||
|
609 |
|
|
(wrburst_end_cnt != 3'b000));
|
610 |
|
|
dqs_reset_int <= (current_state == FIRST_WRITE);
|
611 |
|
|
end
|
612 |
|
|
end
|
613 |
|
|
|
614 |
|
|
always @ (posedge clk) begin
|
615 |
|
|
if (rst0_r == 1'b1) begin
|
616 |
|
|
dqs_enable1 <= 1'b0;
|
617 |
|
|
dqs_enable2 <= 1'b0;
|
618 |
|
|
dqs_enable3 <= 1'b0;
|
619 |
|
|
dqs_reset1_clk0 <= 1'b0;
|
620 |
|
|
dqs_reset2_clk0 <= 1'b0;
|
621 |
|
|
dqs_reset3_clk0 <= 1'b0;
|
622 |
|
|
end
|
623 |
|
|
else begin
|
624 |
|
|
dqs_enable1 <= dqs_enable_int;
|
625 |
|
|
dqs_enable2 <= dqs_enable1;
|
626 |
|
|
dqs_enable3 <= dqs_enable2;
|
627 |
|
|
dqs_reset1_clk0 <= dqs_reset_int;
|
628 |
|
|
dqs_reset2_clk0 <= dqs_reset1_clk0;
|
629 |
|
|
dqs_reset3_clk0 <= dqs_reset2_clk0;
|
630 |
|
|
end
|
631 |
|
|
end
|
632 |
|
|
|
633 |
|
|
//******************************************************************************
|
634 |
|
|
//Write Enable signal to the datapath
|
635 |
|
|
//******************************************************************************
|
636 |
|
|
|
637 |
|
|
|
638 |
|
|
|
639 |
|
|
always @ (negedge clk) begin
|
640 |
|
|
if (rst180_r == 1'b1)
|
641 |
|
|
write_enable <= 1'b0;
|
642 |
|
|
else if(wrburst_end_cnt != 3'b000)
|
643 |
|
|
write_enable <= 1'b1;
|
644 |
|
|
else
|
645 |
|
|
write_enable <= 1'b0;
|
646 |
|
|
end
|
647 |
|
|
|
648 |
|
|
assign cmd_ack = ack_reg;
|
649 |
|
|
|
650 |
|
|
FD ack_reg_inst1
|
651 |
|
|
(
|
652 |
|
|
.Q (ack_reg),
|
653 |
|
|
.D (ack_o),
|
654 |
|
|
.C (~clk)
|
655 |
|
|
);
|
656 |
|
|
|
657 |
|
|
|
658 |
|
|
assign ack_o = ((write_cmd_in == 1'b1) || (write_cmd1 == 1'b1) ||
|
659 |
|
|
(read_cmd_in == 1'b1) || (read_cmd1 == 1'b1));
|
660 |
|
|
|
661 |
|
|
//******************************************************************************
|
662 |
|
|
// init_done will be asserted when initialization sequence is complete
|
663 |
|
|
//******************************************************************************
|
664 |
|
|
|
665 |
|
|
always @ (negedge clk) begin
|
666 |
|
|
if (rst180_r == 1'b1) begin
|
667 |
|
|
init_memory <= 1'b0;
|
668 |
|
|
init_done <= 1'b0;
|
669 |
|
|
init_done_r1 <= 1'b0;
|
670 |
|
|
end
|
671 |
|
|
else begin
|
672 |
|
|
init_memory <= init_mem;
|
673 |
|
|
init_done <= init_done_value && (init_count == 4'b1011);
|
674 |
|
|
init_done_r1 <= init_done;
|
675 |
|
|
end
|
676 |
|
|
end
|
677 |
|
|
|
678 |
|
|
//synthesis translate_off
|
679 |
|
|
always @ (negedge clk) begin
|
680 |
|
|
if (rst180_r == 1'b0)
|
681 |
|
|
if (init_done == 1'b1 && init_done_r1 == 1'b0)
|
682 |
|
|
$display ("INITIALIZATION_DONE");
|
683 |
|
|
end
|
684 |
|
|
//synthesis translate_on
|
685 |
|
|
|
686 |
|
|
always @ (negedge clk) begin
|
687 |
|
|
if (init_cmd_in)
|
688 |
|
|
init_pre_count <= 7'b101_0000;
|
689 |
|
|
else
|
690 |
|
|
init_pre_count <= init_pre_count - 7'h1;
|
691 |
|
|
end
|
692 |
|
|
|
693 |
|
|
always @( negedge clk ) begin
|
694 |
|
|
if ( rst180_r )
|
695 |
|
|
init_mem <= 1'b0;
|
696 |
|
|
else if ( init_cmd_in )
|
697 |
|
|
init_mem <= 1'b1;
|
698 |
|
|
else if ( (init_count == 4'b1011) && (count6 == 8'd0 ))
|
699 |
|
|
init_mem <= 1'b0;
|
700 |
|
|
else
|
701 |
|
|
init_mem <= init_mem;
|
702 |
|
|
end
|
703 |
|
|
|
704 |
|
|
always @( negedge clk ) begin
|
705 |
|
|
if ( rst180_r )
|
706 |
|
|
init_count <= 4'b0;
|
707 |
|
|
else if (((init_current_state == INIT_PRECHARGE) ||
|
708 |
|
|
(init_current_state == INIT_LOAD_MODE_REG)
|
709 |
|
|
|| (init_current_state == INIT_AUTO_REFRESH))
|
710 |
|
|
&& init_memory == 1'b1)
|
711 |
|
|
init_count <= init_count + 1'b1;
|
712 |
|
|
else
|
713 |
|
|
init_count <= init_count;
|
714 |
|
|
end
|
715 |
|
|
|
716 |
|
|
assign init_done_value = (dll_rst_count == 8'b0000_0001) ;
|
717 |
|
|
|
718 |
|
|
|
719 |
|
|
//Counter to count 200 clock cycles When DLL reset is issued during
|
720 |
|
|
//initialization.
|
721 |
|
|
|
722 |
|
|
always @( negedge clk ) begin
|
723 |
|
|
if( rst180_r )
|
724 |
|
|
dll_rst_count <= 8'd0;
|
725 |
|
|
else if(init_count == 4'b0100)
|
726 |
|
|
dll_rst_count <= 8'd200;
|
727 |
|
|
else if(dll_rst_count != 8'b0000_0001)
|
728 |
|
|
dll_rst_count <= dll_rst_count - 8'b0000_0001;
|
729 |
|
|
else
|
730 |
|
|
dll_rst_count <= dll_rst_count;
|
731 |
|
|
end
|
732 |
|
|
|
733 |
|
|
|
734 |
|
|
|
735 |
|
|
assign go_to_active_value =((write_cmd_in == 1'b1) && (accept_cmd_in == 1'b1))
|
736 |
|
|
|| ((read_cmd_in == 1'b1) && (accept_cmd_in == 1'b1))
|
737 |
|
|
? 1'b1 : 1'b0;
|
738 |
|
|
|
739 |
|
|
always @ (negedge clk) begin
|
740 |
|
|
if (rst180_r == 1'b1)
|
741 |
|
|
go_to_active <= 1'b0;
|
742 |
|
|
else
|
743 |
|
|
go_to_active <= go_to_active_value;
|
744 |
|
|
end
|
745 |
|
|
|
746 |
|
|
|
747 |
|
|
always @ (negedge clk) begin
|
748 |
|
|
if (rst180_r == 1'b1) begin
|
749 |
|
|
rfc_count_reg <= 1'b0;
|
750 |
|
|
ar_done_reg <= 1'b0;
|
751 |
|
|
end
|
752 |
|
|
else begin
|
753 |
|
|
if(rfc_count == 8'd2)
|
754 |
|
|
ar_done_reg <= 1'b1;
|
755 |
|
|
else
|
756 |
|
|
ar_done_reg <= 1'b0;
|
757 |
|
|
if(ar_done_reg == 1'b1)
|
758 |
|
|
rfc_count_reg <= 1'b1;
|
759 |
|
|
else if(init_done == 1'b1 && init_mem == 1'b0 &&
|
760 |
|
|
rfc_count == 8'd0)
|
761 |
|
|
rfc_count_reg <= 1'b1;
|
762 |
|
|
else if (auto_ref_issued == 1'b1)
|
763 |
|
|
rfc_count_reg <= 1'b0;
|
764 |
|
|
else
|
765 |
|
|
rfc_count_reg <= rfc_count_reg;
|
766 |
|
|
end
|
767 |
|
|
end
|
768 |
|
|
|
769 |
|
|
|
770 |
|
|
|
771 |
|
|
//******************************************************************************
|
772 |
|
|
// Initialization state machine
|
773 |
|
|
//******************************************************************************
|
774 |
|
|
|
775 |
|
|
always @ (negedge clk) begin
|
776 |
|
|
if (rst180_r == 1'b1)
|
777 |
|
|
init_current_state <= INIT_IDLE;
|
778 |
|
|
else
|
779 |
|
|
init_current_state <= init_next_state;
|
780 |
|
|
end
|
781 |
|
|
|
782 |
|
|
always @ (*) begin
|
783 |
|
|
if (rst180_r == 1'b1)
|
784 |
|
|
init_next_state = INIT_IDLE;
|
785 |
|
|
else begin
|
786 |
|
|
case (init_current_state)
|
787 |
|
|
INIT_IDLE : begin
|
788 |
|
|
if (init_memory == 1'b1) begin
|
789 |
|
|
case (init_count)
|
790 |
|
|
4'b0000 : begin
|
791 |
|
|
if(init_pre_count == 7'b000_0001)
|
792 |
|
|
init_next_state = INIT_PRECHARGE;
|
793 |
|
|
else
|
794 |
|
|
init_next_state = INIT_IDLE;
|
795 |
|
|
end
|
796 |
|
|
4'b0001 : begin
|
797 |
|
|
if (count6 == 8'd0)
|
798 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
799 |
|
|
else
|
800 |
|
|
init_next_state = INIT_IDLE;
|
801 |
|
|
end
|
802 |
|
|
4'b0010 : begin
|
803 |
|
|
if (count6 == 8'd0)
|
804 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
805 |
|
|
else
|
806 |
|
|
init_next_state = INIT_IDLE;
|
807 |
|
|
end
|
808 |
|
|
4'b0011 : begin
|
809 |
|
|
if (count6 == 8'd0)
|
810 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
811 |
|
|
else
|
812 |
|
|
init_next_state = INIT_IDLE;
|
813 |
|
|
end
|
814 |
|
|
4'b0100 : begin
|
815 |
|
|
if (count6 == 8'd0)
|
816 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
817 |
|
|
else
|
818 |
|
|
init_next_state = INIT_IDLE;
|
819 |
|
|
end
|
820 |
|
|
4'b0101 : begin
|
821 |
|
|
if (count6 == 8'd0)
|
822 |
|
|
init_next_state = INIT_PRECHARGE;
|
823 |
|
|
else
|
824 |
|
|
init_next_state = INIT_IDLE;
|
825 |
|
|
end
|
826 |
|
|
4'b0110 : begin
|
827 |
|
|
if (count6 == 8'd0)
|
828 |
|
|
init_next_state = INIT_AUTO_REFRESH;
|
829 |
|
|
else
|
830 |
|
|
init_next_state = INIT_IDLE;
|
831 |
|
|
end
|
832 |
|
|
4'b0111: begin
|
833 |
|
|
if (count6 == 8'd0)
|
834 |
|
|
init_next_state = INIT_AUTO_REFRESH;
|
835 |
|
|
else
|
836 |
|
|
init_next_state = INIT_IDLE;
|
837 |
|
|
end
|
838 |
|
|
4'b1000: begin
|
839 |
|
|
if (count6 == 8'd0)
|
840 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
841 |
|
|
else
|
842 |
|
|
init_next_state = INIT_IDLE;
|
843 |
|
|
end
|
844 |
|
|
4'b1001: begin
|
845 |
|
|
if (count6 == 8'd0)
|
846 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
847 |
|
|
else
|
848 |
|
|
init_next_state = init_current_state;
|
849 |
|
|
end
|
850 |
|
|
4'b1010: begin
|
851 |
|
|
if (count6 == 8'd0)
|
852 |
|
|
init_next_state = INIT_LOAD_MODE_REG;
|
853 |
|
|
else
|
854 |
|
|
init_next_state = init_current_state;
|
855 |
|
|
end
|
856 |
|
|
4'b1011: begin
|
857 |
|
|
if (count6 == 8'd0)
|
858 |
|
|
init_next_state = INIT_IDLE;
|
859 |
|
|
else
|
860 |
|
|
init_next_state = init_current_state;
|
861 |
|
|
end
|
862 |
|
|
default :
|
863 |
|
|
init_next_state = INIT_IDLE;
|
864 |
|
|
endcase
|
865 |
|
|
end
|
866 |
|
|
else
|
867 |
|
|
init_next_state = INIT_IDLE;
|
868 |
|
|
end
|
869 |
|
|
INIT_PRECHARGE :
|
870 |
|
|
init_next_state = INIT_IDLE;
|
871 |
|
|
|
872 |
|
|
INIT_LOAD_MODE_REG :
|
873 |
|
|
init_next_state = INIT_IDLE;
|
874 |
|
|
|
875 |
|
|
INIT_AUTO_REFRESH :
|
876 |
|
|
init_next_state = INIT_IDLE;
|
877 |
|
|
|
878 |
|
|
default :
|
879 |
|
|
init_next_state = INIT_IDLE;
|
880 |
|
|
endcase
|
881 |
|
|
end
|
882 |
|
|
end
|
883 |
|
|
|
884 |
|
|
//******************************************************************************
|
885 |
|
|
// Main state machine
|
886 |
|
|
//******************************************************************************
|
887 |
|
|
|
888 |
|
|
always @ (negedge clk) begin
|
889 |
|
|
if (rst180_r == 1'b1)
|
890 |
|
|
current_state <= IDLE;
|
891 |
|
|
else
|
892 |
|
|
current_state <= next_state;
|
893 |
|
|
end
|
894 |
|
|
|
895 |
|
|
|
896 |
|
|
always @ (*) begin
|
897 |
|
|
if (rst180_r == 1'b1)
|
898 |
|
|
next_state = IDLE;
|
899 |
|
|
else begin
|
900 |
|
|
case (current_state)
|
901 |
|
|
IDLE : begin
|
902 |
|
|
if(~init_mem) begin
|
903 |
|
|
if ( auto_ref == 1'b1 && rfc_count_reg == 1'b1
|
904 |
|
|
&& rp_count == 3'd0 )
|
905 |
|
|
next_state = AUTO_REFRESH;
|
906 |
|
|
else if (go_to_active == 1'b1)
|
907 |
|
|
next_state = ACTIVE;
|
908 |
|
|
else
|
909 |
|
|
next_state = IDLE;
|
910 |
|
|
end
|
911 |
|
|
else
|
912 |
|
|
next_state = IDLE;
|
913 |
|
|
end
|
914 |
|
|
|
915 |
|
|
PRECHARGE :
|
916 |
|
|
next_state = IDLE;
|
917 |
|
|
|
918 |
|
|
AUTO_REFRESH :
|
919 |
|
|
next_state = IDLE;
|
920 |
|
|
|
921 |
|
|
ACTIVE :
|
922 |
|
|
next_state = ACTIVE_WAIT;
|
923 |
|
|
|
924 |
|
|
ACTIVE_WAIT : begin
|
925 |
|
|
if(rcd_count == 3'b000 && write_cmd1)
|
926 |
|
|
next_state = FIRST_WRITE;
|
927 |
|
|
else if (rcd_count == 3'b000 && read_cmd3)
|
928 |
|
|
next_state = BURST_READ;
|
929 |
|
|
else
|
930 |
|
|
next_state = ACTIVE_WAIT;
|
931 |
|
|
end
|
932 |
|
|
|
933 |
|
|
FIRST_WRITE : begin
|
934 |
|
|
next_state = WRITE_WAIT;
|
935 |
|
|
end
|
936 |
|
|
|
937 |
|
|
WRITE_WAIT : begin
|
938 |
|
|
case(wrburst_end)
|
939 |
|
|
1'b1 :
|
940 |
|
|
next_state = PRECHARGE_AFTER_WRITE;
|
941 |
|
|
1'b0 : begin
|
942 |
|
|
if (wrburst_end_cnt == 3'b010)
|
943 |
|
|
next_state = BURST_WRITE;
|
944 |
|
|
else
|
945 |
|
|
next_state = WRITE_WAIT;
|
946 |
|
|
end
|
947 |
|
|
default :
|
948 |
|
|
next_state = WRITE_WAIT;
|
949 |
|
|
endcase
|
950 |
|
|
end
|
951 |
|
|
BURST_WRITE : begin
|
952 |
|
|
next_state = WRITE_WAIT;
|
953 |
|
|
end
|
954 |
|
|
PRECHARGE_AFTER_WRITE : begin
|
955 |
|
|
next_state = PRECHARGE_AFTER_WRITE_2;
|
956 |
|
|
end
|
957 |
|
|
PRECHARGE_AFTER_WRITE_2 : begin
|
958 |
|
|
if(wr_count == 3'd0 && ras_count == 5'd0)
|
959 |
|
|
next_state = PRECHARGE;
|
960 |
|
|
else
|
961 |
|
|
next_state = PRECHARGE_AFTER_WRITE_2;
|
962 |
|
|
end
|
963 |
|
|
READ_WAIT : begin
|
964 |
|
|
case(rdburst_end)
|
965 |
|
|
1'b1 :
|
966 |
|
|
next_state = PRECHARGE_AFTER_WRITE;
|
967 |
|
|
1'b0 : begin
|
968 |
|
|
if (cas_count == 3'b001)
|
969 |
|
|
next_state = BURST_READ;
|
970 |
|
|
else
|
971 |
|
|
next_state = READ_WAIT;
|
972 |
|
|
end
|
973 |
|
|
default :
|
974 |
|
|
next_state = READ_WAIT;
|
975 |
|
|
endcase
|
976 |
|
|
end
|
977 |
|
|
BURST_READ : begin
|
978 |
|
|
next_state = READ_WAIT;
|
979 |
|
|
end
|
980 |
|
|
default :
|
981 |
|
|
next_state = IDLE;
|
982 |
|
|
endcase
|
983 |
|
|
end
|
984 |
|
|
end
|
985 |
|
|
|
986 |
|
|
//******************************************************************************
|
987 |
|
|
// Address generation logic
|
988 |
|
|
//******************************************************************************
|
989 |
|
|
always @( negedge clk ) begin
|
990 |
|
|
if(rst180_r)
|
991 |
|
|
ddr_address1 <= {`ROW_ADDRESS{1'b0}};
|
992 |
|
|
else if(init_mem)
|
993 |
|
|
case ( init_count )
|
994 |
|
|
4'b0000, 4'b0101 : ddr_address1 <= {`ROW_ADDRESS{1'b0}} |
|
995 |
|
|
12'h400;
|
996 |
|
|
4'b0001 : ddr_address1 <= {`ROW_ADDRESS{1'b0}};
|
997 |
|
|
4'b0010 : ddr_address1 <= {`ROW_ADDRESS{1'b0}};
|
998 |
|
|
4'b0011 : ddr_address1 <= emr;
|
999 |
|
|
4'b0100 : ddr_address1 <= lmr_dll_rst;
|
1000 |
|
|
4'b1000 : ddr_address1 <= lmr_dll_set;
|
1001 |
|
|
4'b1001 : ddr_address1 <= emr | 12'h380;
|
1002 |
|
|
4'b1010 : ddr_address1 <= emr & 12'hc7f;
|
1003 |
|
|
default : ddr_address1 <= {`ROW_ADDRESS{1'b0}};
|
1004 |
|
|
endcase
|
1005 |
|
|
else if ( current_state == PRECHARGE ||
|
1006 |
|
|
init_current_state == INIT_PRECHARGE )
|
1007 |
|
|
ddr_address1 <= {`ROW_ADDRESS{1'b0}} | 12'h400;
|
1008 |
|
|
else if ( current_state == ACTIVE )
|
1009 |
|
|
ddr_address1 <= row_address_reg;
|
1010 |
|
|
else if ( current_state == BURST_WRITE || current_state == FIRST_WRITE ||
|
1011 |
|
|
current_state == BURST_READ )
|
1012 |
|
|
ddr_address1 <= column_address_reg1;
|
1013 |
|
|
else
|
1014 |
|
|
ddr_address1 <= `ROW_ADDRESS'b0;
|
1015 |
|
|
end
|
1016 |
|
|
|
1017 |
|
|
always @( negedge clk ) begin
|
1018 |
|
|
if ( rst180_r )
|
1019 |
|
|
ddr_ba1 <= {{`BANK_ADDRESS-1{1'b0}},1'b0};
|
1020 |
|
|
else if ( init_mem )
|
1021 |
|
|
case ( init_count )
|
1022 |
|
|
4'b0001 : ddr_ba1 <= (`BANK_ADDRESS'b10);
|
1023 |
|
|
4'b0010 : ddr_ba1 <= (`BANK_ADDRESS'b11);
|
1024 |
|
|
4'b0011 , 4'b1001 , 4'b1010 : ddr_ba1 <= (`BANK_ADDRESS'b01);
|
1025 |
|
|
default : ddr_ba1 <= {{`BANK_ADDRESS-1{1'b0}},1'b0};
|
1026 |
|
|
endcase
|
1027 |
|
|
else if ( current_state == ACTIVE || current_state == FIRST_WRITE ||
|
1028 |
|
|
current_state == BURST_WRITE || current_state == BURST_READ)
|
1029 |
|
|
ddr_ba1 <= ba_address_reg2;
|
1030 |
|
|
else
|
1031 |
|
|
ddr_ba1 <= `BANK_ADDRESS'b0;
|
1032 |
|
|
end
|
1033 |
|
|
|
1034 |
|
|
|
1035 |
|
|
always @( negedge clk ) begin
|
1036 |
|
|
if ( rst180_r )
|
1037 |
|
|
odt_deassert <= 1'b0;
|
1038 |
|
|
else if (wrburst_end_3)
|
1039 |
|
|
odt_deassert <= 1'b1;
|
1040 |
|
|
else if(!write_cmd3)
|
1041 |
|
|
odt_deassert <= 1'b0;
|
1042 |
|
|
else
|
1043 |
|
|
odt_deassert <= odt_deassert;
|
1044 |
|
|
end
|
1045 |
|
|
|
1046 |
|
|
assign ddr_odt1 = ( write_cmd3 == 1'b1 && (emr[6]|emr[2]) && !odt_deassert )
|
1047 |
|
|
? 1'b1 : 1'b0;
|
1048 |
|
|
|
1049 |
|
|
//******************************************************************************
|
1050 |
|
|
// Register column address
|
1051 |
|
|
//******************************************************************************
|
1052 |
|
|
always @ (negedge clk)
|
1053 |
|
|
column_address_reg1 <= column_address_reg;
|
1054 |
|
|
|
1055 |
|
|
//******************************************************************************
|
1056 |
|
|
//Pipeline stages for ddr_address and ddr_ba
|
1057 |
|
|
//******************************************************************************
|
1058 |
|
|
|
1059 |
|
|
always @ (negedge clk) begin
|
1060 |
|
|
if (rst180_r == 1'b1) begin
|
1061 |
|
|
ddr_odt2 <= 1'b0;
|
1062 |
|
|
ddr_rasb2 <= 1'b1;
|
1063 |
|
|
ddr_casb2 <= 1'b1;
|
1064 |
|
|
ddr_web2 <= 1'b1;
|
1065 |
|
|
end
|
1066 |
|
|
else begin
|
1067 |
|
|
ddr_odt2 <= ddr_odt1;
|
1068 |
|
|
ddr_rasb2 <= ddr_rasb1;
|
1069 |
|
|
ddr_casb2 <= ddr_casb1;
|
1070 |
|
|
ddr_web2 <= ddr_web1;
|
1071 |
|
|
end
|
1072 |
|
|
end
|
1073 |
|
|
|
1074 |
|
|
always @ (negedge clk) begin
|
1075 |
|
|
if (rst180_r == 1'b1)
|
1076 |
|
|
ddr_odt_cntrl <= 1'b0;
|
1077 |
|
|
else
|
1078 |
|
|
ddr_odt_cntrl <= ddr_odt2;
|
1079 |
|
|
end
|
1080 |
|
|
|
1081 |
|
|
//******************************************************************************
|
1082 |
|
|
// Control signals to the Memory
|
1083 |
|
|
//******************************************************************************
|
1084 |
|
|
|
1085 |
|
|
assign ddr_rasb1 = ~((current_state == ACTIVE) ||
|
1086 |
|
|
(current_state == PRECHARGE) ||
|
1087 |
|
|
(current_state == AUTO_REFRESH) ||
|
1088 |
|
|
(init_current_state == INIT_PRECHARGE) ||
|
1089 |
|
|
(init_current_state == INIT_AUTO_REFRESH) ||
|
1090 |
|
|
(init_current_state == INIT_LOAD_MODE_REG));
|
1091 |
|
|
|
1092 |
|
|
assign ddr_casb1 = ~((current_state == BURST_READ) ||
|
1093 |
|
|
(current_state == BURST_WRITE)
|
1094 |
|
|
|| (current_state == FIRST_WRITE) ||
|
1095 |
|
|
(current_state == AUTO_REFRESH) ||
|
1096 |
|
|
(init_current_state == INIT_AUTO_REFRESH) ||
|
1097 |
|
|
(init_current_state == INIT_LOAD_MODE_REG));
|
1098 |
|
|
|
1099 |
|
|
assign ddr_web1 = ~((current_state == BURST_WRITE) ||
|
1100 |
|
|
(current_state == FIRST_WRITE) ||
|
1101 |
|
|
(current_state == PRECHARGE) ||
|
1102 |
|
|
(init_current_state == INIT_PRECHARGE) ||
|
1103 |
|
|
(init_current_state == INIT_LOAD_MODE_REG));
|
1104 |
|
|
|
1105 |
|
|
//******************************************************************************
|
1106 |
|
|
// Register CONTROL SIGNALS outputs
|
1107 |
|
|
//******************************************************************************
|
1108 |
|
|
|
1109 |
|
|
always @ (negedge clk) begin
|
1110 |
|
|
if (rst180_r == 1'b1)
|
1111 |
|
|
dqs_div_cascount <= 3'b0;
|
1112 |
|
|
else if ((ddr_rasb2 == 1'b1) && (ddr_casb2 == 1'b0) && (ddr_web2 == 1'b1))
|
1113 |
|
|
dqs_div_cascount <= burst_cnt_max ;
|
1114 |
|
|
else if (dqs_div_cascount != 3'b000)
|
1115 |
|
|
dqs_div_cascount <= dqs_div_cascount - 1'b1;
|
1116 |
|
|
else
|
1117 |
|
|
dqs_div_cascount <= dqs_div_cascount;
|
1118 |
|
|
end
|
1119 |
|
|
|
1120 |
|
|
always @ (negedge clk) begin
|
1121 |
|
|
if (rst180_r == 1'b1)
|
1122 |
|
|
dqs_div_rdburstcount <= 3'b000;
|
1123 |
|
|
else begin
|
1124 |
|
|
if ((dqs_div_cascount == 3'b001) && (burst_length== 3'b010))
|
1125 |
|
|
dqs_div_rdburstcount <= 3'b010;
|
1126 |
|
|
else if ((dqs_div_cascount == 3'b011) && (burst_length== 3'b011))
|
1127 |
|
|
dqs_div_rdburstcount <= 3'b100;
|
1128 |
|
|
else begin
|
1129 |
|
|
if (dqs_div_rdburstcount != 3'b000)
|
1130 |
|
|
dqs_div_rdburstcount <= dqs_div_rdburstcount - 1'b1;
|
1131 |
|
|
else
|
1132 |
|
|
dqs_div_rdburstcount <= dqs_div_rdburstcount;
|
1133 |
|
|
end
|
1134 |
|
|
end
|
1135 |
|
|
end
|
1136 |
|
|
|
1137 |
|
|
always @ (negedge clk) begin
|
1138 |
|
|
if (rst180_r == 1'b1)
|
1139 |
|
|
rst_dqs_div_r <= 1'b0;
|
1140 |
|
|
else begin
|
1141 |
|
|
if (dqs_div_cascount == 3'b001 && burst_length == 3'b010)
|
1142 |
|
|
rst_dqs_div_r <= 1'b1;
|
1143 |
|
|
else if (dqs_div_cascount == 3'b011 && burst_length == 3'b011)
|
1144 |
|
|
rst_dqs_div_r <= 1'b1;
|
1145 |
|
|
else if (dqs_div_rdburstcount == 3'b001 && dqs_div_cascount == 3'b000)
|
1146 |
|
|
rst_dqs_div_r <= 1'b0;
|
1147 |
|
|
else
|
1148 |
|
|
rst_dqs_div_r <= rst_dqs_div_r;
|
1149 |
|
|
end
|
1150 |
|
|
end // always @ (negedge clk)
|
1151 |
|
|
|
1152 |
|
|
always @ (negedge clk)
|
1153 |
|
|
rst_dqs_div_r1 <= rst_dqs_div_r;
|
1154 |
|
|
|
1155 |
|
|
always @( negedge clk ) begin
|
1156 |
|
|
if(dqs_div_cascount != 3'b0 || dqs_div_rdburstcount != 3'b0 )
|
1157 |
|
|
rst_calib <= 1'b1;
|
1158 |
|
|
else
|
1159 |
|
|
rst_calib <= 1'b0;
|
1160 |
|
|
end
|
1161 |
|
|
|
1162 |
|
|
(* IOB = "FORCE" *) FD rst_iob_out
|
1163 |
|
|
(
|
1164 |
|
|
.Q(rst_dqs_div_int1),
|
1165 |
|
|
.D(rst_dqs_div_r),
|
1166 |
|
|
.C(clk)
|
1167 |
|
|
)/* synthesis syn_useioff = 1 */;
|
1168 |
|
|
|
1169 |
|
|
|
1170 |
|
|
//Read fifo read enable logic, this signal is same as rst_dqs_div_int signal for RDIMM
|
1171 |
|
|
//and one clock ahead of rst_dqs_div_int for component or UDIMM OR SODIMM.
|
1172 |
|
|
|
1173 |
|
|
always @(negedge clk)
|
1174 |
|
|
read_fifo_rden <= rst_dqs_div_r1;
|
1175 |
|
|
|
1176 |
|
|
endmodule
|