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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [mdct/] [DCT1D.vhd] - Blame information for rev 71

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 67 mikel262
--------------------------------------------------------------------------------
2
--                                                                            --
3
--                          V H D L    F I L E                                --
4
--                          COPYRIGHT (C) 2006                                --
5
--                                                                            --
6
--------------------------------------------------------------------------------
7
--
8
-- Title       : DCT1D
9
-- Design      : MDCT Core
10
-- Author      : Michal Krepa
11
--
12
--------------------------------------------------------------------------------
13
--
14
-- File        : DCT1D.VHD
15
-- Created     : Sat Mar 5 7:37 2006
16
--
17
--------------------------------------------------------------------------------
18
--
19
--  Description : 1D Discrete Cosine Transform (1st stage)
20
--
21
--------------------------------------------------------------------------------
22
 
23
 
24
library IEEE;
25
  use IEEE.STD_LOGIC_1164.all;
26
  use IEEE.NUMERIC_STD.all;
27
 
28
library WORK;
29
  use WORK.MDCT_PKG.all;
30
 
31
--------------------------------------------------------------------------------
32
-- ENTITY
33
--------------------------------------------------------------------------------
34
entity DCT1D is
35
        port(
36
                  clk          : in STD_LOGIC;
37
                  rst          : in std_logic;
38
      dcti         : in std_logic_vector(IP_W-1 downto 0);
39
      idv          : in STD_LOGIC;
40
      romedatao    : in T_ROM1DATAO;
41
      romodatao    : in T_ROM1DATAO;
42
 
43
      odv          : out STD_LOGIC;
44
      dcto         : out std_logic_vector(OP_W-1 downto 0);
45
      romeaddro    : out T_ROM1ADDRO;
46
      romoaddro    : out T_ROM1ADDRO;
47
      ramwaddro    : out STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
48
      ramdatai     : out STD_LOGIC_VECTOR(RAMDATA_W-1 downto 0);
49
      ramwe        : out STD_LOGIC;
50
      wmemsel      : out STD_LOGIC
51
                );
52
end DCT1D;
53
 
54
--------------------------------------------------------------------------------
55
-- ARCHITECTURE
56
--------------------------------------------------------------------------------
57
architecture RTL of DCT1D is
58
 
59
  type INPUT_DATA is array (N-1 downto 0) of SIGNED(IP_W downto 0);
60
 
61
  signal databuf_reg     : INPUT_DATA;
62
  signal latchbuf_reg    : INPUT_DATA;
63
  signal col_reg         : UNSIGNED(RAMADRR_W/2-1 downto 0);
64
  signal row_reg         : UNSIGNED(RAMADRR_W/2-1 downto 0);
65
  signal rowr_reg        : UNSIGNED(RAMADRR_W/2-1 downto 0);
66
  signal inpcnt_reg      : UNSIGNED(RAMADRR_W/2-1 downto 0);
67
  signal ramwe_s         : STD_LOGIC;
68
  signal wmemsel_reg     : STD_LOGIC;
69
  signal stage2_reg      : STD_LOGIC;
70
  signal stage2_cnt_reg  : UNSIGNED(RAMADRR_W-1 downto 0);
71
  signal col_2_reg       : UNSIGNED(RAMADRR_W/2-1 downto 0);
72
  signal ramwaddro_s     : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
73
 
74
  signal even_not_odd    : std_logic;
75
  signal even_not_odd_d1 : std_logic;
76
  signal even_not_odd_d2 : std_logic;
77
  signal even_not_odd_d3 : std_logic;
78
  signal ramwe_d1        : STD_LOGIC;
79
  signal ramwe_d2        : STD_LOGIC;
80
  signal ramwe_d3        : STD_LOGIC;
81
  signal ramwe_d4        : STD_LOGIC;
82 71 mikel262
  signal ramwe_d5        : STD_LOGIC;
83
  signal ramwe_d6        : STD_LOGIC;
84 67 mikel262
  signal ramwaddro_d1    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
85
  signal ramwaddro_d2    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
86
  signal ramwaddro_d3    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
87
  signal ramwaddro_d4    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
88
  signal ramwaddro_d5    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
89
  signal ramwaddro_d6    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
90
  signal wmemsel_d1      : STD_LOGIC;
91
  signal wmemsel_d2      : STD_LOGIC;
92
  signal wmemsel_d3      : STD_LOGIC;
93
  signal wmemsel_d4      : STD_LOGIC;
94
  signal wmemsel_d5      : STD_LOGIC;
95
  signal wmemsel_d6      : STD_LOGIC;
96 71 mikel262
  signal wmemsel_d7      : STD_LOGIC;
