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

Subversion Repositories layer2

[/] [layer2/] [trunk/] [vhdl/] [ddr/] [bench/] [tb_ddr.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
--------------------------------------------------------------------------------
2
-- Mycron® DDR2 SDRAM - MT46V32M16 – 8 Meg x 16 x 4 banks                     --
3
--------------------------------------------------------------------------------
4
-- Copyright (C)2011  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
library UNISIM;
24
use UNISIM.vcomponents.all;
25
--
26
--library work;
27
--use work.iwb.all;
28
--use work.iddr.all;
29
 
30
entity tb_ddr is
31
end tb_ddr;
32
 
33
architecture tb of tb_ddr is
34
 
35
   component ddr is
36
     port (
37
       so_ack : out STD_LOGIC;
38
       si_clk : in STD_LOGIC := 'X';
39
       SD_CK_N : out STD_LOGIC;
40
       SD_CK_P : out STD_LOGIC;
41
       si_rst : in STD_LOGIC := 'X';
42
       si_stb : in STD_LOGIC := 'X';
43
       clk0 : in STD_LOGIC := 'X';
44
       clk180 : in STD_LOGIC := 'X';
45
       SD_CKE : out STD_LOGIC;
46
       si_we : in STD_LOGIC := 'X';
47
       clk90 : in STD_LOGIC := 'X';
48
       clk270 : in STD_LOGIC := 'X';
49
       SD_DQ : inout STD_LOGIC_VECTOR ( 15 downto 0 );
50
       SD_DQS : inout STD_LOGIC_VECTOR ( 1 downto 0 );
51
       SD_BA : out STD_LOGIC_VECTOR ( 1 downto 0 );
52
       SD_DM : out STD_LOGIC_VECTOR ( 1 downto 0 );
53
       SD_A : out STD_LOGIC_VECTOR ( 12 downto 0 );
54
       so_dat : out STD_LOGIC_VECTOR ( 31 downto 0 );
55
       SD_CMD : out STD_LOGIC_VECTOR ( 3 downto 0 );
56
       si_dat : in STD_LOGIC_VECTOR ( 31 downto 0 );
57
       si_sel : in STD_LOGIC_VECTOR ( 3 downto 0 );
58
       si_adr : in STD_LOGIC_VECTOR ( 31 downto 0 )
59
     );
60
   end component;
61
 
62
   component model_ddr
63
      port(
64
         Clk   : in    std_logic;
65
         Clk_n : in    std_logic;
66
         Cke   : in    std_logic;
67
         Cs_n  : in    std_logic;
68
         Ras_n : in    std_logic;
69
         Cas_n : in    std_logic;
70
         We_n  : in    std_logic;
71
         Ba    : in    std_logic_vector(1 downto 0);
72
         Addr  : in    std_logic_vector(12 downto 0);
73
         Dm    : in    std_logic_vector(1 downto 0);
74
         Dq    : inout std_logic_vector(15 downto 0);
75
         Dqs   : inout std_logic_vector(1 downto 0)
76
      );
77
   end component;
78
 
79
   signal so_dat : STD_LOGIC_VECTOR ( 31 downto 0 );
80
   signal so_ack : STD_LOGIC;
81
   signal si_clk : STD_LOGIC;
82
   signal si_rst : STD_LOGIC;
83
   signal si_stb : STD_LOGIC;
84
   signal si_we  : STD_LOGIC;
85
   signal si_dat : STD_LOGIC_VECTOR ( 31 downto 0 );
86
   signal si_sel : STD_LOGIC_VECTOR ( 3 downto 0 );
87
   signal si_adr : STD_LOGIC_VECTOR ( 31 downto 0 );
88
 
89
   signal SD_CK_N  : std_logic;
90
   signal SD_CK_P  : std_logic;
91
   signal SD_CKE   : std_logic;
92
   signal SD_BA    : std_logic_vector(1 downto 0);
93
   signal SD_A     : std_logic_vector(12 downto 0);
94
   signal SD_CMD   : std_logic_vector(3 downto 0);
95
   signal SD_DM    : std_logic_vector(1 downto 0);
96
   signal SD_DQS   : std_logic_vector(1 downto 0);
97
   signal SD_DQ    : std_logic_vector(15 downto 0);
98
 
99
   --constant clk_period : time := 7.5 ns; 
100
    constant clk_period : time := 25.0 ns;
101
 
102
    signal clk0   : std_logic;
103
    signal clk90  : std_logic;
104
    signal clk180 : std_logic;
105
    signal clk270 : std_logic;
106
begin
107
 
108
   clk000 : process
109
   begin
110
      clk0 <= '0';
111
      clk90 <= '0';
112
      wait for clk_period / 4;
113
      clk0 <= '1';
114
      clk90 <= '0';
115
      wait for clk_period / 4;
116
      clk0 <= '1';
117
      clk90 <= '1';
118
      wait for clk_period / 4;
119
      clk0 <= '0';
120
      clk90 <= '1';
121
      wait for clk_period / 4;
122
   end process;
123
 
124
   clk180 <= not clk0;
125
   clk270 <= not clk90;
126
 
127
--   uut : ddr
128
--      port map(
129
--         si       => si,
130
--         so       => so,
131
--         clk0     => clk0,
132
--         clk90    => clk90,
133
--         clk180   => clk180,
134
--         clk270   => clk270,
135
--      -- Non Wishbone Signals
136
--         SD_CK_N  => SD_CK_N,
137
--         SD_CK_P  => SD_CK_P,
138
--         SD_CKE   => SD_CKE,
139
--         SD_BA    => SD_BA,
140
--         SD_A     => SD_A,      
141
--         SD_CMD   => SD_CMD,
142
--         SD_DM    => SD_DM,
143
--         SD_DQS   => SD_DQS,
144
--         SD_DQ    => SD_DQ
145
--      );
146
 
147
 
148
 
149
uut : ddr
150
   port map(
151
      so_ack  => so_ack,
152
      si_clk  => si_clk,
153
      SD_CK_N => SD_CK_N,
154
      SD_CK_P => SD_CK_P,
155
      si_rst  => si_rst,
156
      si_stb  => si_stb,
157
      clk0    => clk0,
158
      clk180  => clk180,
159
      SD_CKE  => SD_CKE,
160
      si_we   => si_we,
161
      clk90   => clk90,
162
      clk270  => clk270,
163
      SD_DQ   => SD_DQ,
164
      SD_DQS  => SD_DQS,
165
      SD_BA   => SD_BA,
166
      SD_DM   => SD_DM,
167
      SD_A    => SD_A,
168
      so_dat  => so_dat,
169
      SD_CMD  => SD_CMD,
170
      si_dat  => si_dat,
171
      si_sel  => si_sel,
172
      si_adr  => si_adr
173
   );
174
 
175
 
176
   model : model_ddr
177
      port map(
178
         Clk   => SD_CK_P,
179
         Clk_n => SD_CK_N,
180
         Cke   => SD_CKE,
181
         Cs_n  => SD_CMD(3),
182
         Ras_n => SD_CMD(2),
183
         Cas_n => SD_CMD(1),
184
         We_n  => SD_CMD(0),
185
         Ba    => SD_BA,
186
         Addr  => SD_A,
187
         Dm    => SD_DM,
188
         Dq    => SD_DQ,
189
         Dqs   => SD_DQS
190
      );
191
 
192
   sti : process
193
   begin
194
         si_rst <= '1';
195
      wait for 3*clk_period;
196
         si_rst <= '0';
197
 
198
   -----------------------------------------------------------------------------
199
   -- Same Bank, Same Rows                                                    --
200
   -----------------------------------------------------------------------------         
201
      -- Write 0x12xx5678 to 0x00000000  
202
      -- Row 0, Col 0,1      
203
         si_adr <= x"00000000";
204
         si_dat <= x"12345678";
205
         si_sel <= "1011";
206
         si_stb <= '1';
207
         si_we  <= '1';
208
      wait until so_ack = '1';
209
         si_stb <= '0';
210
         si_we  <= '0';
211
      wait until so_ack = '0';
212
 
213
      -- Write 0x8765xx21 to 0x00000004
214
      -- Row 0, Col 2,3 
215
         si_adr <= x"00000004";
216
         si_dat <= x"87654321";
217
         si_sel <= "1101";
218
         si_stb <= '1';
219
         si_we  <= '1';
220
      wait until so_ack = '1';
221
         si_stb <= '0';
222
         si_we  <= '0';
223
      wait until so_ack = '0';
224
 
225
      -- Read 0x8765xx21 from 0x00000004
226
         si_adr <= x"00000004";
227
         si_sel <= "1111";
228
         si_stb <= '1';
229
         si_we  <= '0';
230
      wait until so_ack = '1';
231
         si_stb <= '0';
232
         si_we  <= '0';
233
      wait until so_ack = '0';
234
 
235
      -- Read 0x12xx5678 from 0x00000000
236
         si_adr <= x"00000000";
237
         si_sel <= "1111";
238
         si_stb <= '1';
239
         si_we  <= '0';
240
      wait until so_ack = '1';
241
         si_stb <= '0';
242
         si_we  <= '0';
243
      wait until so_ack = '0';
244
 
245
 
246
   -----------------------------------------------------------------------------
247
   -- Same Bank, different Rows                                               --
248
   -----------------------------------------------------------------------------  
249
      -- Write 0x12xxxx78 to 0x00001000 
250
      -- Row 2, Col 0,1
251
          si_adr <= x"00001000";
252
          si_dat <= x"12345678";
253
          si_sel <= "1001";
254
          si_stb <= '1';
255
          si_we  <= '1';
256
       wait until so_ack = '1';
257
          si_stb <= '0';
258
          si_we  <= '0';
259
       wait until so_ack = '0';
260
 
261
      -- Write 0xxx6543xx to 0x00002004
262
      -- Row 4, Col 2,3
263
          si_adr <= x"00002004";
264
          si_dat <= x"87654321";
265
          si_sel <= "0110";
266
          si_stb <= '1';
267
          si_we  <= '1';
268
       wait until so_ack = '1';
269
          si_stb <= '0';
270
          si_we  <= '0';
271
       wait until so_ack = '0';
272
 
273
      -- Read 0x12xx5678 from 0x00001000
274
      -- Row 2, Col 0,1
275
          si_adr <= x"00001000";
276
          si_sel <= "1111";
277
          si_stb <= '1';
278
          si_we  <= '0';
279
       wait until so_ack = '1';
280
          si_stb <= '0';
281
          si_we  <= '0';
282
 
283
      -- Read 0x8765xx21 from 0x00002004
284
      -- Row 4, Col 2,3
285
          si_adr <= x"00002004";
286
          si_sel <= "1111";
287
          si_stb <= '1';
288
          si_we  <= '0';
289
       wait until so_ack = '1';
290
          si_stb <= '0';
291
          si_we  <= '0';
292
       wait until so_ack = '0';
293
 
294
 
295
   -----------------------------------------------------------------------------
296
   -- Different Banks, different Rows                                         --
297
   -----------------------------------------------------------------------------  
298
      -- Write 0x12xxxx78 to 0x00001000 
299
      -- Bank 1, Row 2, Col 0,1
300
          si_adr <= x"01001000";
301
          si_dat <= x"12345678";
302
          si_sel <= "1001";
303
          si_stb <= '1';
304
          si_we  <= '1';
305
       wait until so_ack = '1';
306
          si_stb <= '0';
307
          si_we  <= '0';
308
       wait until so_ack = '0';
309
 
310
      -- Write 0xxx6543xx to 0x00002004
311
      -- Bank 2, Row 4, Col 2,3
312
          si_adr <= x"02002004";
313
          si_dat <= x"87654321";
314
          si_sel <= "0110";
315
          si_stb <= '1';
316
          si_we  <= '1';
317
       wait until so_ack = '1';
318
          si_stb <= '0';
319
          si_we  <= '0';
320
       wait until so_ack = '0';
321
 
322
      -- Read 0x12xx5678 from 0x00001000
323
      -- Bank 1, Row 2, Col 0,1
324
          si_adr <= x"01001000";
325
          si_sel <= "1111";
326
          si_stb <= '1';
327
          si_we  <= '0';
328
       wait until so_ack = '1';
329
          si_stb <= '0';
330
          si_we  <= '0';
331
       wait until so_ack = '0';
332
 
333
      -- Read 0x8765xx21 from 0x00002004
334
      -- Bank 2, Row 4, Col 2,3
335
          si_adr <= x"02002004";
336
          si_sel <= "1111";
337
          si_stb <= '1';
338
          si_we  <= '0';
339
       wait until so_ack = '1';
340
          si_stb <= '0';
341
          si_we  <= '0';
342
       wait until so_ack = '0';
343
 
344
      wait;                            -- Important: no wait, no simulation.
345
   end process;
346
end tb;

powered by: WebSVN 2.1.0

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