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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [tb/] [vhdl/] [HostBFM.vhd] - Blame information for rev 25

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 mikel262
-------------------------------------------------------------------------------
2
-- File Name : HostBFM.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : HostBFM
7
--
8
-- Content   : Host BFM (Xilinx OPB v2.1)
9
--
10
-- Description : 
11
--
12
-- Spec.     : 
13
--
14
-- Author    : Michal Krepa
15
--
16
-------------------------------------------------------------------------------
17
-- History :
18
-- 20090301: (MK): Initial Creation.
19
-------------------------------------------------------------------------------
20
 
21
library ieee;
22
  use ieee.std_logic_1164.all;
23
  use ieee.numeric_std.all;
24
  use IEEE.STD_LOGIC_TEXTIO.ALL;
25
 
26
library STD;
27
  use STD.TEXTIO.ALL;
28
 
29
library work;
30
  use work.GPL_V2_Image_Pkg.ALL;
31
  use WORK.MDCT_PKG.all;
32
  use WORK.MDCTTB_PKG.all;
33
 
34
 
35
entity HostBFM is
36
  port
37
  (
38
        CLK                : in  std_logic;
39
        RST                : in  std_logic;
40
        -- OPB
41
        OPB_ABus           : out std_logic_vector(31 downto 0);
42
        OPB_BE             : out std_logic_vector(3 downto 0);
43
        OPB_DBus_in        : out std_logic_vector(31 downto 0);
44
        OPB_RNW            : out std_logic;
45
        OPB_select         : out std_logic;
46
        OPB_DBus_out       : in  std_logic_vector(31 downto 0);
47
        OPB_XferAck        : in  std_logic;
48
        OPB_retry          : in  std_logic;
49
        OPB_toutSup        : in  std_logic;
50
        OPB_errAck         : in  std_logic;
51
 
52
        -- HOST DATA
53
       iram_wdata          : out std_logic_vector(23 downto 0);
54
       iram_wren           : out std_logic;
55
       fifo_almost_full    : in  std_logic;
56
 
57
        sim_done           : out std_logic
58
    );
59
end entity HostBFM;
60
 
61
-------------------------------------------------------------------------------
62
-------------------------------------------------------------------------------
63
----------------------------------- ARCHITECTURE ------------------------------
64
-------------------------------------------------------------------------------
65
-------------------------------------------------------------------------------
66
architecture RTL of HostBFM is
67
 
68
  signal num_comps   : integer;
69
  signal addr_inc    : integer := 0;
70
-------------------------------------------------------------------------------
71
-- Architecture: begin
72
-------------------------------------------------------------------------------
73
begin
74
 
75
 
76
 
77
  -------------------------------------------------------------------
78
  -- code
79
  -------------------------------------------------------------------
80
  p_code : process
81
 
82
    -----------------------------------------------------------------
83
    -- HOST WRITE
84
    -----------------------------------------------------------------
85
    procedure host_write
86
      (
87
        signal clk         : in    std_logic;
88
        constant C_ADDR    : in    unsigned(31 downto 0);
89
        constant C_WDATA   : in    unsigned(31 downto 0);
90
 
91
        signal OPB_ABus    : out   std_logic_vector(31 downto 0);
92
        signal OPB_BE      : out   std_logic_vector(3 downto 0);
93
        signal OPB_DBus_in : out   std_logic_vector(31 downto 0);
94
        signal OPB_RNW     : out   std_logic;
95
        signal OPB_select  : out   std_logic;
96
        signal OPB_XferAck : in  std_logic
97
      ) is
98
    begin
99
      OPB_ABus    <= (others => '0');
100
      OPB_BE      <= (others => '0');
101
      OPB_DBus_in <= (others => '0');
102
      OPB_RNW     <= '0';
103
      OPB_select  <= '0';
104
 
105
      wait until rising_edge(clk);
106
 
107
      OPB_select  <= '1';
108
      OPB_ABus    <= std_logic_vector(C_ADDR);
109
      OPB_RNW     <= '0';
110
      OPB_BE      <= X"F";
111
      OPB_DBus_in <= std_logic_vector(C_WDATA);
112
 
113
      wait until rising_edge(clk);
114
 
115
      while OPB_XferAck /= '1' loop
116
        wait until rising_edge(clk);
117
      end loop;
118
 
119
      OPB_ABus    <= (others => '0');