97 67 mikel262
  signal romedatao_d1    : T_ROM1DATAO;
98
  signal romodatao_d1    : T_ROM1DATAO;
99
  signal romedatao_d2    : T_ROM1DATAO;
100
  signal romodatao_d2    : T_ROM1DATAO;
101
  signal romedatao_d3    : T_ROM1DATAO;
102
  signal romodatao_d3    : T_ROM1DATAO;
103
  signal dcto_1          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
104
  signal dcto_2          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
105
  signal dcto_3          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
106
  signal dcto_4          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
107
 
108
  signal fpr_out         : STD_LOGIC_VECTOR(DA_W-12-1 downto 0);
109
 
110
  component FinitePrecRndNrst is
111
  generic
112
  (
113
    C_IN_SZ   : natural := 37;
114
    C_OUT_SZ  : natural := 16;
115
    C_FRAC_SZ : natural := 15
116
  );
117
  port (
118
    CLK     : in std_logic;
119
    RST     : in std_logic;
120
    datain  : in STD_LOGIC_VECTOR(C_IN_SZ-1 downto 0);
121
    dataval : in std_logic;
122
    dataout : out STD_LOGIC_VECTOR(C_OUT_SZ-1 downto 0);
123
 
124
    clip_inc : out std_logic;
125
    dval_out : out std_logic
126
  );
127
end component;
128
 
129
begin
130
 
131
  ramwaddro <= ramwaddro_d6;
132 71 mikel262
  wmemsel   <= wmemsel_d6; --wmemsel_d4;
133 67 mikel262
 
134 71 mikel262
  odv <= ramwe_d6;
135 67 mikel262
  dcto <= STD_LOGIC_VECTOR(RESIZE(SIGNED(fpr_out),12));
136
 
137
  ramdatai <= fpr_out;
138
 
139
  U_FinitePrecRndNrst : FinitePrecRndNrst
140
  generic map(
141
    C_IN_SZ  => DA_W,
142
    C_OUT_SZ => DA_W-12,
143
    C_FRAC_SZ => 12
144
  )
145
  port map(
146
    CLK         => clk,
147
    RST         => rst,
148
 
149
    datain      => dcto_4,
150
    dataval     => ramwe_d4,
151
    dataout     => fpr_out,
152
 
153
    clip_inc    => open,
154
    dval_out    => ramwe
155
  );
156
 
157
  process(clk,rst)
158
  begin
159
    if rst = '1' then
160
      inpcnt_reg      <= (others => '0');
161
      latchbuf_reg    <= (others => (others => '0'));
162
      databuf_reg     <= (others => (others => '0'));
163
      stage2_reg      <= '0';
164
      stage2_cnt_reg  <= (others => '1');
165
      ramwe_s         <= '0';
166
      ramwaddro_s     <= (others => '0');
167
      col_reg         <= (others => '0');
168
      row_reg         <= (others => '0');
169
      wmemsel_reg     <= '0';
170
      col_2_reg       <= (others => '0');
171
    elsif clk = '1' and clk'event then
172
      stage2_reg     <= '0';
173
      ramwe_s        <= '0';
174
 
175
      --------------------------------
176
      -- 1st stage
177
      --------------------------------
178
      if idv = '1' then
179
 
180
        inpcnt_reg    <= inpcnt_reg + 1;
181
 
182
        -- right shift input data
183
        latchbuf_reg(N-2 downto 0) <= latchbuf_reg(N-1 downto 1);
184
        latchbuf_reg(N-1)          <= SIGNED('0' & dcti) - LEVEL_SHIFT;
185
 
186
        if inpcnt_reg = N-1 then
187
          -- after this sum databuf_reg is in range of -256 to 254 (min to max) 
188
          databuf_reg(0)  <= latchbuf_reg(1)+(SIGNED('0' & dcti) - LEVEL_SHIFT);
189
          databuf_reg(1)  <= latchbuf_reg(2)+latchbuf_reg(7);
190
          databuf_reg(2)  <= latchbuf_reg(3)+latchbuf_reg(6);
191
          databuf_reg(3)  <= latchbuf_reg(4)+latchbuf_reg(5);
192
          databuf_reg(4)  <= latchbuf_reg(1)-(SIGNED('0' & dcti) - LEVEL_SHIFT);
193
          databuf_reg(5)  <= latchbuf_reg(2)-latchbuf_reg(7);
194
          databuf_reg(6)  <= latchbuf_reg(3)-latchbuf_reg(6);
195
          databuf_reg(7)  <= latchbuf_reg(4)-latchbuf_reg(5);
196
          stage2_reg      <= '1';
197
        end if;
198
      end if;
199
      --------------------------------
200
 
