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

Subversion Repositories layer2

[/] [layer2/] [trunk/] [vhdl/] [ddr/] [rtl/] [ddr_init.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
--------------------------------------------------------------------------------
2
-- Mycron® DDR SDRAM - MT46V32M16 - 8 Meg x 16 x 4 banks                      --
3
--------------------------------------------------------------------------------
4
-- Copyright (C)2012  Mathias Hörtnagl <mathias.hoertnagl@gmail.comt>         --
5
--                                                                            --
6
-- This program is free software: you can redistribute it and/or modify       --
7
-- it under the terms of the GNU General Public License as published by       --
8
-- the Free Software Foundation, either version 3 of the License, or          --
9
-- (at your option) any later version.                                        --
10
--                                                                            --
11
-- This program is distributed in the hope that it will be useful,            --
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              --
14
-- GNU General Public License for more details.                               --
15
--                                                                            --
16
-- You should have received a copy of the GNU General Public License          --
17
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.      --
18
--------------------------------------------------------------------------------
19
library ieee;
20
use ieee.std_logic_1164.all;
21
use ieee.numeric_std.all;
22
 
23
entity ddr_init is
24
   port (
25
      clk0      : in  std_logic;
26
      rst       : in  std_logic;
27
      SD_CKE    : out std_logic;
28
      SD_BA     : out std_logic_vector(1 downto 0);
29
      SD_A      : out std_logic_vector(12 downto 0);
30
      SD_CMD    : out std_logic_vector(3 downto 0);
31
      init_done : out boolean
32
   );
33
end ddr_init;
34
 
35
architecture rtl of ddr_init is
36
 
37
   -----------------------------------------------------------------------------
38
   -- Controller Commands                                                     --
39
   -----------------------------------------------------------------------------
40
   constant CMD_LMR          : std_logic_vector(3 downto 0) := "0000";
41
   constant CMD_AUTO_REFRESH : std_logic_vector(3 downto 0) := "0001";
42
   constant CMD_PRECHARGE    : std_logic_vector(3 downto 0) := "0010";
43
   constant CMD_NOP          : std_logic_vector(3 downto 0) := "0111";
44
 
45
   -----------------------------------------------------------------------------
46
   -- Mode Rgister Addresses                                                  --
47
   -----------------------------------------------------------------------------
48
   -- Addresses for the two mode registers, selected via SD_BA.
49
   constant BMR_ADDR : std_logic_vector(1 downto 0) := "00";
50
   constant EMR_ADDR : std_logic_vector(1 downto 0) := "01";
51
 
52
   -----------------------------------------------------------------------------
53
   -- Base Mode Rgister                                                       --
54
   -----------------------------------------------------------------------------
55
   -- Operating modes.
56
   constant OP_NORMAL  : std_logic_vector(5 downto 0) := "000000";
57
   constant OP_DLL_RST : std_logic_vector(5 downto 0) := "000010";
58
 
59
   -- CAS latency.
60
   constant CAS_2  : std_logic_vector(2 downto 0) := "010";
61
 
62
   -- Burst type.
63
   constant BT_S : std_logic := '0';      -- Sequential.
64
 
65
   -- Burst lengths.
66
   constant BL_2 : std_logic_vector(2 downto 0) := "001";
67
 
68
   -----------------------------------------------------------------------------
69
   -- Extended Mode Rgister                                                   --
70
   -----------------------------------------------------------------------------
71
   -- DLL.
72
   constant DLL_ENABLE  : std_logic := '0';
73
   constant DLL_DISABLE : std_logic := '1';
74
 
75
   -- Drive strength.
76
   constant DS_NORMAL  : std_logic := '0';
77
 
78
 
79
   -----------------------------------------------------------------------------
80
   -- Initialization                                                          --
81
   -----------------------------------------------------------------------------
82
   type init_state_t is (
83
      Wait20000,                          -- Wait for 200µs.
84
      CKE_High,                           -- Assert CKE.
85
      Precharge0, Precharge0Wait,         -- First precharge.
86
      ProgramEMR, ProgramEMRWait,         -- Set Extended Mode Register.
87
      ProgramMR, ProgramMRWait,           -- Set Base Mode Register.
88
      Precharge1, Precharge1Wait,         -- second precharge.
89
      AutoRefresh0, AutoRefresh0Wait,     -- First autorefresh.
90
      AutoRefresh1, AutoRefresh1Wait,     -- Second autorefresh.
91
      ProgramMR1, ProgramMR1Wait,         -- Set Base Mode Register.
92
      Wait200,                            -- Wait for 200 cycles.
93
      Done                                -- Initialization done!
94
   );
95
 
96
   type init_t is record
97
      s   : init_state_t;
98
      c   : natural range 0 to 19999;
99
   end record;
100
 
101
   constant init_d  : init_t := init_t'( Wait20000, 0);
102
   signal i, iin    : init_t := init_d;
103
begin
104
 
105
   -----------------------------------------------------------------------------
106
   -- Initialization                                                          --
107
   -----------------------------------------------------------------------------
108
   initial : process(i)
109
   begin
110
 
111
      iin       <= i;
112
      SD_CKE    <= '1';
113
      SD_BA     <= "00";
114
      SD_CMD    <= CMD_NOP;
115
      SD_A      <= (others => '0');
116
      init_done <= false;
117
 
118
      case i.s is
119
 
120
         -----------------------------------------------------------------------
121
         -- 5. Wait for 200µs.                                                --
122
         -----------------------------------------------------------------------
123
         when Wait20000 =>
124
            SD_CKE <= '0';
125
            if i.c = 19999 then
126
               iin.c <= 0;
127
               iin.s <= CKE_High;
128
            else
129
               iin.c <= i.c + 1;
130
            end if;
131
 
132
         -----------------------------------------------------------------------
133
         -- 6. Bring CKE high.                                                --
134
         -----------------------------------------------------------------------
135
         when CKE_High =>
136
            iin.s <= Precharge0;
137
 
138
         -----------------------------------------------------------------------
139
         -- 7. Precharge all banks.                                           --
140
         -----------------------------------------------------------------------
141
         when Precharge0 =>
142
            SD_CMD      <= CMD_PRECHARGE;
143
            SD_A(10) <= '1';               -- Precharge all operation.
144
            iin.s       <= Precharge0Wait;
145
 
146
         -- PRECHARGE command period tRP: 15ns
147
         when Precharge0Wait =>
148
            if i.c = 1 then
149
               iin.c <= 0;
150
               iin.s <= ProgramEMR;
151
            else
152
               iin.c <= i.c + 1;
153
            end if;
154
 
155
         -----------------------------------------------------------------------
156
         -- 9. Program the Extended Mode Register.                            --
157
         -----------------------------------------------------------------------
158
         when ProgramEMR =>
159
            SD_CMD  <= CMD_LMR;
160
            SD_BA   <= EMR_ADDR;              -- Select Extended Mode Register.
161
            SD_A    <= "00000000000" & DS_NORMAL & DLL_DISABLE;
162
            iin.s   <= ProgramEMRWait;
163
 
164
         -- LOAD MODE REGISTER command cycle time tMRD: 12ns
165
         when ProgramEMRWait =>
166
            if i.c = 1 then
167
               iin.c <= 0;
168
               iin.s <= ProgramMR;
169
            else
170
               iin.c <= i.c + 1;
171
            end if;
172
 
173
         -----------------------------------------------------------------------
174
         -- 11. Program the Mode Rgister                                      --
175
         -----------------------------------------------------------------------
176
         when ProgramMR =>
177
            SD_CMD  <= CMD_LMR;
178
            SD_BA   <= BMR_ADDR;              -- Select Base Mode Register.
179
            SD_A    <= OP_NORMAL & CAS_2 & BT_S & BL_2;
180
            iin.s   <= ProgramMRWait;
181
 
182
         -- LOAD MODE REGISTER command cycle time tMRD: 12ns
183
         when ProgramMRWait =>
184
            if i.c = 1 then
185
               iin.c <= 0;
186
               iin.s <= Precharge1;
187
            else
188
               iin.c <= i.c + 1;
189
            end if;
190
 
191
         -----------------------------------------------------------------------
192
         -- 13. Precharge all banks.                                          --
193
         -----------------------------------------------------------------------
194
         when Precharge1 =>
195
            SD_CMD   <= CMD_PRECHARGE;
196
            SD_A(10) <= '1';               -- Precharge all operation.
197
            iin.s    <= Precharge1Wait;
198
 
199
         -- PRECHARGE command period tRP: 15ns
200
         when Precharge1Wait =>
201
            if i.c = 1 then
202
               iin.c <= 0;
203
               iin.s <= AutoRefresh0;
204
            else
205
               iin.c <= i.c + 1;
206
            end if;
207
 
208
         -----------------------------------------------------------------------
209
         -- 15. Auto Refresh.                                                 --
210
         -----------------------------------------------------------------------
211
         when AutoRefresh0 =>
212
            SD_CMD <= CMD_AUTO_REFRESH;
213
            iin.s  <= AutoRefresh0Wait;
214
 
215
         -- AUTO REFRESH command period tRFC: 72ns
216
         when AutoRefresh0Wait =>
217
            if i.c = 7 then
218
               iin.c <= 0;
219
               iin.s <= AutoRefresh1;
220
            else
221
               iin.c <= i.c + 1;
222
            end if;
223
 
224
         -----------------------------------------------------------------------
225
         -- 17. Auto Refresh.                                                 --
226
         -----------------------------------------------------------------------
227
         when AutoRefresh1 =>
228
            SD_CMD <= CMD_AUTO_REFRESH;
229
            iin.s  <= AutoRefresh1Wait;
230
 
231
         -- AUTO REFRESH command period tRFC: 72ns
232
         when AutoRefresh1Wait =>
233
            if i.c = 7 then
234
               iin.c <= 0;
235
               iin.s <= ProgramMR1;
236
            else
237
               iin.c <= i.c + 1;
238
            end if;
239
 
240
         -----------------------------------------------------------------------
241
         -- 19. Program the Mode Rgister (Clear DLL Bit)                      --
242
         -----------------------------------------------------------------------
243
         when ProgramMR1 =>
244
            SD_CMD  <= CMD_LMR;
245
            SD_BA   <= BMR_ADDR;              -- Select Base Mode Register.
246
            SD_A    <= OP_NORMAL & CAS_2 & BT_S & BL_2;
247
            iin.s   <= ProgramMR1Wait;
248
 
249
         -- LOAD MODE REGISTER command cycle time tMRD: 12ns
250
         when ProgramMR1Wait =>
251
            if i.c = 1 then
252
               iin.c <= 0;
253
               iin.s <= Wait200;
254
            else
255
               iin.c <= i.c + 1;
256
            end if;
257
 
258
         -----------------------------------------------------------------------
259
         -- 21. Wait for 200 cycles.                                          --
260
         -----------------------------------------------------------------------
261
         when Wait200 =>
262
            if i.c = 199 then
263
               iin.c <= 0;
264
               iin.s <= Done;
265
            else
266
               iin.c <= i.c + 1;
267
            end if;
268
 
269
         -----------------------------------------------------------------------
270
         -- Initialization done.                                              --
271
         -----------------------------------------------------------------------
272
         when Done =>
273
            init_done <= true;
274
      end case;
275
   end process;
276
 
277
 
278
   -----------------------------------------------------------------------------
279
   -- Register                                                                --
280
   -----------------------------------------------------------------------------
281
   reg : process(clk0)
282
   begin
283
      if rising_edge(clk0) then
284
         if rst = '1' then i <= init_d; else i <= iin; end if;
285
      end if;
286
   end process;
287
end rtl;

powered by: WebSVN 2.1.0

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