OSDN Git Service

works
[fpga-leon-mjpeg/leon-mjpeg.git] / grlib-gpl-1.0.22-b4095 / designs / work_ip / sim_huffdctycc.vhd
1 ------------------------------------------------------------------------------
2 --  Copyright (C) 2010, Kenichi Kurimoto
3 --
4 --  This program is free software; you can redistribute it and/or modify
5 --  it under the terms of the GNU General Public License as published by
6 --  the Free Software Foundation; either version 2 of the License, or
7 --  (at your option) any later version.
8 --
9 --  This program is distributed in the hope that it will be useful,
10 --  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 --  GNU General Public License for more details.
13 --
14 --  You should have received a copy of the GNU General Public License
15 --  along with this program; if not, write to the Free Software
16 --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
17 -----------------------------------------------------------------------------
18
19
20
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use std.textio.all;
24 use ieee.std_logic_textio.all;
25 --use ieee.numeric_std.all;
26
27
28 library gaisler;
29 use gaisler.sim.all;
30 use gaisler.ambatest.all;
31 use gaisler.ahbtbp.all;
32 library techmap;
33 use techmap.gencomp.all;
34 library grlib;
35 use grlib.stdlib.all;
36 library kuri;
37 use kuri.mjpeg.all;
38
39 use work.debug.all;
40 use work.config.all;
41
42
43
44 entity sim_huffdctycc is
45   
46   generic (
47     clkperiod : integer := 20);
48
49 end ;
50
51 architecture behav of sim_huffdctycc is
52
53
54
55   component bus_huffdctycc
56     port(
57       rstn : in std_ulogic;
58       clk : in std_ulogic;
59       ctrl_in1 : in ahbtbm_ctrl_in_type;
60       ctrl_out1 : out ahbtbm_ctrl_out_type
61       );
62     
63   end component;
64
65 signal clk : std_ulogic := '0';
66 signal rst : std_ulogic := '0';
67 signal ctrl1 : ahbtb_ctrl_type;
68 -- signal data_in : std_logic_vector(31 downto 0);
69
70 file in_file : text open read_mode is "in_huff.txt";
71 file in_quantfile : text open read_mode is "in_qtbl.txt";
72 file compare_file : text open read_mode is "out_upycc.txt";
73 file in_acfile : text open read_mode is "in_accache.txt";
74 file in_dcfile : text open read_mode is "in_dccache.txt";
75 file in_maxcfile : text open read_mode is "in_maxcode.txt";
76 file in_offsfile : text open read_mode is "in_valoffs.txt";
77 file in_huffvfile : text open read_mode is "in_huffval.txt";
78
79 begin  -- behav
80
81     b0 : bus_huffdctycc
82     port map (rst,clk,ctrl1.i,ctrl1.o);
83    
84     tictak : process
85     begin
86         clk <= '0';
87         wait for 10 ns;
88         clk <= '1';
89         wait for 10 ns;
90     end process;
91     
92     stim: process
93        variable li : line;
94        variable lc : line;
95        variable i,j : integer;
96  --      variable dctindata : std_logic_vector(11 downto 0);
97        variable indata : std_logic_vector(31 downto 0);
98        variable radd : std_logic_vector(31 downto 0);
99   --     variable cdata1, cdata2 : std_logic_vector(15 downto 0);
100        variable cdata32 : std_logic_vector(31 downto 0);
101        variable quantvec : std_logic_vector(7 downto 0);
102        variable wadd : std_logic_vector(31 downto 0);
103
104     begin
105
106       report " stimulus process start ";      
107       rst  <= '0';   
108       wait for 100 ns;
109       rst <= '1';
110
111     -- initialize
112       ahbtbminit(ctrl1);
113
114 -- Write Control registers through APB bus
115
116 ahbwrite(x"80000200", x"a0000000", "10", "10", '1', 2, false , ctrl1);
117 --ahbwrite(x"80000204", x"00082464", "10", "10", '1', 2, false , ctrl1);
118 ahbwrite(x"80000204", x"005c9a84", "10", "10", '1', 2, false , ctrl1);
119 ahbwrite(x"80000208", x"04E4B504", "10", "10", '1', 2, false , ctrl1);
120 ahbwrite(x"8000020C", x"00000000", "10", "10", '1', 2, false , ctrl1);
121 ahbwrite(x"8000020C", x"f0000000", "10", "10", '1', 2, false , ctrl1);
122
123      ahbtbmidle(true, ctrl1);
124      wait for 100 ns;
125      wadd := x"9000c000";
126      for i in 0 to 191 loop
127          readline(in_quantfile, li);
128          hread(li, quantvec);
129          ahbwrite(wadd, x"000000" & quantvec, "10", "10", '1', 2, false, ctrl1);
130          wadd := wadd + x"00000004";
131      end loop;
132      ahbtbmidle(true, ctrl1);
133
134
135       for i in 0 to 1023 loop
136           readline(in_acfile, li);
137           hread(li, wadd);
138           hread(li, cdata32);    
139           wadd := wadd(29 downto 0) & "00";
140           wadd := wadd  +"100000000000000";
141           wadd := wadd + x"90000000";
142           ahbwrite(wadd, cdata32, "10", "10", '1', 2, false , ctrl1);
143       end loop;
144       for i in 0 to 1023 loop
145           readline(in_dcfile, li);
146           hread(li, wadd);
147           wadd := wadd(29 downto 0) & "00";
148           wadd := wadd  + "1000000000000000";
149           wadd := wadd + x"90000000";
150           hread(li, cdata32);
151           ahbwrite(wadd, cdata32, "10", "10", '1', 2, false , ctrl1);
152       end loop;          
153       for i in 0 to 71 loop
154           readline(in_maxcfile,li);
155           hread(li,wadd);
156           wadd := wadd(29 downto 0) & "00";
157           wadd := x"90000400" + wadd ;
158           hread(li, cdata32);
159           ahbwrite(wadd, cdata32, "10", "10", '1', 2, false , ctrl1);
160       end loop;
161       for i in 0 to 71 loop
162           readline(in_offsfile,li);
163           hread(li,wadd);
164           wadd := wadd(29 downto 0) & "00";
165           wadd := x"90000800" + wadd ;
166           hread(li, cdata32);
167           ahbwrite(wadd, cdata32, "10", "10", '1', 2, false , ctrl1);
168       end loop;      
169       for i in 0 to 1023 loop
170           readline(in_huffvfile,li);
171           hread(li,wadd);
172           wadd := wadd(29 downto 0) & "00";
173           wadd := x"90002000" + wadd ;
174           hread(li, cdata32);
175           ahbwrite(wadd, cdata32, "10", "10", '1', 2, false , ctrl1);
176       end loop;
177       
178     ahbtbmidle(true,ctrl1);
179     wait for 100 ns;   
180
181
182 -- Write scan data for IP core
183 --      for i in 0 to 2718 loop
184       for i in 0 to 120 loop
185         readline(in_file,li);
186         hread(li, cdata32);
187         ahbwrite(x"90000000", cdata32, "10", "10", '1', 2, false , ctrl1);                   
188         ahbtbmidle(true, ctrl1);
189         wait for 40000 ns;
190       end loop;
191
192 ahbtbmidle(true,ctrl1);
193 wait for 100000 ns;   
194
195
196       radd := x"a0000000";  
197 --      for i in 0 to 79 loop
198       for i in 0 to 16 loop
199 --        for j in 0 to 39 loop
200         for j in 0 to 160 loop
201           readline(compare_file, lc);
202           hread(lc, cdata32);
203           ahbread(radd, cdata32, "10", 2, false, ctrl1);
204           radd := radd + x"004";
205         end loop;
206 --        radd := radd + x"460";
207         radd := radd + x"280";
208       end loop;
209
210       ahbtbmidle(true,ctrl1);
211       wait for 100 ns; 
212
213       ahbtbmdone(0, ctrl1);
214       wait for 300 ns;
215
216       report "stimulus process end" severity failure;
217       wait;
218    end process;
219
220 end behav;