201
      --------------------------------
202
      -- 2nd stage
203
      --------------------------------
204
      if stage2_cnt_reg < N then
205
 
206
        stage2_cnt_reg <= stage2_cnt_reg + 1;
207
 
208
        -- write RAM
209
        ramwe_s   <= '1';
210
        -- reverse col/row order for transposition purpose
211
        ramwaddro_s <= STD_LOGIC_VECTOR(col_2_reg & row_reg);
212
        -- increment column counter
213
        col_reg   <= col_reg + 1;
214
        col_2_reg <= col_2_reg + 1;
215
 
216
        -- finished processing one input row
217
        if col_reg = 0 then
218
          row_reg         <= row_reg + 1;
219
          -- switch to 2nd memory
220
          if row_reg = N - 1 then
221
            wmemsel_reg <= not wmemsel_reg;
222
            col_reg         <= (others => '0');
223
          end if;
224
        end if;
225
 
226
      end if;
227
 
228
      if stage2_reg = '1' then
229
        stage2_cnt_reg <= (others => '0');
230
        col_reg        <= (0=>'1',others => '0');
231
        col_2_reg      <= (others => '0');
232
      end if;
233
      ----------------------------------   
234
 
235
 
236
    end if;
237
  end process;
238
 
239
  -- output data pipeline
240
  p_data_out_pipe : process(CLK, RST)
241
  begin
242
    if RST = '1' then
243
      even_not_odd    <= '0';
244
      even_not_odd_d1 <= '0';
245
      even_not_odd_d2 <= '0';
246
      even_not_odd_d3 <= '0';
247
      ramwe_d1        <= '0';
248
      ramwe_d2        <= '0';
249
      ramwe_d3        <= '0';
250
      ramwe_d4        <= '0';
251 71 mikel262
      ramwe_d5        <= '0';
252
      ramwe_d6        <= '0';
253 67 mikel262
      ramwaddro_d1    <= (others => '0');
254
      ramwaddro_d2    <= (others => '0');
255
      ramwaddro_d3    <= (others => '0');
256
      ramwaddro_d4    <= (others => '0');
257 71 mikel262
      ramwaddro_d5    <= (others => '0');
258
      ramwaddro_d6    <= (others => '0');
259 67 mikel262
      wmemsel_d1      <= '0';
260
      wmemsel_d2      <= '0';
261
      wmemsel_d3      <= '0';
262
      wmemsel_d4      <= '0';
263 71 mikel262
      wmemsel_d5      <= '0';
264
      wmemsel_d6      <= '0';
265
      wmemsel_d7      <= '0';
266 67 mikel262
      dcto_1          <= (others => '0');
267
      dcto_2          <= (others => '0');
268
      dcto_3          <= (others => '0');
269
      dcto_4          <= (others => '0');
270
    elsif CLK'event and CLK = '1' then
271
      even_not_odd    <= stage2_cnt_reg(0);
272
      even_not_odd_d1 <= even_not_odd;
273
      even_not_odd_d2 <= even_not_odd_d1;
274
      even_not_odd_d3 <= even_not_odd_d2;
275
      ramwe_d1        <= ramwe_s;
276
      ramwe_d2        <= ramwe_d1;
277
      ramwe_d3        <= ramwe_d2;
278
      ramwe_d4        <= ramwe_d3;
279 71 mikel262
      ramwe_d5        <= ramwe_d4;
280
      ramwe_d6        <= ramwe_d5;
281 67 mikel262
      ramwaddro_d1    <= ramwaddro_s;
282
      ramwaddro_d2    <= ramwaddro_d1;
283
      ramwaddro_d3    <= ramwaddro_d2;
284
      ramwaddro_d4    <= ramwaddro_d3;
285
      ramwaddro_d5    <= ramwaddro_d4;
286
      ramwaddro_d6    <= ramwaddro_d5;
287
      wmemsel_d1      <= wmemsel_reg;
288
      wmemsel_d2      <= wmemsel_d1;
289
      wmemsel_d3      <= wmemsel_d2;
290
      wmemsel_d4      <= wmemsel_d3;
291
      wmemsel_d5      <= wmemsel_d4;
292
      wmemsel_d6      <= wmemsel_d5;
293 71 mikel262
      wmemsel_d7      <= wmemsel_d6;
294 67 mikel262
 
295
      if even_not_odd = '0' then
296
        dcto_1 <= STD_LOGIC_VECTOR(RESIZE
297
          (RESIZE(SIGNED(romedatao(0)),DA_W) +
298
          (RESIZE(SIGNED(romedatao(1)),DA_W-1) & '0') +
299
          (RESIZE(SIGNED(romedatao(2)),DA_W-2) & "00"),
300
          DA_W));
