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

Subversion Repositories avr_hp

[/] [avr_hp/] [trunk/] [bench/] [avr_test_cm2.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tobil
--------------------------------------------------------------
2
--      Simple testbench for AVR CM2 core running program_a.dec
3
--      and program_b.dec
4
--------------------------------------------------------------
5
LIBRARY IEEE;
6
USE IEEE.std_logic_1164.all;
7
USE IEEE.std_logic_arith.all;
8
USE IEEE.std_logic_textio.all;
9
USE std.textio.all;
10
USE WORK.all;
11
LIBRARY STD;
12
USE STD.TEXTIO.ALL;
13
 
14
entity avr_cm2_test is
15
end avr_cm2_test;
16
 
17
architecture behavioral of avr_cm2_test is
18
 
19
constant MAX_ROM_SIZE : positive := 256;
20
constant MAX_RAM_SIZE : positive := 65536;
21
file inFile_a : Text open read_mode is "program_a.dec";
22
file inFile_b : Text open read_mode is "program_b.dec";
23
 
24
signal system_clk       : std_logic;
25
signal system_reset : Std_logic;
26
signal cp2 : std_logic;
27
signal cp2_cml_1 : std_logic;
28
signal cml : integer range 0 to 1;
29
signal cml0_clk : std_logic;
30
signal cml1_clk : std_logic;
31
signal cml0_reset : std_logic;
32
signal cml1_reset : std_logic;
33
signal disable_second : std_logic;
34
 
35
signal core_pc_0   : std_logic_vector (15 downto 0);
36
signal core_pc_1   : std_logic_vector (15 downto 0);
37
signal core_ramadr_0 : std_logic_vector (15 downto 0);
38
signal core_ramadr_1 : std_logic_vector (15 downto 0);
39
signal core_ramre_0 : std_logic;
40
signal core_ramre_1 : std_logic;
41
signal core_ramwe_0 : std_logic;
42
signal core_ramwe_1 : std_logic;
43
 
44
signal gnd : std_logic;
45
signal vcc : std_logic;
46
signal core_pc : std_logic_vector (15 downto 0);
47
signal core_inst : std_logic_vector (15 downto 0);
48
signal core_adr : std_logic_vector (5 downto 0);
49
signal core_iore : std_logic;
50
signal core_iowe : std_logic;
51
signal core_ramadr : std_logic_vector (15 downto 0);
52
signal core_ramre : std_logic;
53
signal core_ramwe : std_logic;
54
signal core_cpuwait : std_logic;
55
signal core_dbusin : std_logic_vector (7 downto 0);
56
signal core_dbusout : std_logic_vector (7 downto 0);
57
signal core_irqlines : std_logic_vector(22 downto 0);
58
signal core_irqack : std_logic;
59
signal core_irqackad : std_logic_vector(4 downto 0);
60
signal sleepi : std_logic;
61
signal irqok : std_logic;
62
signal globint : std_logic;
63
signal core_wdri : std_logic;
64
 
65
component AVR_Core is port(
66
        --Clock and reset
67
                cp2 : in  std_logic;
68
                cp2en : in  std_logic;
69
                ireset : in  std_logic;
70
        -- JTAG OCD support
71
                valid_instr : out std_logic;
72
                insert_nop : in  std_logic;
73
                block_irq : in  std_logic;
74
                change_flow : out std_logic;
75
        -- Program Memory
76
                pc : out std_logic_vector(15 downto 0);
77
                inst : in  std_logic_vector(15 downto 0);
78
        -- I/O control
79
                adr : out std_logic_vector(5 downto 0);
80
                iore : out std_logic;
81
                iowe : out std_logic;
82
        -- Data memory control
83
                ramadr : out std_logic_vector(15 downto 0);
84
                ramre : out std_logic;
85
                ramwe : out std_logic;
86
                cpuwait : in  std_logic;
87
        -- Data paths
88
                dbusin : in  std_logic_vector(7 downto 0);
89
                dbusout : out std_logic_vector(7 downto 0);
90
        -- Interrupt
91
                irqlines : in  std_logic_vector(22 downto 0);
92
                irqack : out std_logic;
93
                irqackad : out std_logic_vector(4 downto 0);
94
        --Sleep Control
95
                sleepi : out std_logic;
96
                irqok   : out std_logic;
97
                globint : out std_logic;
98
        --Watchdog
99
                wdri : out std_logic);
100
end component;
101
 
102
component AVR_Core_cm2 is port(
103
                cp2_cml_1 : in std_logic;
104
        --Clock and reset
105
                cp2 : in  std_logic;
106
                cp2en : in  std_logic;
107
                ireset : in  std_logic;
108
        -- JTAG OCD support
109
                valid_instr : out std_logic;
110
                insert_nop : in  std_logic;
111
                block_irq : in  std_logic;
112
                change_flow : out std_logic;
113
        -- Program Memory
114
                pc : out std_logic_vector(15 downto 0);
115
                inst : in  std_logic_vector(15 downto 0);
116
        -- I/O control
117
                adr : out std_logic_vector(5 downto 0);
118
                iore : out std_logic;
119
                iowe : out std_logic;
120
        -- Data memory control
121
                ramadr : out std_logic_vector(15 downto 0);
122
                ramre : out std_logic;
123
                ramwe : out std_logic;
124
                cpuwait : in  std_logic;
125
        -- Data paths
126
                dbusin : in  std_logic_vector(7 downto 0);
127
                dbusout : out std_logic_vector(7 downto 0);
128
        -- Interrupt
129
                irqlines : in  std_logic_vector(22 downto 0);
130
                irqack : out std_logic;
131
                irqackad : out std_logic_vector(4 downto 0);
132
        --Sleep Control
133
                sleepi : out std_logic;
134
                irqok   : out std_logic;
135
                globint : out std_logic;
136
        --Watchdog
137
                wdri : out std_logic);
138
end component;
139
 
140
TYPE std_logic_array_rom IS ARRAY (INTEGER RANGE 0 to (2 * MAX_ROM_SIZE) - 1) of Std_logic_vector(15 downto 0);
141
SIGNAL rom_array :Std_logic_array_rom;
142
TYPE std_logic_array_ram IS ARRAY (INTEGER RANGE 0 to (2 * MAX_RAM_SIZE) - 1) of Std_logic_vector(7 downto 0);
143
SIGNAL ram_array :Std_logic_array_ram;
144
 
145
 
146
BEGIN
147
 
148
------------------------------------------------------------------------
149
--      CML indicates current pipe
150
--      clocks for AVR Core CM2
151
------------------------------------------------------------------------
152
cml_gen : process (system_clk)
153
begin
154
if (system_clk'event and system_clk = '1') then
155
        if (disable_second = '0') then
156
                cp2 <= system_clk;
157
                cp2_cml_1 <= system_clk;
158
        else
159
                if (cml = 1) then
160
                        cp2 <= system_clk;
161
                else
162
                        cp2_cml_1 <= system_clk;
163
                end if;
164
        end if;
165
        if (cml = 1) then
166
                cml <= 0;
167
        else
168
                cml <= 1;
169
        end if;
170
end if;
171
if (system_clk'event and system_clk = '0') then
172
        cp2 <= '0';
173
        cp2_cml_1 <= '0';
174
end if;
175
end process;
176
 
177
------------------------------------------------------------------------
178
--      stimuli
179
------------------------------------------------------------------------
180
 
181
vcc <= '1';
182
gnd <= '0';
183
core_cpuwait <= '0';
184
core_irqlines <= "00000000000000000000000";
185
 
186
------------------------------------------------------------------------
187
--      ROM
188
------------------------------------------------------------------------
189
rom_read_gen:PROCESS
190
variable thisInt : integer range 0 to 65535;
191
variable i: integer;
192
variable inLine: Line;
193
BEGIN
194
        readline(inFile_a, inLine);
195
        read(inLine, thisInt);
196
        for i in 0 to thisInt - 1 loop
197
                readline(inFile_a, inLine);
198
                read(inLine, thisInt);
199
                rom_array(i) <= conv_std_logic_vector(conv_unsigned(thisInt, 16), 16);
200
        end loop;
201
        readline(inFile_b, inLine);
202
        read(inLine, thisInt);
203
        for i in 0 to thisInt - 1 loop
204
                readline(inFile_b, inLine);
205
                read(inLine, thisInt);
206
                rom_array(MAX_ROM_SIZE + i) <= conv_std_logic_vector(conv_unsigned(thisInt, 16), 16);
207
        end loop;
208
      WAIT FOR 8000 ms;
209
end process;
210
 
211
core_inst_gen : PROCESS(core_pc, cml)
212
BEGIN
213
        if (cml = 0) then
214
                core_inst <=    rom_array(conv_integer(unsigned(core_pc)))(7 downto 0) &
215
                                        rom_array(conv_integer(unsigned(core_pc)))(15 downto 8);
216
        else
217
                core_inst <=    rom_array(MAX_ROM_SIZE + conv_integer(unsigned(core_pc)))(7 downto 0) &
218
                                        rom_array(MAX_ROM_SIZE + conv_integer(unsigned(core_pc)))(15 downto 8);
219
        end if;
220
end process;
221
 
222
------------------------------------------------------------------------
223
--      RAM
224
------------------------------------------------------------------------
225
ram_gen : PROCESS(system_clk, system_reset)
226
variable i: integer;
227
BEGIN
228
if (system_reset = '0') then
229
        if (disable_second = '0') then
230
                for i in 0 to (2 * MAX_RAM_SIZE) - 1 loop
231
                        ram_array(i) <= conv_std_logic_vector(0, 8);
232
                end loop;
233
        end if;
234
else
235
if (system_clk'event and system_clk = '1') then
236
        if (core_ramwe = '1') then
237
                if (cml = 0) then
238
                        ram_array(conv_integer(unsigned(core_ramadr))) <= core_dbusout;
239
                else
240
                        ram_array(MAX_RAM_SIZE + conv_integer(unsigned(core_ramadr))) <= core_dbusout;
241
                end if;
242
        end if;
243
end if;
244
end if;
245
end process;
246
 
247
core_dbusin <=  ram_array(conv_integer(unsigned(core_ramadr)))  when (cml = 0) else
248
                        ram_array(MAX_RAM_SIZE + conv_integer(unsigned(core_ramadr)));
249
 
250
------------------------------------------------------------------------
251
--      system_clk
252
------------------------------------------------------------------------
253
clk_gen:PROCESS
254
VARIABLE lin:line;
255
   BEGIN
256
      system_clk <= '1';
257
      WAIT FOR 12 ns;
258
      system_clk <= '0';
259
      WAIT FOR 12 ns;
260
   END PROCESS;
261
 
262
------------------------------------------------------------------------
263
--      system_reset and kill/restart second core
264
------------------------------------------------------------------------
265
reset_gen:PROCESS
266
   BEGIN
267
      system_reset <= '0';
268
        disable_second <= '0';
269
      WAIT FOR 110 ns;
270
      system_reset <= '1' ;
271
      WAIT FOR 100000 ns;
272
        WAIT UNTIL (cml = 0);
273
        disable_second <= '1';
274
      WAIT FOR 100000 ns;
275
        WAIT UNTIL (cml = 0);
276
        WAIT UNTIL (system_clk = '1');
277
      system_reset <= '0';
278
        WAIT UNTIL (system_clk = '0');
279
      WAIT FOR 2 ns;
280
      system_reset <= '1' ;
281
      WAIT FOR 2 ns;
282
        disable_second <= '0';
283
      WAIT FOR 100000 ns;
284
      ASSERT false REPORT "test passed, done" severity failure;
285
   END PROCESS;
286
 
287
------------------------------------------------------------------------
288
--      AVR_Core CM2
289
------------------------------------------------------------------------
290
AVR_Core_Inst_cm2:  AVR_Core_cm2 port map(
291
                cp2_cml_1 => cp2_cml_1,
292
        --Clock and reset
293
                cp2 => cp2,
294
                cp2en => vcc,
295
                ireset => cml1_reset,
296
        -- JTAG OCD support
297
                valid_instr => open,
298
                insert_nop => gnd,
299
                block_irq => gnd,
300
                change_flow => open,
301
        -- Program Memory
302
                pc => core_pc,
303
                inst => core_inst,
304
        -- I/O control
305
                adr => core_adr,
306
                iore => core_iore,
307
                iowe => core_iowe,
308
        -- Data memory control
309
                ramadr => core_ramadr,
310
                ramre => core_ramre,
311
                ramwe => core_ramwe,
312
                cpuwait => core_cpuwait,
313
        -- Data paths
314
                dbusin => core_dbusin,
315
                dbusout => core_dbusout,
316
        -- Interrupts
317
                irqlines => core_irqlines,
318
                irqack => core_irqack,
319
                irqackad => core_irqackad,
320
        --Sleep Control
321
                sleepi => sleepi,
322
                irqok   => irqok,
323
                globint => globint,
324
        --Watchdog
325
                wdri => core_wdri);
326
 
327
 
328
------------------------------------------------------------------------
329
------------------------------------------------------------------------
330
------------------------------------------------------------------------
331
--      Insertion of 2 additional AVR cores for virtual debugging
332
------------------------------------------------------------------------
333
------------------------------------------------------------------------
334
------------------------------------------------------------------------
335
--      generate individual clocks for AVR 0 and 1
336
------------------------------------------------------------------------
337
subckl_gen : process (system_clk)
338
begin
339
if (cml = 0) then
340
        cml0_clk <= system_clk;
341
        cml1_clk <= '0';
342
else
343
        cml0_clk <= '0';
344
        if (disable_second = '0') then
345
                cml1_clk <= system_clk;
346
        end if;
347
end if;
348
end process;
349
 
350
------------------------------------------------------------------------
351
--      generate individual resets for AVR 0 and 1
352
------------------------------------------------------------------------
353
system_reset_in_gen : PROCESS(system_clk, system_reset, disable_second)
354
BEGIN
355
if (disable_second = '0') then
356
        if (system_clk'event and system_clk = '0') then
357
                cml1_reset <= cml0_reset;
358
                cml0_reset <= system_reset;
359
        end if;
360
else
361
        cml1_reset <= system_reset;
362
end if;
363
end process;
364
 
365
------------------------------------------------------------------------
366
--      output comparison
367
------------------------------------------------------------------------
368
check_gen : PROCESS(system_clk, system_reset)
369
BEGIN
370
if (system_reset = '1') then
371
if (system_clk'event and system_clk = '0') then
372
        if (cml = 0) then
373
                if NOT (core_pc = core_pc_0) then
374
                        ASSERT false REPORT "PC 0 mismatch" severity failure;
375
                end if;
376
                if NOT (core_ramadr = core_ramadr_0) then
377
                        ASSERT false REPORT "RAMADR 0 mismatch" severity failure;
378
                end if;
379
                if NOT (core_ramre = core_ramre_0) then
380
                        ASSERT false REPORT "RAMRE 0 mismatch" severity failure;
381
                end if;
382
                if NOT (core_ramwe = core_ramwe_0) then
383
                        ASSERT false REPORT "RAMWE 0 mismatch" severity failure;
384
                end if;
385
        else
386
                if (disable_second = '0') then
387
                        if NOT (core_pc = core_pc_1) then
388
                                ASSERT false REPORT "PC 1 mismatch" severity failure;
389
                        end if;
390
                        if NOT (core_ramadr = core_ramadr_1) then
391
                                ASSERT false REPORT "RAMADR 1 mismatch" severity failure;
392
                        end if;
393
                        if NOT (core_ramre = core_ramre_1) then
394
                                ASSERT false REPORT "RAMRE 1 mismatch" severity failure;
395
                        end if;
396
                        if NOT (core_ramwe = core_ramwe_1) then
397
                                ASSERT false REPORT "RAMWE 1 mismatch" severity failure;
398
                        end if;
399
                end if;
400
        end if;
401
end if;
402
end if;
403
end process;
404
 
405
 
406
------------------------------------------------------------------------
407
--      AVR_Core virtual 0
408
------------------------------------------------------------------------
409
AVR_Core_Inst_0:  AVR_Core port map(
410
        --Clock and reset
411
                cp2 => cml0_clk,
412
                cp2en => vcc,
413
                ireset => cml0_reset,
414
        -- JTAG OCD support
415
                valid_instr => open,
416
                insert_nop => gnd,
417
                block_irq => gnd,
418
                change_flow => open,
419
        -- Program Memory
420
                pc => core_pc_0,
421
                inst => core_inst,
422
        -- I/O control
423
                adr => open,
424
                iore => open,
425
                iowe => open,
426
        -- Data memory control
427
                ramadr => core_ramadr_0,
428
                ramre => core_ramre_0,
429
                ramwe => core_ramwe_0,
430
                cpuwait => core_cpuwait,
431
        -- Data paths
432
                dbusin => core_dbusin,
433
                dbusout => open,
434
        -- Interrupts
435
                irqlines => core_irqlines,
436
                irqack => open,
437
                irqackad => open,
438
        --Sleep Control
439
                sleepi => open,
440
                irqok   => open,
441
                globint => open,
442
        --Watchdog
443
                wdri => open);
444
 
445
------------------------------------------------------------------------
446
--      AVR_Core virtual 1
447
------------------------------------------------------------------------
448
AVR_Core_Inst_1:  AVR_Core port map(
449
        --Clock and reset
450
                cp2 => cml1_clk,
451
                cp2en => vcc,
452
                ireset => cml1_reset,
453
        -- JTAG OCD support
454
                valid_instr => open,
455
                insert_nop => gnd,
456
                block_irq => gnd,
457
                change_flow => open,
458
        -- Program Memory
459
                pc => core_pc_1,
460
                inst => core_inst,
461
        -- I/O control
462
                adr => open,
463
                iore => open,
464
                iowe => open,
465
        -- Data memory control
466
                ramadr => core_ramadr_1,
467
                ramre => core_ramre_1,
468
                ramwe => core_ramwe_1,
469
                cpuwait => core_cpuwait,
470
        -- Data paths
471
                dbusin => core_dbusin,
472
                dbusout => open,
473
        -- Interrupts
474
                irqlines => core_irqlines,
475
                irqack => open,
476
                irqackad => open,
477
        --Sleep Control
478
                sleepi => open,
479
                irqok   => open,
480
                globint => open,
481
        --Watchdog
482
                wdri => open);
483
 
484
 
485
end behavioral;
486
 
487
 

powered by: WebSVN 2.1.0

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