120
      OPB_BE      <= (others => '0');
121
      OPB_DBus_in <= (others => '0');
122
      OPB_RNW     <= '0';
123
      OPB_select  <= '0';
124
 
125
      assert false
126
      report CR&"Host write access, address = " & HexImage(C_ADDR) & ",data written = " & HexImage(C_WDATA) &CR
127
      severity note;
128
 
129
      wait until rising_edge(clk);
130
 
131
    end procedure host_write;
132
 
133
    -----------------------------------------------------------------
134
    -- HOST READ
135
    -----------------------------------------------------------------
136
    procedure host_read
137
      (
138
        signal clk          : in    std_logic;
139
        constant C_ADDR     : in    unsigned(31 downto 0);
140
        variable RDATA      : out   unsigned(31 downto 0);
141
 
142
        signal OPB_ABus     : out   std_logic_vector(31 downto 0);
143
        signal OPB_BE       : out   std_logic_vector(3 downto 0);
144
        signal OPB_DBus_out : in    std_logic_vector(31 downto 0);
145
        signal OPB_RNW      : out   std_logic;
146
        signal OPB_select   : out   std_logic;
147
        signal OPB_XferAck  : in  std_logic
148
      )
149
    is
150
      variable data_r : std_logic_vector(31 downto 0);
151
    begin
152
      OPB_ABus    <= (others => '0');
153
      OPB_BE      <= (others => '0');
154
      OPB_DBus_in <= (others => '0');
155
      OPB_RNW     <= '0';
156
      OPB_select  <= '0';
157
 
158
      wait until rising_edge(clk);
159
 
160
      OPB_select  <= '1';
161
      OPB_ABus    <= std_logic_vector(C_ADDR);
162
      OPB_RNW     <= '1';
163
      OPB_BE      <= X"F";
164
 
165
      wait until rising_edge(clk);
166
 
167
      while OPB_XferAck /= '1' loop
168
        wait until rising_edge(clk);
169
      end loop;
170
 
171
      RDATA := unsigned(OPB_DBus_out);
172
      data_r := OPB_DBus_out;
173
 
174
      OPB_ABus    <= (others => '0');
175
      OPB_BE      <= (others => '0');
176
      OPB_DBus_in <= (others => '0');
177
      OPB_RNW     <= '0';
178
      OPB_select  <= '0';
179
 
180
      assert false
181
      report CR&"Host read access, address = " & HexImage(C_ADDR) & ",data read = " & HexImage(data_r) &CR
182
      severity note;
183
 
184
 
185
      wait until rising_edge(clk);
186
 
187
    end procedure host_read;
188
 
189
 
190
    --------------------------------------
191
    -- read text image data
192
    --------------------------------------
193
    procedure read_image is
194
      file infile          : TEXT open read_mode is "test.txt";
195
      constant N           : integer := 8;
196
      constant MAX_COMPS   : integer := 3;
197
      variable inline      : LINE;
198
      variable tmp_int     : INTEGER := 0;
199
      variable y_size      : INTEGER := 0;
200
      variable x_size      : INTEGER := 0;
201
      variable matrix      : I_MATRIX_TYPE;
202
      variable x_blk_cnt   : INTEGER := 0;
203
      variable y_blk_cnt   : INTEGER := 0;
204
      variable n_lines_arr : N_LINES_TYPE;
205
      variable line_n      : INTEGER := 0;
206
      variable pix_n       : INTEGER := 0;
207
      variable x_n         : INTEGER := 0;
208
      variable y_n         : INTEGER := 0;
209
      variable data_word   : unsigned(31 downto 0);
210
      variable image_line  : STD_LOGIC_VECTOR(0 to MAX_COMPS*MAX_IMAGE_SIZE_X*IP_W-1);
211
 
212
      constant C_IMAGE_RAM_BASE : unsigned(31 downto 0) := X"0010_0000";
213
 
214
      variable x_cnt       : integer;
215
      variable data_word2  : unsigned(31 downto 0);
216
      variable num_comps_v : integer;
217
    begin
218
      READLINE(infile,inline);
219
      READ(inline,num_comps_v);
220
      READLINE(infile,inline);
221
      READ(inline,y_size);
222
      READLINE(infile,inline);
223
      READ(inline,x_size);
224
 
225
      num_comps <= num_comps_v;
226
 
