OpenCores
URL https://opencores.org/ocsvn/mips_enhanced/mips_enhanced/trunk

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gaisler/] [ddr/] [ddrsp16a.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.