| 1 |
412 |
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 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.0
|
| 44 |
|
|
// \ \ Application: MIG
|
| 45 |
|
|
// / / Filename: ddr2_ctrl.v
|
| 46 |
|
|
// /___/ /\ Date Last Modified: $Date: 2008/12/23 14:26:00 $
|
| 47 |
|
|
// \ \ / \ Date Created: Wed Aug 30 2006
|
| 48 |
|
|
// \___\/\___\
|
| 49 |
|
|
//
|
| 50 |
|
|
//
|
| 51 |
|
|
//Device: Virtex-5
|
| 52 |
|
|
//Design Name: DDR/DDR2
|
| 53 |
|
|
//Purpose:
|
| 54 |
|
|
// This module is the main control logic of the memory interface. All
|
| 55 |
|
|
// commands are issued from here according to the burst, CAS Latency and the
|
| 56 |
|
|
// user commands.
|
| 57 |
|
|
//Reference:
|
| 58 |
|
|
//Revision History:
|
| 59 |
|
|
// Rev 1.2 - Fixed auto refresh to activate bug. KP 11-19-2007
|
| 60 |
|
|
// Rev 1.3 - For Dual Rank parts support CS logic modified. KP. 05/08/08
|
| 61 |
|
|
// Rev 1.4 - AUTO_REFRESH_WAIT state modified for Auto Refresh flag asserted
|
| 62 |
|
|
// immediately after calibration is completed. KP. 07/28/08
|
| 63 |
|
|
// Rev 1.5 - Assignment of bank_valid_r is modified to fix a bug in
|
| 64 |
|
|
// Bank Management logic. PK. 10/29/08
|
| 65 |
|
|
//*****************************************************************************
|
| 66 |
|
|
|
| 67 |
|
|
`timescale 1ns/1ps
|
| 68 |
|
|
|
| 69 |
|
|
module ddr2_ctrl #
|
| 70 |
|
|
(
|
| 71 |
|
|
// Following parameters are for 72-bit RDIMM design (for ML561 Reference
|
| 72 |
|
|
// board design). Actual values may be different. Actual parameters values
|
| 73 |
|
|
// are passed from design top module ddr2_mig module. Please refer to
|
| 74 |
|
|
// the ddr2_mig module for actual values.
|
| 75 |
|
|
parameter BANK_WIDTH = 2,
|
| 76 |
|
|
parameter COL_WIDTH = 10,
|
| 77 |
|
|
parameter CS_BITS = 0,
|
| 78 |
|
|
parameter CS_NUM = 1,
|
| 79 |
|
|
parameter ROW_WIDTH = 14,
|
| 80 |
|
|
parameter ADDITIVE_LAT = 0,
|
| 81 |
|
|
parameter BURST_LEN = 4,
|
| 82 |
|
|
parameter CAS_LAT = 5,
|
| 83 |
|
|
parameter ECC_ENABLE = 0,
|
| 84 |
|
|
parameter REG_ENABLE = 1,
|
| 85 |
|
|
parameter TREFI_NS = 7800,
|
| 86 |
|
|
parameter TRAS = 40000,
|
| 87 |
|
|
parameter TRCD = 15000,
|
| 88 |
|
|
parameter TRRD = 10000,
|
| 89 |
|
|
parameter TRFC = 105000,
|
| 90 |
|
|
parameter TRP = 15000,
|
| 91 |
|
|
parameter TRTP = 7500,
|
| 92 |
|
|
parameter TWR = 15000,
|
| 93 |
|
|
parameter TWTR = 10000,
|
| 94 |
|
|
parameter CLK_PERIOD = 3000,
|
| 95 |
|
|
parameter MULTI_BANK_EN = 1,
|
| 96 |
|
|
parameter TWO_T_TIME_EN = 0,
|
| 97 |
|
|
parameter DDR_TYPE = 1
|
| 98 |
|
|
)
|
| 99 |
|
|
(
|
| 100 |
|
|
input clk,
|
| 101 |
|
|
input rst,
|
| 102 |
|
|
input [2:0] af_cmd,
|
| 103 |
|
|
input [30:0] af_addr,
|
| 104 |
|
|
input af_empty,
|
| 105 |
|
|
input phy_init_done,
|
| 106 |
|
|
output ctrl_ref_flag,
|
| 107 |
|
|
output ctrl_af_rden,
|
| 108 |
|
|
output reg ctrl_wren,
|
| 109 |
|
|
output reg ctrl_rden,
|
| 110 |
|
|
output [ROW_WIDTH-1:0] ctrl_addr,
|
| 111 |
|
|
output [BANK_WIDTH-1:0] ctrl_ba,
|
| 112 |
|
|
output ctrl_ras_n,
|
| 113 |
|
|
output ctrl_cas_n,
|
| 114 |
|
|
output ctrl_we_n,
|
| 115 |
|
|
output [CS_NUM-1:0] ctrl_cs_n
|
| 116 |
|
|
);
|
| 117 |
|
|
|
| 118 |
|
|
// input address split into various ranges
|
| 119 |
|
|
localparam ROW_RANGE_START = COL_WIDTH;
|
| 120 |
|
|
localparam ROW_RANGE_END = ROW_WIDTH + ROW_RANGE_START - 1;
|
| 121 |
|
|
localparam BANK_RANGE_START = ROW_RANGE_END + 1;
|
| 122 |
|
|
localparam BANK_RANGE_END = BANK_WIDTH + BANK_RANGE_START - 1;
|
| 123 |
|
|
localparam CS_RANGE_START = BANK_RANGE_START + BANK_WIDTH;
|
| 124 |
|
|
localparam CS_RANGE_END = CS_BITS + CS_RANGE_START - 1;
|
| 125 |
|
|
// compare address (for determining bank/row hits) split into various ranges
|
| 126 |
|
|
// (compare address doesn't include column bits)
|
| 127 |
|
|
localparam CMP_WIDTH = CS_BITS + BANK_WIDTH + ROW_WIDTH;
|
| 128 |
|
|
localparam CMP_ROW_RANGE_START = 0;
|
| 129 |
|
|
localparam CMP_ROW_RANGE_END = ROW_WIDTH + CMP_ROW_RANGE_START - 1;
|
| 130 |
|
|
localparam CMP_BANK_RANGE_START = CMP_ROW_RANGE_END + 1;
|
| 131 |
|
|
localparam CMP_BANK_RANGE_END = BANK_WIDTH + CMP_BANK_RANGE_START - 1;
|
| 132 |
|
|
localparam CMP_CS_RANGE_START = CMP_BANK_RANGE_END + 1;
|
| 133 |
|
|
localparam CMP_CS_RANGE_END = CS_BITS + CMP_CS_RANGE_START-1;
|
| 134 |
|
|
|
| 135 |
|
|
localparam BURST_LEN_DIV2 = BURST_LEN / 2;
|
| 136 |
|
|
localparam OPEN_BANK_NUM = 4;
|
| 137 |
|
|
localparam CS_BITS_FIX = (CS_BITS == 0) ? 1 : CS_BITS;
|
| 138 |
|
|
|
| 139 |
|
|
// calculation counters based on clock cycle and memory parameters
|
| 140 |
|
|
// TRAS: ACTIVE->PRECHARGE interval - 2
|
| 141 |
|
|
localparam integer TRAS_CYC = (TRAS + CLK_PERIOD)/CLK_PERIOD;
|
| 142 |
|
|
// TRCD: ACTIVE->READ/WRITE interval - 3 (for DDR2 factor in ADD_LAT)
|
| 143 |
|
|
localparam integer TRRD_CYC = (TRRD + CLK_PERIOD)/CLK_PERIOD;
|
| 144 |
|
|
localparam integer TRCD_CYC = (((TRCD + CLK_PERIOD)/CLK_PERIOD) >
|
| 145 |
|
|
ADDITIVE_LAT )?
|
| 146 |
|
|
((TRCD+CLK_PERIOD)/ CLK_PERIOD) - ADDITIVE_LAT : 0;
|
| 147 |
|
|
// TRFC: REFRESH->REFRESH, REFRESH->ACTIVE interval - 2
|
| 148 |
|
|
localparam integer TRFC_CYC = (TRFC + CLK_PERIOD)/CLK_PERIOD;
|
| 149 |
|
|
// TRP: PRECHARGE->COMMAND interval - 2
|
| 150 |
|
|
// for precharge all add 1 extra clock cycle
|
| 151 |
|
|
localparam integer TRP_CYC = ((TRP + CLK_PERIOD)/CLK_PERIOD) +1;
|
| 152 |
|
|
// TRTP: READ->PRECHARGE interval - 2 (Al + BL/2 + (max (TRTP, 2tck))-2
|
| 153 |
|
|
localparam integer TRTP_TMP_MIN = (((TRTP + CLK_PERIOD)/CLK_PERIOD) >= 2)?
|
| 154 |
|
|
((TRTP + CLK_PERIOD)/CLK_PERIOD) : 2;
|
| 155 |
|
|
localparam integer TRTP_CYC = TRTP_TMP_MIN + ADDITIVE_LAT
|
| 156 |
|
|
+ BURST_LEN_DIV2 - 2;
|
| 157 |
|
|
// TWR: WRITE->PRECHARGE interval - 2
|
| 158 |
|
|
localparam integer WR_LAT = (DDR_TYPE > 0) ? CAS_LAT + ADDITIVE_LAT - 1 : 1;
|
| 159 |
|
|
localparam integer TWR_CYC = ((TWR + CLK_PERIOD)/CLK_PERIOD) +
|
| 160 |
|
|
WR_LAT + BURST_LEN_DIV2 ;
|
| 161 |
|
|
// TWTR: WRITE->READ interval - 3 (for DDR1, TWTR = 2 clks)
|
| 162 |
|
|
// DDR2 = CL-1 + BL/2 +TWTR
|
| 163 |
|
|
localparam integer TWTR_TMP_MIN = (TWTR + CLK_PERIOD)/CLK_PERIOD;
|
| 164 |
|
|
localparam integer TWTR_CYC = (DDR_TYPE > 0) ? (TWTR_TMP_MIN + (CAS_LAT -1)
|
| 165 |
|
|
+ BURST_LEN_DIV2 ): 2;
|
| 166 |
|
|
|
| 167 |
|
|
// TRTW: READ->WRITE interval - 3
|
| 168 |
|
|
// DDR1: CL + (BL/2)
|
| 169 |
|
|
// DDR2: (BL/2) + 2. Two more clocks are added to
|
| 170 |
|
|
// the DDR2 counter to account for the delay in
|
| 171 |
|
|
// arrival of the DQS during reads (pcb trace + buffer
|
| 172 |
|
|
// delays + memory parameters).
|
| 173 |
|
|
localparam TRTW_CYC = (DDR_TYPE > 0) ? BURST_LEN_DIV2 + 4 :
|
| 174 |
|
|
(CAS_LAT == 25) ? 2 + BURST_LEN_DIV2 : CAS_LAT + BURST_LEN_DIV2;
|
| 175 |
|
|
|
| 176 |
|
|
localparam integer CAS_LAT_RD = (CAS_LAT == 25) ? 2 : CAS_LAT;
|
| 177 |
|
|
|
| 178 |
|
|
// Make sure all values >= 0 (some may be = 0)
|
| 179 |
|
|
localparam TRAS_COUNT = (TRAS_CYC > 0) ? TRAS_CYC : 0;
|
| 180 |
|
|
localparam TRCD_COUNT = (TRCD_CYC > 0) ? TRCD_CYC : 0;
|
| 181 |
|
|
localparam TRRD_COUNT = (TRRD_CYC > 0) ? TRRD_CYC : 0;
|
| 182 |
|
|
localparam TRFC_COUNT = (TRFC_CYC > 0) ? TRFC_CYC : 0;
|
| 183 |
|
|
localparam TRP_COUNT = (TRP_CYC > 0) ? TRP_CYC : 0;
|
| 184 |
|
|
localparam TRTP_COUNT = (TRTP_CYC > 0) ? TRTP_CYC : 0;
|
| 185 |
|
|
localparam TWR_COUNT = (TWR_CYC > 0) ? TWR_CYC : 0;
|
| 186 |
|
|
localparam TWTR_COUNT = (TWTR_CYC > 0) ? TWTR_CYC : 0;
|
| 187 |
|
|
localparam TRTW_COUNT = (TRTW_CYC > 0) ? TRTW_CYC : 0;
|
| 188 |
|
|
|
| 189 |
|
|
// Auto refresh interval
|
| 190 |
|
|
localparam TREFI_COUNT = ((TREFI_NS * 1000)/CLK_PERIOD) - 1;
|
| 191 |
|
|
|
| 192 |
|
|
// memory controller states
|
| 193 |
|
|
localparam CTRL_IDLE = 5'h00;
|
| 194 |
|
|
localparam CTRL_PRECHARGE = 5'h01;
|
| 195 |
|
|
localparam CTRL_PRECHARGE_WAIT = 5'h02;
|
| 196 |
|
|
localparam CTRL_AUTO_REFRESH = 5'h03;
|
| 197 |
|
|
localparam CTRL_AUTO_REFRESH_WAIT = 5'h04;
|
| 198 |
|
|
localparam CTRL_ACTIVE = 5'h05;
|
| 199 |
|
|
localparam CTRL_ACTIVE_WAIT = 5'h06;
|
| 200 |
|
|
localparam CTRL_BURST_READ = 5'h07;
|
| 201 |
|
|
localparam CTRL_READ_WAIT = 5'h08;
|
| 202 |
|
|
localparam CTRL_BURST_WRITE = 5'h09;
|
| 203 |
|
|
localparam CTRL_WRITE_WAIT = 5'h0A;
|
| 204 |
|
|
localparam CTRL_PRECHARGE_WAIT1 = 5'h0B;
|
| 205 |
|
|
|
| 206 |
|
|
|
| 207 |
|
|
reg [CMP_WIDTH-1:0] act_addr_r;
|
| 208 |
|
|
wire [30:0] af_addr_r;
|
| 209 |
|
|
reg [30:0] af_addr_r1;
|
| 210 |
|
|
reg [30:0] af_addr_r2;
|
| 211 |
|
|
reg [30:0] af_addr_r3;
|
| 212 |
|
|
wire [2:0] af_cmd_r;
|
| 213 |
|
|
reg [2:0] af_cmd_r1;
|
| 214 |
|
|
reg [2:0] af_cmd_r2;
|
| 215 |
|
|
reg af_valid_r;
|
| 216 |
|
|
reg af_valid_r1;
|
| 217 |
|
|
reg af_valid_r2;
|
| 218 |
|
|
reg [CS_BITS_FIX :0] auto_cnt_r;
|
| 219 |
|
|
reg auto_ref_r;
|
| 220 |
|
|
reg [(OPEN_BANK_NUM*CMP_WIDTH)-1:0] bank_cmp_addr_r;
|
| 221 |
|
|
reg [OPEN_BANK_NUM-1:0] bank_hit;
|
| 222 |
|
|
reg [OPEN_BANK_NUM-1:0] bank_hit_r;
|
| 223 |
|
|
reg [OPEN_BANK_NUM-1:0] bank_hit_r1;
|
| 224 |
|
|
reg [OPEN_BANK_NUM-1:0] bank_valid_r;
|
| 225 |
|
|
reg bank_conflict_r;
|
| 226 |
|
|
reg conflict_resolved_r;
|
| 227 |
|
|
reg ctrl_af_rden_r;
|
| 228 |
|
|
reg conflict_detect_r;
|
| 229 |
|
|
wire conflict_detect;
|
| 230 |
|
|
reg cs_change_r;
|
| 231 |
|
|
reg cs_change_sticky_r;
|
| 232 |
|
|
reg [ROW_WIDTH-1:0] ddr_addr_r;
|
| 233 |
|
|
wire [ROW_WIDTH-1:0] ddr_addr_col;
|
| 234 |
|
|
wire [ROW_WIDTH-1:0] ddr_addr_row;
|
| 235 |
|
|
reg [BANK_WIDTH-1:0] ddr_ba_r;
|
| 236 |
|
|
reg ddr_cas_n_r;
|
| 237 |
|
|
reg [CS_NUM-1:0] ddr_cs_n_r;
|
| 238 |
|
|
reg ddr_ras_n_r;
|
| 239 |
|
|
reg ddr_we_n_r;
|
| 240 |
|
|
reg [4:0] next_state;
|
| 241 |
|
|
reg no_precharge_wait_r;
|
| 242 |
|
|
reg no_precharge_r;
|
| 243 |
|
|
reg no_precharge_r1;
|
| 244 |
|
|
reg phy_init_done_r;
|
| 245 |
|
|
reg [4:0] precharge_ok_cnt_r;
|
| 246 |
|
|
reg precharge_ok_r;
|
| 247 |
|
|
reg [4:0] ras_cnt_r;
|
| 248 |
|
|
reg [3:0] rcd_cnt_r;
|
| 249 |
|
|
reg rcd_cnt_ok_r;
|
| 250 |
|
|
reg [2:0] rdburst_cnt_r;
|
| 251 |
|
|
reg rdburst_ok_r;
|
| 252 |
|
|
reg rdburst_rden_ok_r;
|
| 253 |
|
|
reg rd_af_flag_r;
|
| 254 |
|
|
wire rd_flag;
|
| 255 |
|
|
reg rd_flag_r;
|
| 256 |
|
|
reg [4:0] rd_to_wr_cnt_r;
|
| 257 |
|
|
reg rd_to_wr_ok_r;
|
| 258 |
|
|
reg ref_flag_r;
|
| 259 |
|
|
reg [11:0] refi_cnt_r;
|
| 260 |
|
|
reg refi_cnt_ok_r;
|
| 261 |
|
|
reg rst_r
|
| 262 |
|
|
/* synthesis syn_preserve = 1 */;
|
| 263 |
|
|
reg rst_r1
|
| 264 |
|
|
/* synthesis syn_maxfan = 10 */;
|
| 265 |
|
|
reg [7:0] rfc_cnt_r;
|
| 266 |
|
|
reg rfc_ok_r;
|
| 267 |
|
|
reg [3:0] row_miss;
|
| 268 |
|
|
reg [3:0] row_conflict_r;
|
| 269 |
|
|
reg [3:0] rp_cnt_r;
|
| 270 |
|
|
reg rp_cnt_ok_r;
|
| 271 |
|
|
reg [CMP_WIDTH-1:0] sb_open_add_r;
|
| 272 |
|
|
reg [4:0] state_r;
|
| 273 |
|
|
reg [4:0] state_r1;
|
| 274 |
|
|
wire sm_rden;
|
| 275 |
|
|
reg sm_rden_r;
|
| 276 |
|
|
reg [2:0] trrd_cnt_r;
|
| 277 |
|
|
reg trrd_cnt_ok_r;
|
| 278 |
|
|
reg [2:0] two_t_enable_r;
|
| 279 |
|
|
reg [CS_NUM-1:0] two_t_enable_r1;
|
| 280 |
|
|
reg [2:0] wrburst_cnt_r;
|
| 281 |
|
|
reg wrburst_ok_r;
|
| 282 |
|
|
reg wrburst_wren_ok_r;
|
| 283 |
|
|
wire wr_flag;
|
| 284 |
|
|
reg wr_flag_r;
|
| 285 |
|
|
reg [4:0] wr_to_rd_cnt_r;
|
| 286 |
|
|
reg wr_to_rd_ok_r;
|
| 287 |
|
|
|
| 288 |
|
|
// XST attributes for local reset "tree"
|
| 289 |
|
|
// synthesis attribute shreg_extract of rst_r is "no";
|
| 290 |
|
|
// synthesis attribute shreg_extract of rst_r1 is "no";
|
| 291 |
|
|
// synthesis attribute equivalent_register_removal of rst_r is "no"
|
| 292 |
|
|
|
| 293 |
|
|
//***************************************************************************
|
| 294 |
|
|
|
| 295 |
|
|
// sm_rden is used to assert read enable to the address FIFO
|
| 296 |
|
|
assign sm_rden = ((state_r == CTRL_BURST_WRITE) ||
|
| 297 |
|
|
(state_r == CTRL_BURST_READ)) ;
|
| 298 |
|
|
|
| 299 |
|
|
// Assert this when approaching refresh and not in an access
|
| 300 |
|
|
reg ref_approaching;
|
| 301 |
|
|
always @(posedge clk)
|
| 302 |
|
|
ref_approaching <= (refi_cnt_r >= (TREFI_COUNT -80)) & ~af_valid_r2;
|
| 303 |
|
|
|
| 304 |
|
|
reg ref_just_happened;
|
| 305 |
|
|
always @(posedge clk)
|
| 306 |
|
|
ref_just_happened <= (refi_cnt_r < 12'h30) & ~af_valid_r2;
|
| 307 |
|
|
|
| 308 |
|
|
|
| 309 |
|
|
// assert read flag to the adress FIFO
|
| 310 |
|
|
assign ctrl_af_rden = (sm_rden || rd_af_flag_r) & !(ref_approaching | ref_just_happened);
|
| 311 |
|
|
|
| 312 |
|
|
// local reset "tree" for controller logic only. Create this to ease timing
|
| 313 |
|
|
// on reset path. Prohibit equivalent register removal on RST_R to prevent
|
| 314 |
|
|
// "sharing" with other local reset trees (caution: make sure global fanout
|
| 315 |
|
|
// limit is set to large enough value, otherwise SLICES may be used for
|
| 316 |
|
|
// fanout control on RST_R.
|
| 317 |
|
|
always @(posedge clk) begin
|
| 318 |
|
|
rst_r <= rst;
|
| 319 |
|
|
rst_r1 <= rst_r;
|
| 320 |
|
|
end
|
| 321 |
|
|
|
| 322 |
|
|
//*****************************************************************
|
| 323 |
|
|
// interpret commands from Command/Address FIFO
|
| 324 |
|
|
//*****************************************************************
|
| 325 |
|
|
|
| 326 |
|
|
assign wr_flag = (af_valid_r2) ? ((af_cmd_r2 == 3'b000) ? 1'b1 : 1'b0): 1'b0;
|
| 327 |
|
|
assign rd_flag = (af_valid_r2) ? ((af_cmd_r2 == 3'b001) ? 1'b1 : 1'b0): 1'b0;
|
| 328 |
|
|
|
| 329 |
|
|
always @(posedge clk) begin
|
| 330 |
|
|
rd_flag_r <= rd_flag;
|
| 331 |
|
|
wr_flag_r <= wr_flag;
|
| 332 |
|
|
end
|
| 333 |
|
|
|
| 334 |
|
|
//////////////////////////////////////////////////
|
| 335 |
|
|
// The data from the address FIFO is fetched and
|
| 336 |
|
|
// stored in two register stages. The data will be
|
| 337 |
|
|
// pulled out of the second register stage whenever
|
| 338 |
|
|
// the state machine can handle new data from the
|
| 339 |
|
|
// address FIFO.
|
| 340 |
|
|
|
| 341 |
|
|
// This flag is asserted when there is no
|
| 342 |
|
|
// cmd & address in the pipe. When there is
|
| 343 |
|
|
// valid cmd & addr from the address FIFO the
|
| 344 |
|
|
// af_valid signals will be asserted. This flag will
|
| 345 |
|
|
// be set the cycle af_valid_r is de-asserted.
|
| 346 |
|
|
always @(posedge clk) begin
|
| 347 |
|
|
// for simulation purposes - to force CTRL_AF_RDEN low during reset
|
| 348 |
|
|
if (rst_r1)
|
| 349 |
|
|
rd_af_flag_r <= 1'd0;
|
| 350 |
|
|
else if (rd_af_flag_r) // jb - probably should find a way to stop this toggling all the time
|
| 351 |
|
|
rd_af_flag_r <= 0; // jb
|
| 352 |
|
|
else if((ctrl_af_rden_r) ||
|
| 353 |
|
|
(/*rd_af_flag_r &&*/ (af_valid_r || af_valid_r1))) // Fixed bug where third addresses would get lost (pulled off fifo and then clobbered by other value later, thus ignored/skipped) - just make sure we don't get too excited and pull too many off at once - jb
|
| 354 |
|
|
rd_af_flag_r <= 1'd0;
|
| 355 |
|
|
else if (~af_valid_r1 || ~af_valid_r)
|
| 356 |
|
|
rd_af_flag_r <= 1'd1;
|
| 357 |
|
|
|
| 358 |
|
|
end // always @ (posedge clk)
|
| 359 |
|
|
|
| 360 |
|
|
|
| 361 |
|
|
|
| 362 |
|
|
// First register stage for the cmd & add from the FIFO.
|
| 363 |
|
|
// The af_valid_r signal gives the status of the data
|
| 364 |
|
|
// in this stage. The af_valid_r will be asserted when there
|
| 365 |
|
|
// is valid data. This register stage will be updated
|
| 366 |
|
|
// 1. read to the FIFO and the FIFO not empty
|
| 367 |
|
|
// 2. After write and read states
|
| 368 |
|
|
// 3. The valid signal is not asserted in the last stage.
|
| 369 |
|
|
always @(posedge clk) begin
|
| 370 |
|
|
if (rst_r1)begin
|
| 371 |
|
|
af_valid_r <= 1'd0;
|
| 372 |
|
|
end else begin
|
| 373 |
|
|
if (ctrl_af_rden_r || sm_rden_r || ~af_valid_r1
|
| 374 |
|
|
|| ~af_valid_r2)begin
|
| 375 |
|
|
af_valid_r <= ctrl_af_rden_r;
|
| 376 |
|
|
end
|
| 377 |
|
|
end
|
| 378 |
|
|
end
|
| 379 |
|
|
|
| 380 |
|
|
// The output register in the FIFO is used. The addr
|
| 381 |
|
|
// and command are already registered in the FIFO.
|
| 382 |
|
|
assign af_addr_r = af_addr;
|
| 383 |
|
|
assign af_cmd_r = af_cmd;
|
| 384 |
|
|
|
| 385 |
|
|
// Second register stage for the cmd & add from the FIFO.
|
| 386 |
|
|
// The af_valid_r1 signal gives the status of the data
|
| 387 |
|
|
// in this stage. The af_valid_r will be asserted when there
|
| 388 |
|
|
// is valid data. This register stage will be updated
|
| 389 |
|
|
// 1. read to the FIFO and the FIFO not empty and there
|
| 390 |
|
|
// is no valid data on this stage
|
| 391 |
|
|
// 2. After write and read states
|
| 392 |
|
|
// 3. The valid signal is not asserted in the last stage.
|
| 393 |
|
|
always@(posedge clk) begin
|
| 394 |
|
|
if (rst_r1)begin
|
| 395 |
|
|
af_valid_r1 <= 1'd0;
|
| 396 |
|
|
af_addr_r1 <= {31{1'bx}};
|
| 397 |
|
|
af_cmd_r1 <= {3{1'bx}};
|
| 398 |
|
|
end else if (~af_valid_r1 || sm_rden_r ||
|
| 399 |
|
|
~af_valid_r2) begin
|
| 400 |
|
|
af_valid_r1 <= af_valid_r;
|
| 401 |
|
|
af_addr_r1 <= af_addr_r;
|
| 402 |
|
|
af_cmd_r1 <= af_cmd_r;
|
| 403 |
|
|
end
|
| 404 |
|
|
end
|
| 405 |
|
|
|
| 406 |
|
|
// The state machine uses the address and command in this
|
| 407 |
|
|
// register stage. The data is fetched from the second
|
| 408 |
|
|
// register stage whenever the state machine can accept new
|
| 409 |
|
|
// addr. The conflict flags are also generated based on the
|
| 410 |
|
|
// second register stage and updated when the new address
|
| 411 |
|
|
// is loaded for the state machine.
|
| 412 |
|
|
always@(posedge clk) begin
|
| 413 |
|
|
if (rst_r1)begin
|
| 414 |
|
|
af_valid_r2 <= 1'd0;
|
| 415 |
|
|
af_addr_r2 <= {31{1'bx}};
|
| 416 |
|
|
af_cmd_r2 <= {3{1'bx}};
|
| 417 |
|
|
bank_hit_r <= {OPEN_BANK_NUM{1'bx}};
|
| 418 |
|
|
bank_conflict_r <= 1'bx;
|
| 419 |
|
|
row_conflict_r <= 4'bx;
|
| 420 |
|
|
end else if(sm_rden || ~af_valid_r2)begin
|
| 421 |
|
|
af_valid_r2 <= af_valid_r1;
|
| 422 |
|
|
af_addr_r2 <= af_addr_r1;
|
| 423 |
|
|
af_cmd_r2 <= af_cmd_r1;
|
| 424 |
|
|
if(MULTI_BANK_EN)begin
|
| 425 |
|
|
bank_hit_r <= bank_hit;
|
| 426 |
|
|
row_conflict_r <= row_miss;
|
| 427 |
|
|
bank_conflict_r <= (~(|bank_hit));
|
| 428 |
|
|
end else begin
|
| 429 |
|
|
bank_hit_r <= {OPEN_BANK_NUM{1'b0}};
|
| 430 |
|
|
bank_conflict_r <= 1'd0;
|
| 431 |
|
|
row_conflict_r[0] <= (af_addr_r1[CS_RANGE_END:ROW_RANGE_START]
|
| 432 |
|
|
!= sb_open_add_r[CMP_WIDTH-1:0]);
|
| 433 |
|
|
end
|
| 434 |
|
|
end
|
| 435 |
|
|
end // always@ (posedge clk)
|
| 436 |
|
|
|
| 437 |
|
|
//detecting cs change for multi chip select case
|
| 438 |
|
|
generate
|
| 439 |
|
|
if(CS_NUM > 1) begin: gen_cs_change
|
| 440 |
|
|
always @(posedge clk) begin
|
| 441 |
|
|
if(sm_rden || ~af_valid_r2)begin
|
| 442 |
|
|
cs_change_r <= af_addr_r1[CS_RANGE_END:CS_RANGE_START] !=
|
| 443 |
|
|
af_addr_r2[CS_RANGE_END:CS_RANGE_START] ;
|
| 444 |
|
|
cs_change_sticky_r <=
|
| 445 |
|
|
af_addr_r1[CS_RANGE_END:CS_RANGE_START] !=
|
| 446 |
|
|
af_addr_r2[CS_RANGE_END:CS_RANGE_START] ;
|
| 447 |
|
|
end else
|
| 448 |
|
|
cs_change_r <= 1'd0;
|
| 449 |
|
|
end
|
| 450 |
|
|
end // block: gen_cs_change
|
| 451 |
|
|
else begin: gen_cs_0
|
| 452 |
|
|
always @(posedge clk) begin
|
| 453 |
|
|
cs_change_r <= 1'd0;
|
| 454 |
|
|
cs_change_sticky_r <= 1'd0;
|
| 455 |
|
|
end
|
| 456 |
|
|
end
|
| 457 |
|
|
endgenerate
|
| 458 |
|
|
|
| 459 |
|
|
assign conflict_detect = (MULTI_BANK_EN) ?
|
| 460 |
|
|
((|(row_conflict_r[3:0] & bank_hit_r[3:0]))
|
| 461 |
|
|
| bank_conflict_r) & af_valid_r2 :
|
| 462 |
|
|
row_conflict_r[0] & af_valid_r2;
|
| 463 |
|
|
|
| 464 |
|
|
always @(posedge clk) begin
|
| 465 |
|
|
conflict_detect_r <= conflict_detect;
|
| 466 |
|
|
sm_rden_r <= sm_rden;
|
| 467 |
|
|
af_addr_r3 <= af_addr_r2;
|
| 468 |
|
|
ctrl_af_rden_r <= ctrl_af_rden & ~af_empty;
|
| 469 |
|
|
end
|
| 470 |
|
|
|
| 471 |
|
|
// conflict resolved signal. When this signal is asserted
|
| 472 |
|
|
// the conflict is resolved. The address to be compared
|
| 473 |
|
|
// for the conflict_resolved_r will be stored in act_add_r
|
| 474 |
|
|
// when the bank is opened.
|
| 475 |
|
|
always @(posedge clk) begin
|
| 476 |
|
|
conflict_resolved_r <= (act_addr_r ==
|
| 477 |
|
|
af_addr_r2[CS_RANGE_END:ROW_RANGE_START]);
|
| 478 |
|
|
if((state_r == CTRL_ACTIVE))
|
| 479 |
|
|
act_addr_r <= af_addr_r2[CS_RANGE_END:ROW_RANGE_START];
|
| 480 |
|
|
end
|
| 481 |
|
|
|
| 482 |
|
|
//***************************************************************************
|
| 483 |
|
|
// Bank management logic
|
| 484 |
|
|
// Semi-hardcoded for now for 4 banks
|
| 485 |
|
|
// will keep multiple banks open if MULTI_BANK_EN is true.
|
| 486 |
|
|
//***************************************************************************
|
| 487 |
|
|
|
| 488 |
|
|
genvar bank_i;
|
| 489 |
|
|
generate // if multiple bank option chosen
|
| 490 |
|
|
if(MULTI_BANK_EN) begin: gen_multi_bank_open
|
| 491 |
|
|
|
| 492 |
|
|
for (bank_i = 0; bank_i < OPEN_BANK_NUM;
|
| 493 |
|
|
bank_i = bank_i + 1) begin: gen_bank_hit1
|
| 494 |
|
|
// asserted if bank address match + open bank entry is valid
|
| 495 |
|
|
always @(*) begin
|
| 496 |
|
|
bank_hit[bank_i]
|
| 497 |
|
|
= ((bank_cmp_addr_r[(CMP_WIDTH*(bank_i+1))-1:
|
| 498 |
|
|
(CMP_WIDTH*bank_i)+ROW_WIDTH] ==
|
| 499 |
|
|
af_addr_r1[CS_RANGE_END:BANK_RANGE_START]) &&
|
| 500 |
|
|
bank_valid_r[bank_i]);
|
| 501 |
|
|
// asserted if row address match (no check for bank entry valid, rely
|
| 502 |
|
|
// on this term to be used in conjunction with BANK_HIT[])
|
| 503 |
|
|
row_miss[bank_i]
|
| 504 |
|
|
= (bank_cmp_addr_r[(CMP_WIDTH*bank_i)+ROW_WIDTH-1:
|
| 505 |
|
|
(CMP_WIDTH*bank_i)] !=
|
| 506 |
|
|
af_addr_r1[ROW_RANGE_END:ROW_RANGE_START]);
|
| 507 |
|
|
end
|
| 508 |
|
|
end
|
| 509 |
|
|
|
| 510 |
|
|
always @(posedge clk) begin
|
| 511 |
|
|
no_precharge_wait_r <= bank_valid_r[3] & bank_conflict_r;
|
| 512 |
|
|
bank_hit_r1 <= bank_hit_r;
|
| 513 |
|
|
end
|
| 514 |
|
|
|
| 515 |
|
|
always@(*)
|
| 516 |
|
|
no_precharge_r = ~bank_valid_r[3] & bank_conflict_r;
|
| 517 |
|
|
|
| 518 |
|
|
always@(posedge clk)
|
| 519 |
|
|
no_precharge_r1 <= no_precharge_r;
|
| 520 |
|
|
|
| 521 |
|
|
|
| 522 |
|
|
always @(posedge clk) begin
|
| 523 |
|
|
// Clear all bank valid bits during AR (i.e. since all banks get
|
| 524 |
|
|
// precharged during auto-refresh)
|
| 525 |
|
|
if ((state_r1 == CTRL_AUTO_REFRESH)) begin
|
| 526 |
|
|
bank_valid_r <= {OPEN_BANK_NUM{1'b0}};
|
| 527 |
|
|
bank_cmp_addr_r <= {(OPEN_BANK_NUM*CMP_WIDTH-1){1'b0}};
|
| 528 |
|
|
end else begin
|
| 529 |
|
|
if (state_r1 == CTRL_ACTIVE) begin
|
| 530 |
|
|
// 00 is always going to have the latest bank and row.
|
| 531 |
|
|
bank_cmp_addr_r[CMP_WIDTH-1:0]
|
| 532 |
|
|
<= af_addr_r3[CS_RANGE_END:ROW_RANGE_START];
|
| 533 |
|
|
// This indicates the bank was activated
|
| 534 |
|
|
bank_valid_r[0] <= 1'b1;
|
| 535 |
|
|
|
| 536 |
|
|
case ({bank_hit_r1[2:0]})
|
| 537 |
|
|
3'b001: begin
|
| 538 |
|
|
bank_cmp_addr_r[CMP_WIDTH-1:0]
|
| 539 |
|
|
<= af_addr_r3[CS_RANGE_END:ROW_RANGE_START];
|
| 540 |
|
|
// This indicates the bank was activated
|
| 541 |
|
|
bank_valid_r[0] <= 1'b1;
|
| 542 |
|
|
end
|
| 543 |
|
|
3'b010: begin //(b0->b1)
|
| 544 |
|
|
bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH]
|
| 545 |
|
|
<= bank_cmp_addr_r[CMP_WIDTH-1:0];
|
| 546 |
|
|
bank_valid_r[1] <= bank_valid_r[0];
|
| 547 |
|
|
end
|
| 548 |
|
|
3'b100:begin //(b0->b1, b1->b2)
|
| 549 |
|
|
bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH]
|
| 550 |
|
|
<= bank_cmp_addr_r[CMP_WIDTH-1:0];
|
| 551 |
|
|
bank_cmp_addr_r[(3*CMP_WIDTH)-1:2*CMP_WIDTH]
|
| 552 |
|
|
<= bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH];
|
| 553 |
|
|
bank_valid_r[1] <= bank_valid_r[0];
|
| 554 |
|
|
bank_valid_r[2] <= bank_valid_r[1];
|
| 555 |
|
|
end
|
| 556 |
|
|
default: begin //(b0->b1, b1->b2, b2->b3)
|
| 557 |
|
|
bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH]
|
| 558 |
|
|
<= bank_cmp_addr_r[CMP_WIDTH-1:0];
|
| 559 |
|
|
bank_cmp_addr_r[(3*CMP_WIDTH)-1:2*CMP_WIDTH]
|
| 560 |
|
|
<= bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH];
|
| 561 |
|
|
bank_cmp_addr_r[(4*CMP_WIDTH)-1:3*CMP_WIDTH]
|
| 562 |
|
|
<= bank_cmp_addr_r[(3*CMP_WIDTH)-1:2*CMP_WIDTH];
|
| 563 |
|
|
bank_valid_r[1] <= bank_valid_r[0];
|
| 564 |
|
|
bank_valid_r[2] <= bank_valid_r[1];
|
| 565 |
|
|
bank_valid_r[3] <= bank_valid_r[2];
|
| 566 |
|
|
end
|
| 567 |
|
|
endcase
|
| 568 |
|
|
end
|
| 569 |
|
|
end
|
| 570 |
|
|
end
|
| 571 |
|
|
end else begin: gen_single_bank_open // single bank option
|
| 572 |
|
|
always @(posedge clk) begin
|
| 573 |
|
|
no_precharge_r <= 1'd0;
|
| 574 |
|
|
no_precharge_r1 <= 1'd0;
|
| 575 |
|
|
no_precharge_wait_r <= 1'd0;
|
| 576 |
|
|
if (rst_r1)
|
| 577 |
|
|
sb_open_add_r <= {CMP_WIDTH{1'b0}};
|
| 578 |
|
|
else if (state_r == CTRL_ACTIVE)
|
| 579 |
|
|
sb_open_add_r <= af_addr_r2[CS_RANGE_END:ROW_RANGE_START];
|
| 580 |
|
|
end
|
| 581 |
|
|
end
|
| 582 |
|
|
endgenerate
|
| 583 |
|
|
|
| 584 |
|
|
//***************************************************************************
|
| 585 |
|
|
// Timing counters
|
| 586 |
|
|
//***************************************************************************
|
| 587 |
|
|
|
| 588 |
|
|
//*****************************************************************
|
| 589 |
|
|
// Write and read enable generation for PHY
|
| 590 |
|
|
//*****************************************************************
|
| 591 |
|
|
|
| 592 |
|
|
// write burst count. Counts from (BL/2 to 1).
|
| 593 |
|
|
// Also logic for controller write enable.
|
| 594 |
|
|
always @(posedge clk) begin
|
| 595 |
|
|
if (state_r == CTRL_BURST_WRITE) begin
|
| 596 |
|
|
wrburst_cnt_r <= BURST_LEN_DIV2;
|
| 597 |
|
|
end else if (wrburst_cnt_r >= 3'd1)
|
| 598 |
|
|
wrburst_cnt_r <= wrburst_cnt_r - 1;
|
| 599 |
|
|
end // always @ (posedge clk)
|
| 600 |
|
|
|
| 601 |
|
|
|
| 602 |
|
|
always @(posedge clk) begin
|
| 603 |
|
|
if (rst_r1) begin
|
| 604 |
|
|
ctrl_wren <= 1'b0;
|
| 605 |
|
|
end else if (state_r == CTRL_BURST_WRITE) begin
|
| 606 |
|
|
ctrl_wren <= 1'b1;
|
| 607 |
|
|
end else if (wrburst_wren_ok_r)
|
| 608 |
|
|
ctrl_wren <= 1'b0;
|
| 609 |
|
|
end
|
| 610 |
|
|
|
| 611 |
|
|
|
| 612 |
|
|
always @(posedge clk) begin
|
| 613 |
|
|
if ((state_r == CTRL_BURST_WRITE)
|
| 614 |
|
|
&& (BURST_LEN_DIV2 > 2))
|
| 615 |
|
|
wrburst_ok_r <= 1'd0;
|
| 616 |
|
|
else if ((wrburst_cnt_r <= 3'd3) ||
|
| 617 |
|
|
(BURST_LEN_DIV2 <= 2))
|
| 618 |
|
|
wrburst_ok_r <= 1'b1;
|
| 619 |
|
|
end
|
| 620 |
|
|
|
| 621 |
|
|
// flag to check when wrburst count has reached
|
| 622 |
|
|
// a value of 1. This flag is used in the ctrl_wren
|
| 623 |
|
|
// logic
|
| 624 |
|
|
always @(posedge clk) begin
|
| 625 |
|
|
if(wrburst_cnt_r == 3'd2)
|
| 626 |
|
|
wrburst_wren_ok_r <=1'b1;
|
| 627 |
|
|
else
|
| 628 |
|
|
wrburst_wren_ok_r <= 1'b0;
|
| 629 |
|
|
end
|
| 630 |
|
|
|
| 631 |
|
|
|
| 632 |
|
|
// read burst count. Counts from (BL/2 to 1)
|
| 633 |
|
|
always @(posedge clk) begin
|
| 634 |
|
|
if (state_r == CTRL_BURST_READ) begin
|
| 635 |
|
|
rdburst_cnt_r <= BURST_LEN_DIV2;
|
| 636 |
|
|
end else if (rdburst_cnt_r >= 3'd1)
|
| 637 |
|
|
rdburst_cnt_r <= rdburst_cnt_r - 1;
|
| 638 |
|
|
end // always @ (posedge clk)
|
| 639 |
|
|
|
| 640 |
|
|
|
| 641 |
|
|
always @(posedge clk) begin
|
| 642 |
|
|
if (rst_r1) begin
|
| 643 |
|
|
ctrl_rden <= 1'b0;
|
| 644 |
|
|
end else if (state_r == CTRL_BURST_READ) begin
|
| 645 |
|
|
ctrl_rden <= 1'b1;
|
| 646 |
|
|
end else if (rdburst_rden_ok_r)
|
| 647 |
|
|
ctrl_rden <= 1'b0;
|
| 648 |
|
|
end
|
| 649 |
|
|
|
| 650 |
|
|
// the rd_burst_ok_r signal will be asserted one cycle later
|
| 651 |
|
|
// in multi chip select cases if the back to back read is to
|
| 652 |
|
|
// different chip selects. The cs_changed_sticky_r signal will
|
| 653 |
|
|
// be asserted only for multi chip select cases.
|
| 654 |
|
|
always @(posedge clk) begin
|
| 655 |
|
|
if ((state_r == CTRL_BURST_READ)
|
| 656 |
|
|
&& (BURST_LEN_DIV2 > 2))
|
| 657 |
|
|
rdburst_ok_r <= 1'd0;
|
| 658 |
|
|
else if ((rdburst_cnt_r <=( 3'd3 - cs_change_sticky_r)) ||
|
| 659 |
|
|
(BURST_LEN_DIV2 <= 2))
|
| 660 |
|
|
rdburst_ok_r <= 1'b1;
|
| 661 |
|
|
end
|
| 662 |
|
|
|
| 663 |
|
|
// flag to check when rdburst count has reached
|
| 664 |
|
|
// a value of 1. This flag is used in the ctrl_rden
|
| 665 |
|
|
// logic
|
| 666 |
|
|
always @(posedge clk) begin
|
| 667 |
|
|
if (rdburst_cnt_r == 3'd2)
|
| 668 |
|
|
rdburst_rden_ok_r <= 1'b1;
|
| 669 |
|
|
else
|
| 670 |
|
|
rdburst_rden_ok_r <= 1'b0;
|
| 671 |
|
|
end
|
| 672 |
|
|
|
| 673 |
|
|
|
| 674 |
|
|
//*****************************************************************
|
| 675 |
|
|
// Various delay counters
|
| 676 |
|
|
// The counters are checked for value of <= 3 to determine the
|
| 677 |
|
|
// if the count values are reached during different commands.
|
| 678 |
|
|
// It is checked for 3 because
|
| 679 |
|
|
// 1. The counters are loaded during the state when the command
|
| 680 |
|
|
// state is reached (+1)
|
| 681 |
|
|
// 2. After the <= 3 condition is reached the sm takes two cycles
|
| 682 |
|
|
// to transition to the new command state (+2)
|
| 683 |
|
|
//*****************************************************************
|
| 684 |
|
|
|
| 685 |
|
|
// tRP count - precharge command period
|
| 686 |
|
|
always @(posedge clk) begin
|
| 687 |
|
|
if (state_r == CTRL_PRECHARGE)
|
| 688 |
|
|
rp_cnt_r <= TRP_COUNT;
|
| 689 |
|
|
else if (rp_cnt_r != 4'd0)
|
| 690 |
|
|
rp_cnt_r <= rp_cnt_r - 1;
|
| 691 |
|
|
end
|
| 692 |
|
|
|
| 693 |
|
|
always @(posedge clk) begin
|
| 694 |
|
|
if (state_r == CTRL_PRECHARGE)
|
| 695 |
|
|
rp_cnt_ok_r <= 1'd0;
|
| 696 |
|
|
else if (rp_cnt_r <= 4'd3)
|
| 697 |
|
|
rp_cnt_ok_r <= 1'd1;
|
| 698 |
|
|
end
|
| 699 |
|
|
|
| 700 |
|
|
// tRFC count - refresh-refresh, refresh-active
|
| 701 |
|
|
always @(posedge clk) begin
|
| 702 |
|
|
if (state_r == CTRL_AUTO_REFRESH)
|
| 703 |
|
|
rfc_cnt_r <= TRFC_COUNT;
|
| 704 |
|
|
else if (rfc_cnt_r != 8'd0)
|
| 705 |
|
|
rfc_cnt_r <= rfc_cnt_r - 1;
|
| 706 |
|
|
end
|
| 707 |
|
|
|
| 708 |
|
|
always @(posedge clk) begin
|
| 709 |
|
|
if (state_r == CTRL_AUTO_REFRESH)
|
| 710 |
|
|
rfc_ok_r <= 1'b0;
|
| 711 |
|
|
else if(rfc_cnt_r <= 8'd3)
|
| 712 |
|
|
rfc_ok_r <= 1'b1;
|
| 713 |
|
|
end
|
| 714 |
|
|
|
| 715 |
|
|
// tRCD count - active to read/write
|
| 716 |
|
|
always @(posedge clk) begin
|
| 717 |
|
|
if (state_r == CTRL_ACTIVE)
|
| 718 |
|
|
rcd_cnt_r <= TRCD_COUNT;
|
| 719 |
|
|
else if (rcd_cnt_r != 4'd0)
|
| 720 |
|
|
rcd_cnt_r <= rcd_cnt_r - 1;
|
| 721 |
|
|
end
|
| 722 |
|
|
|
| 723 |
|
|
always @(posedge clk) begin
|
| 724 |
|
|
if ((state_r == CTRL_ACTIVE)
|
| 725 |
|
|
&& (TRCD_COUNT > 2))
|
| 726 |
|
|
rcd_cnt_ok_r <= 1'd0;
|
| 727 |
|
|
else if (rcd_cnt_r <= 4'd3)
|
| 728 |
|
|
rcd_cnt_ok_r <= 1;
|
| 729 |
|
|
end
|
| 730 |
|
|
|
| 731 |
|
|
// tRRD count - active to active
|
| 732 |
|
|
always @(posedge clk) begin
|
| 733 |
|
|
if (state_r == CTRL_ACTIVE)
|
| 734 |
|
|
trrd_cnt_r <= TRRD_COUNT;
|
| 735 |
|
|
else if (trrd_cnt_r != 3'd0)
|
| 736 |
|
|
trrd_cnt_r <= trrd_cnt_r - 1;
|
| 737 |
|
|
end
|
| 738 |
|
|
|
| 739 |
|
|
always @(posedge clk) begin
|
| 740 |
|
|
if (state_r == CTRL_ACTIVE)
|
| 741 |
|
|
trrd_cnt_ok_r <= 1'd0;
|
| 742 |
|
|
else if (trrd_cnt_r <= 3'd3)
|
| 743 |
|
|
trrd_cnt_ok_r <= 1;
|
| 744 |
|
|
end
|
| 745 |
|
|
|
| 746 |
|
|
// tRAS count - active to precharge
|
| 747 |
|
|
always @(posedge clk) begin
|
| 748 |
|
|
if (state_r == CTRL_ACTIVE)
|
| 749 |
|
|
ras_cnt_r <= TRAS_COUNT;
|
| 750 |
|
|
else if (ras_cnt_r != 5'd0)
|
| 751 |
|
|
ras_cnt_r <= ras_cnt_r - 1;
|
| 752 |
|
|
end
|
| 753 |
|
|
|
| 754 |
|
|
// counter for write to prcharge
|
| 755 |
|
|
// read to precharge and
|
| 756 |
|
|
// activate to precharge
|
| 757 |
|
|
// precharge_ok_cnt_r is added with trtp count,
|
| 758 |
|
|
// there can be cases where the sm can go from
|
| 759 |
|
|
// activate to read and the act->pre count time
|
| 760 |
|
|
// would not have been satisfied. The rd->pre
|
| 761 |
|
|
// time is very less. wr->pre time is almost the
|
| 762 |
|
|
// same as act-> pre
|
| 763 |
|
|
always @(posedge clk) begin
|
| 764 |
|
|
if (state_r == CTRL_BURST_READ) begin
|
| 765 |
|
|
// assign only if the cnt is < TRTP_COUNT
|
| 766 |
|
|
if (precharge_ok_cnt_r < TRTP_COUNT)
|
| 767 |
|
|
precharge_ok_cnt_r <= TRTP_COUNT;
|
| 768 |
|
|
end else if (state_r == CTRL_BURST_WRITE)
|
| 769 |
|
|
precharge_ok_cnt_r <= TWR_COUNT;
|
| 770 |
|
|
else if (state_r == CTRL_ACTIVE)
|
| 771 |
|
|
precharge_ok_cnt_r <= TRAS_COUNT;
|
| 772 |
|
|
else if (precharge_ok_cnt_r != 5'd0)
|
| 773 |
|
|
precharge_ok_cnt_r <= precharge_ok_cnt_r - 1;
|
| 774 |
|
|
end
|
| 775 |
|
|
|
| 776 |
|
|
always @(posedge clk) begin
|
| 777 |
|
|
if ((state_r == CTRL_BURST_READ) ||
|
| 778 |
|
|
(state_r == CTRL_BURST_WRITE)||
|
| 779 |
|
|
(state_r == CTRL_ACTIVE))
|
| 780 |
|
|
precharge_ok_r <= 1'd0;
|
| 781 |
|
|
else if(precharge_ok_cnt_r <= 5'd3)
|
| 782 |
|
|
precharge_ok_r <=1'd1;
|
| 783 |
|
|
end
|
| 784 |
|
|
|
| 785 |
|
|
// write to read counter
|
| 786 |
|
|
// write to read includes : write latency + burst time + tWTR
|
| 787 |
|
|
always @(posedge clk) begin
|
| 788 |
|
|
if (rst_r1)
|
| 789 |
|
|
wr_to_rd_cnt_r <= 5'd0;
|
| 790 |
|
|
else if (state_r == CTRL_BURST_WRITE)
|
| 791 |
|
|
wr_to_rd_cnt_r <= (TWTR_COUNT);
|
| 792 |
|
|
else if (wr_to_rd_cnt_r != 5'd0)
|
| 793 |
|
|
wr_to_rd_cnt_r <= wr_to_rd_cnt_r - 1;
|
| 794 |
|
|
end
|
| 795 |
|
|
|
| 796 |
|
|
always @(posedge clk) begin
|
| 797 |
|
|
if (state_r == CTRL_BURST_WRITE)
|
| 798 |
|
|
wr_to_rd_ok_r <= 1'd0;
|
| 799 |
|
|
else if (wr_to_rd_cnt_r <= 5'd3)
|
| 800 |
|
|
wr_to_rd_ok_r <= 1'd1;
|
| 801 |
|
|
end
|
| 802 |
|
|
|
| 803 |
|
|
// read to write counter
|
| 804 |
|
|
always @(posedge clk) begin
|
| 805 |
|
|
if (rst_r1)
|
| 806 |
|
|
rd_to_wr_cnt_r <= 5'd0;
|
| 807 |
|
|
else if (state_r == CTRL_BURST_READ)
|
| 808 |
|
|
rd_to_wr_cnt_r <= (TRTW_COUNT);
|
| 809 |
|
|
else if (rd_to_wr_cnt_r != 5'd0)
|
| 810 |
|
|
rd_to_wr_cnt_r <= rd_to_wr_cnt_r - 1;
|
| 811 |
|
|
end
|
| 812 |
|
|
|
| 813 |
|
|
always @(posedge clk) begin
|
| 814 |
|
|
if (state_r == CTRL_BURST_READ)
|
| 815 |
|
|
rd_to_wr_ok_r <= 1'b0;
|
| 816 |
|
|
else if (rd_to_wr_cnt_r <= 5'd3)
|
| 817 |
|
|
rd_to_wr_ok_r <= 1'b1;
|
| 818 |
|
|
end
|
| 819 |
|
|
|
| 820 |
|
|
always @(posedge clk) begin
|
| 821 |
|
|
if(refi_cnt_r == (TREFI_COUNT -1))
|
| 822 |
|
|
refi_cnt_ok_r <= 1'b1;
|
| 823 |
|
|
else
|
| 824 |
|
|
refi_cnt_ok_r <= 1'b0;
|
| 825 |
|
|
end
|
| 826 |
|
|
|
| 827 |
|
|
// auto refresh interval counter in refresh_clk domain
|
| 828 |
|
|
always @(posedge clk) begin
|
| 829 |
|
|
if ((rst_r1) || (refi_cnt_ok_r)) begin
|
| 830 |
|
|
refi_cnt_r <= 12'd0;
|
| 831 |
|
|
end else begin
|
| 832 |
|
|
refi_cnt_r <= refi_cnt_r + 1;
|
| 833 |
|
|
end
|
| 834 |
|
|
end // always @ (posedge clk)
|
| 835 |
|
|
|
| 836 |
|
|
// auto refresh flag
|
| 837 |
|
|
always @(posedge clk) begin
|
| 838 |
|
|
if (refi_cnt_ok_r) begin
|
| 839 |
|
|
ref_flag_r <= 1'b1;
|
| 840 |
|
|
end else begin
|
| 841 |
|
|
ref_flag_r <= 1'b0;
|
| 842 |
|
|
end
|
| 843 |
|
|
end // always @ (posedge clk)
|
| 844 |
|
|
|
| 845 |
|
|
assign ctrl_ref_flag = ref_flag_r;
|
| 846 |
|
|
|
| 847 |
|
|
//refresh flag detect
|
| 848 |
|
|
//auto_ref high indicates auto_refresh requirement
|
| 849 |
|
|
//auto_ref is held high until auto refresh command is issued.
|
| 850 |
|
|
always @(posedge clk)begin
|
| 851 |
|
|
if (rst_r1)
|
| 852 |
|
|
auto_ref_r <= 1'b0;
|
| 853 |
|
|
else if (ref_flag_r)
|
| 854 |
|
|
auto_ref_r <= 1'b1;
|
| 855 |
|
|
else if (state_r == CTRL_AUTO_REFRESH)
|
| 856 |
|
|
auto_ref_r <= 1'b0;
|
| 857 |
|
|
end
|
| 858 |
|
|
|
| 859 |
|
|
|
| 860 |
|
|
// keep track of which chip selects got auto-refreshed (avoid auto-refreshing
|
| 861 |
|
|
// all CS's at once to avoid current spike)
|
| 862 |
|
|
always @(posedge clk)begin
|
| 863 |
|
|
if (rst_r1 || (state_r1 == CTRL_PRECHARGE))
|
| 864 |
|
|
auto_cnt_r <= 'd0;
|
| 865 |
|
|
else if (state_r1 == CTRL_AUTO_REFRESH)
|
| 866 |
|
|
auto_cnt_r <= auto_cnt_r + 1;
|
| 867 |
|
|
end
|
| 868 |
|
|
|
| 869 |
|
|
// register for timing purposes. Extra delay doesn't really matter
|
| 870 |
|
|
always @(posedge clk)
|
| 871 |
|
|
phy_init_done_r <= phy_init_done;
|
| 872 |
|
|
|
| 873 |
|
|
always @(posedge clk)begin
|
| 874 |
|
|
if (rst_r1) begin
|
| 875 |
|
|
state_r <= CTRL_IDLE;
|
| 876 |
|
|
state_r1 <= CTRL_IDLE;
|
| 877 |
|
|
end else begin
|
| 878 |
|
|
state_r <= next_state;
|
| 879 |
|
|
state_r1 <= state_r;
|
| 880 |
|
|
end
|
| 881 |
|
|
end
|
| 882 |
|
|
|
| 883 |
|
|
//***************************************************************************
|
| 884 |
|
|
// main control state machine
|
| 885 |
|
|
//***************************************************************************
|
| 886 |
|
|
|
| 887 |
|
|
always @(*) begin
|
| 888 |
|
|
next_state = state_r;
|
| 889 |
|
|
(* full_case, parallel_case *) case (state_r)
|
| 890 |
|
|
CTRL_IDLE: begin
|
| 891 |
|
|
// perform auto refresh as soon as we are done with calibration.
|
| 892 |
|
|
// The calibration logic does not do any refreshes.
|
| 893 |
|
|
if (phy_init_done_r)
|
| 894 |
|
|
next_state = CTRL_AUTO_REFRESH;
|
| 895 |
|
|
end
|
| 896 |
|
|
|
| 897 |
|
|
CTRL_PRECHARGE: begin
|
| 898 |
|
|
if (auto_ref_r)
|
| 899 |
|
|
next_state = CTRL_PRECHARGE_WAIT1;
|
| 900 |
|
|
// when precharging an LRU bank, do not have to go to wait state
|
| 901 |
|
|
// since we can't possibly be activating row in same bank next
|
| 902 |
|
|
// disabled for 2t timing. There needs to be a gap between cmds
|
| 903 |
|
|
// in 2t timing
|
| 904 |
|
|
else if (no_precharge_wait_r && !TWO_T_TIME_EN)
|
| 905 |
|
|
next_state = CTRL_ACTIVE;
|
| 906 |
|
|
else
|
| 907 |
|
|
next_state = CTRL_PRECHARGE_WAIT;
|
| 908 |
|
|
end
|
| 909 |
|
|
|
| 910 |
|
|
CTRL_PRECHARGE_WAIT:begin
|
| 911 |
|
|
if (rp_cnt_ok_r)begin
|
| 912 |
|
|
if (auto_ref_r)
|
| 913 |
|
|
// precharge again to make sure we close all the banks
|
| 914 |
|
|
next_state = CTRL_PRECHARGE;
|
| 915 |
|
|
else
|
| 916 |
|
|
next_state = CTRL_ACTIVE;
|
| 917 |
|
|
end
|
| 918 |
|
|
end
|
| 919 |
|
|
|
| 920 |
|
|
CTRL_PRECHARGE_WAIT1:
|
| 921 |
|
|
if (rp_cnt_ok_r)
|
| 922 |
|
|
next_state = CTRL_AUTO_REFRESH;
|
| 923 |
|
|
|
| 924 |
|
|
CTRL_AUTO_REFRESH:
|
| 925 |
|
|
next_state = CTRL_AUTO_REFRESH_WAIT;
|
| 926 |
|
|
|
| 927 |
|
|
CTRL_AUTO_REFRESH_WAIT:
|
| 928 |
|
|
//staggering Auto refresh for multi
|
| 929 |
|
|
// chip select designs. The SM waits
|
| 930 |
|
|
// for the rfc time before issuing the
|
| 931 |
|
|
// next auto refresh.
|
| 932 |
|
|
if (auto_cnt_r < (CS_NUM))begin
|
| 933 |
|
|
if (rfc_ok_r )
|
| 934 |
|
|
next_state = CTRL_AUTO_REFRESH;
|
| 935 |
|
|
end else if (rfc_ok_r)begin
|
| 936 |
|
|
if(auto_ref_r)
|
| 937 |
|
|
// MIG 2.3: For deep designs if Auto Refresh
|
| 938 |
|
|
// flag asserted immediately after calibration is completed
|
| 939 |
|
|
next_state = CTRL_PRECHARGE;
|
| 940 |
|
|
else if ( wr_flag || rd_flag)
|
| 941 |
|
|
next_state = CTRL_ACTIVE;
|
| 942 |
|
|
end
|
| 943 |
|
|
|
| 944 |
|
|
CTRL_ACTIVE:
|
| 945 |
|
|
next_state = CTRL_ACTIVE_WAIT;
|
| 946 |
|
|
|
| 947 |
|
|
CTRL_ACTIVE_WAIT: begin
|
| 948 |
|
|
if (rcd_cnt_ok_r) begin
|
| 949 |
|
|
if ((conflict_detect_r && ~conflict_resolved_r) ||
|
| 950 |
|
|
auto_ref_r) begin
|
| 951 |
|
|
if (no_precharge_r1 && ~auto_ref_r && trrd_cnt_ok_r)
|
| 952 |
|
|
next_state = CTRL_ACTIVE;
|
| 953 |
|
|
else if(precharge_ok_r)
|
| 954 |
|
|
next_state = CTRL_PRECHARGE;
|
| 955 |
|
|
end else if ((wr_flag_r) && (rd_to_wr_ok_r))
|
| 956 |
|
|
next_state = CTRL_BURST_WRITE;
|
| 957 |
|
|
else if ((rd_flag_r)&& (wr_to_rd_ok_r))
|
| 958 |
|
|
next_state = CTRL_BURST_READ;
|
| 959 |
|
|
end
|
| 960 |
|
|
end
|
| 961 |
|
|
|
| 962 |
|
|
// beginning of write burst
|
| 963 |
|
|
CTRL_BURST_WRITE: begin
|
| 964 |
|
|
if (BURST_LEN_DIV2 == 1) begin
|
| 965 |
|
|
// special case if BL = 2 (i.e. burst lasts only one clk cycle)
|
| 966 |
|
|
if (wr_flag)
|
| 967 |
|
|
// if we have another non-conflict write command right after the
|
| 968 |
|
|
// current write, then stay in this state
|
| 969 |
|
|
next_state = CTRL_BURST_WRITE;
|
| 970 |
|
|
else
|
| 971 |
|
|
// otherwise, if we're done with this burst, and have no write
|
| 972 |
|
|
// immediately scheduled after this one, wait until write-read
|
| 973 |
|
|
// delay has passed
|
| 974 |
|
|
next_state = CTRL_WRITE_WAIT;
|
| 975 |
|
|
end else
|
| 976 |
|
|
// otherwise BL > 2, and we have at least one more write cycle for
|
| 977 |
|
|
// current burst
|
| 978 |
|
|
next_state = CTRL_WRITE_WAIT;
|
| 979 |
|
|
// continuation of write burst (also covers waiting after write burst
|
| 980 |
|
|
// has completed for write-read delay to pass)
|
| 981 |
|
|
end
|
| 982 |
|
|
|
| 983 |
|
|
CTRL_WRITE_WAIT: begin
|
| 984 |
|
|
if ((conflict_detect) || auto_ref_r) begin
|
| 985 |
|
|
if (no_precharge_r && ~auto_ref_r && wrburst_ok_r)
|
| 986 |
|
|
next_state = CTRL_ACTIVE;
|
| 987 |
|
|
else if (precharge_ok_r)
|
| 988 |
|
|
next_state = CTRL_PRECHARGE;
|
| 989 |
|
|
end else if (wrburst_ok_r && wr_flag)
|
| 990 |
|
|
next_state = CTRL_BURST_WRITE;
|
| 991 |
|
|
else if ((rd_flag) && (wr_to_rd_ok_r))
|
| 992 |
|
|
next_state = CTRL_BURST_READ;
|
| 993 |
|
|
end
|
| 994 |
|
|
|
| 995 |
|
|
CTRL_BURST_READ: begin
|
| 996 |
|
|
if (BURST_LEN_DIV2 == 1) begin
|
| 997 |
|
|
// special case if BL = 2 (i.e. burst lasts only one clk cycle)
|
| 998 |
|
|
if (rd_flag)
|
| 999 |
|
|
next_state = CTRL_BURST_READ;
|
| 1000 |
|
|
else
|
| 1001 |
|
|
next_state = CTRL_READ_WAIT;
|
| 1002 |
|
|
end else
|
| 1003 |
|
|
next_state = CTRL_READ_WAIT;
|
| 1004 |
|
|
end
|
| 1005 |
|
|
|
| 1006 |
|
|
CTRL_READ_WAIT: begin
|
| 1007 |
|
|
if ((conflict_detect) || auto_ref_r)begin
|
| 1008 |
|
|
if (no_precharge_r && ~auto_ref_r && rdburst_ok_r)
|
| 1009 |
|
|
next_state = CTRL_ACTIVE;
|
| 1010 |
|
|
else if (precharge_ok_r)
|
| 1011 |
|
|
next_state = CTRL_PRECHARGE;
|
| 1012 |
|
|
// for burst of 4 in multi chip select
|
| 1013 |
|
|
// if there is a change in cs wait one cycle before the
|
| 1014 |
|
|
// next read command. cs_change_r will be asserted.
|
| 1015 |
|
|
end else if (rdburst_ok_r && rd_flag && ~cs_change_r)
|
| 1016 |
|
|
next_state = CTRL_BURST_READ;
|
| 1017 |
|
|
else if (wr_flag && (rd_to_wr_ok_r))
|
| 1018 |
|
|
next_state = CTRL_BURST_WRITE;
|
| 1019 |
|
|
end
|
| 1020 |
|
|
endcase
|
| 1021 |
|
|
end
|
| 1022 |
|
|
|
| 1023 |
|
|
//***************************************************************************
|
| 1024 |
|
|
// control signals to memory
|
| 1025 |
|
|
//***************************************************************************
|
| 1026 |
|
|
|
| 1027 |
|
|
always @(posedge clk) begin
|
| 1028 |
|
|
if ((state_r == CTRL_AUTO_REFRESH) ||
|
| 1029 |
|
|
(state_r == CTRL_ACTIVE) ||
|
| 1030 |
|
|
(state_r == CTRL_PRECHARGE)) begin
|
| 1031 |
|
|
ddr_ras_n_r <= 1'b0;
|
| 1032 |
|
|
two_t_enable_r[0] <= 1'b0;
|
| 1033 |
|
|
end else begin
|
| 1034 |
|
|
if (TWO_T_TIME_EN)
|
| 1035 |
|
|
ddr_ras_n_r <= two_t_enable_r[0] ;
|
| 1036 |
|
|
else
|
| 1037 |
|
|
ddr_ras_n_r <= 1'd1;
|
| 1038 |
|
|
two_t_enable_r[0] <= 1'b1;
|
| 1039 |
|
|
end
|
| 1040 |
|
|
end
|
| 1041 |
|
|
|
| 1042 |
|
|
always @(posedge clk)begin
|
| 1043 |
|
|
if ((state_r == CTRL_BURST_WRITE) ||
|
| 1044 |
|
|
(state_r == CTRL_BURST_READ) ||
|
| 1045 |
|
|
(state_r == CTRL_AUTO_REFRESH)) begin
|
| 1046 |
|
|
ddr_cas_n_r <= 1'b0;
|
| 1047 |
|
|
two_t_enable_r[1] <= 1'b0;
|
| 1048 |
|
|
end else begin
|
| 1049 |
|
|
if (TWO_T_TIME_EN)
|
| 1050 |
|
|
ddr_cas_n_r <= two_t_enable_r[1];
|
| 1051 |
|
|
else
|
| 1052 |
|
|
ddr_cas_n_r <= 1'b1;
|
| 1053 |
|
|
two_t_enable_r[1] <= 1'b1;
|
| 1054 |
|
|
end
|
| 1055 |
|
|
end
|
| 1056 |
|
|
|
| 1057 |
|
|
always @(posedge clk) begin
|
| 1058 |
|
|
if ((state_r == CTRL_BURST_WRITE) ||
|
| 1059 |
|
|
(state_r == CTRL_PRECHARGE)) begin
|
| 1060 |
|
|
ddr_we_n_r <= 1'b0;
|
| 1061 |
|
|
two_t_enable_r[2] <= 1'b0;
|
| 1062 |
|
|
end else begin
|
| 1063 |
|
|
if(TWO_T_TIME_EN)
|
| 1064 |
|
|
ddr_we_n_r <= two_t_enable_r[2];
|
| 1065 |
|
|
else
|
| 1066 |
|
|
ddr_we_n_r <= 1'b1;
|
| 1067 |
|
|
two_t_enable_r[2] <= 1'b1;
|
| 1068 |
|
|
end
|
| 1069 |
|
|
end
|
| 1070 |
|
|
|
| 1071 |
|
|
// turn off auto-precharge when issuing commands (A10 = 0)
|
| 1072 |
|
|
// mapping the col add for linear addressing.
|
| 1073 |
|
|
generate
|
| 1074 |
|
|
if (TWO_T_TIME_EN) begin: gen_addr_col_two_t
|
| 1075 |
|
|
if (COL_WIDTH == ROW_WIDTH-1) begin: gen_ddr_addr_col_0
|
| 1076 |
|
|
assign ddr_addr_col = {af_addr_r3[COL_WIDTH-1:10], 1'b0,
|
| 1077 |
|
|
af_addr_r3[9:0]};
|
| 1078 |
|
|
end else begin
|
| 1079 |
|
|
if (COL_WIDTH > 10) begin: gen_ddr_addr_col_1
|
| 1080 |
|
|
assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}},
|
| 1081 |
|
|
af_addr_r3[COL_WIDTH-1:10], 1'b0,
|
| 1082 |
|
|
af_addr_r3[9:0]};
|
| 1083 |
|
|
end else begin: gen_ddr_addr_col_2
|
| 1084 |
|
|
assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, 1'b0,
|
| 1085 |
|
|
af_addr_r3[COL_WIDTH-1:0]};
|
| 1086 |
|
|
end
|
| 1087 |
|
|
end
|
| 1088 |
|
|
end else begin: gen_addr_col_one_t
|
| 1089 |
|
|
if (COL_WIDTH == ROW_WIDTH-1) begin: gen_ddr_addr_col_0_1
|
| 1090 |
|
|
assign ddr_addr_col = {af_addr_r2[COL_WIDTH-1:10], 1'b0,
|
| 1091 |
|
|
af_addr_r2[9:0]};
|
| 1092 |
|
|
end else begin
|
| 1093 |
|
|
if (COL_WIDTH > 10) begin: gen_ddr_addr_col_1_1
|
| 1094 |
|
|
assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}},
|
| 1095 |
|
|
af_addr_r2[COL_WIDTH-1:10], 1'b0,
|
| 1096 |
|
|
af_addr_r2[9:0]};
|
| 1097 |
|
|
end else begin: gen_ddr_addr_col_2_1
|
| 1098 |
|
|
assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, 1'b0,
|
| 1099 |
|
|
af_addr_r2[COL_WIDTH-1:0]};
|
| 1100 |
|
|
end
|
| 1101 |
|
|
end
|
| 1102 |
|
|
end
|
| 1103 |
|
|
endgenerate
|
| 1104 |
|
|
|
| 1105 |
|
|
// Assign address during row activate
|
| 1106 |
|
|
generate
|
| 1107 |
|
|
if (TWO_T_TIME_EN)
|
| 1108 |
|
|
assign ddr_addr_row = af_addr_r3[ROW_RANGE_END:ROW_RANGE_START];
|
| 1109 |
|
|
else
|
| 1110 |
|
|
assign ddr_addr_row = af_addr_r2[ROW_RANGE_END:ROW_RANGE_START];
|
| 1111 |
|
|
endgenerate
|
| 1112 |
|
|
|
| 1113 |
|
|
|
| 1114 |
|
|
always @(posedge clk)begin
|
| 1115 |
|
|
if ((state_r == CTRL_ACTIVE) ||
|
| 1116 |
|
|
((state_r1 == CTRL_ACTIVE) && TWO_T_TIME_EN))
|
| 1117 |
|
|
ddr_addr_r <= ddr_addr_row;
|
| 1118 |
|
|
else if ((state_r == CTRL_BURST_WRITE) ||
|
| 1119 |
|
|
(state_r == CTRL_BURST_READ) ||
|
| 1120 |
|
|
(((state_r1 == CTRL_BURST_WRITE) ||
|
| 1121 |
|
|
(state_r1 == CTRL_BURST_READ)) &&
|
| 1122 |
|
|
TWO_T_TIME_EN))
|
| 1123 |
|
|
ddr_addr_r <= ddr_addr_col;
|
| 1124 |
|
|
else if (((state_r == CTRL_PRECHARGE) ||
|
| 1125 |
|
|
((state_r1 == CTRL_PRECHARGE) && TWO_T_TIME_EN))
|
| 1126 |
|
|
&& auto_ref_r) begin
|
| 1127 |
|
|
// if we're precharging as a result of AUTO-REFRESH, precharge all banks
|
| 1128 |
|
|
ddr_addr_r <= {ROW_WIDTH{1'b0}};
|
| 1129 |
|
|
ddr_addr_r[10] <= 1'b1;
|
| 1130 |
|
|
end else if ((state_r == CTRL_PRECHARGE) ||
|
| 1131 |
|
|
((state_r1 == CTRL_PRECHARGE) && TWO_T_TIME_EN))
|
| 1132 |
|
|
// if we're precharging to close a specific bank/row, set A10=0
|
| 1133 |
|
|
ddr_addr_r <= {ROW_WIDTH{1'b0}};
|
| 1134 |
|
|
else
|
| 1135 |
|
|
ddr_addr_r <= {ROW_WIDTH{1'bx}};
|
| 1136 |
|
|
end
|
| 1137 |
|
|
|
| 1138 |
|
|
always @(posedge clk)begin
|
| 1139 |
|
|
// whenever we're precharging, we're either: (1) precharging all banks (in
|
| 1140 |
|
|
// which case banks bits are don't care, (2) precharging the LRU bank,
|
| 1141 |
|
|
// b/c we've exceeded the limit of # of banks open (need to close the LRU
|
| 1142 |
|
|
// bank to make room for a new one), (3) we haven't exceed the maximum #
|
| 1143 |
|
|
// of banks open, but we trying to open a different row in a bank that's
|
| 1144 |
|
|
// already open
|
| 1145 |
|
|
if (((state_r == CTRL_PRECHARGE) ||
|
| 1146 |
|
|
((state_r1 == CTRL_PRECHARGE) && TWO_T_TIME_EN)) &&
|
| 1147 |
|
|
bank_conflict_r && MULTI_BANK_EN)
|
| 1148 |
|
|
// When LRU bank needs to be closed
|
| 1149 |
|
|
ddr_ba_r <= bank_cmp_addr_r[(3*CMP_WIDTH)+CMP_BANK_RANGE_END:
|
| 1150 |
|
|
(3*CMP_WIDTH)+CMP_BANK_RANGE_START];
|
| 1151 |
|
|
else begin
|
| 1152 |
|
|
// Either precharge due to refresh or bank hit case
|
| 1153 |
|
|
if (TWO_T_TIME_EN)
|
| 1154 |
|
|
ddr_ba_r <= af_addr_r3[BANK_RANGE_END:BANK_RANGE_START];
|
| 1155 |
|
|
else
|
| 1156 |
|
|
ddr_ba_r <= af_addr_r2[BANK_RANGE_END:BANK_RANGE_START];
|
| 1157 |
|
|
end
|
| 1158 |
|
|
end
|
| 1159 |
|
|
|
| 1160 |
|
|
// chip enable generation logic
|
| 1161 |
|
|
generate
|
| 1162 |
|
|
// if only one chip select, always assert it after reset
|
| 1163 |
|
|
if (CS_BITS == 0) begin: gen_ddr_cs_0
|
| 1164 |
|
|
always @(posedge clk)
|
| 1165 |
|
|
if (rst_r1)
|
| 1166 |
|
|
ddr_cs_n_r[0] <= 1'b1;
|
| 1167 |
|
|
else
|
| 1168 |
|
|
ddr_cs_n_r[0] <= 1'b0;
|
| 1169 |
|
|
// otherwise if we have multiple chip selects
|
| 1170 |
|
|
end else begin: gen_ddr_cs_1
|
| 1171 |
|
|
if(TWO_T_TIME_EN) begin: gen_2t_cs
|
| 1172 |
|
|
always @(posedge clk)
|
| 1173 |
|
|
if (rst_r1)
|
| 1174 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1175 |
|
|
else if ((state_r1 == CTRL_AUTO_REFRESH)) begin
|
| 1176 |
|
|
// if auto-refreshing, only auto-refresh one CS at any time (avoid
|
| 1177 |
|
|
// beating on the ground plane by refreshing all CS's at same time)
|
| 1178 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1179 |
|
|
ddr_cs_n_r[auto_cnt_r] <= 1'b0;
|
| 1180 |
|
|
end else if (auto_ref_r && (state_r1 == CTRL_PRECHARGE)) begin
|
| 1181 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b0}};
|
| 1182 |
|
|
end else if ((state_r1 == CTRL_PRECHARGE) && ( bank_conflict_r
|
| 1183 |
|
|
&& MULTI_BANK_EN))begin
|
| 1184 |
|
|
// precharging the LRU bank
|
| 1185 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1186 |
|
|
ddr_cs_n_r[bank_cmp_addr_r[(3*CMP_WIDTH)+CMP_CS_RANGE_END:
|
| 1187 |
|
|
(3*CMP_WIDTH)+CMP_CS_RANGE_START]] <= 1'b0;
|
| 1188 |
|
|
end else begin
|
| 1189 |
|
|
// otherwise, check the upper address bits to see which CS to assert
|
| 1190 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1191 |
|
|
ddr_cs_n_r[af_addr_r3[CS_RANGE_END:CS_RANGE_START]] <= 1'b0;
|
| 1192 |
|
|
end // else: !if(((state_r == CTRL_PRECHARGE) ||...
|
| 1193 |
|
|
end else begin: gen_1t_cs // block: gen_2t_cs
|
| 1194 |
|
|
always @(posedge clk)
|
| 1195 |
|
|
if (rst_r1)
|
| 1196 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1197 |
|
|
else if ((state_r == CTRL_AUTO_REFRESH) ) begin
|
| 1198 |
|
|
// if auto-refreshing, only auto-refresh one CS at any time (avoid
|
| 1199 |
|
|
// beating on the ground plane by refreshing all CS's at same time)
|
| 1200 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1201 |
|
|
ddr_cs_n_r[auto_cnt_r] <= 1'b0;
|
| 1202 |
|
|
end else if (auto_ref_r && (state_r == CTRL_PRECHARGE) ) begin
|
| 1203 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b0}};
|
| 1204 |
|
|
end else if ((state_r == CTRL_PRECHARGE) &&
|
| 1205 |
|
|
(bank_conflict_r && MULTI_BANK_EN))begin
|
| 1206 |
|
|
// precharging the LRU bank
|
| 1207 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1208 |
|
|
ddr_cs_n_r[bank_cmp_addr_r[(3*CMP_WIDTH)+CMP_CS_RANGE_END:
|
| 1209 |
|
|
(3*CMP_WIDTH)+CMP_CS_RANGE_START]] <= 1'b0;
|
| 1210 |
|
|
end else begin
|
| 1211 |
|
|
// otherwise, check the upper address bits to see which CS to assert
|
| 1212 |
|
|
ddr_cs_n_r <= {CS_NUM{1'b1}};
|
| 1213 |
|
|
ddr_cs_n_r[af_addr_r2[CS_RANGE_END:CS_RANGE_START]] <= 1'b0;
|
| 1214 |
|
|
end // else: !if(((state_r == CTRL_PRECHARGE) ||...
|
| 1215 |
|
|
end // block: gen_1t_cs
|
| 1216 |
|
|
end
|
| 1217 |
|
|
endgenerate
|
| 1218 |
|
|
|
| 1219 |
|
|
// registring the two_t timing enable signal.
|
| 1220 |
|
|
// This signal will be asserted (low) when the
|
| 1221 |
|
|
// chip select has to be asserted.
|
| 1222 |
|
|
always @(posedge clk)begin
|
| 1223 |
|
|
if(&two_t_enable_r)
|
| 1224 |
|
|
two_t_enable_r1 <= {CS_NUM{1'b1}};
|
| 1225 |
|
|
else
|
| 1226 |
|
|
two_t_enable_r1 <= {CS_NUM{1'b0}};
|
| 1227 |
|
|
end
|
| 1228 |
|
|
|
| 1229 |
|
|
assign ctrl_addr = ddr_addr_r;
|
| 1230 |
|
|
assign ctrl_ba = ddr_ba_r;
|
| 1231 |
|
|
assign ctrl_ras_n = ddr_ras_n_r;
|
| 1232 |
|
|
assign ctrl_cas_n = ddr_cas_n_r;
|
| 1233 |
|
|
assign ctrl_we_n = ddr_we_n_r;
|
| 1234 |
|
|
assign ctrl_cs_n = (TWO_T_TIME_EN) ?
|
| 1235 |
|
|
(ddr_cs_n_r | two_t_enable_r1) :
|
| 1236 |
|
|
ddr_cs_n_r;
|
| 1237 |
|
|
|
| 1238 |
|
|
endmodule
|
| 1239 |
|
|
|