301
      else
302
        dcto_1 <= STD_LOGIC_VECTOR(RESIZE
303
          (RESIZE(SIGNED(romodatao(0)),DA_W) +
304
          (RESIZE(SIGNED(romodatao(1)),DA_W-1) & '0') +
305
          (RESIZE(SIGNED(romodatao(2)),DA_W-2) & "00"),
306
          DA_W));
307
      end if;
308
 
309
      if even_not_odd_d1 = '0' then
310
        dcto_2 <= STD_LOGIC_VECTOR(RESIZE
311
          (signed(dcto_1) +
312
          (RESIZE(SIGNED(romedatao_d1(3)),DA_W-3) & "000") +
313
          (RESIZE(SIGNED(romedatao_d1(4)),DA_W-4) & "0000"),
314
          DA_W));
315
      else
316
        dcto_2 <= STD_LOGIC_VECTOR(RESIZE
317
          (signed(dcto_1) +
318
          (RESIZE(SIGNED(romodatao_d1(3)),DA_W-3) & "000") +
319
          (RESIZE(SIGNED(romodatao_d1(4)),DA_W-4) & "0000"),
320
          DA_W));
321
      end if;
322
 
323
      if even_not_odd_d2 = '0' then
324
        dcto_3 <= STD_LOGIC_VECTOR(RESIZE
325
          (signed(dcto_2) +
326
          (RESIZE(SIGNED(romedatao_d2(5)),DA_W-5) & "00000") +
327
          (RESIZE(SIGNED(romedatao_d2(6)),DA_W-6) & "000000"),
328
          DA_W));
329
      else
330
        dcto_3 <= STD_LOGIC_VECTOR(RESIZE
331
          (signed(dcto_2) +
332
          (RESIZE(SIGNED(romodatao_d2(5)),DA_W-5) & "00000") +
333
          (RESIZE(SIGNED(romodatao_d2(6)),DA_W-6) & "000000"),
334
          DA_W));
335
      end if;
336
 
337
      if even_not_odd_d3 = '0' then
338
        dcto_4 <= STD_LOGIC_VECTOR(RESIZE
339
          (signed(dcto_3) +
340
          (RESIZE(SIGNED(romedatao_d3(7)),DA_W-7) & "0000000") -
341
          (RESIZE(SIGNED(romedatao_d3(8)),DA_W-8) & "00000000"),
342
          DA_W));
343
      else
344
        dcto_4 <= STD_LOGIC_VECTOR(RESIZE
345
          (signed(dcto_3) +
346
          (RESIZE(SIGNED(romodatao_d3(7)),DA_W-7) & "0000000") -
347
          (RESIZE(SIGNED(romodatao_d3(8)),DA_W-8) & "00000000"),
348
          DA_W));
349
      end if;
350
    end if;
351
  end process;
352
 
353
  -- read precomputed MAC results from LUT
354
  p_romaddr : process(CLK, RST)
355
  begin
356
    if RST = '1' then
357
      romeaddro   <= (others => (others => '0'));
358
      romoaddro   <= (others => (others => '0'));
359
    elsif CLK'event and CLK = '1' then
360
      for i in 0 to 8 loop
361
        -- even
362
        romeaddro(i) <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
363
                 databuf_reg(0)(i) &
364
                 databuf_reg(1)(i) &
365
                 databuf_reg(2)(i) &
366
                 databuf_reg(3)(i);
367
        -- odd
368
        romoaddro(i) <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
369
                 databuf_reg(4)(i) &
370
                 databuf_reg(5)(i) &
371
                 databuf_reg(6)(i) &
372
                 databuf_reg(7)(i);
373
      end loop;
374
    end if;
375
  end process;
376
 
377
  p_romdatao_d1 : process(CLK, RST)
378
  begin
379
    if RST = '1' then
380
      romedatao_d1    <= (others => (others => '0'));
381
      romodatao_d1    <= (others => (others => '0'));
382
      romedatao_d2    <= (others => (others => '0'));
383
      romodatao_d2    <= (others => (others => '0'));
384
      romedatao_d3    <= (others => (others => '0'));
385
      romodatao_d3    <= (others => (others => '0'));
386
    elsif CLK'event and CLK = '1' then
387
      romedatao_d1   <= romedatao;
388
      romodatao_d1   <= romodatao;
389
      romedatao_d2   <= romedatao_d1;
390
      romodatao_d2   <= romodatao_d1;
391
      romedatao_d3   <= romedatao_d2;
392
      romodatao_d3   <= romodatao_d2;
393
    end if;
394
  end process;
395
 
396
end RTL;
397
--------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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