| 1 |
2 |
dimamali |
------------------------------------------------------------------------------
|
| 2 |
|
|
-- This file is a part of the GRLIB VHDL IP LIBRARY
|
| 3 |
|
|
-- Copyright (C) 2003, Gaisler Research
|
| 4 |
|
|
--
|
| 5 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
| 6 |
|
|
-- it under the terms of the GNU General Public License as published by
|
| 7 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
| 8 |
|
|
-- (at your option) any later version.
|
| 9 |
|
|
--
|
| 10 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 11 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
-- GNU General Public License for more details.
|
| 14 |
|
|
--
|
| 15 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 16 |
|
|
-- along with this program; if not, write to the Free Software
|
| 17 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
|
|
-----------------------------------------------------------------------------
|
| 19 |
|
|
-- Entity: ddrsp32a
|
| 20 |
|
|
-- File: ddrsp32a.vhd
|
| 21 |
|
|
-- Author: Jiri Gaisler - Gaisler Research
|
| 22 |
|
|
-- Description: 32-bit DDR266 memory controller with asych AHB interface
|
| 23 |
|
|
------------------------------------------------------------------------------
|
| 24 |
|
|
|
| 25 |
|
|
library ieee;
|
| 26 |
|
|
use ieee.std_logic_1164.all;
|
| 27 |
|
|
library grlib;
|
| 28 |
|
|
use grlib.amba.all;
|
| 29 |
|
|
use grlib.stdlib.all;
|
| 30 |
|
|
library gaisler;
|
| 31 |
|
|
use grlib.devices.all;
|
| 32 |
|
|
use gaisler.memctrl.all;
|
| 33 |
|
|
library techmap;
|
| 34 |
|
|
use techmap.gencomp.all;
|
| 35 |
|
|
|
| 36 |
|
|
entity ddrsp32a is
|
| 37 |
|
|
generic (
|
| 38 |
|
|
memtech : integer := 0;
|
| 39 |
|
|
hindex : integer := 0;
|
| 40 |
|
|
haddr : integer := 0;
|
| 41 |
|
|
hmask : integer := 16#f00#;
|
| 42 |
|
|
ioaddr : integer := 16#000#;
|
| 43 |
|
|
iomask : integer := 16#fff#;
|
| 44 |
|
|
MHz : integer := 100;
|
| 45 |
|
|
col : integer := 9;
|
| 46 |
|
|
Mbyte : integer := 8;
|
| 47 |
|
|
fast : integer := 0;
|
| 48 |
|
|
pwron : integer := 0;
|
| 49 |
|
|
oepol : integer := 0;
|
| 50 |
|
|
mobile : integer := 0;
|
| 51 |
|
|
confapi : integer := 0;
|
| 52 |
|
|
conf0 : integer := 0;
|
| 53 |
|
|
conf1 : integer := 0;
|
| 54 |
|
|
regoutput : integer := 0
|
| 55 |
|
|
);
|
| 56 |
|
|
port (
|
| 57 |
|
|
rst : in std_ulogic;
|
| 58 |
|
|
clk_ddr : in std_ulogic;
|
| 59 |
|
|
clk_ahb : in std_ulogic;
|
| 60 |
|
|
ahbsi : in ahb_slv_in_type;
|
| 61 |
|
|
ahbso : out ahb_slv_out_type;
|
| 62 |
|
|
sdi : in sdctrl_in_type;
|
| 63 |
|
|
sdo : out sdctrl_out_type
|
| 64 |
|
|
);
|
| 65 |
|
|
end;
|
| 66 |
|
|
|
| 67 |
|
|
architecture rtl of ddrsp32a is
|
| 68 |
|
|
|
| 69 |
|
|
constant REVISION : integer := 0;
|
| 70 |
|
|
|
| 71 |
|
|
constant CMD_PRE : std_logic_vector(2 downto 0) := "010";
|
| 72 |
|
|
constant CMD_REF : std_logic_vector(2 downto 0) := "100";
|
| 73 |
|
|
constant CMD_LMR : std_logic_vector(2 downto 0) := "110";
|
| 74 |
|
|
constant CMD_EMR : std_logic_vector(2 downto 0) := "111";
|
| 75 |
|
|
|
| 76 |
|
|
constant PM_PD : std_logic_vector(2 downto 0) := "001";
|
| 77 |
|
|
constant PM_SR : std_logic_vector(2 downto 0) := "010";
|
| 78 |
|
|
constant PM_CKS : std_logic_vector(2 downto 0) := "100";
|
| 79 |
|
|
constant PM_DPD : std_logic_vector(2 downto 0) := "101";
|
| 80 |
|
|
|
| 81 |
|
|
constant abuf : integer := 6;
|
| 82 |
|
|
constant hconfig : ahb_config_type := (
|
| 83 |
|
|
|
| 84 |
|
|
4 => ahb_membar(haddr, '1', '1', hmask),
|
| 85 |
|
|
5 => ahb_iobar(ioaddr, iomask),
|
| 86 |
|
|
others => zero32);
|
| 87 |
|
|
|
| 88 |
|
|
type mcycletype is (midle, active, ext, leadout);
|
| 89 |
|
|
type ahb_state_type is (midle, rhold, dread, dwrite, whold1, whold2);
|
| 90 |
|
|
type sdcycletype is (act1, act2, act3, rd1, rd2, rd2a, rd3, rd3a, rd4, rd5, rd6, rd7, rd8,
|
| 91 |
|
|
wr1, wr2, wr3, wr4a, wr4, wr5, sidle, ioreg1, ioreg2,
|
| 92 |
|
|
sref, cks, pd, dpd, srr1, srr2, srr3);
|
| 93 |
|
|
type icycletype is (iidle, pre, ref1, ref2, emode, lmode, finish);
|
| 94 |
|
|
|
| 95 |
|
|
-- sdram configuration register
|
| 96 |
|
|
|
| 97 |
|
|
type sdram_cfg_type is record
|
| 98 |
|
|
command : std_logic_vector(2 downto 0);
|
| 99 |
|
|
csize : std_logic_vector(1 downto 0);
|
| 100 |
|
|
bsize : std_logic_vector(2 downto 0);
|
| 101 |
|
|
trcd : std_ulogic; -- tCD : 2/3 clock cycles
|
| 102 |
|
|
trfc : std_logic_vector(2 downto 0);
|
| 103 |
|
|
trp : std_ulogic; -- precharge to activate: 2/3 clock cycles
|
| 104 |
|
|
refresh : std_logic_vector(11 downto 0);
|
| 105 |
|
|
renable : std_ulogic;
|
| 106 |
|
|
dllrst : std_ulogic;
|
| 107 |
|
|
refon : std_ulogic;
|
| 108 |
|
|
cke : std_ulogic;
|
| 109 |
|
|
pasr : std_logic_vector(5 downto 0); -- pasr(2:0) (pasr(5:3) used to detect update)
|
| 110 |
|
|
tcsr : std_logic_vector(3 downto 0); -- tcrs(1:0) (tcrs(3:2) used to detect update)
|
| 111 |
|
|
ds : std_logic_vector(5 downto 0); -- ds(1:0) (ds(3:2) used to detect update)
|
| 112 |
|
|
pmode : std_logic_vector(2 downto 0); -- Power-Saving mode
|
| 113 |
|
|
mobileen : std_logic_vector(1 downto 0); -- Mobile SD support, Mobile SD enabled
|
| 114 |
|
|
txsr : std_logic_vector(3 downto 0); -- Exit Self Refresh timing
|
| 115 |
|
|
txp : std_logic; -- Exit Power-Down timing
|
| 116 |
|
|
tcke : std_logic; -- Clock enable timing
|
| 117 |
|
|
cl : std_logic; -- CAS latency 2/3 (0/1)
|
| 118 |
|
|
conf : std_logic_vector(63 downto 0); -- PHY control
|
| 119 |
|
|
end record;
|
| 120 |
|
|
|
| 121 |
|
|
type access_param is record
|
| 122 |
|
|
haddr : std_logic_vector(31 downto 0);
|
| 123 |
|
|
size : std_logic_vector(1 downto 0);
|
| 124 |
|
|
hwrite : std_ulogic;
|
| 125 |
|
|
hio : std_ulogic;
|
| 126 |
|
|
end record;
|
| 127 |
|
|
-- local registers
|
| 128 |
|
|
|
| 129 |
|
|
type ahb_reg_type is record
|
| 130 |
|
|
hready : std_ulogic;
|
| 131 |
|
|
hsel : std_ulogic;
|
| 132 |
|
|
hio : std_ulogic;
|
| 133 |
|
|
startsd : std_ulogic;
|
| 134 |
|
|
ready : std_ulogic;
|
| 135 |
|
|
ready2 : std_ulogic;
|
| 136 |
|
|
write : std_logic_vector(1 downto 0);
|
| 137 |
|
|
state : ahb_state_type;
|
| 138 |
|
|
haddr : std_logic_vector(31 downto 0);
|
| 139 |
|
|
hrdata : std_logic_vector(31 downto 0);
|
| 140 |
|
|
hwdata : std_logic_vector(31 downto 0);
|
| 141 |
|
|
hwrite : std_ulogic;
|
| 142 |
|
|
htrans : std_logic_vector(1 downto 0);
|
| 143 |
|
|
hresp : std_logic_vector(1 downto 0);
|
| 144 |
|
|
raddr : std_logic_vector(abuf-1 downto 0);
|
| 145 |
|
|
size : std_logic_vector(1 downto 0);
|
| 146 |
|
|
acc : access_param;
|
| 147 |
|
|
end record;
|
| 148 |
|
|
|
| 149 |
|
|
type ddr_reg_type is record
|
| 150 |
|
|
startsd : std_ulogic;
|
| 151 |
|
|
startsdold : std_ulogic;
|
| 152 |
|
|
burst : std_ulogic;
|
| 153 |
|
|
hready : std_ulogic;
|
| 154 |
|
|
bdrive : std_ulogic;
|
| 155 |
|
|
qdrive : std_ulogic;
|
| 156 |
|
|
nbdrive : std_ulogic;
|
| 157 |
|
|
mstate : mcycletype;
|
| 158 |
|
|
sdstate : sdcycletype;
|
| 159 |
|
|
cmstate : mcycletype;
|
| 160 |
|
|
istate : icycletype;
|
| 161 |
|
|
trfc : std_logic_vector(3 downto 0);
|
| 162 |
|
|
refresh : std_logic_vector(11 downto 0);
|
| 163 |
|
|
sdcsn : std_logic_vector(1 downto 0);
|
| 164 |
|
|
sdwen : std_ulogic;
|
| 165 |
|
|
rasn : std_ulogic;
|
| 166 |
|
|
casn : std_ulogic;
|
| 167 |
|
|
dqm : std_logic_vector(7 downto 0);
|
| 168 |
|
|
dqm_dly : std_logic_vector(7 downto 0); -- *** ??? delay ctrl
|
| 169 |
|
|
wdata : std_logic_vector(63 downto 0); -- *** ??? delay ctrl
|
| 170 |
|
|
address : std_logic_vector(15 downto 2); -- memory address
|
| 171 |
|
|
ba : std_logic_vector(1 downto 0);
|
| 172 |
|
|
waddr : std_logic_vector(abuf-1 downto 0);
|
| 173 |
|
|
cfg : sdram_cfg_type;
|
| 174 |
|
|
hrdata : std_logic_vector(63 downto 0);
|
| 175 |
|
|
idlecnt : std_logic_vector(3 downto 0); -- Counter, 16 idle clock sycles before entering Power-Saving mode
|
| 176 |
|
|
ck : std_logic_vector(2 downto 0); -- Clock stop signal, 0 = clock stoped, 1 = clock running
|
| 177 |
|
|
txp : std_logic;
|
| 178 |
|
|
tcke : std_logic;
|
| 179 |
|
|
sref_tmpcom : std_logic_vector(2 downto 0); -- Save SD command when exit sref
|
| 180 |
|
|
extdqs : std_logic; -- Extend dqs postamble
|
| 181 |
|
|
sdo_bdrive : std_logic; -- *** ??? delay ctrl
|
| 182 |
|
|
sdo_qdrive : std_logic; -- *** ??? delay ctrl
|
| 183 |
|
|
ck_dly : std_logic_vector(2 downto 0); -- *** ??? delay ctrl
|
| 184 |
|
|
cke_dly : std_logic; -- *** ??? delay ctrl
|
| 185 |
|
|
end record;
|
| 186 |
|
|
|
| 187 |
|
|
signal vcc : std_ulogic;
|
| 188 |
|
|
signal r, ri : ddr_reg_type;
|
| 189 |
|
|
signal ra, rai : ahb_reg_type;
|
| 190 |
|
|
signal rbdrive, ribdrive : std_logic_vector(31 downto 0);
|
| 191 |
|
|
signal rdata, wdata : std_logic_vector(63 downto 0);
|
| 192 |
|
|
signal ddr_rst : std_logic;
|
| 193 |
|
|
signal ddr_rst_gen : std_logic_vector(3 downto 0);
|
| 194 |
|
|
attribute syn_preserve : boolean;
|
| 195 |
|
|
attribute syn_preserve of rbdrive : signal is true;
|
| 196 |
|
|
|
| 197 |
|
|
begin
|
| 198 |
|
|
|
| 199 |
|
|
vcc <= '1';
|
| 200 |
|
|
|
| 201 |
|
|
ddr_rst <= (ddr_rst_gen(3) and ddr_rst_gen(2) and ddr_rst_gen(1) and rst); -- Reset signal in DDR clock domain
|
| 202 |
|
|
|
| 203 |
|
|
ahb_ctrl : process(rst, ahbsi, r, ra, rdata)
|
| 204 |
|
|
variable v : ahb_reg_type; -- local variables for registers
|
| 205 |
|
|
variable startsd : std_ulogic;
|
| 206 |
|
|
variable dout : std_logic_vector(31 downto 0);
|
| 207 |
|
|
begin
|
| 208 |
|
|
|
| 209 |
|
|
v := ra; v.hresp := HRESP_OKAY; v.write := "00";
|
| 210 |
|
|
|
| 211 |
|
|
if ra.raddr(0) = '0' then v.hrdata := rdata(63 downto 32);
|
| 212 |
|
|
else v.hrdata := rdata(31 downto 0); end if;
|
| 213 |
|
|
|
| 214 |
|
|
v.ready := not (ra.startsd xor r.startsdold);
|
| 215 |
|
|
v.ready2 := ra.ready;
|
| 216 |
|
|
if ((ahbsi.hready and ahbsi.hsel(hindex)) = '1') then
|
| 217 |
|
|
v.htrans := ahbsi.htrans; v.haddr := ahbsi.haddr;
|
| 218 |
|
|
v.size := ahbsi.hsize(1 downto 0); v.hwrite := ahbsi.hwrite;
|
| 219 |
|
|
if ahbsi.htrans(1) = '1' then
|
| 220 |
|
|
v.hio := ahbsi.hmbsel(1);
|
| 221 |
|
|
v.hsel := '1'; v.hready := '0';
|
| 222 |
|
|
end if;
|
| 223 |
|
|
end if;
|
| 224 |
|
|
|
| 225 |
|
|
if ahbsi.hready = '1' then v.hsel := ahbsi.hsel(hindex); end if;
|
| 226 |
|
|
|
| 227 |
|
|
case ra.state is
|
| 228 |
|
|
when midle =>
|
| 229 |
|
|
if ((v.hsel and v.htrans(1)) = '1') then
|
| 230 |
|
|
if v.hwrite = '0' then
|
| 231 |
|
|
v.state := rhold; v.startsd := not ra.startsd;
|
| 232 |
|
|
else
|
| 233 |
|
|
v.state := dwrite; v.hready := '1';
|
| 234 |
|
|
v.write(0) := not v.haddr(2); v.write(1) := v.haddr(2);
|
| 235 |
|
|
end if;
|
| 236 |
|
|
end if;
|
| 237 |
|
|
v.raddr := ra.haddr(7 downto 2);
|
| 238 |
|
|
v.ready := '0'; v.ready2 := '0';
|
| 239 |
|
|
if ahbsi.hready = '1' then
|
| 240 |
|
|
v.acc := (v.haddr, v.size, v.hwrite, v.hio);
|
| 241 |
|
|
end if;
|
| 242 |
|
|
when rhold =>
|
| 243 |
|
|
v.raddr := ra.haddr(7 downto 2);
|
| 244 |
|
|
if ra.ready2 = '1' then
|
| 245 |
|
|
v.state := dread; v.hready := '1'; v.raddr := ra.raddr + 1;
|
| 246 |
|
|
end if;
|
| 247 |
|
|
when dread =>
|
| 248 |
|
|
v.raddr := ra.raddr + 1; v.hready := '1';
|
| 249 |
|
|
if ((v.hsel and v.htrans(1) and v.htrans(0)) = '0') or
|
| 250 |
|
|
(ra.raddr(2 downto 0) = "000")
|
| 251 |
|
|
then v.state := midle; v.hready := '0'; end if;
|
| 252 |
|
|
v.acc := (v.haddr, v.size, v.hwrite, v.hio);
|
| 253 |
|
|
when dwrite =>
|
| 254 |
|
|
v.raddr := ra.haddr(7 downto 2); v.hready := '1';
|
| 255 |
|
|
v.write(0) := not v.haddr(2); v.write(1) := v.haddr(2);
|
| 256 |
|
|
if ((v.hsel and v.htrans(1) and v.htrans(0)) = '0') or
|
| 257 |
|
|
(ra.haddr(4 downto 2) = "111")
|
| 258 |
|
|
then
|
| 259 |
|
|
v.startsd := not ra.startsd; v.state := whold1;
|
| 260 |
|
|
v.write := "00"; v.hready := '0';
|
| 261 |
|
|
end if;
|
| 262 |
|
|
when whold1 =>
|
| 263 |
|
|
v.state := whold2; v.ready := '0';
|
| 264 |
|
|
when whold2 =>
|
| 265 |
|
|
if ra.ready = '1' then
|
| 266 |
|
|
v.state := midle; v.acc := (v.haddr, v.size, v.hwrite, v.hio);
|
| 267 |
|
|
end if;
|
| 268 |
|
|
end case;
|
| 269 |
|
|
|
| 270 |
|
|
v.hwdata := ahbsi.hwdata;
|
| 271 |
|
|
|
| 272 |
|
|
if (ahbsi.hready and ahbsi.hsel(hindex) ) = '1' then
|
| 273 |
|
|
if ahbsi.htrans(1) = '0' then v.hready := '1'; end if;
|
| 274 |
|
|
end if;
|
| 275 |
|
|
|
| 276 |
|
|
dout := ra.hrdata(31 downto 0);
|
| 277 |
|
|
|
| 278 |
|
|
if rst = '0' then
|
| 279 |
|
|
v.hsel := '0';
|
| 280 |
|
|
v.hready := '1';
|
| 281 |
|
|
v.state := midle;
|
| 282 |
|
|
v.startsd := '0';
|
| 283 |
|
|
v.hio := '0';
|
| 284 |
|
|
end if;
|
| 285 |
|
|
|
| 286 |
|
|
rai <= v;
|
| 287 |
|
|
ahbso.hready <= ra.hready;
|
| 288 |
|
|
ahbso.hresp <= ra.hresp;
|
| 289 |
|
|
ahbso.hrdata <= dout;
|
| 290 |
|
|
ahbso.hcache <= not ra.hio;
|
| 291 |
|
|
|
| 292 |
|
|
end process;
|
| 293 |
|
|
|
| 294 |
|
|
ddr_ctrl : process(ddr_rst, r, ra, sdi, rbdrive, wdata)
|
| 295 |
|
|
variable v : ddr_reg_type; -- local variables for registers
|
| 296 |
|
|
variable startsd : std_ulogic;
|
| 297 |
|
|
variable dqm : std_logic_vector(7 downto 0);
|
| 298 |
|
|
variable raddr : std_logic_vector(13 downto 0);
|
| 299 |
|
|
variable adec : std_ulogic;
|
| 300 |
|
|
variable rams : std_logic_vector(1 downto 0);
|
| 301 |
|
|
variable ba : std_logic_vector(1 downto 0);
|
| 302 |
|
|
variable haddr : std_logic_vector(31 downto 0);
|
| 303 |
|
|
variable hsize : std_logic_vector(1 downto 0);
|
| 304 |
|
|
variable hwrite : std_ulogic;
|
| 305 |
|
|
variable htrans : std_logic_vector(1 downto 0);
|
| 306 |
|
|
variable hready : std_ulogic;
|
| 307 |
|
|
variable vbdrive : std_logic_vector(31 downto 0);
|
| 308 |
|
|
variable bdrive : std_ulogic;
|
| 309 |
|
|
variable writecfg: std_ulogic;
|
| 310 |
|
|
variable regsd1 : std_logic_vector(31 downto 0); -- data from registers
|
| 311 |
|
|
variable regsd2 : std_logic_vector(31 downto 0); -- data from registers
|
| 312 |
|
|
variable regsd3 : std_logic_vector(31 downto 0); -- data from registers
|
| 313 |
|
|
variable arefresh : std_logic;
|
| 314 |
|
|
begin
|
| 315 |
|
|
|
| 316 |
|
|
-- Variable default settings to avoid latches
|
| 317 |
|
|
|
| 318 |
|
|
v := r; v.hready := '0'; writecfg := '0'; vbdrive := rbdrive;
|
| 319 |
|
|
v.hrdata := sdi.data(63 downto 0); v.qdrive :='0'; v.txp := '0'; v.tcke := '0';
|
| 320 |
|
|
arefresh := '0';
|
| 321 |
|
|
v.wdata := wdata; -- *** ??? delay ctrl
|
| 322 |
|
|
v.dqm_dly := r.dqm; -- *** ??? delay ctrl
|
| 323 |
|
|
v.ck_dly := r.ck; -- *** ??? delay ctrl
|
| 324 |
|
|
v.cke_dly := r.cfg.cke; -- *** ??? delay ctrl
|
| 325 |
|
|
|
| 326 |
|
|
regsd1 := (others => '0');
|
| 327 |
|
|
regsd1(31 downto 15) := r.cfg.refon & r.cfg.trp & r.cfg.trfc &
|
| 328 |
|
|
r.cfg.trcd & r.cfg.bsize & r.cfg.csize & r.cfg.command &
|
| 329 |
|
|
r.cfg.dllrst & r.cfg.renable & r.cfg.cke;
|
| 330 |
|
|
regsd1(11 downto 0) := r.cfg.refresh;
|
| 331 |
|
|
regsd2 := (others => '0');
|
| 332 |
|
|
regsd2(8 downto 0) := conv_std_logic_vector(MHz, 9);
|
| 333 |
|
|
regsd2(14 downto 12) := conv_std_logic_vector(2, 3);
|
| 334 |
|
|
regsd2(15) := r.cfg.mobileen(1); -- Mobile DDR support
|
| 335 |
|
|
regsd2(19 downto 16) := conv_std_logic_vector(confapi, 4);
|
| 336 |
|
|
regsd3 := (others => '0');
|
| 337 |
|
|
regsd3(31) := r.cfg.mobileen(0); -- Mobile DDR enable
|
| 338 |
|
|
regsd3(24 downto 19) := r.cfg.tcke & r.cfg.txsr & r.cfg.txp;
|
| 339 |
|
|
regsd3(18 downto 16) := r.cfg.pmode;
|
| 340 |
|
|
regsd3( 7 downto 0) := r.cfg.ds(2 downto 0) & r.cfg.tcsr(1 downto 0)
|
| 341 |
|
|
& r.cfg.pasr(2 downto 0);
|
| 342 |
|
|
|
| 343 |
|
|
if ra.acc.haddr(4) = '1' and confapi /= 0 then
|
| 344 |
|
|
regsd2(31 downto 0) := r.cfg.conf(31 downto 0);
|
| 345 |
|
|
regsd3(31 downto 0) := r.cfg.conf(63 downto 32);
|
| 346 |
|
|
end if;
|
| 347 |
|
|
|
| 348 |
|
|
|
| 349 |
|
|
-- generate DQM from address and write size
|
| 350 |
|
|
|
| 351 |
|
|
case ra.acc.size is
|
| 352 |
|
|
when "00" =>
|
| 353 |
|
|
case ra.acc.haddr(2 downto 0) is
|
| 354 |
|
|
when "000" => dqm := "01111111";
|
| 355 |
|
|
when "001" => dqm := "10111111";
|
| 356 |
|
|
when "010" => dqm := "11011111";
|
| 357 |
|
|
when "011" => dqm := "11101111";
|
| 358 |
|
|
when "100" => dqm := "11110111";
|
| 359 |
|
|
when "101" => dqm := "11111011";
|
| 360 |
|
|
when "110" => dqm := "11111101";
|
| 361 |
|
|
when others => dqm := "11111110";
|
| 362 |
|
|
end case;
|
| 363 |
|
|
when "01" =>
|
| 364 |
|
|
case ra.acc.haddr(2 downto 1) is
|
| 365 |
|
|
when "00" => dqm := "00111111";
|
| 366 |
|
|
when "01" => dqm := "11001111";
|
| 367 |
|
|
when "10" => dqm := "11110011";
|
| 368 |
|
|
when others => dqm := "11111100";
|
| 369 |
|
|
end case;
|
| 370 |
|
|
when others => dqm := "00000000";
|
| 371 |
|
|
end case;
|
| 372 |
|
|
|
| 373 |
|
|
v.startsd := ra.startsd;
|
| 374 |
|
|
|
| 375 |
|
|
-- main FSM
|
| 376 |
|
|
|
| 377 |
|
|
case r.mstate is
|
| 378 |
|
|
when midle =>
|
| 379 |
|
|
if r.startsd = '1' then
|
| 380 |
|
|
if (r.sdstate = sidle) and (r.cfg.command = "000") and
|
| 381 |
|
|
(r.cmstate = midle)
|
| 382 |
|
|
then
|
| 383 |
|
|
startsd := '1'; v.mstate := active;
|
| 384 |
|
|
end if;
|
| 385 |
|
|
end if;
|
| 386 |
|
|
when others => null;
|
| 387 |
|
|
end case;
|
| 388 |
|
|
|
| 389 |
|
|
startsd := r.startsd xor r.startsdold;
|
| 390 |
|
|
|
| 391 |
|
|
-- generate row and column address size
|
| 392 |
|
|
|
| 393 |
|
|
haddr := ra.acc.haddr;
|
| 394 |
|
|
haddr(31 downto 20) := haddr(31 downto 20) and not conv_std_logic_vector(hmask, 12);
|
| 395 |
|
|
|
| 396 |
|
|
case r.cfg.csize is
|
| 397 |
|
|
when "00" => raddr := haddr(24 downto 11);
|
| 398 |
|
|
when "01" => raddr := haddr(25 downto 12);
|
| 399 |
|
|
when "10" => raddr := haddr(26 downto 13);
|
| 400 |
|
|
when others => raddr := haddr(27 downto 14);
|
| 401 |
|
|
end case;
|
| 402 |
|
|
|
| 403 |
|
|
-- generate bank address
|
| 404 |
|
|
|
| 405 |
|
|
ba := genmux(r.cfg.bsize, haddr(29 downto 22)) &
|
| 406 |
|
|
genmux(r.cfg.bsize, haddr(28 downto 21));
|
| 407 |
|
|
|
| 408 |
|
|
-- generate chip select
|
| 409 |
|
|
|
| 410 |
|
|
adec := genmux(r.cfg.bsize, haddr(30 downto 23));
|
| 411 |
|
|
|
| 412 |
|
|
rams := adec & not adec;
|
| 413 |
|
|
|
| 414 |
|
|
-- sdram access FSM
|
| 415 |
|
|
|
| 416 |
|
|
if r.trfc /= "0000" then v.trfc := r.trfc - 1; end if;
|
| 417 |
|
|
|
| 418 |
|
|
if r.idlecnt /= "0000" then v.idlecnt := r.idlecnt - 1; end if;
|
| 419 |
|
|
|
| 420 |
|
|
case r.sdstate is
|
| 421 |
|
|
when sidle =>
|
| 422 |
|
|
v.extdqs := '1';
|
| 423 |
|
|
if (startsd = '1') and (r.cfg.command = "000") and (r.cmstate = midle)
|
| 424 |
|
|
and (r.istate = finish)
|
| 425 |
|
|
then
|
| 426 |
|
|
v.address := raddr; v.ba := ba;
|
| 427 |
|
|
if ra.acc.hio = '0' then
|
| 428 |
|
|
v.sdcsn := not rams(1 downto 0); v.rasn := '0'; v.sdstate := act1;
|
| 429 |
|
|
elsif ra.acc.haddr(4 downto 2) = "100" and r.cfg.mobileen(0) = '1' then v.sdstate := srr1;
|
| 430 |
|
|
else v.sdstate := ioreg1; end if;
|
| 431 |
|
|
elsif (r.cfg.command = "000") and (r.cmstate = midle)
|
| 432 |
|
|
and (r.istate = finish) and r.idlecnt = "0000" and (r.cfg.mobileen(1) = '1') then
|
| 433 |
|
|
case r.cfg.pmode is
|
| 434 |
|
|
when PM_SR => v.cfg.cke := '0'; v.sdstate := sref;
|
| 435 |
|
|
when PM_CKS => v.ck := (others => '0'); v.sdstate := cks;
|
| 436 |
|
|
when PM_PD => v.cfg.cke := '0'; v.sdstate := pd;
|
| 437 |
|
|
when PM_DPD => v.cfg.cke := '0'; v.sdstate := dpd;
|
| 438 |
|
|
when others =>
|
| 439 |
|
|
end case;
|
| 440 |
|
|
if r.cfg.pmode /= "000" then v.trfc := (r.cfg.trp and r.cfg.mobileen(1)) & r.cfg.trfc; end if; -- Extend trfc for mobile ddr
|
| 441 |
|
|
end if;
|
| 442 |
|
|
v.waddr := ra.acc.haddr(7 downto 2);
|
| 443 |
|
|
when act1 =>
|
| 444 |
|
|
v.rasn := '1'; v.trfc := (r.cfg.trp and r.cfg.mobileen(1)) & r.cfg.trfc; -- Extend trfc for mobile ddr
|
| 445 |
|
|
if r.cfg.trcd = '1' then v.sdstate := act2; else
|
| 446 |
|
|
v.sdstate := act3; v.hready := ra.acc.hwrite;
|
| 447 |
|
|
end if;
|
| 448 |
|
|
v.waddr := ra.acc.haddr(7 downto 2);
|
| 449 |
|
|
when act2 =>
|
| 450 |
|
|
v.sdstate := act3; v.hready := ra.acc.hwrite;
|
| 451 |
|
|
when act3 =>
|
| 452 |
|
|
v.casn := '0';
|
| 453 |
|
|
v.address := ra.acc.haddr(14 downto 12) & '0' & ra.acc.haddr(11 downto 3) & '0';
|
| 454 |
|
|
v.dqm := dqm;
|
| 455 |
|
|
if ra.acc.hwrite = '1' then
|
| 456 |
|
|
v.waddr := r.waddr + 2; v.waddr(0) := '0';
|
| 457 |
|
|
v.sdstate := wr1; v.sdwen := '0'; v.bdrive := '0'; v.qdrive := '1';
|
| 458 |
|
|
if (r.waddr /= ra.raddr) then v.hready := '1';
|
| 459 |
|
|
if r.waddr(0) = '1' then v.dqm(7 downto 4) := (others => '1'); end if;
|
| 460 |
|
|
else
|
| 461 |
|
|
if r.waddr(0) = '0' then v.dqm(3 downto 0) := (others => '1');
|
| 462 |
|
|
else v.dqm(7 downto 4) := (others => '1'); end if;
|
| 463 |
|
|
end if;
|
| 464 |
|
|
else v.sdstate := rd1; end if;
|
| 465 |
|
|
when wr1 =>
|
| 466 |
|
|
v.sdwen := '1'; v.casn := '1'; v.qdrive := '1';
|
| 467 |
|
|
v.waddr := r.waddr + 2; v.dqm(7 downto 4) := (others => '0');
|
| 468 |
|
|
v.address(8 downto 3) := r.waddr;
|
| 469 |
|
|
if (r.waddr <= ra.raddr) and (r.waddr(5 downto 1) /= "00000") and (r.hready = '1')
|
| 470 |
|
|
then
|
| 471 |
|
|
v.extdqs := '0';
|
| 472 |
|
|
v.hready := '1';
|
| 473 |
|
|
if (r.hready = '1') and (r.waddr(2 downto 0) = "000") then
|
| 474 |
|
|
v.sdwen := '0'; v.casn := '0'; v.extdqs := '1';
|
| 475 |
|
|
end if;
|
| 476 |
|
|
if (r.waddr = ra.raddr) and (r.waddr /= "000000") and (r.waddr(0) = '0') then
|
| 477 |
|
|
v.dqm(3 downto 0) := (others => '1');
|
| 478 |
|
|
end if;
|
| 479 |
|
|
else
|
| 480 |
|
|
v.sdstate := wr2;
|
| 481 |
|
|
v.dqm := (others => '1'); --v.bdrive := '1';
|
| 482 |
|
|
v.startsdold := r.startsd;
|
| 483 |
|
|
end if;
|
| 484 |
|
|
when wr2 =>
|
| 485 |
|
|
v.sdstate := wr3; v.qdrive := '1';
|
| 486 |
|
|
when wr3 =>
|
| 487 |
|
|
v.sdstate := wr4a; v.qdrive := '1';
|
| 488 |
|
|
when wr4a =>
|
| 489 |
|
|
v.bdrive := '1';
|
| 490 |
|
|
v.rasn := '0'; v.sdwen := '0'; v.sdstate := wr4; v.qdrive := '1';
|
| 491 |
|
|
when wr4 =>
|
| 492 |
|
|
v.sdcsn := "11"; v.rasn := '1'; v.sdwen := '1'; --v.qdrive := '0';
|
| 493 |
|
|
if r.extdqs = '1' then v.qdrive := '1'; else v.qdrive := '0'; end if;
|
| 494 |
|
|
v.sdstate := wr5;
|
| 495 |
|
|
when wr5 =>
|
| 496 |
|
|
v.sdstate := sidle;
|
| 497 |
|
|
v.qdrive := '0';
|
| 498 |
|
|
v.idlecnt := (others => '1');
|
| 499 |
|
|
when rd1 =>
|
| 500 |
|
|
v.casn := '1'; v.sdstate := rd7;
|
| 501 |
|
|
-- if ra.acc.haddr(4 downto 2) = "011" then
|
| 502 |
|
|
-- v.casn := '0'; v.burst := '1'; v.address(5 downto 3) := "100";
|
| 503 |
|
|
-- end if;
|
| 504 |
|
|
when rd7 =>
|
| 505 |
|
|
v.casn := '1'; v.sdstate := rd2;
|
| 506 |
|
|
-- if ra.acc.haddr(4 downto 2) = "010" then
|
| 507 |
|
|
-- v.casn := '0'; v.burst := '1'; v.address(5 downto 3) := "100";
|
| 508 |
|
|
-- end if;
|
| 509 |
|
|
when rd2 =>
|
| 510 |
|
|
--v.casn := '1'; v.sdstate := rd3;
|
| 511 |
|
|
v.casn := '1';
|
| 512 |
|
|
if regoutput = 1 then v.sdstate := rd2a; else v.sdstate := rd3; end if; -- delay if registered output
|
| 513 |
|
|
-- if ra.acc.haddr(4 downto 2) = "001" then
|
| 514 |
|
|
-- v.casn := '0'; v.burst := '1'; v.address(5 downto 3) := "100";
|
| 515 |
|
|
-- end if;
|
| 516 |
|
|
-- if v.sdwen = '0' then v.dqm := (others => '1'); end if;
|
| 517 |
|
|
when rd2a => -- delay if registered output
|
| 518 |
|
|
v.sdstate := rd3;
|
| 519 |
|
|
when rd3 =>
|
| 520 |
|
|
if r.cfg.cl = '0' then -- CL = 2
|
| 521 |
|
|
if fast = 0 then v.startsdold := r.startsd; end if;
|
| 522 |
|
|
v.sdstate := rd4; v.hready := '1'; v.casn := '1';
|
| 523 |
|
|
else -- CL = 3
|
| 524 |
|
|
v.sdstate := rd3a; v.hready := '0'; v.casn := '1';
|
| 525 |
|
|
end if;
|
| 526 |
|
|
-- if r.sdwen = '0' then
|
| 527 |
|
|
-- v.rasn := '1'; v.sdwen := '1'; v.sdcsn := "11"; v.dqm := (others => '1');
|
| 528 |
|
|
-- elsif ra.acc.haddr(4 downto 2) = "000" then
|
| 529 |
|
|
-- v.casn := '0'; v.burst := '1'; v.address(5) := '1';
|
| 530 |
|
|
-- v.waddr := v.address(8 downto 3);
|
| 531 |
|
|
-- end if;
|
| 532 |
|
|
if v.hready = '1' then v.waddr := r.waddr + 2; end if;
|
| 533 |
|
|
when rd3a =>
|
| 534 |
|
|
if fast = 0 then v.startsdold := r.startsd; end if;
|
| 535 |
|
|
v.sdstate := rd4; v.hready := '1'; v.casn := '1';
|
| 536 |
|
|
if v.hready = '1' then v.waddr := r.waddr + 2; end if;
|
| 537 |
|
|
when rd4 =>
|
| 538 |
|
|
v.hready := '1'; v.casn := '1';
|
| 539 |
|
|
-- if (r.sdcsn /= "11") and (r.waddr(1 downto 0) = "11") and (r.burst = '1')
|
| 540 |
|
|
-- then
|
| 541 |
|
|
-- v.burst := '0';
|
| 542 |
|
|
if (r.sdcsn = "11") or (r.waddr(2 downto 1) = "11") then
|
| 543 |
|
|
v.dqm := (others => '1'); v.burst := '0';
|
| 544 |
|
|
if fast /= 0 then v.startsdold := r.startsd; end if;
|
| 545 |
|
|
if (r.sdcsn /= "11") then
|
| 546 |
|
|
v.rasn := '0'; v.sdwen := '0'; v.sdstate := rd5;
|
| 547 |
|
|
else
|
| 548 |
|
|
if r.cfg.trp = '1' then v.sdstate := rd6;
|
| 549 |
|
|
else v.sdstate := sidle; v.idlecnt := (others => '1'); end if;
|
| 550 |
|
|
end if;
|
| 551 |
|
|
end if;
|
| 552 |
|
|
if v.hready = '1' then v.waddr := r.waddr + 2; end if;
|
| 553 |
|
|
when rd5 =>
|
| 554 |
|
|
if r.cfg.trp = '1' then v.sdstate := rd6;
|
| 555 |
|
|
else v.sdstate := sidle; v.idlecnt := (others => '1'); end if;
|
| 556 |
|
|
v.sdcsn := (others => '1'); v.rasn := '1'; v.sdwen := '1';
|
| 557 |
|
|
v.dqm := (others => '1');
|
| 558 |
|
|
when rd6 =>
|
| 559 |
|
|
v.sdstate := sidle; v.dqm := (others => '1');
|
| 560 |
|
|
v.idlecnt := (others => '1');
|
| 561 |
|
|
v.sdcsn := (others => '1'); v.rasn := '1'; v.sdwen := '1';
|
| 562 |
|
|
when ioreg1 =>
|
| 563 |
|
|
if r.waddr(1) = '0' then
|
| 564 |
|
|
v.hrdata := regsd1 & regsd2;
|
| 565 |
|
|
else
|
| 566 |
|
|
v.hrdata := regsd3 & regsd3;
|
| 567 |
|
|
end if;
|
| 568 |
|
|
v.sdstate := ioreg2;
|
| 569 |
|
|
if ra.acc.hwrite = '0' then v.hready := '1'; end if;
|
| 570 |
|
|
when ioreg2 =>
|
| 571 |
|
|
writecfg := ra.acc.hwrite; v.startsdold := r.startsd;
|
| 572 |
|
|
case r.cfg.pmode is
|
| 573 |
|
|
when PM_SR => v.cfg.cke := '0'; v.sdstate := sref;
|
| 574 |
|
|
when PM_CKS => v.ck := (others => '0'); v.sdstate := cks;
|
| 575 |
|
|
when PM_PD => v.cfg.cke := '0'; v.sdstate := pd;
|
| 576 |
|
|
when PM_DPD => v.cfg.cke := '0'; v.sdstate := dpd;
|
| 577 |
|
|
when others => v.sdstate := sidle; v.idlecnt := (others => '1');
|
| 578 |
|
|
end case;
|
| 579 |
|
|
if r.cfg.pmode /= "000" and r.cfg.cke = '1' then v.trfc := (r.cfg.trp and r.cfg.mobileen(1)) & r.cfg.trfc; end if; -- Extend trfc for mobile ddr
|
| 580 |
|
|
when sref =>
|
| 581 |
|
|
v.sdcsn := (others => '0'); v.rasn := '0'; v.casn := '0';
|
| 582 |
|
|
if (startsd = '1' and (ra.acc.hio = '0' or ra.acc.haddr(4 downto 2) = "100"))
|
| 583 |
|
|
or (r.cfg.command /= "000") or r.cfg.pmode /= PM_SR then
|
| 584 |
|
|
if r.trfc = "0000" then v.cfg.cke := '1'; end if;
|
| 585 |
|
|
if r.cfg.cke = '1' then
|
| 586 |
|
|
v.sdcsn := (others => '0'); v.rasn := '1'; v.casn := '1';
|
| 587 |
|
|
if (r.idlecnt = "0000" and r.cfg.mobileen(0) = '1') -- 120 ns with NOP
|
| 588 |
|
|
or (r.refresh(8) = '0' and r.cfg.mobileen(0) = '0') then -- 200 clock cycles
|
| 589 |
|
|
v.sdstate := sidle;
|
| 590 |
|
|
v.idlecnt := (others => '1');
|
| 591 |
|
|
v.sref_tmpcom := r.cfg.command;
|
| 592 |
|
|
v.cfg.command := CMD_REF;
|
| 593 |
|
|
end if;
|
| 594 |
|
|
else
|
| 595 |
|
|
v.idlecnt := r.cfg.txsr;
|
| 596 |
|
|
end if;
|
| 597 |
|
|
elsif (startsd = '1' and ra.acc.hio = '1') then
|
| 598 |
|
|
v.waddr := ra.acc.haddr(7 downto 2);
|
| 599 |
|
|
v.sdstate := ioreg1;
|
| 600 |
|
|
end if;
|
| 601 |
|
|
when cks =>
|
| 602 |
|
|
if (startsd = '1' and (ra.acc.hio = '0' or ra.acc.haddr(4 downto 2) = "100"))
|
| 603 |
|
|
or (r.cfg.command /= "000") or r.cfg.pmode /= PM_CKS then
|
| 604 |
|
|
v.ck := (others => '1');
|
| 605 |
|
|
v.sdstate := sidle; v.idlecnt := (others => '1');
|
| 606 |
|
|
elsif (startsd = '1' and ra.acc.hio = '1') then
|
| 607 |
|
|
v.waddr := ra.acc.haddr(7 downto 2);
|
| 608 |
|
|
v.sdstate := ioreg1;
|
| 609 |
|
|
end if;
|
| 610 |
|
|
when pd =>
|
| 611 |
|
|
v.tcke := '1'; -- *****
|
| 612 |
|
|
if ((startsd = '1' and (ra.acc.hio = '0' or ra.acc.haddr(4 downto 2) = "100"))
|
| 613 |
|
|
or (r.cfg.command /= "000") or r.cfg.pmode /= PM_PD)
|
| 614 |
|
|
and (r.tcke = '1' or r.cfg.tcke = '0') then -- *****
|
| 615 |
|
|
v.cfg.cke := '1';
|
| 616 |
|
|
v.txp := r.cfg.cke;
|
| 617 |
|
|
if r.cfg.cke = '1' and (r.txp = '1' or r.cfg.txp = '0') then -- 1 - 2 clock cycles
|
| 618 |
|
|
v.sdstate := sidle;
|
| 619 |
|
|
v.idlecnt := (others => '1');
|
| 620 |
|
|
end if;
|
| 621 |
|
|
elsif startsd = '1' and ra.acc.hio = '1' and (r.tcke = '1' or r.cfg.tcke = '0') then
|
| 622 |
|
|
v.waddr := ra.acc.haddr(7 downto 2);
|
| 623 |
|
|
v.sdstate := ioreg1;
|
| 624 |
|
|
end if;
|
| 625 |
|
|
when dpd =>
|
| 626 |
|
|
v.sdcsn := (others => '0'); v.sdwen := '0'; v.rasn := '1'; v.casn := '1';
|
| 627 |
|
|
v.cfg.refon := '0';
|
| 628 |
|
|
if (startsd = '1' and ra.acc.hio = '1') then
|
| 629 |
|
|
v.waddr := ra.acc.haddr(7 downto 2);
|
| 630 |
|
|
v.sdstate := ioreg1;
|
| 631 |
|
|
elsif startsd = '1' then
|
| 632 |
|
|
v.startsdold := r.startsd; -- acc all accesses
|
| 633 |
|
|
elsif r.cfg.pmode /= PM_DPD then
|
| 634 |
|
|
v.cfg.cke := '1';
|
| 635 |
|
|
if r.cfg.cke = '1' then
|
| 636 |
|
|
v.sdcsn := (others => '0'); v.sdwen := '1'; v.rasn := '1'; v.casn := '1';
|
| 637 |
|
|
v.sdstate := sidle;
|
| 638 |
|
|
v.idlecnt := (others => '1');
|
| 639 |
|
|
end if;
|
| 640 |
|
|
end if;
|
| 641 |
|
|
when srr1 => -- Load Mode Register "01"
|
| 642 |
|
|
v.trfc := "0001";
|
| 643 |
|
|
v.sdcsn := (0 => '0', others => '1'); v.rasn := '0'; v.casn := '0';
|
| 644 |
|
|
v.sdwen := '0'; v.address := (others => '0'); v.ba := "01";
|
| 645 |
|
|
v.sdstate := srr2;
|
| 646 |
|
|
when srr2 => -- Read 0
|
| 647 |
|
|
v.sdcsn := (others => '1'); v.rasn := '1'; v.casn := '1'; v.sdwen := '1';
|
| 648 |
|
|
if r.trfc = "0000" then
|
| 649 |
|
|
--if r.cfg.cl = '1' then v.trfc := "0100"; else v.trfc := "0011"; end if;
|
| 650 |
|
|
if regoutput = 1 then -- delay if registered output
|
| 651 |
|
|
if r.cfg.cl = '1' then v.trfc := "0101"; else v.trfc := "0100"; end if; -- Extend trfc for mobile ddr
|
| 652 |
|
|
else
|
| 653 |
|
|
if r.cfg.cl = '1' then v.trfc := "0100"; else v.trfc := "0011"; end if; -- Extend trfc for mobile ddr
|
| 654 |
|
|
end if;
|
| 655 |
|
|
v.sdcsn := (0 => '0', others => '1'); v.casn := '0';
|
| 656 |
|
|
v.sdstate := srr3;
|
| 657 |
|
|
end if;
|
| 658 |
|
|
when srr3 => -- SRR done
|
| 659 |
|
|
v.sdcsn := (others => '1'); v.rasn := '1'; v.casn := '1'; v.sdwen := '1';
|
| 660 |
|
|
if r.trfc = "0000" then
|
| 661 |
|
|
v.hready := '1';
|
| 662 |
|
|
v.startsdold := r.startsd;
|
| 663 |
|
|
v.sdstate := sidle;
|
| 664 |
|
|
v.idlecnt := (others => '1');
|
| 665 |
|
|
end if;
|
| 666 |
|
|
when others =>
|
| 667 |
|
|
v.sdstate := sidle;
|
| 668 |
|
|
v.idlecnt := (others => '1');
|
| 669 |
|
|
end case;
|
| 670 |
|
|
|
| 671 |
|
|
-- sdram commands
|
| 672 |
|
|
|
| 673 |
|
|
case r.cmstate is
|
| 674 |
|
|
when midle =>
|
| 675 |
|
|
if r.sdstate = sidle then
|
| 676 |
|
|
case r.cfg.command is
|
| 677 |
|
|
when CMD_PRE => -- precharge
|
| 678 |
|
|
v.sdcsn := (others => '0'); v.rasn := '0'; v.sdwen := '0';
|
| 679 |
|
|
v.address(12) := '1'; v.cmstate := active;
|
| 680 |
|
|
when CMD_REF => -- auto-refresh
|
| 681 |
|
|
v.sdcsn := (others => '0'); v.rasn := '0'; v.casn := '0';
|
| 682 |
|
|
v.cmstate := active;
|
| 683 |
|
|
when CMD_EMR => -- load-ext-mode-reg
|
| 684 |
|
|
v.sdcsn := (others => '0'); v.rasn := '0'; v.casn := '0';
|
| 685 |
|
|
v.sdwen := '0'; v.cmstate := active; --v.ba := "01";
|
| 686 |
|
|
--v.address := "00000000000000";
|
| 687 |
|
|
if r.cfg.mobileen = "11" then
|
| 688 |
|
|
v.ba := "10";
|
| 689 |
|
|
v.address := "000000" & r.cfg.ds(2 downto 0) & r.cfg.tcsr(1 downto 0)
|
| 690 |
|
|
& r.cfg.pasr(2 downto 0);
|
| 691 |
|
|
else
|
| 692 |
|
|
v.ba := "01";
|
| 693 |
|
|
v.address := "00000000000000";
|
| 694 |
|
|
end if;
|
| 695 |
|
|
when CMD_LMR => -- load-mode-reg
|
| 696 |
|
|
v.sdcsn := (others => '0'); v.rasn := '0'; v.casn := '0';
|
| 697 |
|
|
v.sdwen := '0'; v.cmstate := active; v.ba := "00";
|
| 698 |
|
|
v.address := "00000" & r.cfg.dllrst & "0" & "01" & r.cfg.cl & "0011";
|
| 699 |
|
|
when others => null;
|
| 700 |
|
|
end case;
|
| 701 |
|
|
end if;
|
| 702 |
|
|
when active =>
|
| 703 |
|
|
v.sdcsn := (others => '1'); v.rasn := '1'; v.casn := '1';
|
| 704 |
|
|
v.sdwen := '1'; --v.cfg.command := "000";
|
| 705 |
|
|
v.cfg.command := r.sref_tmpcom; v.sref_tmpcom := "000";
|
| 706 |
|
|
v.cmstate := leadout; v.trfc := (r.cfg.trp and r.cfg.mobileen(1)) & r.cfg.trfc; -- Extend trfc for mobile ddr
|
| 707 |
|
|
when others =>
|
| 708 |
|
|
if r.trfc = "0000" then v.cmstate := midle; end if;
|
| 709 |
|
|
|
| 710 |
|
|
end case;
|
| 711 |
|
|
|
| 712 |
|
|
-- sdram init
|
| 713 |
|
|
|
| 714 |
|
|
case r.istate is
|
| 715 |
|
|
when iidle =>
|
| 716 |
|
|
if r.cfg.renable = '1' then
|
| 717 |
|
|
v.cfg.cke := '1'; v.cfg.dllrst := '1';
|
| 718 |
|
|
if r.cfg.cke = '1' then v.istate := pre; v.cfg.command := CMD_PRE; end if;
|
| 719 |
|
|
end if;
|
| 720 |
|
|
when pre =>
|
| 721 |
|
|
if r.cfg.command = "000" then
|
| 722 |
|
|
if r.cfg.mobileen = "11" then
|
| 723 |
|
|
v.cfg.command := CMD_REF; v.istate := ref1;
|
| 724 |
|
|
else
|
| 725 |
|
|
v.cfg.command := "11" & r.cfg.dllrst; -- CMD_LMR/CMD_EMR
|
| 726 |
|
|
if r.cfg.dllrst = '1' then v.istate := emode; else v.istate := lmode; end if;
|
| 727 |
|
|
end if;
|
| 728 |
|
|
end if;
|
| 729 |
|
|
when emode =>
|
| 730 |
|
|
if r.cfg.command = "000" then
|
| 731 |
|
|
if r.cfg.mobileen = "11" then
|
| 732 |
|
|
v.istate := finish; --v.cfg.command := CMD_LMR;
|
| 733 |
|
|
v.cfg.refon := '1'; v.cfg.renable := '0';
|
| 734 |
|
|
else
|
| 735 |
|
|
v.istate := lmode; v.cfg.command := CMD_LMR;
|
| 736 |
|
|
end if;
|
| 737 |
|
|
end if;
|
| 738 |
|
|
when lmode =>
|
| 739 |
|
|
if r.cfg.command = "000" then
|
| 740 |
|
|
if r.cfg.mobileen = "11" then
|
| 741 |
|
|
v.cfg.command := CMD_EMR; v.istate := emode;
|
| 742 |
|
|
else
|
| 743 |
|
|
if r.cfg.dllrst = '1' then
|
| 744 |
|
|
if r.refresh(9 downto 8) = "00" then -- > 200 clocks delay
|
| 745 |
|
|
v.cfg.command := CMD_PRE; v.istate := ref1;
|
| 746 |
|
|
end if;
|
| 747 |
|
|
else
|
| 748 |
|
|
v.istate := finish; --v.cfg.command := CMD_LMR;
|
| 749 |
|
|
v.cfg.refon := '1'; v.cfg.renable := '0';
|
| 750 |
|
|
end if;
|
| 751 |
|
|
end if;
|
| 752 |
|
|
end if;
|
| 753 |
|
|
when ref1 =>
|
| 754 |
|
|
if r.cfg.command = "000" then
|
| 755 |
|
|
v.cfg.command := CMD_REF; v.cfg.dllrst := '0'; v.istate := ref2;
|
| 756 |
|
|
end if;
|
| 757 |
|
|
when ref2 =>
|
| 758 |
|
|
if r.cfg.command = "000" then
|
| 759 |
|
|
--v.cfg.command := CMD_REF; v.istate := pre;
|
| 760 |
|
|
if r.cfg.mobileen = "11" then v.istate := lmode; v.cfg.command := CMD_LMR;
|
| 761 |
|
|
else v.cfg.command := CMD_REF; v.istate := pre; end if;
|
| 762 |
|
|
end if;
|
| 763 |
|
|
when others =>
|
| 764 |
|
|
--if r.cfg.renable = '1' then
|
| 765 |
|
|
if r.cfg.renable = '1' and r.sdstate /= dpd then
|
| 766 |
|
|
v.istate := iidle; v.cfg.dllrst := '1';
|
| 767 |
|
|
end if;
|
| 768 |
|
|
end case;
|
| 769 |
|
|
|
| 770 |
|
|
-- second part of main fsm
|
| 771 |
|
|
|
| 772 |
|
|
case r.mstate is
|
| 773 |
|
|
when active =>
|
| 774 |
|
|
if v.hready = '1' then
|
| 775 |
|
|
v.mstate := midle;
|
| 776 |
|
|
end if;
|
| 777 |
|
|
when others => null;
|
| 778 |
|
|
end case;
|
| 779 |
|
|
|
| 780 |
|
|
-- sdram refresh counter
|
| 781 |
|
|
|
| 782 |
|
|
if (((r.cfg.refon = '1') and (r.istate = finish)) or
|
| 783 |
|
|
(r.cfg.dllrst = '1')) and (r.cfg.pmode /= PM_SR or r.cfg.mobileen(0) = '0')
|
| 784 |
|
|
then
|
| 785 |
|
|
v.refresh := r.refresh - 1;
|
| 786 |
|
|
if r.cfg.pmode = PM_SR and r.cfg.mobileen(0) = '0' and r.cfg.cke = '0' then
|
| 787 |
|
|
v.refresh := (8 => '1', 7 => '1', 6 => '1', 3 => '1', others => '0');
|
| 788 |
|
|
else
|
| 789 |
|
|
if (v.refresh(11) and not r.refresh(11)) = '1' then
|
| 790 |
|
|
v.refresh := r.cfg.refresh;
|
| 791 |
|
|
if r.cfg.dllrst = '0' then v.cfg.command := "100"; arefresh := '1'; end if;
|
| 792 |
|
|
end if;
|
| 793 |
|
|
end if;
|
| 794 |
|
|
end if;
|
| 795 |
|
|
|
| 796 |
|
|
-- AHB register access
|
| 797 |
|
|
|
| 798 |
|
|
if (ra.acc.hio and ra.acc.hwrite and writecfg) = '1' then
|
| 799 |
|
|
if r.waddr(2 downto 0) = "000" then
|
| 800 |
|
|
v.cfg.refresh := wdata(11+32 downto 0+32);
|
| 801 |
|
|
v.cfg.dllrst := wdata(17+32);
|
| 802 |
|
|
v.cfg.command := wdata(20+32 downto 18+32);
|
| 803 |
|
|
v.cfg.csize := wdata(22+32 downto 21+32);
|
| 804 |
|
|
v.cfg.bsize := wdata(25+32 downto 23+32);
|
| 805 |
|
|
v.cfg.trcd := wdata(26+32);
|
| 806 |
|
|
v.cfg.trfc := wdata(29+32 downto 27+32);
|
| 807 |
|
|
v.cfg.trp := wdata(30+32);
|
| 808 |
|
|
if r.cfg.pmode = "000" then
|
| 809 |
|
|
v.cfg.cke := wdata(15+32);
|
| 810 |
|
|
v.cfg.renable := wdata(16+32);
|
| 811 |
|
|
v.cfg.refon := wdata(31+32);
|
| 812 |
|
|
end if;
|
| 813 |
|
|
elsif r.waddr(2 downto 0) = "010" then
|
| 814 |
|
|
v.cfg.cl := wdata(30+32);
|
| 815 |
|
|
if r.cfg.mobileen(1) = '1' and mobile /= 3 then
|
| 816 |
|
|
v.cfg.mobileen(0) := wdata(31+32);
|
| 817 |
|
|
end if;
|
| 818 |
|
|
if r.cfg.mobileen(1) = '1' then
|
| 819 |
|
|
v.cfg.pasr(5 downto 3) := wdata( 2+32 downto 0+32);
|
| 820 |
|
|
v.cfg.tcsr(3 downto 2) := wdata( 4+32 downto 3+32);
|
| 821 |
|
|
v.cfg.ds(5 downto 3) := wdata( 7+32 downto 5+32);
|
| 822 |
|
|
v.cfg.pmode := wdata(18+32 downto 16+32);
|
| 823 |
|
|
v.cfg.txp := wdata(19+32);
|
| 824 |
|
|
v.cfg.txsr := wdata(23+32 downto 20+32);
|
| 825 |
|
|
v.cfg.tcke := wdata(24+32);
|
| 826 |
|
|
end if;
|
| 827 |
|
|
elsif r.waddr(2 downto 0) = "101" and confapi /= 0 then
|
| 828 |
|
|
v.cfg.conf(31 downto 0) := wdata(31 downto 0);
|
| 829 |
|
|
elsif r.waddr(2 downto 0) = "110" and confapi /= 0 then
|
| 830 |
|
|
v.cfg.conf(63 downto 32) := wdata(31+32 downto 0+32);
|
| 831 |
|
|
end if;
|
| 832 |
|
|
end if;
|
| 833 |
|
|
|
| 834 |
|
|
-- Disable CS and DPD when Mobile DDR is Disabled
|
| 835 |
|
|
if r.cfg.mobileen(0) = '0' then v.cfg.pmode(2) := '0'; end if;
|
| 836 |
|
|
|
| 837 |
|
|
-- Update EMR when ds, tcsr or pasr change
|
| 838 |
|
|
if r.cfg.command = "000" and arefresh = '0' and r.cfg.mobileen(0) = '1' then
|
| 839 |
|
|
if r.cfg.ds(2 downto 0) /= r.cfg.ds(5 downto 3) then
|
| 840 |
|
|
v.cfg.command := "111"; v.cfg.ds(2 downto 0) := r.cfg.ds(5 downto 3);
|
| 841 |
|
|
end if;
|
| 842 |
|
|
if r.cfg.tcsr(1 downto 0) /= r.cfg.tcsr(3 downto 2) then
|
| 843 |
|
|
v.cfg.command := "111"; v.cfg.tcsr(1 downto 0) := r.cfg.tcsr(3 downto 2);
|
| 844 |
|
|
end if;
|
| 845 |
|
|
if r.cfg.pasr(2 downto 0) /= r.cfg.pasr(5 downto 3) then
|
| 846 |
|
|
v.cfg.command := "111"; v.cfg.pasr(2 downto 0) := r.cfg.pasr(5 downto 3);
|
| 847 |
|
|
end if;
|
| 848 |
|
|
end if;
|
| 849 |
|
|
|
| 850 |
|
|
v.nbdrive := not v.bdrive;
|
| 851 |
|
|
|
| 852 |
|
|
if oepol = 1 then bdrive := r.nbdrive; vbdrive := (others => v.nbdrive);
|
| 853 |
|
|
else bdrive := r.bdrive; vbdrive := (others => v.bdrive);end if;
|
| 854 |
|
|
|
| 855 |
|
|
-- reset
|
| 856 |
|
|
|
| 857 |
|
|
if ddr_rst = '0' then
|
| 858 |
|
|
v.sdstate := sidle;
|
| 859 |
|
|
v.mstate := midle;
|
| 860 |
|
|
v.istate := finish;
|
| 861 |
|
|
v.cmstate := midle;
|
| 862 |
|
|
v.cfg.command := "000";
|
| 863 |
|
|
v.cfg.csize := conv_std_logic_vector(col-9, 2);
|
| 864 |
|
|
v.cfg.bsize := conv_std_logic_vector(log2(Mbyte/8), 3);
|
| 865 |
|
|
if MHz > 100 then v.cfg.trcd := '1'; else v.cfg.trcd := '0'; end if;
|
| 866 |
|
|
v.cfg.refon := '0';
|
| 867 |
|
|
if mobile >= 2 then -- Extend trfc for mobile ddr
|
| 868 |
|
|
if MHz > 100 then v.cfg.trfc := conv_std_logic_vector(98*MHz/1000-10, 3);
|
| 869 |
|
|
else v.cfg.trfc := conv_std_logic_vector(98*MHz/1000-2, 3); end if;
|
| 870 |
|
|
else v.cfg.trfc := conv_std_logic_vector(75*MHz/1000-2, 3); end if;
|
| 871 |
|
|
v.cfg.refresh := conv_std_logic_vector(7800*MHz/1000, 12);
|
| 872 |
|
|
v.refresh := (others => '0');
|
| 873 |
|
|
if pwron = 1 then v.cfg.renable := '1';
|
| 874 |
|
|
else v.cfg.renable := '0'; end if;
|
| 875 |
|
|
if MHz > 100 then v.cfg.trp := '1'; else v.cfg.trp := '0'; end if;
|
| 876 |
|
|
v.dqm := (others => '1');
|
| 877 |
|
|
v.sdwen := '1';
|
| 878 |
|
|
v.rasn := '1';
|
| 879 |
|
|
v.casn := '1';
|
| 880 |
|
|
v.hready := '0';
|
| 881 |
|
|
v.startsd := '0';
|
| 882 |
|
|
v.startsdold := '0';
|
| 883 |
|
|
v.cfg.dllrst := '0';
|
| 884 |
|
|
if mobile >= 2 then v.cfg.cke := '1';
|
| 885 |
|
|
else v.cfg.cke := '0'; end if;
|
| 886 |
|
|
v.cfg.pasr := (others => '0');
|
| 887 |
|
|
v.cfg.tcsr := (others => '0');
|
| 888 |
|
|
v.cfg.ds := (others => '0');
|
| 889 |
|
|
v.cfg.pmode := (others => '0');
|
| 890 |
|
|
v.cfg.txsr := conv_std_logic_vector(120*MHz/1000, 4);
|
| 891 |
|
|
v.cfg.txp := '1';
|
| 892 |
|
|
v.idlecnt := (others => '1');
|
| 893 |
|
|
v.ck := (others => '1');
|
| 894 |
|
|
if mobile >= 2 then v.cfg.mobileen := "11"; -- Default: Mobile DDR
|
| 895 |
|
|
elsif mobile = 1 then v.cfg.mobileen := "10"; -- Mobile DDR support enable
|
| 896 |
|
|
else v.cfg.mobileen := "00"; end if; -- Mobile DDR support disable
|
| 897 |
|
|
v.sref_tmpcom := "000";
|
| 898 |
|
|
v.cfg.cl := '0'; -- CL = 3/2 -- ****
|
| 899 |
|
|
v.cfg.tcke := '1';
|
| 900 |
|
|
if confapi /= 0 then
|
| 901 |
|
|
v.cfg.conf(31 downto 0) := conv_std_logic_vector(conf0, 32); --x"0000A0A0";
|
| 902 |
|
|
v.cfg.conf(63 downto 32) := conv_std_logic_vector(conf1, 32); --x"00060606";
|
| 903 |
|
|
end if;
|
| 904 |
|
|
end if;
|
| 905 |
|
|
|
| 906 |
|
|
if regoutput = 1 then
|
| 907 |
|
|
if oepol = 1 then v.sdo_bdrive := r.nbdrive; -- *** ??? delay ctrl
|
| 908 |
|
|
else v.sdo_bdrive := r.bdrive; end if;
|
| 909 |
|
|
v.sdo_qdrive := not (v.qdrive or r.nbdrive);
|
| 910 |
|
|
end if;
|
| 911 |
|
|
|
| 912 |
|
|
ri <= v;
|
| 913 |
|
|
ribdrive <= vbdrive;
|
| 914 |
|
|
|
| 915 |
|
|
|
| 916 |
|
|
end process;
|
| 917 |
|
|
|
| 918 |
|
|
--sdo.sdcke <= (others => r.cfg.cke);
|
| 919 |
|
|
ahbso.hconfig <= hconfig;
|
| 920 |
|
|
ahbso.hirq <= (others => '0');
|
| 921 |
|
|
ahbso.hindex <= hindex;
|
| 922 |
|
|
|
| 923 |
|
|
ahbregs : process(clk_ahb) begin
|
| 924 |
|
|
if rising_edge(clk_ahb) then
|
| 925 |
|
|
ra <= rai;
|
| 926 |
|
|
end if;
|
| 927 |
|
|
end process;
|
| 928 |
|
|
|
| 929 |
|
|
ddrregs : process(clk_ddr, rst, ddr_rst) begin
|
| 930 |
|
|
if rising_edge(clk_ddr) then
|
| 931 |
|
|
r <= ri; rbdrive <= ribdrive;
|
| 932 |
|
|
ddr_rst_gen <= ddr_rst_gen(2 downto 0) & '1';
|
| 933 |
|
|
end if;
|
| 934 |
|
|
if (rst = '0') then
|
| 935 |
|
|
ddr_rst_gen <= "0000";
|
| 936 |
|
|
end if;
|
| 937 |
|
|
if (ddr_rst = '0') then
|
| 938 |
|
|
r.sdcsn <= (others => '1'); r.bdrive <= '1'; r.nbdrive <= '0';
|
| 939 |
|
|
if oepol = 0 then rbdrive <= (others => '1');
|
| 940 |
|
|
else rbdrive <= (others => '0'); end if;
|
| 941 |
|
|
--r.cfg.cke <= '0';
|
| 942 |
|
|
if mobile = 2 then r.cfg.cke <= '1';
|
| 943 |
|
|
else r.cfg.cke <= '0'; end if;
|
| 944 |
|
|
end if;
|
| 945 |
|
|
end process;
|
| 946 |
|
|
|
| 947 |
|
|
sdo.address <= '0' & r.address when regoutput = 1 else '0' & ri.address; -- *** ??? delay ctrl
|
| 948 |
|
|
sdo.ba <= r.ba when regoutput = 1 else ri.ba; -- *** ??? delay ctrl
|
| 949 |
|
|
sdo.bdrive <= r.sdo_bdrive when regoutput = 1 else r.nbdrive when oepol = 1 else r.bdrive; -- *** ??? delay ctrl
|
| 950 |
|
|
sdo.qdrive <= r.sdo_qdrive when regoutput = 1 else not (ri.qdrive or r.nbdrive); -- *** ??? delay ctrl
|
| 951 |
|
|
sdo.vbdrive <= rbdrive;
|
| 952 |
|
|
sdo.sdcsn <= r.sdcsn when regoutput = 1 else ri.sdcsn; -- *** ??? delay ctrl
|
| 953 |
|
|
sdo.sdwen <= r.sdwen when regoutput = 1 else ri.sdwen; -- *** ??? delay ctrl
|
| 954 |
|
|
sdo.dqm <= "11111111" & r.dqm_dly when regoutput = 1 else "11111111" & r.dqm; -- *** ??? delay ctrl
|
| 955 |
|
|
sdo.rasn <= r.rasn when regoutput = 1 else ri.rasn; -- *** ??? delay ctrl
|
| 956 |
|
|
sdo.casn <= r.casn when regoutput = 1 else ri.casn; -- *** ??? delay ctrl
|
| 957 |
|
|
sdo.data <= zero32 & zero32 & r.wdata when regoutput = 1 else zero32 & zero32 & wdata; -- *** ??? delay ctrl
|
| 958 |
|
|
sdo.sdck <= r.ck_dly when regoutput = 1 else r.ck; -- *** ??? delay ctrl
|
| 959 |
|
|
sdo.sdcke <= (others => r.cke_dly) when regoutput = 1 else (others => r.cfg.cke); -- *** ??? delay ctrl
|
| 960 |
|
|
sdo.moben <= r.cfg.mobileen(0);
|
| 961 |
|
|
sdo.conf <= r.cfg.conf;
|
| 962 |
|
|
|
| 963 |
|
|
read_buff : syncram_2p
|
| 964 |
|
|
generic map (tech => memtech, abits => 5, dbits => 64, sepclk => 1, wrfst => 0)
|
| 965 |
|
|
port map ( rclk => clk_ahb, renable => vcc, raddress => rai.raddr(5 downto 1),
|
| 966 |
|
|
dataout => rdata, wclk => clk_ddr, write => ri.hready,
|
| 967 |
|
|
waddress => r.waddr(5 downto 1), datain => ri.hrdata);
|
| 968 |
|
|
|
| 969 |
|
|
write_buff1 : syncram_2p
|
| 970 |
|
|
generic map (tech => memtech, abits => 5, dbits => 32, sepclk => 1, wrfst => 0)
|
| 971 |
|
|
port map ( rclk => clk_ddr, renable => vcc, raddress => r.waddr(5 downto 1),
|
| 972 |
|
|
dataout => wdata(63 downto 32), wclk => clk_ahb, write => ra.write(0),
|
| 973 |
|
|
waddress => ra.haddr(7 downto 3), datain => ahbsi.hwdata);
|
| 974 |
|
|
|
| 975 |
|
|
write_buff2 : syncram_2p
|
| 976 |
|
|
generic map (tech => memtech, abits => 5, dbits => 32, sepclk => 1, wrfst => 0)
|
| 977 |
|
|
port map ( rclk => clk_ddr, renable => vcc, raddress => r.waddr(5 downto 1),
|
| 978 |
|
|
dataout => wdata(31 downto 0), wclk => clk_ahb, write => ra.write(1),
|
| 979 |
|
|
waddress => ra.haddr(7 downto 3), datain => ahbsi.hwdata);
|
| 980 |
|
|
|
| 981 |
|
|
-- pragma translate_off
|
| 982 |
|
|
bootmsg : report_version
|
| 983 |
|
|
generic map (
|
| 984 |
|
|
msg1 => "ddrsp" & tost(hindex) & ": 32-bit DDR266 controller rev " &
|
| 985 |
|
|
tost(REVISION) & ", " & tost(Mbyte) & " Mbyte, " & tost(MHz) &
|
| 986 |
|
|
" MHz DDR clock");
|
| 987 |
|
|
-- pragma translate_on
|
| 988 |
|
|
|
| 989 |
|
|
end;
|
| 990 |
|
|
|