[10] | 1 | //***************************************************************************** |
---|
| 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.6 |
---|
| 44 | // \ \ Application: MIG |
---|
| 45 | // / / Filename: ddr2_ctrl.v |
---|
| 46 | // /___/ /\ Date Last Modified: $Date: 2010/06/29 12:03:43 $ |
---|
| 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 dram module. Please refer to |
---|
| 74 | // the dram 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)?((TWTR + CLK_PERIOD)/CLK_PERIOD) + 1:(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 read flag to the adress FIFO |
---|
| 300 | assign ctrl_af_rden = sm_rden || rd_af_flag_r; |
---|
| 301 | |
---|
| 302 | // local reset "tree" for controller logic only. Create this to ease timing |
---|
| 303 | // on reset path. Prohibit equivalent register removal on RST_R to prevent |
---|
| 304 | // "sharing" with other local reset trees (caution: make sure global fanout |
---|
| 305 | // limit is set to large enough value, otherwise SLICES may be used for |
---|
| 306 | // fanout control on RST_R. |
---|
| 307 | always @(posedge clk) begin |
---|
| 308 | rst_r <= rst; |
---|
| 309 | rst_r1 <= rst_r; |
---|
| 310 | end |
---|
| 311 | |
---|
| 312 | //***************************************************************** |
---|
| 313 | // interpret commands from Command/Address FIFO |
---|
| 314 | //***************************************************************** |
---|
| 315 | |
---|
| 316 | assign wr_flag = (af_valid_r2) ? ((af_cmd_r2 == 3'b000) ? 1'b1 : 1'b0): 1'b0; |
---|
| 317 | assign rd_flag = (af_valid_r2) ? ((af_cmd_r2 == 3'b001) ? 1'b1 : 1'b0): 1'b0; |
---|
| 318 | |
---|
| 319 | always @(posedge clk) begin |
---|
| 320 | rd_flag_r <= rd_flag; |
---|
| 321 | wr_flag_r <= wr_flag; |
---|
| 322 | end |
---|
| 323 | |
---|
| 324 | ////////////////////////////////////////////////// |
---|
| 325 | // The data from the address FIFO is fetched and |
---|
| 326 | // stored in two register stages. The data will be |
---|
| 327 | // pulled out of the second register stage whenever |
---|
| 328 | // the state machine can handle new data from the |
---|
| 329 | // address FIFO. |
---|
| 330 | |
---|
| 331 | // This flag is asserted when there is no |
---|
| 332 | // cmd & address in the pipe. When there is |
---|
| 333 | // valid cmd & addr from the address FIFO the |
---|
| 334 | // af_valid signals will be asserted. This flag will |
---|
| 335 | // be set the cycle af_valid_r is de-asserted. |
---|
| 336 | always @(posedge clk) begin |
---|
| 337 | // for simulation purposes - to force CTRL_AF_RDEN low during reset |
---|
| 338 | if (rst_r1) |
---|
| 339 | rd_af_flag_r <= 1'd0; |
---|
| 340 | else if((ctrl_af_rden_r) || |
---|
| 341 | (rd_af_flag_r && (af_valid_r || af_valid_r1))) |
---|
| 342 | rd_af_flag_r <= 1'd0; |
---|
| 343 | else if (~af_valid_r1 || ~af_valid_r) |
---|
| 344 | rd_af_flag_r <= 1'd1; |
---|
| 345 | |
---|
| 346 | end |
---|
| 347 | |
---|
| 348 | // First register stage for the cmd & add from the FIFO. |
---|
| 349 | // The af_valid_r signal gives the status of the data |
---|
| 350 | // in this stage. The af_valid_r will be asserted when there |
---|
| 351 | // is valid data. This register stage will be updated |
---|
| 352 | // 1. read to the FIFO and the FIFO not empty |
---|
| 353 | // 2. After write and read states |
---|
| 354 | // 3. The valid signal is not asserted in the last stage. |
---|
| 355 | always @(posedge clk) begin |
---|
| 356 | if (rst_r1)begin |
---|
| 357 | af_valid_r <= 1'd0; |
---|
| 358 | end else begin |
---|
| 359 | if (ctrl_af_rden_r || sm_rden_r || ~af_valid_r1 |
---|
| 360 | || ~af_valid_r2)begin |
---|
| 361 | af_valid_r <= ctrl_af_rden_r; |
---|
| 362 | end |
---|
| 363 | end |
---|
| 364 | end |
---|
| 365 | |
---|
| 366 | // The output register in the FIFO is used. The addr |
---|
| 367 | // and command are already registered in the FIFO. |
---|
| 368 | assign af_addr_r = af_addr; |
---|
| 369 | assign af_cmd_r = af_cmd; |
---|
| 370 | |
---|
| 371 | // Second register stage for the cmd & add from the FIFO. |
---|
| 372 | // The af_valid_r1 signal gives the status of the data |
---|
| 373 | // in this stage. The af_valid_r will be asserted when there |
---|
| 374 | // is valid data. This register stage will be updated |
---|
| 375 | // 1. read to the FIFO and the FIFO not empty and there |
---|
| 376 | // is no valid data on this stage |
---|
| 377 | // 2. After write and read states |
---|
| 378 | // 3. The valid signal is not asserted in the last stage. |
---|
| 379 | always@(posedge clk) begin |
---|
| 380 | if (rst_r1)begin |
---|
| 381 | af_valid_r1 <= 1'd0; |
---|
| 382 | af_addr_r1 <= {31{1'bx}}; |
---|
| 383 | af_cmd_r1 <= {3{1'bx}}; |
---|
| 384 | end else if (~af_valid_r1 || sm_rden_r || |
---|
| 385 | ~af_valid_r2) begin |
---|
| 386 | af_valid_r1 <= af_valid_r; |
---|
| 387 | af_addr_r1 <= af_addr_r; |
---|
| 388 | af_cmd_r1 <= af_cmd_r; |
---|
| 389 | end |
---|
| 390 | end |
---|
| 391 | |
---|
| 392 | // The state machine uses the address and command in this |
---|
| 393 | // register stage. The data is fetched from the second |
---|
| 394 | // register stage whenever the state machine can accept new |
---|
| 395 | // addr. The conflict flags are also generated based on the |
---|
| 396 | // second register stage and updated when the new address |
---|
| 397 | // is loaded for the state machine. |
---|
| 398 | always@(posedge clk) begin |
---|
| 399 | if (rst_r1)begin |
---|
| 400 | af_valid_r2 <= 1'd0; |
---|
| 401 | af_addr_r2 <= {31{1'bx}}; |
---|
| 402 | af_cmd_r2 <= {3{1'bx}}; |
---|
| 403 | bank_hit_r <= {OPEN_BANK_NUM{1'bx}}; |
---|
| 404 | bank_conflict_r <= 1'bx; |
---|
| 405 | row_conflict_r <= 4'bx; |
---|
| 406 | end else if(sm_rden || ~af_valid_r2)begin |
---|
| 407 | af_valid_r2 <= af_valid_r1; |
---|
| 408 | af_addr_r2 <= af_addr_r1; |
---|
| 409 | af_cmd_r2 <= af_cmd_r1; |
---|
| 410 | if(MULTI_BANK_EN)begin |
---|
| 411 | bank_hit_r <= bank_hit; |
---|
| 412 | row_conflict_r <= row_miss; |
---|
| 413 | bank_conflict_r <= (~(|bank_hit)); |
---|
| 414 | end else begin |
---|
| 415 | bank_hit_r <= {OPEN_BANK_NUM{1'b0}}; |
---|
| 416 | bank_conflict_r <= 1'd0; |
---|
| 417 | row_conflict_r[0] <= (af_addr_r1[CS_RANGE_END:ROW_RANGE_START] |
---|
| 418 | != sb_open_add_r[CMP_WIDTH-1:0]); |
---|
| 419 | end |
---|
| 420 | end |
---|
| 421 | end // always@ (posedge clk) |
---|
| 422 | |
---|
| 423 | //detecting cs change for multi chip select case |
---|
| 424 | generate |
---|
| 425 | if(CS_NUM > 1) begin: gen_cs_change |
---|
| 426 | always @(posedge clk) begin |
---|
| 427 | if(sm_rden || ~af_valid_r2)begin |
---|
| 428 | cs_change_r <= af_addr_r1[CS_RANGE_END:CS_RANGE_START] != |
---|
| 429 | af_addr_r2[CS_RANGE_END:CS_RANGE_START] ; |
---|
| 430 | cs_change_sticky_r <= |
---|
| 431 | af_addr_r1[CS_RANGE_END:CS_RANGE_START] != |
---|
| 432 | af_addr_r2[CS_RANGE_END:CS_RANGE_START] ; |
---|
| 433 | end else |
---|
| 434 | cs_change_r <= 1'd0; |
---|
| 435 | end |
---|
| 436 | end // block: gen_cs_change |
---|
| 437 | else begin: gen_cs_0 |
---|
| 438 | always @(posedge clk) begin |
---|
| 439 | cs_change_r <= 1'd0; |
---|
| 440 | cs_change_sticky_r <= 1'd0; |
---|
| 441 | end |
---|
| 442 | end |
---|
| 443 | endgenerate |
---|
| 444 | |
---|
| 445 | assign conflict_detect = (MULTI_BANK_EN) ? |
---|
| 446 | ((|(row_conflict_r[3:0] & bank_hit_r[3:0])) |
---|
| 447 | | bank_conflict_r) & af_valid_r2 : |
---|
| 448 | row_conflict_r[0] & af_valid_r2; |
---|
| 449 | |
---|
| 450 | always @(posedge clk) begin |
---|
| 451 | conflict_detect_r <= conflict_detect; |
---|
| 452 | sm_rden_r <= sm_rden; |
---|
| 453 | af_addr_r3 <= af_addr_r2; |
---|
| 454 | ctrl_af_rden_r <= ctrl_af_rden & ~af_empty; |
---|
| 455 | end |
---|
| 456 | |
---|
| 457 | // conflict resolved signal. When this signal is asserted |
---|
| 458 | // the conflict is resolved. The address to be compared |
---|
| 459 | // for the conflict_resolved_r will be stored in act_add_r |
---|
| 460 | // when the bank is opened. |
---|
| 461 | always @(posedge clk) begin |
---|
| 462 | conflict_resolved_r <= (act_addr_r == |
---|
| 463 | af_addr_r2[CS_RANGE_END:ROW_RANGE_START]); |
---|
| 464 | if((state_r == CTRL_ACTIVE)) |
---|
| 465 | act_addr_r <= af_addr_r2[CS_RANGE_END:ROW_RANGE_START]; |
---|
| 466 | end |
---|
| 467 | |
---|
| 468 | //*************************************************************************** |
---|
| 469 | // Bank management logic |
---|
| 470 | // Semi-hardcoded for now for 4 banks |
---|
| 471 | // will keep multiple banks open if MULTI_BANK_EN is true. |
---|
| 472 | //*************************************************************************** |
---|
| 473 | |
---|
| 474 | genvar bank_i; |
---|
| 475 | generate // if multiple bank option chosen |
---|
| 476 | if(MULTI_BANK_EN) begin: gen_multi_bank_open |
---|
| 477 | |
---|
| 478 | for (bank_i = 0; bank_i < OPEN_BANK_NUM; |
---|
| 479 | bank_i = bank_i + 1) begin: gen_bank_hit1 |
---|
| 480 | // asserted if bank address match + open bank entry is valid |
---|
| 481 | always @(*) begin |
---|
| 482 | bank_hit[bank_i] |
---|
| 483 | = ((bank_cmp_addr_r[(CMP_WIDTH*(bank_i+1))-1: |
---|
| 484 | (CMP_WIDTH*bank_i)+ROW_WIDTH] == |
---|
| 485 | af_addr_r1[CS_RANGE_END:BANK_RANGE_START]) && |
---|
| 486 | bank_valid_r[bank_i]); |
---|
| 487 | // asserted if row address match (no check for bank entry valid, rely |
---|
| 488 | // on this term to be used in conjunction with BANK_HIT[]) |
---|
| 489 | row_miss[bank_i] |
---|
| 490 | = (bank_cmp_addr_r[(CMP_WIDTH*bank_i)+ROW_WIDTH-1: |
---|
| 491 | (CMP_WIDTH*bank_i)] != |
---|
| 492 | af_addr_r1[ROW_RANGE_END:ROW_RANGE_START]); |
---|
| 493 | end |
---|
| 494 | end |
---|
| 495 | |
---|
| 496 | always @(posedge clk) begin |
---|
| 497 | no_precharge_wait_r <= bank_valid_r[3] & bank_conflict_r; |
---|
| 498 | bank_hit_r1 <= bank_hit_r; |
---|
| 499 | end |
---|
| 500 | |
---|
| 501 | always@(*) |
---|
| 502 | no_precharge_r = ~bank_valid_r[3] & bank_conflict_r; |
---|
| 503 | |
---|
| 504 | always@(posedge clk) |
---|
| 505 | no_precharge_r1 <= no_precharge_r; |
---|
| 506 | |
---|
| 507 | |
---|
| 508 | always @(posedge clk) begin |
---|
| 509 | // Clear all bank valid bits during AR (i.e. since all banks get |
---|
| 510 | // precharged during auto-refresh) |
---|
| 511 | if ((state_r1 == CTRL_AUTO_REFRESH)) begin |
---|
| 512 | bank_valid_r <= {OPEN_BANK_NUM{1'b0}}; |
---|
| 513 | bank_cmp_addr_r <= {(OPEN_BANK_NUM*CMP_WIDTH-1){1'b0}}; |
---|
| 514 | end else begin |
---|
| 515 | if (state_r1 == CTRL_ACTIVE) begin |
---|
| 516 | // 00 is always going to have the latest bank and row. |
---|
| 517 | bank_cmp_addr_r[CMP_WIDTH-1:0] |
---|
| 518 | <= af_addr_r3[CS_RANGE_END:ROW_RANGE_START]; |
---|
| 519 | // This indicates the bank was activated |
---|
| 520 | bank_valid_r[0] <= 1'b1; |
---|
| 521 | |
---|
| 522 | case ({bank_hit_r1[2:0]}) |
---|
| 523 | 3'b001: begin |
---|
| 524 | bank_cmp_addr_r[CMP_WIDTH-1:0] |
---|
| 525 | <= af_addr_r3[CS_RANGE_END:ROW_RANGE_START]; |
---|
| 526 | // This indicates the bank was activated |
---|
| 527 | bank_valid_r[0] <= 1'b1; |
---|
| 528 | end |
---|
| 529 | 3'b010: begin //(b0->b1) |
---|
| 530 | bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH] |
---|
| 531 | <= bank_cmp_addr_r[CMP_WIDTH-1:0]; |
---|
| 532 | bank_valid_r[1] <= bank_valid_r[0]; |
---|
| 533 | end |
---|
| 534 | 3'b100:begin //(b0->b1, b1->b2) |
---|
| 535 | bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH] |
---|
| 536 | <= bank_cmp_addr_r[CMP_WIDTH-1:0]; |
---|
| 537 | bank_cmp_addr_r[(3*CMP_WIDTH)-1:2*CMP_WIDTH] |
---|
| 538 | <= bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH]; |
---|
| 539 | bank_valid_r[1] <= bank_valid_r[0]; |
---|
| 540 | bank_valid_r[2] <= bank_valid_r[1]; |
---|
| 541 | end |
---|
| 542 | default: begin //(b0->b1, b1->b2, b2->b3) |
---|
| 543 | bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH] |
---|
| 544 | <= bank_cmp_addr_r[CMP_WIDTH-1:0]; |
---|
| 545 | bank_cmp_addr_r[(3*CMP_WIDTH)-1:2*CMP_WIDTH] |
---|
| 546 | <= bank_cmp_addr_r[(2*CMP_WIDTH)-1:CMP_WIDTH]; |
---|
| 547 | bank_cmp_addr_r[(4*CMP_WIDTH)-1:3*CMP_WIDTH] |
---|
| 548 | <= bank_cmp_addr_r[(3*CMP_WIDTH)-1:2*CMP_WIDTH]; |
---|
| 549 | bank_valid_r[1] <= bank_valid_r[0]; |
---|
| 550 | bank_valid_r[2] <= bank_valid_r[1]; |
---|
| 551 | bank_valid_r[3] <= bank_valid_r[2]; |
---|
| 552 | end |
---|
| 553 | endcase |
---|
| 554 | end |
---|
| 555 | end |
---|
| 556 | end |
---|
| 557 | end else begin: gen_single_bank_open // single bank option |
---|
| 558 | always @(posedge clk) begin |
---|
| 559 | no_precharge_r <= 1'd0; |
---|
| 560 | no_precharge_r1 <= 1'd0; |
---|
| 561 | no_precharge_wait_r <= 1'd0; |
---|
| 562 | if (rst_r1) |
---|
| 563 | sb_open_add_r <= {CMP_WIDTH{1'b0}}; |
---|
| 564 | else if (state_r == CTRL_ACTIVE) |
---|
| 565 | sb_open_add_r <= af_addr_r2[CS_RANGE_END:ROW_RANGE_START]; |
---|
| 566 | end |
---|
| 567 | end |
---|
| 568 | endgenerate |
---|
| 569 | |
---|
| 570 | //*************************************************************************** |
---|
| 571 | // Timing counters |
---|
| 572 | //*************************************************************************** |
---|
| 573 | |
---|
| 574 | //***************************************************************** |
---|
| 575 | // Write and read enable generation for PHY |
---|
| 576 | //***************************************************************** |
---|
| 577 | |
---|
| 578 | // write burst count. Counts from (BL/2 to 1). |
---|
| 579 | // Also logic for controller write enable. |
---|
| 580 | always @(posedge clk) begin |
---|
| 581 | if (state_r == CTRL_BURST_WRITE) begin |
---|
| 582 | wrburst_cnt_r <= BURST_LEN_DIV2; |
---|
| 583 | end else if (wrburst_cnt_r >= 3'd1) |
---|
| 584 | wrburst_cnt_r <= wrburst_cnt_r - 1; |
---|
| 585 | end // always @ (posedge clk) |
---|
| 586 | |
---|
| 587 | |
---|
| 588 | always @(posedge clk) begin |
---|
| 589 | if (rst_r1) begin |
---|
| 590 | ctrl_wren <= 1'b0; |
---|
| 591 | end else if (state_r == CTRL_BURST_WRITE) begin |
---|
| 592 | ctrl_wren <= 1'b1; |
---|
| 593 | end else if (wrburst_wren_ok_r) |
---|
| 594 | ctrl_wren <= 1'b0; |
---|
| 595 | end |
---|
| 596 | |
---|
| 597 | |
---|
| 598 | always @(posedge clk) begin |
---|
| 599 | if ((state_r == CTRL_BURST_WRITE) |
---|
| 600 | && (BURST_LEN_DIV2 > 2)) |
---|
| 601 | wrburst_ok_r <= 1'd0; |
---|
| 602 | else if ((wrburst_cnt_r <= 3'd3) || |
---|
| 603 | (BURST_LEN_DIV2 <= 2)) |
---|
| 604 | wrburst_ok_r <= 1'b1; |
---|
| 605 | end |
---|
| 606 | |
---|
| 607 | // flag to check when wrburst count has reached |
---|
| 608 | // a value of 1. This flag is used in the ctrl_wren |
---|
| 609 | // logic |
---|
| 610 | always @(posedge clk) begin |
---|
| 611 | if(wrburst_cnt_r == 3'd2) |
---|
| 612 | wrburst_wren_ok_r <=1'b1; |
---|
| 613 | else |
---|
| 614 | wrburst_wren_ok_r <= 1'b0; |
---|
| 615 | end |
---|
| 616 | |
---|
| 617 | |
---|
| 618 | // read burst count. Counts from (BL/2 to 1) |
---|
| 619 | always @(posedge clk) begin |
---|
| 620 | if (state_r == CTRL_BURST_READ) begin |
---|
| 621 | rdburst_cnt_r <= BURST_LEN_DIV2; |
---|
| 622 | end else if (rdburst_cnt_r >= 3'd1) |
---|
| 623 | rdburst_cnt_r <= rdburst_cnt_r - 1; |
---|
| 624 | end // always @ (posedge clk) |
---|
| 625 | |
---|
| 626 | |
---|
| 627 | always @(posedge clk) begin |
---|
| 628 | if (rst_r1) begin |
---|
| 629 | ctrl_rden <= 1'b0; |
---|
| 630 | end else if (state_r == CTRL_BURST_READ) begin |
---|
| 631 | ctrl_rden <= 1'b1; |
---|
| 632 | end else if (rdburst_rden_ok_r) |
---|
| 633 | ctrl_rden <= 1'b0; |
---|
| 634 | end |
---|
| 635 | |
---|
| 636 | // the rd_burst_ok_r signal will be asserted one cycle later |
---|
| 637 | // in multi chip select cases if the back to back read is to |
---|
| 638 | // different chip selects. The cs_changed_sticky_r signal will |
---|
| 639 | // be asserted only for multi chip select cases. |
---|
| 640 | always @(posedge clk) begin |
---|
| 641 | if ((state_r == CTRL_BURST_READ) |
---|
| 642 | && (BURST_LEN_DIV2 > 2)) |
---|
| 643 | rdburst_ok_r <= 1'd0; |
---|
| 644 | else if ((rdburst_cnt_r <=( 3'd3 - cs_change_sticky_r)) || |
---|
| 645 | (BURST_LEN_DIV2 <= 2)) |
---|
| 646 | rdburst_ok_r <= 1'b1; |
---|
| 647 | end |
---|
| 648 | |
---|
| 649 | // flag to check when rdburst count has reached |
---|
| 650 | // a value of 1. This flag is used in the ctrl_rden |
---|
| 651 | // logic |
---|
| 652 | always @(posedge clk) begin |
---|
| 653 | if (rdburst_cnt_r == 3'd2) |
---|
| 654 | rdburst_rden_ok_r <= 1'b1; |
---|
| 655 | else |
---|
| 656 | rdburst_rden_ok_r <= 1'b0; |
---|
| 657 | end |
---|
| 658 | |
---|
| 659 | |
---|
| 660 | //***************************************************************** |
---|
| 661 | // Various delay counters |
---|
| 662 | // The counters are checked for value of <= 3 to determine the |
---|
| 663 | // if the count values are reached during different commands. |
---|
| 664 | // It is checked for 3 because |
---|
| 665 | // 1. The counters are loaded during the state when the command |
---|
| 666 | // state is reached (+1) |
---|
| 667 | // 2. After the <= 3 condition is reached the sm takes two cycles |
---|
| 668 | // to transition to the new command state (+2) |
---|
| 669 | //***************************************************************** |
---|
| 670 | |
---|
| 671 | // tRP count - precharge command period |
---|
| 672 | always @(posedge clk) begin |
---|
| 673 | if (state_r == CTRL_PRECHARGE) |
---|
| 674 | rp_cnt_r <= TRP_COUNT; |
---|
| 675 | else if (rp_cnt_r != 4'd0) |
---|
| 676 | rp_cnt_r <= rp_cnt_r - 1; |
---|
| 677 | end |
---|
| 678 | |
---|
| 679 | always @(posedge clk) begin |
---|
| 680 | if (state_r == CTRL_PRECHARGE) |
---|
| 681 | rp_cnt_ok_r <= 1'd0; |
---|
| 682 | else if (rp_cnt_r <= 4'd3) |
---|
| 683 | rp_cnt_ok_r <= 1'd1; |
---|
| 684 | end |
---|
| 685 | |
---|
| 686 | // tRFC count - refresh-refresh, refresh-active |
---|
| 687 | always @(posedge clk) begin |
---|
| 688 | if (state_r == CTRL_AUTO_REFRESH) |
---|
| 689 | rfc_cnt_r <= TRFC_COUNT; |
---|
| 690 | else if (rfc_cnt_r != 8'd0) |
---|
| 691 | rfc_cnt_r <= rfc_cnt_r - 1; |
---|
| 692 | end |
---|
| 693 | |
---|
| 694 | always @(posedge clk) begin |
---|
| 695 | if (state_r == CTRL_AUTO_REFRESH) |
---|
| 696 | rfc_ok_r <= 1'b0; |
---|
| 697 | else if(rfc_cnt_r <= 8'd3) |
---|
| 698 | rfc_ok_r <= 1'b1; |
---|
| 699 | end |
---|
| 700 | |
---|
| 701 | // tRCD count - active to read/write |
---|
| 702 | always @(posedge clk) begin |
---|
| 703 | if (state_r == CTRL_ACTIVE) |
---|
| 704 | rcd_cnt_r <= TRCD_COUNT; |
---|
| 705 | else if (rcd_cnt_r != 4'd0) |
---|
| 706 | rcd_cnt_r <= rcd_cnt_r - 1; |
---|
| 707 | end |
---|
| 708 | |
---|
| 709 | always @(posedge clk) begin |
---|
| 710 | if ((state_r == CTRL_ACTIVE) |
---|
| 711 | && (TRCD_COUNT > 2)) |
---|
| 712 | rcd_cnt_ok_r <= 1'd0; |
---|
| 713 | else if (rcd_cnt_r <= 4'd3) |
---|
| 714 | rcd_cnt_ok_r <= 1; |
---|
| 715 | end |
---|
| 716 | |
---|
| 717 | // tRRD count - active to active |
---|
| 718 | always @(posedge clk) begin |
---|
| 719 | if (state_r == CTRL_ACTIVE) |
---|
| 720 | trrd_cnt_r <= TRRD_COUNT; |
---|
| 721 | else if (trrd_cnt_r != 3'd0) |
---|
| 722 | trrd_cnt_r <= trrd_cnt_r - 1; |
---|
| 723 | end |
---|
| 724 | |
---|
| 725 | always @(posedge clk) begin |
---|
| 726 | if (state_r == CTRL_ACTIVE) |
---|
| 727 | trrd_cnt_ok_r <= 1'd0; |
---|
| 728 | else if (trrd_cnt_r <= 3'd3) |
---|
| 729 | trrd_cnt_ok_r <= 1; |
---|
| 730 | end |
---|
| 731 | |
---|
| 732 | // tRAS count - active to precharge |
---|
| 733 | always @(posedge clk) begin |
---|
| 734 | if (state_r == CTRL_ACTIVE) |
---|
| 735 | ras_cnt_r <= TRAS_COUNT; |
---|
| 736 | else if (ras_cnt_r != 5'd0) |
---|
| 737 | ras_cnt_r <= ras_cnt_r - 1; |
---|
| 738 | end |
---|
| 739 | |
---|
| 740 | // counter for write to prcharge |
---|
| 741 | // read to precharge and |
---|
| 742 | // activate to precharge |
---|
| 743 | // precharge_ok_cnt_r is added with trtp count, |
---|
| 744 | // there can be cases where the sm can go from |
---|
| 745 | // activate to read and the act->pre count time |
---|
| 746 | // would not have been satisfied. The rd->pre |
---|
| 747 | // time is very less. wr->pre time is almost the |
---|
| 748 | // same as act-> pre |
---|
| 749 | always @(posedge clk) begin |
---|
| 750 | if (rst_r1) |
---|
| 751 | precharge_ok_cnt_r <= 5'd0; |
---|
| 752 | else if (state_r == CTRL_BURST_READ) begin |
---|
| 753 | // assign only if the cnt is < TRTP_COUNT |
---|
| 754 | if (precharge_ok_cnt_r < TRTP_COUNT) |
---|
| 755 | precharge_ok_cnt_r <= TRTP_COUNT; |
---|
| 756 | end else if (state_r == CTRL_BURST_WRITE) |
---|
| 757 | precharge_ok_cnt_r <= TWR_COUNT; |
---|
| 758 | else if (state_r == CTRL_ACTIVE) |
---|
| 759 | if (precharge_ok_cnt_r <= TRAS_COUNT) |
---|
| 760 | precharge_ok_cnt_r <= TRAS_COUNT; |
---|
| 761 | else |
---|
| 762 | precharge_ok_cnt_r <= precharge_ok_cnt_r - 1; |
---|
| 763 | else if (precharge_ok_cnt_r != 5'd0) |
---|
| 764 | precharge_ok_cnt_r <= precharge_ok_cnt_r - 1; |
---|
| 765 | end |
---|
| 766 | |
---|
| 767 | always @(posedge clk) begin |
---|
| 768 | if ((state_r == CTRL_BURST_READ) || |
---|
| 769 | (state_r == CTRL_BURST_WRITE)|| |
---|
| 770 | (state_r == CTRL_ACTIVE)) |
---|
| 771 | precharge_ok_r <= 1'd0; |
---|
| 772 | else if(precharge_ok_cnt_r <= 5'd3) |
---|
| 773 | precharge_ok_r <=1'd1; |
---|
| 774 | end |
---|
| 775 | |
---|
| 776 | // write to read counter |
---|
| 777 | // write to read includes : write latency + burst time + tWTR |
---|
| 778 | always @(posedge clk) begin |
---|
| 779 | if (rst_r1) |
---|
| 780 | wr_to_rd_cnt_r <= 5'd0; |
---|
| 781 | else if (state_r == CTRL_BURST_WRITE) |
---|
| 782 | wr_to_rd_cnt_r <= (TWTR_COUNT); |
---|
| 783 | else if (wr_to_rd_cnt_r != 5'd0) |
---|
| 784 | wr_to_rd_cnt_r <= wr_to_rd_cnt_r - 1; |
---|
| 785 | end |
---|
| 786 | |
---|
| 787 | always @(posedge clk) begin |
---|
| 788 | if (state_r == CTRL_BURST_WRITE) |
---|
| 789 | wr_to_rd_ok_r <= 1'd0; |
---|
| 790 | else if (wr_to_rd_cnt_r <= 5'd3) |
---|
| 791 | wr_to_rd_ok_r <= 1'd1; |
---|
| 792 | end |
---|
| 793 | |
---|
| 794 | // read to write counter |
---|
| 795 | always @(posedge clk) begin |
---|
| 796 | if (rst_r1) |
---|
| 797 | rd_to_wr_cnt_r <= 5'd0; |
---|
| 798 | else if (state_r == CTRL_BURST_READ) |
---|
| 799 | rd_to_wr_cnt_r <= (TRTW_COUNT); |
---|
| 800 | else if (rd_to_wr_cnt_r != 5'd0) |
---|
| 801 | rd_to_wr_cnt_r <= rd_to_wr_cnt_r - 1; |
---|
| 802 | end |
---|
| 803 | |
---|
| 804 | always @(posedge clk) begin |
---|
| 805 | if (state_r == CTRL_BURST_READ) |
---|
| 806 | rd_to_wr_ok_r <= 1'b0; |
---|
| 807 | else if (rd_to_wr_cnt_r <= 5'd3) |
---|
| 808 | rd_to_wr_ok_r <= 1'b1; |
---|
| 809 | end |
---|
| 810 | |
---|
| 811 | always @(posedge clk) begin |
---|
| 812 | if(refi_cnt_r == (TREFI_COUNT -1)) |
---|
| 813 | refi_cnt_ok_r <= 1'b1; |
---|
| 814 | else |
---|
| 815 | refi_cnt_ok_r <= 1'b0; |
---|
| 816 | end |
---|
| 817 | |
---|
| 818 | // auto refresh interval counter in refresh_clk domain |
---|
| 819 | always @(posedge clk) begin |
---|
| 820 | if ((rst_r1) || (refi_cnt_ok_r)) begin |
---|
| 821 | refi_cnt_r <= 12'd0; |
---|
| 822 | end else begin |
---|
| 823 | refi_cnt_r <= refi_cnt_r + 1; |
---|
| 824 | end |
---|
| 825 | end // always @ (posedge clk) |
---|
| 826 | |
---|
| 827 | // auto refresh flag |
---|
| 828 | always @(posedge clk) begin |
---|
| 829 | if (refi_cnt_ok_r) begin |
---|
| 830 | ref_flag_r <= 1'b1; |
---|
| 831 | end else begin |
---|
| 832 | ref_flag_r <= 1'b0; |
---|
| 833 | end |
---|
| 834 | end // always @ (posedge clk) |
---|
| 835 | |
---|
| 836 | assign ctrl_ref_flag = ref_flag_r; |
---|
| 837 | |
---|
| 838 | //refresh flag detect |
---|
| 839 | //auto_ref high indicates auto_refresh requirement |
---|
| 840 | //auto_ref is held high until auto refresh command is issued. |
---|
| 841 | always @(posedge clk)begin |
---|
| 842 | if (rst_r1) |
---|
| 843 | auto_ref_r <= 1'b0; |
---|
| 844 | else if (ref_flag_r) |
---|
| 845 | auto_ref_r <= 1'b1; |
---|
| 846 | else if (state_r == CTRL_AUTO_REFRESH) |
---|
| 847 | auto_ref_r <= 1'b0; |
---|
| 848 | end |
---|
| 849 | |
---|
| 850 | |
---|
| 851 | // keep track of which chip selects got auto-refreshed (avoid auto-refreshing |
---|
| 852 | // all CS's at once to avoid current spike) |
---|
| 853 | always @(posedge clk)begin |
---|
| 854 | if (rst_r1 || (state_r1 == CTRL_PRECHARGE)) |
---|
| 855 | auto_cnt_r <= 'd0; |
---|
| 856 | else if (state_r1 == CTRL_AUTO_REFRESH) |
---|
| 857 | auto_cnt_r <= auto_cnt_r + 1; |
---|
| 858 | end |
---|
| 859 | |
---|
| 860 | // register for timing purposes. Extra delay doesn't really matter |
---|
| 861 | always @(posedge clk) |
---|
| 862 | phy_init_done_r <= phy_init_done; |
---|
| 863 | |
---|
| 864 | always @(posedge clk)begin |
---|
| 865 | if (rst_r1) begin |
---|
| 866 | state_r <= CTRL_IDLE; |
---|
| 867 | state_r1 <= CTRL_IDLE; |
---|
| 868 | end else begin |
---|
| 869 | state_r <= next_state; |
---|
| 870 | state_r1 <= state_r; |
---|
| 871 | end |
---|
| 872 | end |
---|
| 873 | |
---|
| 874 | //*************************************************************************** |
---|
| 875 | // main control state machine |
---|
| 876 | //*************************************************************************** |
---|
| 877 | |
---|
| 878 | always @(*) begin |
---|
| 879 | next_state = state_r; |
---|
| 880 | (* full_case, parallel_case *) case (state_r) |
---|
| 881 | CTRL_IDLE: begin |
---|
| 882 | // perform auto refresh as soon as we are done with calibration. |
---|
| 883 | // The calibration logic does not do any refreshes. |
---|
| 884 | if (phy_init_done_r) |
---|
| 885 | next_state = CTRL_AUTO_REFRESH; |
---|
| 886 | end |
---|
| 887 | |
---|
| 888 | CTRL_PRECHARGE: begin |
---|
| 889 | if (auto_ref_r) |
---|
| 890 | next_state = CTRL_PRECHARGE_WAIT1; |
---|
| 891 | // when precharging an LRU bank, do not have to go to wait state |
---|
| 892 | // since we can't possibly be activating row in same bank next |
---|
| 893 | // disabled for 2t timing. There needs to be a gap between cmds |
---|
| 894 | // in 2t timing |
---|
| 895 | else if (no_precharge_wait_r && !TWO_T_TIME_EN) |
---|
| 896 | next_state = CTRL_ACTIVE; |
---|
| 897 | else |
---|
| 898 | next_state = CTRL_PRECHARGE_WAIT; |
---|
| 899 | end |
---|
| 900 | |
---|
| 901 | CTRL_PRECHARGE_WAIT:begin |
---|
| 902 | if (rp_cnt_ok_r)begin |
---|
| 903 | if (auto_ref_r) |
---|
| 904 | // precharge again to make sure we close all the banks |
---|
| 905 | next_state = CTRL_PRECHARGE; |
---|
| 906 | else |
---|
| 907 | next_state = CTRL_ACTIVE; |
---|
| 908 | end |
---|
| 909 | end |
---|
| 910 | |
---|
| 911 | CTRL_PRECHARGE_WAIT1: |
---|
| 912 | if (rp_cnt_ok_r) |
---|
| 913 | next_state = CTRL_AUTO_REFRESH; |
---|
| 914 | |
---|
| 915 | CTRL_AUTO_REFRESH: |
---|
| 916 | next_state = CTRL_AUTO_REFRESH_WAIT; |
---|
| 917 | |
---|
| 918 | CTRL_AUTO_REFRESH_WAIT: |
---|
| 919 | //staggering Auto refresh for multi |
---|
| 920 | // chip select designs. The SM waits |
---|
| 921 | // for the rfc time before issuing the |
---|
| 922 | // next auto refresh. |
---|
| 923 | if (auto_cnt_r < (CS_NUM))begin |
---|
| 924 | if (rfc_ok_r ) |
---|
| 925 | next_state = CTRL_AUTO_REFRESH; |
---|
| 926 | end else if (rfc_ok_r)begin |
---|
| 927 | if(auto_ref_r) |
---|
| 928 | // MIG 2.3: For deep designs if Auto Refresh |
---|
| 929 | // flag asserted immediately after calibration is completed |
---|
| 930 | next_state = CTRL_PRECHARGE; |
---|
| 931 | else if ( wr_flag || rd_flag) |
---|
| 932 | next_state = CTRL_ACTIVE; |
---|
| 933 | end |
---|
| 934 | |
---|
| 935 | CTRL_ACTIVE: |
---|
| 936 | next_state = CTRL_ACTIVE_WAIT; |
---|
| 937 | |
---|
| 938 | CTRL_ACTIVE_WAIT: begin |
---|
| 939 | if (rcd_cnt_ok_r) begin |
---|
| 940 | if ((conflict_detect_r && ~conflict_resolved_r) || |
---|
| 941 | auto_ref_r) begin |
---|
| 942 | if (no_precharge_r1 && ~auto_ref_r && trrd_cnt_ok_r) |
---|
| 943 | next_state = CTRL_ACTIVE; |
---|
| 944 | else if(precharge_ok_r) |
---|
| 945 | next_state = CTRL_PRECHARGE; |
---|
| 946 | end else if ((wr_flag_r) && (rd_to_wr_ok_r)) |
---|
| 947 | next_state = CTRL_BURST_WRITE; |
---|
| 948 | else if ((rd_flag_r)&& (wr_to_rd_ok_r)) |
---|
| 949 | next_state = CTRL_BURST_READ; |
---|
| 950 | end |
---|
| 951 | end |
---|
| 952 | |
---|
| 953 | // beginning of write burst |
---|
| 954 | CTRL_BURST_WRITE: begin |
---|
| 955 | if (BURST_LEN_DIV2 == 1) begin |
---|
| 956 | // special case if BL = 2 (i.e. burst lasts only one clk cycle) |
---|
| 957 | if (wr_flag) |
---|
| 958 | // if we have another non-conflict write command right after the |
---|
| 959 | // current write, then stay in this state |
---|
| 960 | next_state = CTRL_BURST_WRITE; |
---|
| 961 | else |
---|
| 962 | // otherwise, if we're done with this burst, and have no write |
---|
| 963 | // immediately scheduled after this one, wait until write-read |
---|
| 964 | // delay has passed |
---|
| 965 | next_state = CTRL_WRITE_WAIT; |
---|
| 966 | end else |
---|
| 967 | // otherwise BL > 2, and we have at least one more write cycle for |
---|
| 968 | // current burst |
---|
| 969 | next_state = CTRL_WRITE_WAIT; |
---|
| 970 | // continuation of write burst (also covers waiting after write burst |
---|
| 971 | // has completed for write-read delay to pass) |
---|
| 972 | end |
---|
| 973 | |
---|
| 974 | CTRL_WRITE_WAIT: begin |
---|
| 975 | if ((conflict_detect) || auto_ref_r) begin |
---|
| 976 | if (no_precharge_r && ~auto_ref_r && wrburst_ok_r) |
---|
| 977 | next_state = CTRL_ACTIVE; |
---|
| 978 | else if (precharge_ok_r) |
---|
| 979 | next_state = CTRL_PRECHARGE; |
---|
| 980 | end else if (wrburst_ok_r && wr_flag) |
---|
| 981 | next_state = CTRL_BURST_WRITE; |
---|
| 982 | else if ((rd_flag) && (wr_to_rd_ok_r)) |
---|
| 983 | next_state = CTRL_BURST_READ; |
---|
| 984 | end |
---|
| 985 | |
---|
| 986 | CTRL_BURST_READ: begin |
---|
| 987 | if (BURST_LEN_DIV2 == 1) begin |
---|
| 988 | // special case if BL = 2 (i.e. burst lasts only one clk cycle) |
---|
| 989 | if (rd_flag) |
---|
| 990 | next_state = CTRL_BURST_READ; |
---|
| 991 | else |
---|
| 992 | next_state = CTRL_READ_WAIT; |
---|
| 993 | end else |
---|
| 994 | next_state = CTRL_READ_WAIT; |
---|
| 995 | end |
---|
| 996 | |
---|
| 997 | CTRL_READ_WAIT: begin |
---|
| 998 | if ((conflict_detect) || auto_ref_r)begin |
---|
| 999 | if (no_precharge_r && ~auto_ref_r && rdburst_ok_r) |
---|
| 1000 | next_state = CTRL_ACTIVE; |
---|
| 1001 | else if (precharge_ok_r) |
---|
| 1002 | next_state = CTRL_PRECHARGE; |
---|
| 1003 | // for burst of 4 in multi chip select |
---|
| 1004 | // if there is a change in cs wait one cycle before the |
---|
| 1005 | // next read command. cs_change_r will be asserted. |
---|
| 1006 | end else if (rdburst_ok_r && rd_flag && ~cs_change_r) |
---|
| 1007 | next_state = CTRL_BURST_READ; |
---|
| 1008 | else if (wr_flag && (rd_to_wr_ok_r)) |
---|
| 1009 | next_state = CTRL_BURST_WRITE; |
---|
| 1010 | end |
---|
| 1011 | endcase |
---|
| 1012 | end |
---|
| 1013 | |
---|
| 1014 | //*************************************************************************** |
---|
| 1015 | // control signals to memory |
---|
| 1016 | //*************************************************************************** |
---|
| 1017 | |
---|
| 1018 | always @(posedge clk) begin |
---|
| 1019 | if ((state_r == CTRL_AUTO_REFRESH) || |
---|
| 1020 | (state_r == CTRL_ACTIVE) || |
---|
| 1021 | (state_r == CTRL_PRECHARGE)) begin |
---|
| 1022 | ddr_ras_n_r <= 1'b0; |
---|
| 1023 | two_t_enable_r[0] <= 1'b0; |
---|
| 1024 | end else begin |
---|
| 1025 | if (TWO_T_TIME_EN) |
---|
| 1026 | ddr_ras_n_r <= two_t_enable_r[0] ; |
---|
| 1027 | else |
---|
| 1028 | ddr_ras_n_r <= 1'd1; |
---|
| 1029 | two_t_enable_r[0] <= 1'b1; |
---|
| 1030 | end |
---|
| 1031 | end |
---|
| 1032 | |
---|
| 1033 | always @(posedge clk)begin |
---|
| 1034 | if ((state_r == CTRL_BURST_WRITE) || |
---|
| 1035 | (state_r == CTRL_BURST_READ) || |
---|
| 1036 | (state_r == CTRL_AUTO_REFRESH)) begin |
---|
| 1037 | ddr_cas_n_r <= 1'b0; |
---|
| 1038 | two_t_enable_r[1] <= 1'b0; |
---|
| 1039 | end else begin |
---|
| 1040 | if (TWO_T_TIME_EN) |
---|
| 1041 | ddr_cas_n_r <= two_t_enable_r[1]; |
---|
| 1042 | else |
---|
| 1043 | ddr_cas_n_r <= 1'b1; |
---|
| 1044 | two_t_enable_r[1] <= 1'b1; |
---|
| 1045 | end |
---|
| 1046 | end |
---|
| 1047 | |
---|
| 1048 | always @(posedge clk) begin |
---|
| 1049 | if ((state_r == CTRL_BURST_WRITE) || |
---|
| 1050 | (state_r == CTRL_PRECHARGE)) begin |
---|
| 1051 | ddr_we_n_r <= 1'b0; |
---|
| 1052 | two_t_enable_r[2] <= 1'b0; |
---|
| 1053 | end else begin |
---|
| 1054 | if(TWO_T_TIME_EN) |
---|
| 1055 | ddr_we_n_r <= two_t_enable_r[2]; |
---|
| 1056 | else |
---|
| 1057 | ddr_we_n_r <= 1'b1; |
---|
| 1058 | two_t_enable_r[2] <= 1'b1; |
---|
| 1059 | end |
---|
| 1060 | end |
---|
| 1061 | |
---|
| 1062 | // turn off auto-precharge when issuing commands (A10 = 0) |
---|
| 1063 | // mapping the col add for linear addressing. |
---|
| 1064 | generate |
---|
| 1065 | if (TWO_T_TIME_EN) begin: gen_addr_col_two_t |
---|
| 1066 | if (COL_WIDTH == ROW_WIDTH-1) begin: gen_ddr_addr_col_0 |
---|
| 1067 | assign ddr_addr_col = {af_addr_r3[COL_WIDTH-1:10], 1'b0, |
---|
| 1068 | af_addr_r3[9:0]}; |
---|
| 1069 | end else begin |
---|
| 1070 | if (COL_WIDTH > 10) begin: gen_ddr_addr_col_1 |
---|
| 1071 | assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, |
---|
| 1072 | af_addr_r3[COL_WIDTH-1:10], 1'b0, |
---|
| 1073 | af_addr_r3[9:0]}; |
---|
| 1074 | end else begin: gen_ddr_addr_col_2 |
---|
| 1075 | assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, 1'b0, |
---|
| 1076 | af_addr_r3[COL_WIDTH-1:0]}; |
---|
| 1077 | end |
---|
| 1078 | end |
---|
| 1079 | end else begin: gen_addr_col_one_t |
---|
| 1080 | if (COL_WIDTH == ROW_WIDTH-1) begin: gen_ddr_addr_col_0_1 |
---|
| 1081 | assign ddr_addr_col = {af_addr_r2[COL_WIDTH-1:10], 1'b0, |
---|
| 1082 | af_addr_r2[9:0]}; |
---|
| 1083 | end else begin |
---|
| 1084 | if (COL_WIDTH > 10) begin: gen_ddr_addr_col_1_1 |
---|
| 1085 | assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, |
---|
| 1086 | af_addr_r2[COL_WIDTH-1:10], 1'b0, |
---|
| 1087 | af_addr_r2[9:0]}; |
---|
| 1088 | end else begin: gen_ddr_addr_col_2_1 |
---|
| 1089 | assign ddr_addr_col = {{(ROW_WIDTH-COL_WIDTH-1){1'b0}}, 1'b0, |
---|
| 1090 | af_addr_r2[COL_WIDTH-1:0]}; |
---|
| 1091 | end |
---|
| 1092 | end |
---|
| 1093 | end |
---|
| 1094 | endgenerate |
---|
| 1095 | |
---|
| 1096 | // Assign address during row activate |
---|
| 1097 | generate |
---|
| 1098 | if (TWO_T_TIME_EN) |
---|
| 1099 | assign ddr_addr_row = af_addr_r3[ROW_RANGE_END:ROW_RANGE_START]; |
---|
| 1100 | else |
---|
| 1101 | assign ddr_addr_row = af_addr_r2[ROW_RANGE_END:ROW_RANGE_START]; |
---|
| 1102 | endgenerate |
---|
| 1103 | |
---|
| 1104 | |
---|
| 1105 | always @(posedge clk)begin |
---|
| 1106 | if ((state_r == CTRL_ACTIVE) || |
---|
| 1107 | ((state_r1 == CTRL_ACTIVE) && TWO_T_TIME_EN)) |
---|
| 1108 | ddr_addr_r <= ddr_addr_row; |
---|
| 1109 | else if ((state_r == CTRL_BURST_WRITE) || |
---|
| 1110 | (state_r == CTRL_BURST_READ) || |
---|
| 1111 | (((state_r1 == CTRL_BURST_WRITE) || |
---|
| 1112 | (state_r1 == CTRL_BURST_READ)) && |
---|
| 1113 | TWO_T_TIME_EN)) |
---|
| 1114 | ddr_addr_r <= ddr_addr_col; |
---|
| 1115 | else if (((state_r == CTRL_PRECHARGE) || |
---|
| 1116 | ((state_r1 == CTRL_PRECHARGE) && TWO_T_TIME_EN)) |
---|
| 1117 | && auto_ref_r) begin |
---|
| 1118 | // if we're precharging as a result of AUTO-REFRESH, precharge all banks |
---|
| 1119 | ddr_addr_r <= {ROW_WIDTH{1'b0}}; |
---|
| 1120 | ddr_addr_r[10] <= 1'b1; |
---|
| 1121 | end else if ((state_r == CTRL_PRECHARGE) || |
---|
| 1122 | ((state_r1 == CTRL_PRECHARGE) && TWO_T_TIME_EN)) |
---|
| 1123 | // if we're precharging to close a specific bank/row, set A10=0 |
---|
| 1124 | ddr_addr_r <= {ROW_WIDTH{1'b0}}; |
---|
| 1125 | else |
---|
| 1126 | ddr_addr_r <= {ROW_WIDTH{1'bx}}; |
---|
| 1127 | end |
---|
| 1128 | |
---|
| 1129 | always @(posedge clk)begin |
---|
| 1130 | // whenever we're precharging, we're either: (1) precharging all banks (in |
---|
| 1131 | // which case banks bits are don't care, (2) precharging the LRU bank, |
---|
| 1132 | // b/c we've exceeded the limit of # of banks open (need to close the LRU |
---|
| 1133 | // bank to make room for a new one), (3) we haven't exceed the maximum # |
---|
| 1134 | // of banks open, but we trying to open a different row in a bank that's |
---|
| 1135 | // already open |
---|
| 1136 | if (((state_r == CTRL_PRECHARGE) || |
---|
| 1137 | ((state_r1 == CTRL_PRECHARGE) && TWO_T_TIME_EN)) && |
---|
| 1138 | bank_conflict_r && MULTI_BANK_EN) |
---|
| 1139 | // When LRU bank needs to be closed |
---|
| 1140 | ddr_ba_r <= bank_cmp_addr_r[(3*CMP_WIDTH)+CMP_BANK_RANGE_END: |
---|
| 1141 | (3*CMP_WIDTH)+CMP_BANK_RANGE_START]; |
---|
| 1142 | else begin |
---|
| 1143 | // Either precharge due to refresh or bank hit case |
---|
| 1144 | if (TWO_T_TIME_EN) |
---|
| 1145 | ddr_ba_r <= af_addr_r3[BANK_RANGE_END:BANK_RANGE_START]; |
---|
| 1146 | else |
---|
| 1147 | ddr_ba_r <= af_addr_r2[BANK_RANGE_END:BANK_RANGE_START]; |
---|
| 1148 | end |
---|
| 1149 | end |
---|
| 1150 | |
---|
| 1151 | // chip enable generation logic |
---|
| 1152 | generate |
---|
| 1153 | // if only one chip select, always assert it after reset |
---|
| 1154 | if (CS_BITS == 0) begin: gen_ddr_cs_0 |
---|
| 1155 | always @(posedge clk) |
---|
| 1156 | if (rst_r1) |
---|
| 1157 | ddr_cs_n_r[0] <= 1'b1; |
---|
| 1158 | else |
---|
| 1159 | ddr_cs_n_r[0] <= 1'b0; |
---|
| 1160 | // otherwise if we have multiple chip selects |
---|
| 1161 | end else begin: gen_ddr_cs_1 |
---|
| 1162 | if(TWO_T_TIME_EN) begin: gen_2t_cs |
---|
| 1163 | always @(posedge clk) |
---|
| 1164 | if (rst_r1) |
---|
| 1165 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1166 | else if ((state_r1 == CTRL_AUTO_REFRESH)) begin |
---|
| 1167 | // if auto-refreshing, only auto-refresh one CS at any time (avoid |
---|
| 1168 | // beating on the ground plane by refreshing all CS's at same time) |
---|
| 1169 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1170 | ddr_cs_n_r[auto_cnt_r] <= 1'b0; |
---|
| 1171 | end else if (auto_ref_r && (state_r1 == CTRL_PRECHARGE)) begin |
---|
| 1172 | ddr_cs_n_r <= {CS_NUM{1'b0}}; |
---|
| 1173 | end else if ((state_r1 == CTRL_PRECHARGE) && ( bank_conflict_r |
---|
| 1174 | && MULTI_BANK_EN))begin |
---|
| 1175 | // precharging the LRU bank |
---|
| 1176 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1177 | ddr_cs_n_r[bank_cmp_addr_r[(3*CMP_WIDTH)+CMP_CS_RANGE_END: |
---|
| 1178 | (3*CMP_WIDTH)+CMP_CS_RANGE_START]] <= 1'b0; |
---|
| 1179 | end else begin |
---|
| 1180 | // otherwise, check the upper address bits to see which CS to assert |
---|
| 1181 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1182 | ddr_cs_n_r[af_addr_r3[CS_RANGE_END:CS_RANGE_START]] <= 1'b0; |
---|
| 1183 | end // else: !if(((state_r == CTRL_PRECHARGE) ||... |
---|
| 1184 | end else begin: gen_1t_cs // block: gen_2t_cs |
---|
| 1185 | always @(posedge clk) |
---|
| 1186 | if (rst_r1) |
---|
| 1187 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1188 | else if ((state_r == CTRL_AUTO_REFRESH) ) begin |
---|
| 1189 | // if auto-refreshing, only auto-refresh one CS at any time (avoid |
---|
| 1190 | // beating on the ground plane by refreshing all CS's at same time) |
---|
| 1191 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1192 | ddr_cs_n_r[auto_cnt_r] <= 1'b0; |
---|
| 1193 | end else if (auto_ref_r && (state_r == CTRL_PRECHARGE) ) begin |
---|
| 1194 | ddr_cs_n_r <= {CS_NUM{1'b0}}; |
---|
| 1195 | end else if ((state_r == CTRL_PRECHARGE) && |
---|
| 1196 | (bank_conflict_r && MULTI_BANK_EN))begin |
---|
| 1197 | // precharging the LRU bank |
---|
| 1198 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1199 | ddr_cs_n_r[bank_cmp_addr_r[(3*CMP_WIDTH)+CMP_CS_RANGE_END: |
---|
| 1200 | (3*CMP_WIDTH)+CMP_CS_RANGE_START]] <= 1'b0; |
---|
| 1201 | end else begin |
---|
| 1202 | // otherwise, check the upper address bits to see which CS to assert |
---|
| 1203 | ddr_cs_n_r <= {CS_NUM{1'b1}}; |
---|
| 1204 | ddr_cs_n_r[af_addr_r2[CS_RANGE_END:CS_RANGE_START]] <= 1'b0; |
---|
| 1205 | end // else: !if(((state_r == CTRL_PRECHARGE) ||... |
---|
| 1206 | end // block: gen_1t_cs |
---|
| 1207 | end |
---|
| 1208 | endgenerate |
---|
| 1209 | |
---|
| 1210 | // registring the two_t timing enable signal. |
---|
| 1211 | // This signal will be asserted (low) when the |
---|
| 1212 | // chip select has to be asserted. |
---|
| 1213 | always @(posedge clk)begin |
---|
| 1214 | if(&two_t_enable_r) |
---|
| 1215 | two_t_enable_r1 <= {CS_NUM{1'b1}}; |
---|
| 1216 | else |
---|
| 1217 | two_t_enable_r1 <= {CS_NUM{1'b0}}; |
---|
| 1218 | end |
---|
| 1219 | |
---|
| 1220 | assign ctrl_addr = ddr_addr_r; |
---|
| 1221 | assign ctrl_ba = ddr_ba_r; |
---|
| 1222 | assign ctrl_ras_n = ddr_ras_n_r; |
---|
| 1223 | assign ctrl_cas_n = ddr_cas_n_r; |
---|
| 1224 | assign ctrl_we_n = ddr_we_n_r; |
---|
| 1225 | assign ctrl_cs_n = (TWO_T_TIME_EN) ? |
---|
| 1226 | (ddr_cs_n_r | two_t_enable_r1) : |
---|
| 1227 | ddr_cs_n_r; |
---|
| 1228 | |
---|
| 1229 | endmodule |
---|
| 1230 | |
---|