227
      if y_size rem N > 0 then
228
        assert false
229
          report "E03: Image height dimension is not multiply of 8!"
230
          severity Failure;
231
      end if;
232
      if x_size rem N > 0 then
233
        assert false
234
          report "E03: Image width dimension is not multiply of 8!"
235
          severity Failure;
236
      end if;
237
 
238
      addr_inc <= 0;
239
 
240
      -- image size
241
      host_write(CLK, X"0000_0004", to_unsigned(x_size,16) & to_unsigned(y_size,16),
242
               OPB_ABus, OPB_BE, OPB_DBus_in, OPB_RNW, OPB_select, OPB_XferAck);
243
 
244
      iram_wren <= '0';
245
      for y_n in 0 to y_size-1 loop
246
        READLINE(infile,inline);
247
        HREAD(inline,image_line(0 to num_comps*x_size*IP_W-1));
248
        x_cnt := 0;
249
        for x_n in 0 to x_size-1 loop
250
          data_word := X"00" & UNSIGNED(image_line(x_cnt to x_cnt+num_comps*IP_W-1));
251
          data_word2(7 downto 0)   := data_word(23 downto 16);
252
          data_word2(15 downto 8)  := data_word(15 downto 8);
253
          data_word2(23 downto 16) := data_word(7 downto 0);
254
 
255
          iram_wren  <= '0';
256
          iram_wdata <= (others => 'X');
257
          while(fifo_almost_full = '1') loop
258
            wait until rising_edge(clk);
259
          end loop;
260
 
261
          --for i in 0 to 20 loop
262
          --  wait until rising_edge(clk);
263
          --end loop;
264
 
265
          --iram_addr <= std_logic_vector(to_unsigned(addr_inc,20));
266
          iram_wren <= '1';
267
          iram_wdata <= std_logic_vector(data_word2(23 downto 0));
268
          wait until rising_edge(clk);
269
 
270
          x_cnt := x_cnt + num_comps*IP_W;
271
 
272
          addr_inc <= addr_inc + 1;
273
        end loop;
274
      end loop;
275
      iram_wren <= '0';
276
 
277
    end read_image;
278
 
279
    ------------------
280
    type ROMQ_TYPE is array (0 to 64-1)
281
            of unsigned(7 downto 0);
282
 
283
  constant qrom : ROMQ_TYPE :=
284
  (
285
  -- 100%
286
  --others => X"01"
287
 
288
  -- 85%
289
  --X"05", X"03", X"04", X"04", 
290
  --X"04", X"03", X"05", X"04", 
291
  --X"04", X"04", X"05", X"05", 
292
  --X"05", X"06", X"07", X"0C",
293
  --X"08", X"07", X"07", X"07", 
294
  --X"07", X"0F", X"0B", X"0B", 
295
  --X"09", X"0C", X"11", X"0F", 
296
  --X"12", X"12", X"11", X"0F",
297
  --X"11", X"11", X"13", X"16", 
298
  --X"1C", X"17", X"13", X"14", 
299
  --X"1A", X"15", X"11", X"11", 
300
  --X"18", X"21", X"18", X"1A",
301
  --X"1D", X"1D", X"1F", X"1F", 
302
  --X"1F", X"13", X"17", X"22", 
303
  --X"24", X"22", X"1E", X"24", 
304
  --X"1C", X"1E", X"1F", X"1E"
305
 
306
  -- 75%
307
   --X"08", X"06", X"06", X"07", X"06", X"05", X"08", X"07", X"07", X"07", X"09", X"09", X"08", X"0A", X"0C", X"14",
308
   --X"0D", X"0C", X"0B", X"0B", X"0C", X"19", X"12", X"13", X"0F", X"14", X"1D", X"1A", X"1F", X"1E", X"1D", X"1A",
309
   --X"1C", X"1C", X"20", X"24", X"2E", X"27", X"20", X"22", X"2C", X"23", X"1C", X"1C", X"28", X"37", X"29", X"2C",
310
   --X"30", X"31", X"34", X"34", X"34", X"1F", X"27", X"39", X"3D", X"38", X"32", X"3C", X"2E", X"33", X"34", X"32"
311
 
312
   -- 15 %
313
   --X"35", X"25", X"28", X"2F", 
314
   --X"28", X"21", X"35", X"2F", 
315
   --X"2B", X"2F", X"3C", X"39", 
316
   --X"35", X"3F", X"50", X"85", 
317
   --X"57", X"50", X"49", X"49", 
318
   --X"50", X"A3", X"75", X"7B", 
319
   --X"61", X"85", X"C1", X"AA", 
320
   --X"CB", X"C8", X"BE", X"AA", 
321
   --X"BA", X"B7", X"D5", X"F0", 
322
   --X"FF", X"FF", X"D5", X"E2", 
323
   --X"FF", X"E6", X"B7", X"BA", 
324
   --X"FF", X"FF", X"FF", X"FF", 
325
   --X"FF", X"FF", X"FF", X"FF", 
326
   --X"FF", X"CE", X"FF", X"FF", 
327
   --X"FF", X"FF", X"FF", X"FF", 
328
   --X"FF", X"FF", X"FF", X"FF"                                              
329
 
330
   -- 50%
331
   X"10", X"0B", X"0C", X"0E", X"0C", X"0A", X"10", X"0E",
332
   X"0D", X"0E", X"12", X"11", X"10", X"13", X"18", X"28",
333
   X"1A", X"18", X"16", X"16", X"18", X"31", X"23", X"25",
334
   X"1D", X"28", X"3A", X"33", X"3D", X"3C", X"39", X"33",
335
   X"38", X"37", X"40", X"48", X"5C", X"4E", X"40", X"44",
336
   X"57", X"45", X"37", X"38", X"50", X"6D", X"51", X"57",
337
   X"5F", X"62", X"67", X"68", X"67", X"3E", X"4D", X"71",
338
   X"79", X"70", X"64", X"78", X"5C", X"65", X"67", X"63"
339
  );
340
 
341
    variable data_read  : unsigned(31 downto 0);
342
    variable data_write : unsigned(31 downto 0);
343
    variable addr       : unsigned(31 downto 0);
344
 
345
 
346
  ------------------------------------------------------------------------------
347
  -- BEGIN
348
  ------------------------------------------------------------------------------
349
  begin
350
    sim_done <= '0';
351
    iram_wren <= '0';
352
 
353
    while RST /= '0' loop
354
      wait until rising_edge(clk);
355
    end loop;
356
 
357
    for i in 0 to 100 loop
358
      wait until rising_edge(clk);
359
    end loop;
360
 
361
 
362
 
363
    host_read(CLK, X"0000_0000", data_read,
364
               OPB_ABus, OPB_BE, OPB_DBus_out, OPB_RNW, OPB_select, OPB_XferAck);
365
 
366
 
367
    host_read(CLK, X"0000_0004", data_read,
368
               OPB_ABus, OPB_BE, OPB_DBus_out, OPB_RNW, OPB_select, OPB_XferAck);
369
 
370
    -- write quantization table
371
    for i in 0 to 64-1 loop
372
      data_write := X"0000_00" & qrom(i);
373
      addr := X"0000_0100" + to_unsigned(4*i,32);
374
      -- SOF & num_comps
375
      host_write(CLK, addr, data_write,
376
               OPB_ABus, OPB_BE, OPB_DBus_in, OPB_RNW, OPB_select, OPB_XferAck);
377
 
378
    end loop;
379
 
380
 
381
 
382
    data_write := to_unsigned(1,32) + shift_left(to_unsigned(3,32),1);
383
 
384
    -- SOF & num_comps
385
    host_write(CLK, X"0000_0000", data_write,
386
               OPB_ABus, OPB_BE, OPB_DBus_in, OPB_RNW, OPB_select, OPB_XferAck);
387
 
388
    -- write BUF_FIFO with bitmap
389
    read_image;
390
 
391
    -- wait until JPEG encoding is done
392
    host_read(CLK, X"0000_000C", data_read,
393
               OPB_ABus, OPB_BE, OPB_DBus_out, OPB_RNW, OPB_select, OPB_XferAck);
394
    while data_read /= 2 loop
395
     host_read(CLK, X"0000_000C", data_read,
396
               OPB_ABus, OPB_BE, OPB_DBus_out, OPB_RNW, OPB_select, OPB_XferAck);
397
    end loop;
398
 
399
    sim_done <= '1';
400
 
401
    wait;
402
 
403
  end process;
404
 
405
 
406
end architecture RTL;
407
-------------------------------------------------------------------------------
408
-- Architecture: end
409
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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